refactor: 重构前端骨架,及admin模块子路由和懒加载
refactor: 优化多次请求,并使用pinia状态管理
This commit is contained in:
1 parent
f877f61efd
commit
61693d014d
74 files changed
+9493
-6418
No files matched your search
@@ -0,0 +1,128 @@
|
||||
/**
|
||||
* features/admin/components/AdminNav.vue
|
||||
* 管理后台左侧导航,使用子路由跳转。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import {
|
||||
LayoutDashboard, UserPlus, UserCog, Building, Bot, FileText,
|
||||
Settings2, Megaphone, MessageCircleQuestion, Link2, Users, ShieldCheck, BarChart2,
|
||||
} from 'lucide-vue-next';
|
||||
import type { Component } from 'vue';
|
||||
import { config } from '@/config';
|
||||
import { ADMIN_MODULE_METAS, ADMIN_REPORT_TABLES } from '../constants/modules';
|
||||
import { useAdminNavStore } from '../stores/admin-nav.store';
|
||||
import type { AdminModuleId } from '../types/admin.types';
|
||||
|
||||
const { t } = useI18n();
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const navStore = useAdminNavStore();
|
||||
|
||||
const iconMap: Record<AdminModuleId, Component> = {
|
||||
dashboard: LayoutDashboard,
|
||||
approvals: UserPlus,
|
||||
users: UserCog,
|
||||
departments: Building,
|
||||
agents: Bot,
|
||||
knowledge_base: FileText,
|
||||
schedules: Settings2,
|
||||
announcements: Megaphone,
|
||||
questions: MessageCircleQuestion,
|
||||
wecom: Link2,
|
||||
permissions: Users,
|
||||
requests: ShieldCheck,
|
||||
reports: BarChart2,
|
||||
};
|
||||
|
||||
const visibleModules = computed(() =>
|
||||
ADMIN_MODULE_METAS.filter((item) => config.admin.modules[item.configKey] !== false),
|
||||
);
|
||||
|
||||
const isModuleActive = (moduleId: AdminModuleId): boolean =>
|
||||
route.meta.adminModule === moduleId;
|
||||
|
||||
const isReportsActive = computed(() => route.meta.adminModule === 'reports');
|
||||
|
||||
const getReportTableLabel = (table: string): string => {
|
||||
const i18nKey = `admin.report.tables.${table}`;
|
||||
const translated = t(i18nKey);
|
||||
if (translated && translated !== i18nKey) return translated;
|
||||
return table.replace(/_/g, ' ').replace(/\b\w/g, (m) => m.toUpperCase());
|
||||
};
|
||||
|
||||
const navigateModule = (routeName: string): void => {
|
||||
router.push({ name: routeName });
|
||||
};
|
||||
|
||||
const navigateReport = (table: string): void => {
|
||||
router.push({ name: 'AdminReports', params: { table } });
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<aside
|
||||
class="surface-panel rounded-2xl shadow-sm h-fit md:sticky md:top-24 overflow-hidden shrink-0 z-10 transition-all duration-300"
|
||||
:class="navStore.sidebarCollapsed ? 'w-0 md:w-20' : 'w-full md:w-64'"
|
||||
>
|
||||
<nav class="flex md:flex-col p-3 gap-1 overflow-x-auto md:overflow-visible no-scrollbar">
|
||||
<button
|
||||
v-for="item in visibleModules"
|
||||
:key="item.id"
|
||||
type="button"
|
||||
class="admin-nav-btn group"
|
||||
:class="{ 'admin-nav-btn--active': isModuleActive(item.id) }"
|
||||
:title="navStore.sidebarCollapsed ? t(item.labelKey) : ''"
|
||||
@click="navigateModule(item.routeName)"
|
||||
>
|
||||
<component
|
||||
:is="iconMap[item.id]"
|
||||
class="w-5 h-5 transition-transform group-hover:scale-110 flex-shrink-0"
|
||||
:class="isModuleActive(item.id) ? 'text-brand-600' : 'text-muted group-hover:text-secondary'"
|
||||
/>
|
||||
<span :class="navStore.sidebarCollapsed ? 'md:hidden' : ''">{{ t(item.labelKey) }}</span>
|
||||
<span
|
||||
v-if="navStore.badgeForModule(item.id) && !navStore.sidebarCollapsed"
|
||||
class="ml-auto bg-red-500 text-white text-[10px] font-bold px-2 py-0.5 rounded-full shadow-sm"
|
||||
>
|
||||
{{ navStore.badgeForModule(item.id) }}
|
||||
</span>
|
||||
<div
|
||||
v-if="isModuleActive(item.id)"
|
||||
class="absolute left-0 top-1/2 -translate-y-1/2 w-1 h-6 bg-brand-600 rounded-r-full"
|
||||
/>
|
||||
</button>
|
||||
|
||||
<div v-if="config.admin.modules.reports !== false" class="flex flex-col flex-shrink-0">
|
||||
<button
|
||||
type="button"
|
||||
class="admin-nav-btn group justify-between"
|
||||
:class="{ 'admin-nav-btn--active': isReportsActive }"
|
||||
@click="navStore.reportsExpanded = !navStore.reportsExpanded"
|
||||
>
|
||||
<div class="flex items-center gap-3">
|
||||
<BarChart2 class="w-5 h-5 flex-shrink-0" :class="isReportsActive ? 'text-brand-600' : 'text-muted'" />
|
||||
<span :class="navStore.sidebarCollapsed ? 'md:hidden' : ''">{{ t('admin.nav.reports') }}</span>
|
||||
</div>
|
||||
</button>
|
||||
<div
|
||||
v-if="navStore.reportsExpanded && !navStore.sidebarCollapsed"
|
||||
class="pl-4 space-y-1 mt-1 border-l-2 border-subtle ml-6"
|
||||
>
|
||||
<button
|
||||
v-for="table in ADMIN_REPORT_TABLES"
|
||||
:key="table"
|
||||
type="button"
|
||||
class="admin-nav-subitem"
|
||||
:class="{ 'admin-nav-subitem--active': isReportsActive && route.params.table === table }"
|
||||
@click="navigateReport(table)"
|
||||
>
|
||||
{{ getReportTableLabel(table) }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</aside>
|
||||
</template>
|
||||
Reference in new issue
Block a user