Files
vmall/apps/shop-admin/app.vue
T

63 lines
3.9 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="min-h-screen bg-bg font-sans text-text">
<div class="flex min-h-screen">
<aside class="w-60 shrink-0 border-r border-border bg-surface px-4 py-5">
<div class="mb-6 px-3 text-lg font-bold text-text">{{ $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="rounded-md px-3 py-2 text-sm font-medium text-muted hover:bg-bg">{{ $t("nav.dashboard") }}</NuxtLink>
<NuxtLink to="/products" active-class="bg-primary-soft text-primary" class="rounded-md px-3 py-2 text-sm font-medium text-muted hover:bg-bg">{{ $t("nav.products") }}</NuxtLink>
<NuxtLink to="/shop-profile" active-class="bg-primary-soft text-primary" class="rounded-md px-3 py-2 text-sm font-medium text-muted hover:bg-bg">{{ $t("nav.shopProfile") }}</NuxtLink>
<NuxtLink to="/orders" active-class="bg-primary-soft text-primary" class="rounded-md px-3 py-2 text-sm font-medium text-muted hover:bg-bg">{{ $t("nav.orders") }}</NuxtLink>
<NuxtLink to="/aftersales" active-class="bg-primary-soft text-primary" class="rounded-md px-3 py-2 text-sm font-medium text-muted hover:bg-bg">{{ $t("nav.aftersales") }}</NuxtLink>
<NuxtLink to="/shipments" active-class="bg-primary-soft text-primary" class="rounded-md px-3 py-2 text-sm font-medium text-muted hover:bg-bg">{{ $t("nav.shipments") }}</NuxtLink>
<NuxtLink to="/invoices" active-class="bg-primary-soft text-primary" class="rounded-md px-3 py-2 text-sm font-medium text-muted hover:bg-bg">{{ $t("nav.invoices") }}</NuxtLink>
<NuxtLink to="/coupons" active-class="bg-primary-soft text-primary" class="rounded-md px-3 py-2 text-sm font-medium text-muted hover:bg-bg">{{ $t("nav.coupons") }}</NuxtLink>
<NuxtLink to="/flash-sales" active-class="bg-primary-soft text-primary" class="rounded-md px-3 py-2 text-sm font-medium text-muted hover:bg-bg">{{ $t("nav.flashSales") }}</NuxtLink>
<NuxtLink to="/group-buying" active-class="bg-primary-soft text-primary" class="rounded-md px-3 py-2 text-sm font-medium text-muted hover:bg-bg">{{ $t("nav.groupBuying") }}</NuxtLink>
</nav>
</aside>
<main class="min-w-0 flex-1">
<header class="flex min-h-16 items-center justify-end gap-4 border-b border-border bg-surface px-6">
<VAccentSwatch />
<select
:value="locale"
:aria-label="$t('common.language')"
class="rounded-md border border-border bg-surface px-3 py-2 text-sm text-text focus:border-primary focus:outline-2 focus:outline-primary/30"
@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-sm text-muted">{{ session.user?.display_name }}</span>
<VBtn size="sm" @click="session.logout()">{{ $t("common.logout") }}</VBtn>
</template>
<NuxtLink v-else to="/login" class="inline-flex items-center justify-center rounded-md border border-primary bg-primary px-2.5 py-1 text-[13px] font-medium text-white hover:bg-primary-hover">{{ $t("common.login") }}</NuxtLink>
</header>
<div class="px-6">
<NuxtPage />
</div>
</main>
</div>
</div>
</template>