2026-08-28 15:06:01 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<el-container class="layout" style="min-height:100vh">
|
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 }">
|
|
|
|
|
|
<div class="logo">
|
|
|
|
|
|
<el-icon :size="22"><Monitor /></el-icon>
|
|
|
|
|
|
<span v-show="!isCollapse">MES 产线控制</span>
|
|
|
|
|
|
</div>
|
2026-09-04 14:18:53 +08:00
|
|
|
|
<el-menu v-if="menus.length" :key="menuKey" :default-active="$route.path" :default-openeds="defaultOpeneds"
|
|
|
|
|
|
router background-color="#001529" text-color="#a6adb4" active-text-color="#409eff"
|
|
|
|
|
|
style="border-right:none" :collapse="isCollapse && !isMobile">
|
|
|
|
|
|
<el-sub-menu v-for="g in menus" :key="g.title" :index="'group:' + g.title">
|
|
|
|
|
|
<template #title>
|
|
|
|
|
|
<el-icon style="margin-right:8px"><component :is="g.icon" /></el-icon>
|
|
|
|
|
|
<span>{{ g.title }}</span>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<el-menu-item v-for="m in g.children" :key="m.path" :index="m.path">
|
|
|
|
|
|
<el-icon style="margin-right:8px"><component :is="m.icon" /></el-icon>
|
|
|
|
|
|
<span>{{ m.name }}</span>
|
|
|
|
|
|
</el-menu-item>
|
|
|
|
|
|
</el-sub-menu>
|
2026-08-28 15:06:01 +08:00
|
|
|
|
</el-menu>
|
2026-08-31 08:06:55 +08:00
|
|
|
|
<div v-else class="no-menu">
|
|
|
|
|
|
<p>无可用菜单</p>
|
|
|
|
|
|
<p class="sub">请联系管理员分配权限</p>
|
|
|
|
|
|
</div>
|
2026-08-28 15:06:01 +08:00
|
|
|
|
</el-aside>
|
|
|
|
|
|
<el-container>
|
|
|
|
|
|
<el-header 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="page-title">{{ $route.meta.title || '' }}</span>
|
|
|
|
|
|
</div>
|
2026-08-28 17:42:50 +08:00
|
|
|
|
<div class="spacer"></div>
|
2026-08-31 12:58:28 +08:00
|
|
|
|
<div class="header-right">
|
2026-09-17 12:49:07 +08:00
|
|
|
|
<el-badge :value="unreadAlerts" :hidden="unreadAlerts === 0" :max="99" class="alert-badge">
|
|
|
|
|
|
<el-tooltip content="预警中心" placement="bottom">
|
|
|
|
|
|
<el-button class="alert-btn" text @click="goAlertCenter">
|
|
|
|
|
|
<el-icon :size="18" :class="{ 'alert-ring': unreadAlerts > 0 }"><Bell /></el-icon>
|
|
|
|
|
|
</el-button>
|
|
|
|
|
|
</el-tooltip>
|
|
|
|
|
|
</el-badge>
|
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
|
|
|
|
</div>
|
|
|
|
|
|
</el-header>
|
|
|
|
|
|
<el-main style="padding:14px">
|
|
|
|
|
|
<router-view />
|
|
|
|
|
|
</el-main>
|
|
|
|
|
|
</el-container>
|
|
|
|
|
|
</el-container>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<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 { useRouter } from 'vue-router'
|
2026-08-31 12:58:28 +08:00
|
|
|
|
import {
|
|
|
|
|
|
Document, Calendar, Box, Goods, ShoppingCart, Monitor, Tools,
|
2026-08-31 18:54:15 +08:00
|
|
|
|
Operation, Link, DataLine, EditPen, Search, CircleCheck, Clock, User,
|
2026-09-17 12:49:07 +08:00
|
|
|
|
Key, Fold, Expand, Warning, Paperclip, Tickets, Bell
|
2026-08-31 12:58:28 +08:00
|
|
|
|
} from '@element-plus/icons-vue'
|
2026-09-17 12:49:07 +08:00
|
|
|
|
import { ElNotification } from 'element-plus'
|
2026-08-28 15:06:01 +08:00
|
|
|
|
import { getUser, logout } from '../utils/auth'
|
|
|
|
|
|
import request from '../utils/request'
|
|
|
|
|
|
|
|
|
|
|
|
const router = useRouter()
|
|
|
|
|
|
|
2026-08-31 18:54:15 +08:00
|
|
|
|
// ===== 响应式侧边栏:桌面可折叠,移动端抽屉 =====
|
2026-09-07 11:58:19 +08:00
|
|
|
|
const isCollapse = ref(false) // 桌面端默认展开(汉堡菜单展开态);基础配置/系统管理分组靠 defaultOpeneds 默认收起
|
2026-08-31 18:54:15 +08:00
|
|
|
|
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(() => router.currentRoute.value.path, () => {
|
|
|
|
|
|
if (isMobile.value) mobileOpen.value = false
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
|
onScreenChange()
|
|
|
|
|
|
window.addEventListener('resize', onScreenChange)
|
|
|
|
|
|
})
|
2026-09-17 12:49:07 +08:00
|
|
|
|
onBeforeUnmount(() => {
|
|
|
|
|
|
window.removeEventListener('resize', onScreenChange)
|
|
|
|
|
|
if (alertTimer) clearInterval(alertTimer)
|
|
|
|
|
|
})
|
2026-08-31 18:54:15 +08:00
|
|
|
|
|
2026-08-28 15:06:01 +08:00
|
|
|
|
const menus = computed(() => {
|
|
|
|
|
|
const me = getUser()
|
2026-09-04 14:18:53 +08:00
|
|
|
|
if (!me) return menuGroups.map((g) => ({ ...g, children: [...g.children] }))
|
2026-08-28 15:06:01 +08:00
|
|
|
|
const owned = me.permissionCodes || []
|
|
|
|
|
|
const ok = (c) => me.roleCode === 'SUPER_ADMIN' || owned.includes('*') || owned.includes(c)
|
2026-09-04 14:18:53 +08:00
|
|
|
|
return menuGroups
|
|
|
|
|
|
.map((g) => ({ ...g, children: g.children.filter((m) => ok(m.code)) }))
|
|
|
|
|
|
.filter((g) => g.children.length > 0)
|
2026-08-28 15:06:01 +08:00
|
|
|
|
})
|
|
|
|
|
|
|
2026-09-04 14:18:53 +08:00
|
|
|
|
// 侧栏菜单按业务域分组(参考 WMS MainLayout):组无权限码,子项各自带 code 过滤,
|
|
|
|
|
|
// 组内子项全被过滤则整组隐藏。SUPER_ADMIN / '*' 全放行。
|
|
|
|
|
|
const menuGroups = [
|
|
|
|
|
|
{
|
|
|
|
|
|
title: '生产管理', icon: Document, children: [
|
|
|
|
|
|
{ code: 'produce.workorder', name: '工单管理', path: '/work-order', icon: Document },
|
|
|
|
|
|
{ code: 'produce.dailyplan', name: '日排产', path: '/daily-plan', icon: Calendar },
|
2026-09-17 12:49:07 +08:00
|
|
|
|
{ code: 'produce.bom', name: '产品物料清单', path: '/bom', icon: Goods },
|
2026-09-04 14:18:53 +08:00
|
|
|
|
{ code: 'produce.material', name: '备料单', path: '/material-request', icon: ShoppingCart },
|
2026-09-17 12:49:07 +08:00
|
|
|
|
{ code: 'produce.performance', name: '绩效报表', path: '/performance', icon: DataLine },
|
|
|
|
|
|
{ code: 'produce.quality', name: '质量检验', path: '/quality', icon: CircleCheck }
|
2026-09-04 14:18:53 +08:00
|
|
|
|
]
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
title: '现场作业', icon: Monitor, children: [
|
2026-09-15 16:37:39 +08:00
|
|
|
|
{ code: 'produce.plc', name: '工位组合下发', path: '/plc-send', icon: Monitor },
|
2026-09-04 14:18:53 +08:00
|
|
|
|
{ code: 'produce.scan', name: '手动报工', path: '/scan', icon: EditPen },
|
2026-09-17 12:49:07 +08:00
|
|
|
|
{ code: 'produce.wip', name: '在制品', path: '/wip', icon: Clock },
|
2026-09-04 14:18:53 +08:00
|
|
|
|
{ code: 'produce.trace', name: '工件追溯', path: '/trace', icon: Search },
|
2026-09-15 16:37:39 +08:00
|
|
|
|
{ code: 'produce.processcard', name: '生产流程卡', path: '/process-card', icon: Tickets },
|
2026-09-04 14:18:53 +08:00
|
|
|
|
{ code: 'produce.torque', name: '拧紧查询', path: '/torque', icon: Tools },
|
|
|
|
|
|
{ code: 'sys.inspect', name: '巡检终端', path: '/inspect', icon: CircleCheck }
|
|
|
|
|
|
]
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
title: '基础配置', icon: Box, children: [
|
|
|
|
|
|
{ code: 'produce.processflow', name: '工艺流程', path: '/process-flow', icon: Operation },
|
|
|
|
|
|
{ code: 'produce.station', name: '关联工位', path: '/station', icon: Link },
|
2026-09-15 16:37:39 +08:00
|
|
|
|
{ code: 'produce.product', name: '产品型号', path: '/product-type', icon: Box },
|
|
|
|
|
|
{ code: 'produce.qtyreport', name: '数量不符上报', path: '/qty-report', icon: Warning }
|
2026-09-04 14:18:53 +08:00
|
|
|
|
]
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
title: '系统管理', icon: Key, children: [
|
|
|
|
|
|
{ code: 'sys.account', name: '账号管理', path: '/account', icon: User },
|
|
|
|
|
|
{ code: 'sys.role', name: '角色管理', path: '/role', icon: Key },
|
2026-09-14 16:31:08 +08:00
|
|
|
|
{ code: 'sys.eventlog', name: '操作日志', path: '/event-log', icon: Clock },
|
|
|
|
|
|
{ code: 'sys.alert', name: '预警中心', path: '/alert-center', icon: Warning },
|
|
|
|
|
|
{ code: 'sys.attachment', name: '附件中心', path: '/attachment', icon: Paperclip }
|
2026-09-04 14:18:53 +08:00
|
|
|
|
]
|
|
|
|
|
|
}
|
2026-08-28 15:06:01 +08:00
|
|
|
|
]
|
|
|
|
|
|
|
2026-09-07 11:58:19 +08:00
|
|
|
|
// 默认展开分组:仅展开高频业务组(生产管理/现场作业);
|
|
|
|
|
|
// 基础配置(用户称"集成配置")、系统管理 默认收起,需手动点开。
|
|
|
|
|
|
// 折叠→展开时重建菜单使 default-openeds 重新生效
|
2026-09-04 14:18:53 +08:00
|
|
|
|
// (Element Plus 折叠会清空内部 openedMenus,default-openeds 仅在初始化时读取一次,
|
|
|
|
|
|
// 故用 key 变化强制重建实例 —— 同 WMS 的处理)
|
2026-09-07 11:58:19 +08:00
|
|
|
|
const collapsedGroups = ['基础配置', '系统管理']
|
|
|
|
|
|
const defaultOpeneds = computed(() =>
|
|
|
|
|
|
menus.value
|
|
|
|
|
|
.map((g) => 'group:' + g.title)
|
|
|
|
|
|
.filter((k) => !collapsedGroups.includes(k.replace('group:', '')))
|
|
|
|
|
|
)
|
2026-09-04 14:18:53 +08:00
|
|
|
|
const menuKey = ref(0)
|
|
|
|
|
|
watch(isCollapse, (collapsed) => {
|
|
|
|
|
|
if (!collapsed) menuKey.value++
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2026-08-28 15:06:01 +08:00
|
|
|
|
const userName = computed(() => {
|
|
|
|
|
|
const me = getUser()
|
|
|
|
|
|
return me ? (me.name || me.username) : '未登录'
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
onMounted(async () => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const u = await request.get('/userinfo')
|
|
|
|
|
|
localStorage.setItem('user', JSON.stringify(u))
|
|
|
|
|
|
} catch { /* ignore */ }
|
2026-09-17 12:49:07 +08:00
|
|
|
|
|
|
|
|
|
|
// 顶部预警铃铛:立即拉一次未读数,随后每 30s 轮询
|
|
|
|
|
|
pollAlerts()
|
|
|
|
|
|
alertTimer = setInterval(pollAlerts, 30000)
|
2026-08-28 15:06:01 +08:00
|
|
|
|
})
|
|
|
|
|
|
|
2026-09-17 12:49:07 +08:00
|
|
|
|
// ===== 顶部预警铃铛(plan 4.10):未读角标 + 30s 轮询 + 新增弹提示 =====
|
|
|
|
|
|
const unreadAlerts = ref(0)
|
|
|
|
|
|
let alertTimer = null
|
|
|
|
|
|
let alertInited = false
|
|
|
|
|
|
|
|
|
|
|
|
async function pollAlerts() {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const list = await request.get('/alerts', { params: { status: 'UNREAD' } })
|
|
|
|
|
|
const n = Array.isArray(list) ? list.length : 0
|
|
|
|
|
|
// 首轮仅初始化角标;之后未读数增加时弹提示,避免反复骚扰
|
|
|
|
|
|
if (alertInited && n > unreadAlerts.value) {
|
|
|
|
|
|
ElNotification({
|
|
|
|
|
|
title: '新预警',
|
|
|
|
|
|
message: `有 ${n - unreadAlerts.value} 条新的未读预警,请及时处理`,
|
|
|
|
|
|
type: 'warning',
|
|
|
|
|
|
duration: 5000,
|
|
|
|
|
|
position: 'bottom-right'
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
unreadAlerts.value = n
|
|
|
|
|
|
alertInited = true
|
|
|
|
|
|
} catch { /* 忽略轮询异常 */ }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function goAlertCenter() {
|
|
|
|
|
|
router.push('/alert-center')
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-08-28 15:06:01 +08:00
|
|
|
|
function doLogout() {
|
2026-09-10 16:59:15 +08:00
|
|
|
|
// 尽力通知后端记录"退出登录"操作日志,失败不阻塞本地退出
|
|
|
|
|
|
request.post('/logout').catch(() => {})
|
2026-08-28 15:06:01 +08:00
|
|
|
|
logout()
|
|
|
|
|
|
router.replace('/login')
|
|
|
|
|
|
}
|
2026-08-31 12:58:28 +08:00
|
|
|
|
|
|
|
|
|
|
// 打开当前页面帮助(PageHelp 监听该全局事件弹出抽屉)
|
|
|
|
|
|
function openHelp() {
|
|
|
|
|
|
window.dispatchEvent(new CustomEvent('mes:open-page-help'))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function onUserCmd(cmd) {
|
|
|
|
|
|
if (cmd === 'password') {
|
|
|
|
|
|
router.push('/change-password')
|
|
|
|
|
|
} else if (cmd === 'logout') {
|
|
|
|
|
|
doLogout()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-08-28 15:06:01 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
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; }
|
|
|
|
|
|
.logo { display: flex; align-items: center; justify-content: center; gap: 8px; color: #fff; font-size: 17px; font-weight: 600; height: 60px; white-space: nowrap; }
|
2026-08-31 08:06:55 +08:00
|
|
|
|
.no-menu { padding: 24px 10px; text-align: center; color: #a6adb4; font-size: 14px; }
|
|
|
|
|
|
.no-menu .sub { margin-top: 6px; font-size: 12px; color: #6b7684; }
|
2026-08-28 15:06:01 +08:00
|
|
|
|
.header { display: flex; align-items: center; justify-content: space-between; background: #fff; border-bottom: 1px solid #eee; }
|
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; }
|
|
|
|
|
|
.page-title { font-size: 16px; font-weight: 600; color: #303133; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
2026-08-28 17:42:50 +08:00
|
|
|
|
.spacer { flex: 1; }
|
2026-08-31 18:54:15 +08:00
|
|
|
|
.header-right { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
|
2026-09-17 12:49:07 +08:00
|
|
|
|
.alert-badge { margin-right: 4px; }
|
|
|
|
|
|
.alert-btn { color: #606266; padding: 4px 6px; }
|
|
|
|
|
|
.alert-btn:hover { color: #1668dc; background: #f2f6fc; }
|
|
|
|
|
|
.alert-ring { color: #e6a23c; animation: alert-ring 1.1s ease-in-out infinite; transform-origin: top center; }
|
|
|
|
|
|
@keyframes alert-ring {
|
|
|
|
|
|
0%, 60%, 100% { transform: rotate(0); }
|
|
|
|
|
|
10% { transform: rotate(14deg); }
|
|
|
|
|
|
20% { transform: rotate(-12deg); }
|
|
|
|
|
|
30% { transform: rotate(9deg); }
|
|
|
|
|
|
40% { transform: rotate(-6deg); }
|
|
|
|
|
|
50% { transform: rotate(0); }
|
|
|
|
|
|
}
|
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
|
|
|
|
</style>
|