Files
bj_power/bj_power_mes/frontend/src/layouts/MainLayout.vue
T
weixiao_world@163.com 72374f80cb feat: 新增工件生命周期状态流水表及工单状态流转逻辑
新增工件生命周期状态流水表,记录所有工件状态变更动作,替代原半成品质检计数源
调整工单状态流转,将「下发工单」与「开始执行」合并为「下发并开工」,自动启用关联排产
新增工件物理位置字段,区分业务位置与实际物理工位,解决工位对账滞后问题
统一物料类别处理,避免 WMS 同步时覆盖合法值或错误设置为 0
移除已废弃的返修状态,更新相关显示与逻辑
2026-10-12 22:32:55 +08:00

284 lines
12 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<el-container class="layout" style="min-height:100vh">
<!-- 移动端遮罩 -->
<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>
<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>
</el-menu>
<div v-else class="no-menu">
<p>无可用菜单</p>
<p class="sub">请联系管理员分配权限</p>
</div>
</el-aside>
<el-container>
<el-header class="header">
<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>
<div class="spacer"></div>
<div class="header-right">
<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>
<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>
</div>
</el-header>
<el-main style="padding:14px">
<router-view />
</el-main>
</el-container>
</el-container>
</template>
<script setup>
import { ref, computed, onMounted, onBeforeUnmount, watch } from 'vue'
import { useRouter } from 'vue-router'
import {
Document, Calendar, Box, Goods, ShoppingCart, Monitor, Tools,
Operation, Link, DataLine, Search, CircleCheck, Clock, User,
Key, Fold, Expand, Warning, Paperclip, Tickets, Bell, Aim, Setting
} from '@element-plus/icons-vue'
import { ElNotification } from 'element-plus'
import { getUser, logout } from '../utils/auth'
import request from '../utils/request'
const router = useRouter()
// ===== 响应式侧边栏:桌面可折叠,移动端抽屉 =====
const isCollapse = ref(false) // 桌面端默认展开(汉堡菜单展开态);基础配置/系统管理分组靠 defaultOpeneds 默认收起
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)
})
onBeforeUnmount(() => {
window.removeEventListener('resize', onScreenChange)
if (alertTimer) clearInterval(alertTimer)
})
const menus = computed(() => {
const me = getUser()
if (!me) return menuGroups.map((g) => ({ ...g, children: [...g.children] }))
const owned = me.permissionCodes || []
const ok = (c) => me.roleCode === 'SUPER_ADMIN' || owned.includes('*') || owned.includes(c)
return menuGroups
.map((g) => ({ ...g, children: g.children.filter((m) => ok(m.code)) }))
.filter((g) => g.children.length > 0)
})
// 侧栏菜单按业务域分组(参考 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 },
{ code: 'produce.producible', name: '排产支撑', path: '/producible-support', icon: DataLine },
{ code: 'produce.material', name: '备料单', path: '/material-request', icon: ShoppingCart },
{ code: 'produce.qty', name: '数量不符处理', path: '/qty-report', icon: Warning },
{ code: 'produce.performance', name: '绩效报表', path: '/performance', icon: DataLine },
{ code: 'produce.quality', name: '质量检验', path: '/quality', icon: CircleCheck }
]
},
{
title: '现场作业', icon: Monitor, children: [
{ code: 'produce.plc', name: '工位组合下发', path: '/plc-send', icon: Monitor },
{ code: 'produce.wip', name: '在制品', path: '/wip', icon: Clock },
{ code: 'produce.trace', name: '工件追溯', path: '/trace', icon: Search },
{ code: 'produce.virtualstation', name: '虚拟工位作业', path: '/virtual-station', icon: Goods },
{ code: 'produce.processcard', name: '生产流程卡', path: '/process-card', icon: Tickets },
{ code: 'produce.audit', name: '待审核签字', path: '/audit-pending', icon: CircleCheck },
{ 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 },
{ code: 'produce.dock', name: '接驳台维护', path: '/dock', icon: Aim },
{ code: 'produce.product', name: '物料档案', path: '/product-type', icon: Box }
]
},
{
title: '系统管理', icon: Key, children: [
{ code: 'sys.account', name: '账号管理', path: '/account', icon: User },
{ code: 'sys.role', name: '角色管理', path: '/role', icon: Key },
{ code: 'sys.eventlog', name: '操作日志', path: '/event-log', icon: Clock },
{ code: 'sys.alert', name: '预警中心', path: '/alert-center', icon: Warning },
{ code: 'sys.alertrule', name: '预警规则', path: '/alert-rule', icon: Setting },
{ code: 'sys.attachment', name: '附件中心', path: '/attachment', icon: Paperclip },
{ code: 'sys.settings', name: '基础设置', path: '/settings', icon: Setting }
]
}
]
// 默认展开分组:仅展开高频业务组(生产管理/现场作业);
// 基础配置(用户称"集成配置")、系统管理 默认收起,需手动点开。
// 折叠→展开时重建菜单使 default-openeds 重新生效
// (Element Plus 折叠会清空内部 openedMenus,default-openeds 仅在初始化时读取一次,
// 故用 key 变化强制重建实例 —— 同 WMS 的处理)
const collapsedGroups = ['基础配置', '系统管理']
const defaultOpeneds = computed(() =>
menus.value
.map((g) => 'group:' + g.title)
.filter((k) => !collapsedGroups.includes(k.replace('group:', '')))
)
const menuKey = ref(0)
watch(isCollapse, (collapsed) => {
if (!collapsed) menuKey.value++
})
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 */ }
// 顶部预警铃铛:立即拉一次未读数,随后每 30s 轮询
pollAlerts()
alertTimer = setInterval(pollAlerts, 30000)
})
// ===== 顶部预警铃铛(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')
}
function doLogout() {
// 尽力通知后端记录"退出登录"操作日志,失败不阻塞本地退出
request.post('/logout').catch(() => {})
logout()
router.replace('/login')
}
// 打开当前页面帮助(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()
}
}
</script>
<style scoped>
.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; }
.no-menu { padding: 24px 10px; text-align: center; color: #a6adb4; font-size: 14px; }
.no-menu .sub { margin-top: 6px; font-size: 12px; color: #6b7684; }
.header { display: flex; align-items: center; justify-content: space-between; background: #fff; border-bottom: 1px solid #eee; }
.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; }
.spacer { flex: 1; }
.header-right { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.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); }
}
.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; }
</style>