120 lines
4.6 KiB
Vue
120 lines
4.6 KiB
Vue
<script setup lang="ts">
|
|
const session = useSessionStore();
|
|
const { locale, locales, setLocale } = useI18n();
|
|
const route = useRoute();
|
|
const { boot } = useAccent();
|
|
|
|
const isAuthPage = computed(() => route.path === "/login");
|
|
|
|
boot();
|
|
onMounted(() => session.hydrate());
|
|
watchEffect(() => {
|
|
if (import.meta.client && session.token === null && !isAuthPage.value && route.path !== "/") {
|
|
// pages opt into auth middleware; nothing global here
|
|
}
|
|
});
|
|
</script>
|
|
|
|
<template>
|
|
<div v-if="isAuthPage">
|
|
<NuxtPage />
|
|
</div>
|
|
<div v-else class="bg-bg text-text min-h-screen font-sans">
|
|
<div class="flex min-h-screen">
|
|
<aside class="border-border bg-surface w-60 shrink-0 border-r px-4 py-5">
|
|
<div class="text-text mb-6 px-3 text-lg font-bold">{{ $t("common.appName") }} · Shop</div>
|
|
<nav class="grid gap-1" :aria-label="$t('common.appName')">
|
|
<NuxtLink
|
|
to="/"
|
|
exact-active-class="bg-primary-soft text-primary"
|
|
class="text-muted hover:bg-bg rounded-md px-3 py-2 text-sm font-medium"
|
|
>{{ $t("nav.dashboard") }}</NuxtLink
|
|
>
|
|
<NuxtLink
|
|
to="/products"
|
|
active-class="bg-primary-soft text-primary"
|
|
class="text-muted hover:bg-bg rounded-md px-3 py-2 text-sm font-medium"
|
|
>{{ $t("nav.products") }}</NuxtLink
|
|
>
|
|
<NuxtLink
|
|
to="/shop-profile"
|
|
active-class="bg-primary-soft text-primary"
|
|
class="text-muted hover:bg-bg rounded-md px-3 py-2 text-sm font-medium"
|
|
>{{ $t("nav.shopProfile") }}</NuxtLink
|
|
>
|
|
<NuxtLink
|
|
to="/orders"
|
|
active-class="bg-primary-soft text-primary"
|
|
class="text-muted hover:bg-bg rounded-md px-3 py-2 text-sm font-medium"
|
|
>{{ $t("nav.orders") }}</NuxtLink
|
|
>
|
|
<NuxtLink
|
|
to="/aftersales"
|
|
active-class="bg-primary-soft text-primary"
|
|
class="text-muted hover:bg-bg rounded-md px-3 py-2 text-sm font-medium"
|
|
>{{ $t("nav.aftersales") }}</NuxtLink
|
|
>
|
|
<NuxtLink
|
|
to="/shipments"
|
|
active-class="bg-primary-soft text-primary"
|
|
class="text-muted hover:bg-bg rounded-md px-3 py-2 text-sm font-medium"
|
|
>{{ $t("nav.shipments") }}</NuxtLink
|
|
>
|
|
<NuxtLink
|
|
to="/invoices"
|
|
active-class="bg-primary-soft text-primary"
|
|
class="text-muted hover:bg-bg rounded-md px-3 py-2 text-sm font-medium"
|
|
>{{ $t("nav.invoices") }}</NuxtLink
|
|
>
|
|
<NuxtLink
|
|
to="/coupons"
|
|
active-class="bg-primary-soft text-primary"
|
|
class="text-muted hover:bg-bg rounded-md px-3 py-2 text-sm font-medium"
|
|
>{{ $t("nav.coupons") }}</NuxtLink
|
|
>
|
|
<NuxtLink
|
|
to="/flash-sales"
|
|
active-class="bg-primary-soft text-primary"
|
|
class="text-muted hover:bg-bg rounded-md px-3 py-2 text-sm font-medium"
|
|
>{{ $t("nav.flashSales") }}</NuxtLink
|
|
>
|
|
<NuxtLink
|
|
to="/group-buying"
|
|
active-class="bg-primary-soft text-primary"
|
|
class="text-muted hover:bg-bg rounded-md px-3 py-2 text-sm font-medium"
|
|
>{{ $t("nav.groupBuying") }}</NuxtLink
|
|
>
|
|
</nav>
|
|
</aside>
|
|
<main class="min-w-0 flex-1">
|
|
<header
|
|
class="border-border bg-surface flex min-h-16 items-center justify-end gap-4 border-b px-6"
|
|
>
|
|
<VAccentSwatch />
|
|
<select
|
|
:value="locale"
|
|
:aria-label="$t('common.language')"
|
|
class="border-border bg-surface text-text focus:border-primary focus:outline-primary/30 rounded-md border px-3 py-2 text-sm focus:outline-2"
|
|
@change="setLocale(($event.target as HTMLSelectElement).value as 'en' | 'zh')"
|
|
>
|
|
<option v-for="l in locales" :key="l.code" :value="l.code">{{ l.name }}</option>
|
|
</select>
|
|
<template v-if="session.isLoggedIn">
|
|
<span class="text-muted text-sm">{{ session.user?.display_name }}</span>
|
|
<VBtn size="sm" @click="session.logout()">{{ $t("common.logout") }}</VBtn>
|
|
</template>
|
|
<NuxtLink
|
|
v-else
|
|
to="/login"
|
|
class="border-primary bg-primary hover:bg-primary-hover inline-flex items-center justify-center rounded-md border px-2.5 py-1 text-[13px] font-medium text-white"
|
|
>{{ $t("common.login") }}</NuxtLink
|
|
>
|
|
</header>
|
|
<div class="px-6">
|
|
<NuxtPage />
|
|
</div>
|
|
</main>
|
|
</div>
|
|
</div>
|
|
</template>
|