2026-08-28 15:06:01 +08:00
|
|
|
|
<script setup>
|
2026-08-31 18:54:15 +08:00
|
|
|
|
import { ref, computed, onMounted, onBeforeUnmount, watch } from 'vue'
|
2026-08-28 15:06:01 +08:00
|
|
|
|
import { useRoute, useRouter } from 'vue-router'
|
|
|
|
|
|
import { ElMessage } from 'element-plus'
|
|
|
|
|
|
import {
|
|
|
|
|
|
HomeFilled, Download, Upload, Search, CircleCheck, List,
|
2026-09-03 18:13:59 +08:00
|
|
|
|
Box, Tickets, Monitor, EditPen, Fold, Expand, Location, Goods, Key
|
2026-08-28 15:06:01 +08:00
|
|
|
|
} from '@element-plus/icons-vue'
|
2026-09-02 14:54:54 +08:00
|
|
|
|
import { getUser, getToken, logout, setSession } from '../utils/auth'
|
|
|
|
|
|
import request from '../utils/request'
|
2026-08-28 15:06:01 +08:00
|
|
|
|
|
|
|
|
|
|
const route = useRoute()
|
|
|
|
|
|
const router = useRouter()
|
|
|
|
|
|
|
2026-09-02 14:54:54 +08:00
|
|
|
|
// 当前登录用户(含 permissionCodes),挂载时从 /user/info 刷新
|
|
|
|
|
|
const me = ref(getUser() || {})
|
|
|
|
|
|
const userName = computed(() => me.value?.realName || me.value?.username || '未登录')
|
2026-08-28 15:06:01 +08:00
|
|
|
|
const pageTitle = computed(() => route.meta?.title || '')
|
|
|
|
|
|
|
2026-09-02 14:54:54 +08:00
|
|
|
|
// 菜单按权限码过滤(与 MES 的 defaultMenus + permissionCodes 机制一致)
|
|
|
|
|
|
const permissionCodes = computed(() => me.value?.permissionCodes || [])
|
|
|
|
|
|
|
|
|
|
|
|
async function loadMe() {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const u = await request.get('/user/info')
|
|
|
|
|
|
me.value = u
|
|
|
|
|
|
setSession(getToken(), u) // 刷新本地用户(含最新 permissionCodes/角色)
|
|
|
|
|
|
} catch { /* 用登录时写入的 user 兜底 */ }
|
2026-09-03 14:20:37 +08:00
|
|
|
|
// 幂等初始化 RBAC 种子:权限码与内置角色仅首次创建,已存在则跳过。
|
|
|
|
|
|
// 管理员登录后自动执行,保证前端菜单/角色页有数据。
|
|
|
|
|
|
try {
|
|
|
|
|
|
await request.post('/rbac/seed', {})
|
|
|
|
|
|
} catch { /* 无权限或已初始化,忽略 */ }
|
2026-09-02 14:54:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-08-31 18:54:15 +08:00
|
|
|
|
// ===== 响应式侧边栏:桌面可折叠,移动端抽屉 =====
|
|
|
|
|
|
const isCollapse = ref(false) // 桌面端折叠(仅图标)
|
|
|
|
|
|
const isMobile = ref(false) // 移动端(≤767px)
|
|
|
|
|
|
const mobileOpen = ref(false) // 移动端抽屉展开
|
|
|
|
|
|
|
|
|
|
|
|
const asideWidth = computed(() => (isMobile.value ? '210px' : isCollapse.value ? '64px' : '210px'))
|
|
|
|
|
|
|
|
|
|
|
|
function toggleAside() {
|
|
|
|
|
|
if (isMobile.value) {
|
|
|
|
|
|
mobileOpen.value = !mobileOpen.value
|
|
|
|
|
|
} else {
|
|
|
|
|
|
isCollapse.value = !isCollapse.value
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function onScreenChange() {
|
|
|
|
|
|
const mq = window.matchMedia('(max-width: 767px)')
|
|
|
|
|
|
isMobile.value = mq.matches
|
|
|
|
|
|
if (!isMobile.value) mobileOpen.value = false
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 路由切换后自动收起移动端抽屉
|
|
|
|
|
|
watch(() => route.path, () => {
|
|
|
|
|
|
if (isMobile.value) mobileOpen.value = false
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
|
onScreenChange()
|
|
|
|
|
|
window.addEventListener('resize', onScreenChange)
|
2026-09-02 14:54:54 +08:00
|
|
|
|
loadMe()
|
2026-08-31 18:54:15 +08:00
|
|
|
|
})
|
|
|
|
|
|
onBeforeUnmount(() => window.removeEventListener('resize', onScreenChange))
|
|
|
|
|
|
|
2026-09-02 14:54:54 +08:00
|
|
|
|
const defaultMenus = [
|
|
|
|
|
|
{ path: '/', title: '工作台', icon: HomeFilled, code: 'dashboard:view' },
|
|
|
|
|
|
{ path: '/inbound', title: '入库管理', icon: Download, code: 'inbound:view' },
|
2026-09-03 14:20:37 +08:00
|
|
|
|
{ path: '/outbound', title: '出库管理', icon: Upload, code: 'outbound:view' },
|
2026-09-02 14:54:54 +08:00
|
|
|
|
{ path: '/inventory', title: '库存查询', icon: Search, code: 'inventory:view' },
|
|
|
|
|
|
{ path: '/inspection', title: '质量检验', icon: CircleCheck, code: 'inspection:view' },
|
|
|
|
|
|
{ path: '/stocktake', title: '库存盘点', icon: List, code: 'stocktake:view' },
|
|
|
|
|
|
{ path: '/semi', title: '半成品/成品', icon: Box, code: 'semi:view' },
|
|
|
|
|
|
{ path: '/ledger', title: '备料台账', icon: Tickets, code: 'ledger:view' },
|
|
|
|
|
|
{ path: '/zone', title: '区域维护', icon: Location, code: 'zone:view' },
|
|
|
|
|
|
{ path: '/material', title: '物料档案', icon: Goods, code: 'material:view' },
|
2026-09-03 14:20:37 +08:00
|
|
|
|
{ path: '/users', title: '账号管理', icon: EditPen, code: 'user:manage' },
|
|
|
|
|
|
{ path: '/roles', title: '角色管理', icon: Key, code: 'role:manage' }
|
2026-08-28 15:06:01 +08:00
|
|
|
|
]
|
|
|
|
|
|
|
2026-09-02 14:54:54 +08:00
|
|
|
|
// 按当前用户权限码过滤菜单(无 code 的常驻;user:manage 仅管理员可见)
|
|
|
|
|
|
const menus = computed(() =>
|
|
|
|
|
|
defaultMenus.filter((m) => !m.code || permissionCodes.value.includes(m.code))
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2026-09-03 14:20:37 +08:00
|
|
|
|
// keep-alive 缓存列表页组件:从路由 meta.keepAlive 收集组件名
|
|
|
|
|
|
// (返回列表页时保留筛选/页码/已加载数据,避免重复请求)
|
|
|
|
|
|
const cachedNames = computed(() => {
|
|
|
|
|
|
const names = []
|
|
|
|
|
|
for (const r of router.getRoutes()) {
|
|
|
|
|
|
const meta = r.meta || {}
|
|
|
|
|
|
if (meta.keepAlive && meta.componentName) names.push(meta.componentName)
|
|
|
|
|
|
}
|
|
|
|
|
|
return names
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2026-08-31 12:58:28 +08:00
|
|
|
|
// 打开当前页面帮助(各页面 PageHelp 监听 wms:open-page-help 事件弹出抽屉)
|
|
|
|
|
|
function openHelp() {
|
|
|
|
|
|
window.dispatchEvent(new CustomEvent('wms:open-page-help'))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function onUserCmd(cmd) {
|
|
|
|
|
|
if (cmd === 'password') {
|
|
|
|
|
|
router.push('/change-password')
|
|
|
|
|
|
} else if (cmd === 'logout') {
|
|
|
|
|
|
onLogout()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-08-28 15:06:01 +08:00
|
|
|
|
function onLogout() {
|
|
|
|
|
|
logout()
|
|
|
|
|
|
ElMessage.success('已退出登录')
|
|
|
|
|
|
router.push('/login')
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
|
<el-container class="layout">
|
2026-08-31 18:54:15 +08:00
|
|
|
|
<!-- 移动端遮罩 -->
|
|
|
|
|
|
<div v-if="isMobile && mobileOpen" class="drawer-mask" @click="mobileOpen = false"></div>
|
|
|
|
|
|
<el-aside :width="asideWidth" class="aside"
|
|
|
|
|
|
:class="{ 'drawer': isMobile, 'drawer-open': isMobile && mobileOpen }">
|
2026-08-28 15:06:01 +08:00
|
|
|
|
<div class="brand">
|
|
|
|
|
|
<el-icon :size="22"><Box /></el-icon>
|
2026-08-31 18:54:15 +08:00
|
|
|
|
<span v-show="!isCollapse">库房客户端</span>
|
2026-08-28 15:06:01 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<el-menu :default-active="route.path" class="menu" background-color="#001529"
|
2026-08-31 18:54:15 +08:00
|
|
|
|
text-color="#c2cad8" active-text-color="#ffffff" router
|
|
|
|
|
|
:collapse="isCollapse && !isMobile">
|
2026-08-28 15:06:01 +08:00
|
|
|
|
<el-menu-item v-for="m in menus" :key="m.path" :index="m.path">
|
|
|
|
|
|
<el-icon><component :is="m.icon" /></el-icon>
|
|
|
|
|
|
<span>{{ m.title }}</span>
|
|
|
|
|
|
</el-menu-item>
|
|
|
|
|
|
</el-menu>
|
|
|
|
|
|
</el-aside>
|
|
|
|
|
|
|
|
|
|
|
|
<el-container>
|
|
|
|
|
|
<el-header height="56px" class="header">
|
2026-08-31 18:54:15 +08:00
|
|
|
|
<div class="header-left">
|
|
|
|
|
|
<el-icon class="collapse-btn" @click="toggleAside">
|
|
|
|
|
|
<Expand v-if="isMobile ? !mobileOpen : isCollapse" />
|
|
|
|
|
|
<Fold v-else />
|
|
|
|
|
|
</el-icon>
|
|
|
|
|
|
<span class="title">{{ pageTitle }}</span>
|
|
|
|
|
|
</div>
|
2026-08-28 15:06:01 +08:00
|
|
|
|
<div class="spacer"></div>
|
|
|
|
|
|
<el-button text type="primary" @click="router.push('/display')">
|
|
|
|
|
|
<el-icon style="margin-right:4px"><Monitor /></el-icon>免登录大屏
|
|
|
|
|
|
</el-button>
|
2026-08-31 12:58:28 +08:00
|
|
|
|
<el-button class="help-btn" text @click="openHelp">帮助</el-button>
|
|
|
|
|
|
<el-dropdown trigger="click" @command="onUserCmd">
|
|
|
|
|
|
<span class="user-name">{{ userName }} <span class="caret">▾</span></span>
|
|
|
|
|
|
<template #dropdown>
|
|
|
|
|
|
<el-dropdown-menu>
|
|
|
|
|
|
<el-dropdown-item command="password">修改密码</el-dropdown-item>
|
|
|
|
|
|
<el-dropdown-item divided command="logout">退出登录</el-dropdown-item>
|
|
|
|
|
|
</el-dropdown-menu>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-dropdown>
|
2026-08-28 15:06:01 +08:00
|
|
|
|
</el-header>
|
|
|
|
|
|
<el-main class="main">
|
2026-09-03 14:20:37 +08:00
|
|
|
|
<router-view v-slot="{ Component, route }">
|
|
|
|
|
|
<keep-alive :include="cachedNames">
|
|
|
|
|
|
<component :is="Component" :key="route.name" />
|
|
|
|
|
|
</keep-alive>
|
|
|
|
|
|
</router-view>
|
2026-08-28 15:06:01 +08:00
|
|
|
|
</el-main>
|
|
|
|
|
|
</el-container>
|
|
|
|
|
|
</el-container>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
.layout { height: 100vh; }
|
2026-08-31 18:54:15 +08:00
|
|
|
|
.aside { background: #001529; transition: width .2s ease; }
|
|
|
|
|
|
.drawer { position: fixed; left: 0; top: 0; bottom: 0; z-index: 1001; transform: translateX(-100%); transition: transform .3s ease; }
|
|
|
|
|
|
.drawer-open { transform: translateX(0); }
|
|
|
|
|
|
.drawer-mask { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 1000; }
|
2026-08-28 15:06:01 +08:00
|
|
|
|
.brand {
|
|
|
|
|
|
display: flex; align-items: center; gap: 8px;
|
|
|
|
|
|
height: 56px; padding: 0 16px;
|
|
|
|
|
|
color: #fff; font-weight: 600; font-size: 15px;
|
|
|
|
|
|
border-bottom: 1px solid rgba(255, 255, 255, 0.08);
|
2026-08-31 18:54:15 +08:00
|
|
|
|
white-space: nowrap;
|
2026-08-28 15:06:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
.menu { border-right: none; }
|
|
|
|
|
|
.header {
|
|
|
|
|
|
display: flex; align-items: center; gap: 10px;
|
|
|
|
|
|
background: #fff; border-bottom: 1px solid #ebeef5;
|
|
|
|
|
|
}
|
2026-08-31 18:54:15 +08:00
|
|
|
|
.header-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
|
|
|
|
|
|
.collapse-btn { font-size: 20px; cursor: pointer; color: #303133; display: flex; align-items: center; flex-shrink: 0; }
|
|
|
|
|
|
.collapse-btn:hover { color: #1668dc; }
|
|
|
|
|
|
.title { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
2026-08-28 15:06:01 +08:00
|
|
|
|
.spacer { flex: 1; }
|
2026-08-31 12:58:28 +08:00
|
|
|
|
.help-btn { font-size: 13px; color: #606266; }
|
|
|
|
|
|
.user-name {
|
|
|
|
|
|
display: inline-flex; align-items: center; gap: 4px; cursor: pointer;
|
|
|
|
|
|
font-size: 14px; color: #303133; outline: none; padding: 4px 6px; border-radius: 4px;
|
|
|
|
|
|
}
|
|
|
|
|
|
.user-name:hover { color: #1668dc; background: #f2f6fc; }
|
|
|
|
|
|
.caret { font-size: 10px; color: #909399; }
|
2026-08-28 15:06:01 +08:00
|
|
|
|
.main { background: #f0f2f5; padding: 14px; overflow: auto; }
|
|
|
|
|
|
</style>
|