mirror of
https://github.com/keven1024/015.git
synced 2026-05-26 07:08:02 +00:00
refactor(front): update FileUpload and Navbar components for improved code clarity and consistency
This commit is contained in:
@@ -1,41 +1,37 @@
|
||||
<script setup lang="ts">
|
||||
import { cx } from "class-variance-authority";
|
||||
import { cx } from 'class-variance-authority'
|
||||
|
||||
const { availableLocales, setLocale, locale: currentLocale, t } = useI18n();
|
||||
const route = useRoute();
|
||||
const props = defineProps<{
|
||||
hide: () => void
|
||||
}>()
|
||||
|
||||
const { availableLocales, setLocale, locale: currentLocale, t } = useI18n()
|
||||
|
||||
const localeMap = {
|
||||
"zh-CN": "简体中文",
|
||||
en: "English",
|
||||
// 'ja': '日本語',
|
||||
// 'ko': '한국어',
|
||||
// 'fr': 'Français',
|
||||
// 'de': 'Deutsch',
|
||||
};
|
||||
'zh-CN': '简体中文',
|
||||
en: 'English',
|
||||
// 'ja': '日本語',
|
||||
// 'ko': '한국어',
|
||||
// 'fr': 'Français',
|
||||
// 'de': 'Deutsch',
|
||||
}
|
||||
|
||||
const switchLocale = async (locale: string) => {
|
||||
await setLocale(locale as keyof typeof localeMap);
|
||||
navigateTo(route.path, {
|
||||
external: true,
|
||||
});
|
||||
};
|
||||
await setLocale(locale as keyof typeof localeMap)
|
||||
props.hide()
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col gap-1 py-2">
|
||||
<div class="text-xl font-bold mb-3">{{ t("i18n.switchLocale") }}</div>
|
||||
<div
|
||||
v-for="locale in availableLocales"
|
||||
:key="locale"
|
||||
:class="
|
||||
cx(
|
||||
'rounded-md hover:bg-black/10 p-2 cursor-pointer',
|
||||
currentLocale === locale && 'bg-black/10 font-bold',
|
||||
)
|
||||
"
|
||||
@click="() => switchLocale(locale)"
|
||||
>
|
||||
{{ localeMap?.[locale as keyof typeof localeMap] }}
|
||||
<div class="flex flex-col gap-1 py-2">
|
||||
<div class="text-xl font-bold mb-3">{{ t('i18n.switchLocale') }}</div>
|
||||
<div
|
||||
v-for="locale in availableLocales"
|
||||
:key="locale"
|
||||
:class="cx('rounded-md hover:bg-black/10 p-2 cursor-pointer', currentLocale === locale && 'bg-black/10 font-bold')"
|
||||
@click="() => switchLocale(locale)"
|
||||
>
|
||||
{{ localeMap?.[locale as keyof typeof localeMap] }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -59,7 +59,7 @@ onChange((files) => {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div ref="dropZoneRef" @click="open">
|
||||
<div ref="dropZoneRef" @click="() => open()">
|
||||
<slot :isOverDropZone="isOverDropZone" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -1,90 +1,81 @@
|
||||
<template>
|
||||
<div
|
||||
class="flex flex-row bg-white/50 backdrop-blur-xl p-2 rounded-full gap-1 sticky top-0 z-10"
|
||||
>
|
||||
<div
|
||||
v-for="item in routes"
|
||||
:key="item.key"
|
||||
:class="
|
||||
cx(
|
||||
'flex flex-row items-center text-sm px-4 py-2 font-bold rounded-full relative select-none cursor-pointer',
|
||||
!isActive(item) && 'hover:bg-black/5',
|
||||
item?.name && 'gap-2',
|
||||
item?.className,
|
||||
)
|
||||
"
|
||||
@click="handleClick(item)"
|
||||
>
|
||||
<motion.div
|
||||
v-if="isActive(item)"
|
||||
layoutId="navbar-active"
|
||||
class="absolute inset-0 rounded-full w-full h-full bg-black/10"
|
||||
/>
|
||||
<component :is="item.icon" />
|
||||
<div class="hidden sm:block">{{ item.name }}</div>
|
||||
<div class="flex flex-row bg-white/50 backdrop-blur-xl p-2 rounded-full gap-1 sticky top-0 z-10">
|
||||
<div
|
||||
v-for="item in routes"
|
||||
:key="item.key"
|
||||
:class="
|
||||
cx(
|
||||
'flex flex-row items-center text-sm px-4 py-2 font-bold rounded-full relative select-none cursor-pointer',
|
||||
!isActive(item) && 'hover:bg-black/5',
|
||||
item?.name && 'gap-2',
|
||||
item?.className
|
||||
)
|
||||
"
|
||||
@click="handleClick(item)"
|
||||
>
|
||||
<motion.div v-if="isActive(item)" layoutId="navbar-active" class="absolute inset-0 rounded-full w-full h-full bg-black/10" />
|
||||
<component :is="item.icon" />
|
||||
<div class="hidden sm:block">{{ item.name }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { cx } from "class-variance-authority";
|
||||
import { LucideClipboardType, LucidePaperclip } from "#components";
|
||||
import { motion } from "motion-v";
|
||||
import { LucideGlobe } from "lucide-vue-next";
|
||||
import showDrawer from "@/lib/showDrawer";
|
||||
import I18nSwitchDrawer from "./Drawer/I18nSwitchDrawer.vue";
|
||||
const { t } = useI18n();
|
||||
const routes = [
|
||||
{
|
||||
key: "about",
|
||||
icon: () =>
|
||||
h("img", {
|
||||
class: "size-10 rounded-full border-2 border-white/50",
|
||||
src: "/logo.png",
|
||||
}),
|
||||
onClick: () => {
|
||||
router.push("/about");
|
||||
import { cx } from 'class-variance-authority'
|
||||
import { LucideClipboardType, LucidePaperclip } from '#components'
|
||||
import { motion } from 'motion-v'
|
||||
import { LucideGlobe } from 'lucide-vue-next'
|
||||
import showDrawer from '@/lib/showDrawer'
|
||||
import I18nSwitchDrawer from './Drawer/I18nSwitchDrawer.vue'
|
||||
const { t } = useI18n()
|
||||
const routes = computed(() => [
|
||||
{
|
||||
key: 'about',
|
||||
icon: () =>
|
||||
h('img', {
|
||||
class: 'size-10 rounded-full border-2 border-white/50',
|
||||
src: '/logo.png',
|
||||
}),
|
||||
onClick: () => {
|
||||
router.push('/about')
|
||||
},
|
||||
isActive: (item: { key: string }) => route.path?.endsWith(item.key),
|
||||
className: '!p-1.5',
|
||||
},
|
||||
isActive: (item: { key: string }) => route.path?.endsWith(item.key),
|
||||
className: "!p-1.5",
|
||||
},
|
||||
{ name: t("navbar.file"), key: "file", icon: LucidePaperclip },
|
||||
{ name: t("navbar.text"), key: "text", icon: LucideClipboardType },
|
||||
{
|
||||
key: "i18n",
|
||||
icon: LucideGlobe,
|
||||
onClick: () => {
|
||||
showDrawer({
|
||||
render: () => h(I18nSwitchDrawer),
|
||||
});
|
||||
{ name: t('navbar.file'), key: 'file', icon: LucidePaperclip },
|
||||
{ name: t('navbar.text'), key: 'text', icon: LucideClipboardType },
|
||||
{
|
||||
key: 'i18n',
|
||||
icon: LucideGlobe,
|
||||
onClick: () => {
|
||||
showDrawer({
|
||||
render: (props) => h(I18nSwitchDrawer, { ...props }),
|
||||
})
|
||||
},
|
||||
className: 'size-12 !p-1.5 justify-center items-center',
|
||||
},
|
||||
className: "size-12 !p-1.5 justify-center items-center",
|
||||
},
|
||||
];
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const type = computed(() => route?.query?.type);
|
||||
])
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const type = computed(() => route?.query?.type)
|
||||
|
||||
const isActive = (item: {
|
||||
key: string;
|
||||
isActive?: (item: { key: string }) => boolean;
|
||||
}) => {
|
||||
const { key, isActive } = item || {};
|
||||
return isActive ? isActive(item) : type.value === key;
|
||||
};
|
||||
const isActive = (item: { key: string; isActive?: (item: { key: string }) => boolean }) => {
|
||||
const { key, isActive } = item || {}
|
||||
return isActive ? isActive(item) : type.value === key
|
||||
}
|
||||
|
||||
const handleClick = (item: { key: string; onClick?: () => void }) => {
|
||||
const { key, onClick } = item || {};
|
||||
if (onClick) {
|
||||
onClick();
|
||||
return;
|
||||
}
|
||||
router.push({
|
||||
path: "/",
|
||||
query: {
|
||||
...route.query,
|
||||
type: key,
|
||||
},
|
||||
});
|
||||
};
|
||||
const { key, onClick } = item || {}
|
||||
if (onClick) {
|
||||
onClick()
|
||||
return
|
||||
}
|
||||
router.push({
|
||||
path: '/',
|
||||
query: {
|
||||
...route.query,
|
||||
type: key,
|
||||
},
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user