242 lines
9.4 KiB
Vue
242 lines
9.4 KiB
Vue
<template>
|
|
<div class="min-h-screen bg-bg-primary">
|
|
<div class="flex min-h-screen">
|
|
<!-- 移动端遮罩 -->
|
|
<div
|
|
v-if="mobileNavOpen"
|
|
class="fixed inset-0 z-40 bg-black/60 backdrop-blur-sm lg:hidden"
|
|
@click="mobileNavOpen = false"
|
|
></div>
|
|
|
|
<!-- 侧边栏 -->
|
|
<aside
|
|
class="fixed inset-y-0 left-0 z-50 flex w-64 max-w-[80vw] flex-col border-r border-border bg-bg-secondary transition-transform duration-200 lg:w-56 lg:max-w-none lg:translate-x-0"
|
|
:class="mobileNavOpen ? 'translate-x-0' : '-translate-x-full'"
|
|
>
|
|
<!-- Logo 区域 -->
|
|
<div class="flex items-center justify-between border-b border-border p-3 lg:block">
|
|
<div class="flex items-center gap-2.5">
|
|
<div class="flex h-9 w-9 items-center justify-center overflow-hidden rounded-lg border border-border bg-bg-elevated">
|
|
<img v-if="siteStore.logoUrl" :src="siteStore.logoUrl" alt="logo" class="h-full w-full object-cover" />
|
|
<span v-else class="text-sm font-bold text-white">资</span>
|
|
</div>
|
|
<div class="min-w-0 flex-1">
|
|
<h1 class="truncate text-sm font-semibold text-text-primary">{{ siteStore.siteName }}</h1>
|
|
<p class="text-xs text-text-tertiary">固定资产</p>
|
|
</div>
|
|
</div>
|
|
<button type="button" class="btn-icon lg:hidden" @click="mobileNavOpen = false" aria-label="关闭导航">
|
|
<XMarkIcon class="h-5 w-5" />
|
|
</button>
|
|
</div>
|
|
|
|
<!-- 导航菜单 -->
|
|
<nav class="flex-1 space-y-0.5 overflow-y-auto p-2">
|
|
<router-link
|
|
v-for="item in visibleNavItems"
|
|
:key="item.path"
|
|
:to="item.path"
|
|
class="nav-link"
|
|
:class="{ active: isActive(item.path) }"
|
|
@click="mobileNavOpen = false"
|
|
>
|
|
<component :is="item.icon" class="h-5 w-5" />
|
|
<span>{{ item.title }}</span>
|
|
</router-link>
|
|
</nav>
|
|
|
|
<!-- 用户区域 - 固定在底部 -->
|
|
<div class="shrink-0 border-t border-border p-3">
|
|
<div class="flex items-center gap-2.5">
|
|
<div class="flex h-8 w-8 items-center justify-center rounded-lg bg-bg-elevated">
|
|
<span class="text-sm text-text-secondary">{{ userInitials }}</span>
|
|
</div>
|
|
<div class="min-w-0 flex-1">
|
|
<p class="truncate text-sm font-medium text-text-primary">
|
|
{{ authStore.user?.name || authStore.user?.username || '用户' }}
|
|
</p>
|
|
<p class="text-xs text-text-tertiary">
|
|
{{ getRoleLabel(authStore.user?.role) }}
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="mt-3 grid gap-1.5" :class="authStore.can(PERMISSIONS.SYSTEM_SETTINGS) ? 'grid-cols-2' : 'grid-cols-1'">
|
|
<button
|
|
v-if="authStore.can(PERMISSIONS.SYSTEM_SETTINGS)"
|
|
type="button"
|
|
class="btn-secondary min-h-[34px] px-2.5 text-xs"
|
|
@click="router.push('/settings')"
|
|
>
|
|
设置
|
|
</button>
|
|
<button
|
|
type="button"
|
|
class="btn-secondary min-h-[34px] px-2.5 text-xs"
|
|
@click="handleLogout"
|
|
>
|
|
退出
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</aside>
|
|
|
|
<!-- 主内容区 -->
|
|
<main class="flex min-w-0 flex-1 flex-col lg:ml-56">
|
|
<!-- 顶部栏 -->
|
|
<header class="sticky top-0 z-30 border-b border-border bg-bg-secondary/95 backdrop-blur">
|
|
<div class="flex items-center justify-between gap-4 px-3 py-3 sm:px-4">
|
|
<div class="flex min-w-0 items-center gap-2.5">
|
|
<button type="button" class="btn-icon lg:hidden" @click="mobileNavOpen = true" aria-label="打开导航">
|
|
<Bars3Icon class="h-5 w-5" />
|
|
</button>
|
|
<div class="min-w-0">
|
|
<h2 class="truncate text-base font-semibold text-text-primary">{{ currentSection }}</h2>
|
|
<p v-if="currentSubtitle" class="text-xs text-text-tertiary">{{ currentSubtitle }}</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="hidden items-center gap-2 lg:flex">
|
|
<button
|
|
v-if="authStore.can(PERMISSIONS.NOTIFICATIONS_VIEW)"
|
|
type="button"
|
|
class="btn-icon relative"
|
|
title="站内消息"
|
|
@click="router.push('/notifications')"
|
|
>
|
|
<BellIcon class="h-5 w-5" />
|
|
<span
|
|
v-if="notificationStore.unreadCount > 0"
|
|
class="absolute -right-1 -top-1 min-w-[16px] rounded-full bg-status-error px-1 py-0.5 text-center text-[10px] font-semibold leading-none text-white"
|
|
>
|
|
{{ notificationStore.unreadCount > 99 ? '99+' : notificationStore.unreadCount }}
|
|
</span>
|
|
</button>
|
|
<div class="rounded-full border border-border px-2.5 py-1 text-xs text-text-tertiary">
|
|
{{ getRoleLabel(authStore.user?.role) }}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</header>
|
|
|
|
<!-- 页面内容 -->
|
|
<div class="flex-1 overflow-auto px-3 py-4 sm:px-4">
|
|
<router-view />
|
|
</div>
|
|
</main>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { computed, onMounted, ref, watch } from 'vue'
|
|
import { useRoute, useRouter } from 'vue-router'
|
|
import { useAuthStore } from '@/stores/auth'
|
|
import { useNotificationStore } from '@/stores/notifications'
|
|
import { useSiteStore } from '@/stores/site'
|
|
import {
|
|
HomeIcon,
|
|
CubeIcon,
|
|
ClipboardDocumentCheckIcon,
|
|
ArrowRightIcon,
|
|
ChartBarIcon,
|
|
BellIcon,
|
|
Cog6ToothIcon,
|
|
Bars3Icon,
|
|
XMarkIcon,
|
|
WrenchScrewdriverIcon,
|
|
ArchiveBoxXMarkIcon,
|
|
UserCircleIcon
|
|
} from '@heroicons/vue/24/outline'
|
|
import { getRoleLabel, PERMISSIONS } from '@/auth/permissions'
|
|
|
|
const router = useRouter()
|
|
const route = useRoute()
|
|
const authStore = useAuthStore()
|
|
const notificationStore = useNotificationStore()
|
|
const siteStore = useSiteStore()
|
|
const mobileNavOpen = ref(false)
|
|
|
|
const navItems = [
|
|
{ path: '/dashboard', title: '首页', icon: HomeIcon },
|
|
{ path: '/equipment', title: '资产管理', icon: CubeIcon, permission: PERMISSIONS.ASSETS_VIEW_ALL },
|
|
{ path: '/my-assets', title: '我的资产', icon: UserCircleIcon, permission: PERMISSIONS.ASSETS_VIEW_OWN },
|
|
{ path: '/inventory', title: '资产盘点', icon: ClipboardDocumentCheckIcon, permission: PERMISSIONS.INVENTORY_MANAGE },
|
|
{ path: '/borrow', title: '使用管理', icon: ArrowRightIcon, permission: PERMISSIONS.ASSETS_BORROW },
|
|
{ path: '/maintenance', title: '维修管理', icon: WrenchScrewdriverIcon, permission: PERMISSIONS.ASSETS_MAINTENANCE },
|
|
{
|
|
path: '/workflows/disposals',
|
|
title: '报废流程',
|
|
icon: ArchiveBoxXMarkIcon,
|
|
anyPermissions: [PERMISSIONS.DISPOSALS_APPLY, PERMISSIONS.DISPOSALS_APPROVE, PERMISSIONS.DISPOSALS_COMPLETE]
|
|
},
|
|
{ path: '/statistics', title: '统计', icon: ChartBarIcon, permission: PERMISSIONS.REPORTS_VIEW },
|
|
{ path: '/notifications', title: '消息', icon: BellIcon, permission: PERMISSIONS.NOTIFICATIONS_VIEW },
|
|
{ path: '/settings', title: '设置', icon: Cog6ToothIcon, permission: PERMISSIONS.SYSTEM_SETTINGS }
|
|
]
|
|
|
|
const visibleNavItems = computed(() => {
|
|
return navItems.filter((item) => {
|
|
if (item.permission && !authStore.can(item.permission)) return false
|
|
if (item.anyPermissions && !authStore.canAny(item.anyPermissions)) return false
|
|
return true
|
|
})
|
|
})
|
|
|
|
const currentSection = computed(() => {
|
|
const matchedNav = navItems.find((item) => route.path.startsWith(item.path))
|
|
return (route.meta.title as string) || matchedNav?.title || '工作台'
|
|
})
|
|
|
|
const currentSubtitle = computed(() => {
|
|
if (route.path === '/dashboard') return '资产运行总览'
|
|
if (route.path === '/equipment') return '资产维护与盘点'
|
|
if (route.path.startsWith('/equipment/')) return '移动录入与现场维护'
|
|
if (route.path === '/inventory') return '任务范围与现场进度'
|
|
if (route.path === '/inventory/create') return '生成新的盘点任务'
|
|
if (route.path.startsWith('/inventory/')) return '查看盘点人、资产与异常结果'
|
|
if (route.path.startsWith('/borrow')) return '借还管理'
|
|
if (route.path.startsWith('/return/')) return '扫码归还'
|
|
if (route.path === '/my-assets') return '当前未归还资产'
|
|
if (route.path.startsWith('/maintenance')) return '维修任务与结果'
|
|
if (route.path.startsWith('/workflows/disposals')) return '申请、审批与处置'
|
|
if (route.path === '/statistics') return '数据分析'
|
|
if (route.path === '/notifications') return '同步提醒与待办'
|
|
if (route.path === '/settings') return '系统配置'
|
|
return ''
|
|
})
|
|
|
|
const isActive = (path: string) => route.path === path || route.path.startsWith(`${path}/`)
|
|
|
|
const userInitials = computed(() => {
|
|
const name = authStore.user?.name || authStore.user?.username || 'U'
|
|
return name.charAt(0).toUpperCase()
|
|
})
|
|
|
|
const handleLogout = async () => {
|
|
await authStore.logout()
|
|
router.push('/login')
|
|
}
|
|
|
|
watch(
|
|
() => route.fullPath,
|
|
() => {
|
|
mobileNavOpen.value = false
|
|
}
|
|
)
|
|
|
|
watch(
|
|
() => authStore.user?.permissions,
|
|
() => {
|
|
if (authStore.can(PERMISSIONS.NOTIFICATIONS_VIEW)) {
|
|
notificationStore.fetchUnreadCount()
|
|
}
|
|
},
|
|
{ immediate: true }
|
|
)
|
|
|
|
onMounted(() => {
|
|
siteStore.fetchSiteConfig()
|
|
})
|
|
</script>
|