197 lines
7.0 KiB
Vue
197 lines
7.0 KiB
Vue
/**
|
|
* features/admin/components/AdminNav.vue
|
|
* 绠$悊鍚庡彴宸︿晶瀵艰埅锛屼娇鐢ㄥ瓙璺敱璺宠浆銆?
|
|
* 渚濊禆锛歛dmin-nav.store銆乵odules 甯搁噺銆乿ue-router銆?
|
|
* 閫昏緫锛氭姤琛?浼佸井瀛愯彍鍗曢粯璁ゆ姌鍙狅紱褰撳墠璺敱钀藉湪瀵瑰簲妯″潡鏃惰嚜鍔ㄥ睍寮€浠ヤ究鐪嬪埌婵€娲婚」銆?
|
|
*/
|
|
<script setup lang="ts">
|
|
import { computed, watch } from 'vue';
|
|
import { useI18n } from 'vue-i18n';
|
|
import { useRoute, useRouter } from 'vue-router';
|
|
import { LayoutDashboard, UserCog, Building, Bot, FileText,
|
|
Settings2, Megaphone, MessageCircleQuestion, Link2, Users, ShieldCheck, BarChart2, AppWindow,
|
|
ScrollText, ExternalLink,
|
|
} 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,
|
|
users: UserCog,
|
|
departments: Building,
|
|
agents: Bot,
|
|
knowledge_base: FileText,
|
|
schedules: Settings2,
|
|
announcements: Megaphone,
|
|
questions: MessageCircleQuestion,
|
|
wecom: Link2,
|
|
linked_services: ExternalLink,
|
|
permissions: Users,
|
|
platform_apps: AppWindow,
|
|
procurement_contract: ScrollText,
|
|
requests: ShieldCheck,
|
|
reports: BarChart2,
|
|
};
|
|
|
|
const visibleModules = computed(() =>
|
|
ADMIN_MODULE_METAS.filter((item) => config.admin.modules[item.configKey] !== false),
|
|
);
|
|
|
|
const standardModules = computed(() =>
|
|
visibleModules.value.filter((item) => item.id !== 'wecom'),
|
|
);
|
|
|
|
const isModuleActive = (moduleId: AdminModuleId): boolean =>
|
|
route.meta.adminModule === moduleId;
|
|
|
|
const isReportsActive = computed(() => route.meta.adminModule === 'reports');
|
|
const isWecomActive = computed(() => route.meta.adminModule === 'wecom');
|
|
|
|
const wecomSubRoutes = [
|
|
{ name: 'AdminWecomSettings', labelKey: 'admin.wecom.nav.settings' },
|
|
{ name: 'AdminWecomBindings', labelKey: 'admin.wecom.nav.bindings' },
|
|
{ name: 'AdminWecomAudits', labelKey: 'admin.wecom.nav.audits' },
|
|
] as const;
|
|
|
|
const navigateWecom = (routeName: string): void => {
|
|
router.push({ name: routeName });
|
|
};
|
|
|
|
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 } });
|
|
};
|
|
|
|
/**
|
|
* 杩涘叆鎶ヨ〃/浼佸井妯″潡鏃惰嚜鍔ㄥ睍寮€瀛愯彍鍗曪紝閬垮厤褰撳墠椤靛湪鎶樺彔鐘舵€佷笅涓嶅彲瑙併€?
|
|
*/
|
|
watch(
|
|
isReportsActive,
|
|
(active) => {
|
|
if (active) navStore.reportsExpanded = true;
|
|
},
|
|
{ immediate: true },
|
|
);
|
|
|
|
watch(
|
|
isWecomActive,
|
|
(active) => {
|
|
if (active) navStore.wecomExpanded = true;
|
|
},
|
|
{ immediate: true },
|
|
);
|
|
</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 standardModules"
|
|
: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.wecom !== false" class="flex flex-col flex-shrink-0">
|
|
<button
|
|
type="button"
|
|
class="admin-nav-btn group justify-between"
|
|
:class="{ 'admin-nav-btn--active': isWecomActive }"
|
|
@click="navStore.wecomExpanded = !navStore.wecomExpanded"
|
|
>
|
|
<div class="flex items-center gap-3">
|
|
<Link2 class="w-5 h-5 flex-shrink-0" :class="isWecomActive ? 'text-brand-600' : 'text-muted'" />
|
|
<span :class="navStore.sidebarCollapsed ? 'md:hidden' : ''">{{ t('admin.nav.wecom') }}</span>
|
|
</div>
|
|
</button>
|
|
<div
|
|
v-if="navStore.wecomExpanded && !navStore.sidebarCollapsed"
|
|
class="pl-4 space-y-1 mt-1 border-l-2 border-subtle ml-6"
|
|
>
|
|
<button
|
|
v-for="sub in wecomSubRoutes"
|
|
:key="sub.name"
|
|
type="button"
|
|
class="admin-nav-subitem"
|
|
:class="{ 'admin-nav-subitem--active': route.name === sub.name }"
|
|
@click="navigateWecom(sub.name)"
|
|
>
|
|
{{ t(sub.labelKey) }}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<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>
|
|
|