230 lines
6.5 KiB
Vue
230 lines
6.5 KiB
Vue
<template>
|
|
<n-layout has-sider position="absolute" class="admin-layout">
|
|
<n-layout-sider
|
|
bordered
|
|
:collapsed="collapsed"
|
|
collapse-mode="width"
|
|
:collapsed-width="64"
|
|
:width="224"
|
|
:native-scrollbar="false"
|
|
show-trigger="arrow-circle"
|
|
@collapse="collapsed = true"
|
|
@expand="collapsed = false"
|
|
>
|
|
<div class="brand">
|
|
<span class="brand-logo">艺</span>
|
|
<span v-show="!collapsed" class="brand-name text-ellipsis">{{ appName }}</span>
|
|
</div>
|
|
<n-menu
|
|
:collapsed="collapsed"
|
|
:collapsed-width="64"
|
|
:value="activeKey"
|
|
:options="menuOptions"
|
|
@update:value="onMenu"
|
|
/>
|
|
</n-layout-sider>
|
|
|
|
<n-layout class="admin-main">
|
|
<n-layout-header bordered class="header">
|
|
<div class="header-title text-ellipsis">{{ currentTitle }}</div>
|
|
<div class="spacer" />
|
|
<theme-switch />
|
|
<lang-switch />
|
|
<n-dropdown :options="userOptions" @select="onUser">
|
|
<n-button quaternary>
|
|
<template #icon><n-icon :component="PersonCircleOutline" /></template>
|
|
{{ auth.user?.realName || auth.user?.username }}
|
|
</n-button>
|
|
</n-dropdown>
|
|
</n-layout-header>
|
|
|
|
<n-layout-content class="content" :native-scrollbar="false">
|
|
<router-view v-slot="{ Component }">
|
|
<transition name="fade" mode="out-in">
|
|
<component :is="Component" />
|
|
</transition>
|
|
</router-view>
|
|
</n-layout-content>
|
|
|
|
<n-layout-footer bordered class="footer">
|
|
<span>© 2026 {{ appName }}</span>
|
|
<span v-if="filingInfo">{{ filingInfo }}</span>
|
|
</n-layout-footer>
|
|
</n-layout>
|
|
</n-layout>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { computed, h, onMounted, onUnmounted, ref } from 'vue';
|
|
import { useRoute, useRouter } from 'vue-router';
|
|
import { useI18n } from 'vue-i18n';
|
|
import { NIcon } from 'naive-ui';
|
|
import type { MenuOption } from 'naive-ui';
|
|
import {
|
|
GridOutline,
|
|
DocumentTextOutline,
|
|
ImagesOutline,
|
|
CubeOutline,
|
|
ListOutline,
|
|
PeopleOutline,
|
|
SettingsOutline,
|
|
PersonCircleOutline,
|
|
LogOutOutline,
|
|
KeyOutline,
|
|
ShieldCheckmarkOutline,
|
|
} from '@vicons/ionicons5';
|
|
import { useAuthStore } from '@/stores/auth';
|
|
import { settingsApi } from '@/api';
|
|
import { dialog } from '@/utils/feedback';
|
|
import LangSwitch from '@/components/LangSwitch.vue';
|
|
import ThemeSwitch from '@/components/ThemeSwitch.vue';
|
|
|
|
const route = useRoute();
|
|
const router = useRouter();
|
|
const { t } = useI18n();
|
|
const auth = useAuthStore();
|
|
|
|
const collapsed = ref(window.innerWidth < 900);
|
|
const appName = ref(t('pages.login.title'));
|
|
const filingInfo = ref('');
|
|
|
|
function renderIcon(icon: unknown) {
|
|
return () => h(NIcon, null, { default: () => h(icon as never) });
|
|
}
|
|
|
|
const menuOptions = computed<MenuOption[]>(() => {
|
|
const items: Array<MenuOption & { superOnly?: boolean; auditOnly?: boolean }> = [
|
|
{ label: t('menu.dashboard'), key: 'dashboard', icon: renderIcon(GridOutline) },
|
|
{ label: t('menu.templates'), key: 'templates', icon: renderIcon(DocumentTextOutline) },
|
|
{ label: t('menu.artworks'), key: 'artworks', icon: renderIcon(ImagesOutline) },
|
|
{ label: t('menu.outbound'), key: 'outbound', icon: renderIcon(CubeOutline) },
|
|
{ label: t('menu.audit'), key: 'audit', icon: renderIcon(ShieldCheckmarkOutline), auditOnly: true },
|
|
{ label: t('menu.queryLogs'), key: 'queryLogs', icon: renderIcon(ListOutline) },
|
|
{ label: t('menu.operationLogs'), key: 'operationLogs', icon: renderIcon(ListOutline), superOnly: true },
|
|
{ label: t('menu.users'), key: 'users', icon: renderIcon(PeopleOutline), superOnly: true },
|
|
{ label: t('menu.settings'), key: 'settings', icon: renderIcon(SettingsOutline), superOnly: true },
|
|
];
|
|
return items.filter(
|
|
(i) => (!i.superOnly || auth.isSuperAdmin) && (!i.auditOnly || auth.canAudit),
|
|
);
|
|
});
|
|
|
|
const activeKey = computed(() => (['artwork-detail', 'artwork-trace-codes', 'traceCodes'].includes(route.name as string) ? 'artworks' : (route.name as string)));
|
|
const currentTitle = computed(() => (activeKey.value ? t(`menu.${activeKey.value}`) : ''));
|
|
|
|
const userOptions = computed(() => [
|
|
{ label: t('menu.profile'), key: 'profile', icon: renderIcon(KeyOutline) },
|
|
{ label: t('common.action.logout'), key: 'logout', icon: renderIcon(LogOutOutline) },
|
|
]);
|
|
|
|
function onMenu(key: string) {
|
|
router.push({ name: key });
|
|
}
|
|
|
|
function onUser(key: string) {
|
|
if (key === 'profile') {
|
|
router.push({ name: 'profile' });
|
|
} else if (key === 'logout') {
|
|
dialog.warning({
|
|
title: t('common.action.logout'),
|
|
content: '确定退出登录?',
|
|
positiveText: t('common.action.confirm'),
|
|
negativeText: t('common.action.cancel'),
|
|
onPositiveClick: () => {
|
|
auth.logout();
|
|
router.push({ name: 'login' });
|
|
},
|
|
});
|
|
}
|
|
}
|
|
|
|
let resizeHandler: () => void;
|
|
onMounted(async () => {
|
|
resizeHandler = () => {
|
|
collapsed.value = window.innerWidth < 900;
|
|
};
|
|
window.addEventListener('resize', resizeHandler);
|
|
try {
|
|
const s = await settingsApi.getAll();
|
|
if (s.appName) appName.value = s.appName;
|
|
filingInfo.value = s.filingInfo || '';
|
|
} catch {
|
|
/* ignore */
|
|
}
|
|
});
|
|
onUnmounted(() => window.removeEventListener('resize', resizeHandler));
|
|
</script>
|
|
|
|
<style scoped>
|
|
.brand {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 10px;
|
|
height: 56px;
|
|
padding: 0 16px;
|
|
}
|
|
.brand-logo {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
width: 32px;
|
|
height: 32px;
|
|
border-radius: 8px;
|
|
background: var(--brand);
|
|
color: #fff;
|
|
font-weight: 700;
|
|
flex-shrink: 0;
|
|
}
|
|
.brand-name {
|
|
font-size: 15px;
|
|
font-weight: 600;
|
|
color: var(--brand);
|
|
}
|
|
.admin-layout {
|
|
min-width: var(--admin-min-width);
|
|
min-height: var(--admin-min-height);
|
|
}
|
|
.admin-main {
|
|
min-width: 0;
|
|
}
|
|
.header {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 10px;
|
|
height: 56px;
|
|
padding: 0 16px;
|
|
}
|
|
.header-title {
|
|
font-size: 16px;
|
|
font-weight: 600;
|
|
max-width: 40vw;
|
|
}
|
|
.spacer {
|
|
flex: 1 1 auto;
|
|
}
|
|
.content {
|
|
height: calc(max(100vh, var(--admin-min-height)) - var(--admin-header-height) - var(--admin-footer-height));
|
|
min-height: calc(var(--admin-min-height) - var(--admin-header-height) - var(--admin-footer-height));
|
|
}
|
|
.footer {
|
|
height: var(--admin-footer-height);
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
gap: 16px;
|
|
padding: 0 16px;
|
|
color: var(--n-text-color-3);
|
|
font-size: 12px;
|
|
line-height: 1;
|
|
white-space: nowrap;
|
|
}
|
|
.fade-enter-active,
|
|
.fade-leave-active {
|
|
transition: opacity 0.15s ease;
|
|
}
|
|
.fade-enter-from,
|
|
.fade-leave-to {
|
|
opacity: 0;
|
|
}
|
|
</style>
|