Files
bj_power/bj_power_wms/frontend/src/layouts/MainLayout.vue
T
SunYF 46fcb59079 feat: 退料闭环定稿(损耗台账/备料清单/退料AGV自动派车/剩余量参考)+ 工位托盘守卫
- MES 新增损耗台账 loss_ledger,差异确认损耗接口 ConfirmReceiveLoss(按工单归集)
- 备料清单 preparation:MES 按 日计划×工单×工位×物料 实时计算,WMS 只读展示 PreparationList
- 退料闭环:N5 工位托盘守卫(未完成禁止退料)、退料 AGV 自动派车(JBT21 空位判定 + 托盘回收链路)、退料参考剩余量接口(应剩余=实备-已耗-已退-已损)
- 新增 AGV 车辆状态表 agv_vehicle_state 及查询
- 整合接驳台/叫料池/库存锁既有闭环,清理 sql 目录注释生成脚本与 catalog,更新文档
2026-11-04 19:06:03 +08:00

332 lines
14 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.
<script setup>
import { ref, computed, onMounted, onBeforeUnmount, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { ElMessage, ElNotification } from 'element-plus'
import {
HomeFilled, Download, Upload, Search, CircleCheck, List, Bell,
Box, Monitor, EditPen, Fold, Expand, Location, Goods, Key, Operation, Van, Clock, RefreshLeft, Folder, WarningFilled, Tools, Setting, Tickets
} from '@element-plus/icons-vue'
import { getUser, getToken, logout, setSession } from '../utils/auth'
import request from '../utils/request'
const route = useRoute()
const router = useRouter()
// 当前登录用户(含 permissionCodes),挂载时从 /user/info 刷新
const me = ref(getUser() || {})
const userName = computed(() => me.value?.realName || me.value?.username || '未登录')
const pageTitle = computed(() => route.meta?.title || '')
// 菜单按权限码过滤(与 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 兜底 */ }
// 幂等初始化 RBAC 种子:权限码与内置角色仅首次创建,已存在则跳过。
// 管理员登录后自动执行,保证前端菜单/角色页有数据。
try {
await request.post('/rbac/seed', {})
} catch { /* 无权限或已初始化,忽略 */ }
}
// ===== 响应式侧边栏:桌面可折叠,移动端抽屉 =====
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)
loadMe()
// 顶部预警铃铛:立即拉一次未读数,随后每 30s 轮询
pollAlerts()
alertTimer = setInterval(pollAlerts, 30000)
})
// 说明:数据归档清理提醒已从顶栏角标移除,统一由「预警中心」承载
// (后端在备份超期时写入 backup_overdue 预警,处理入口为「预警中心」页)。
onBeforeUnmount(() => {
window.removeEventListener('resize', onScreenChange)
if (alertTimer) clearInterval(alertTimer)
})
// 顶部预警铃铛未读数。
const unreadAlerts = ref(0)
let alertTimer = null
let alertInited = false
async function pollAlerts() {
try {
const data = await request.get('/alerts', { params: { status: 'unread', pageSize: 1 } })
const n = (data && data.unreadCount) || 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')
}
// 侧栏菜单:按业务域分组。分组无权限码,子项各自带 code(无 code 的常驻),
// 组内子项全部被过滤掉则整组隐藏。
const topMenu = { path: '/', title: '工作台', icon: HomeFilled, code: 'dashboard:view' }
const menuGroups = [
{
title: '基础资料', icon: Goods, children: [
{ path: '/material', title: '物料档案', icon: Goods, code: 'material:view' },
{ path: '/zone', title: '区域维护', icon: Location, code: 'zone:view' }
]
},
{
title: '仓储作业', icon: Operation, children: [
{ path: '/inbound', title: '入库管理', icon: Download, code: 'inbound:view' },
{ path: '/finished-inbound', title: '成品入库', icon: Box, code: 'wms.finished:edit' },
{ path: '/inspection-incoming', title: '来料检验', icon: CircleCheck, code: 'inspection:view' },
{ path: '/project-outbound', title: '科技项目出库', icon: Upload, code: 'outbound:view' },
{ path: '/general-outbound', title: '通用出库', icon: Upload, code: 'outbound:view' },
{ path: '/outbound', title: '全部出库记录', icon: List, code: 'outbound:view' },
{ path: '/call-queue', title: '叫料队列', icon: Bell, code: 'call:view' },
{ path: '/return-order', title: '退库确认', icon: RefreshLeft, code: 'return:view' },
{ path: '/pallet-workbench', title: '托盘工作台', icon: Box, code: 'return:view' },
// P1(2026-11-04 用户拍板):备料清单——只读展示"今天及以后×工单×工位×物料×数量"(数据源 MES 日排产实时算)
{ path: '/preparation', title: '备料清单', icon: Tickets, code: 'preparation:view' },
{ path: '/production-return', title: '生产退不良', icon: WarningFilled, code: 'prodreturn:manage' }
]
},
{
title: '库存管理', icon: Box, children: [
{ path: '/inventory', title: '库存查询', icon: Search, code: 'inventory:view' },
{ path: '/stocktake', title: '库存盘点', icon: List, code: 'stocktake:view' },
{ path: '/semi', title: '半成品管理', icon: Box, code: 'semi:view' }
]
},
{
title: '系统管理', icon: Key, children: [
{ path: '/users', title: '账号管理', icon: EditPen, code: 'user:manage' },
{ path: '/roles', title: '角色管理', icon: Key, code: 'role:manage' },
{ path: '/event-log', title: '操作日志', icon: Clock, code: 'eventlog:manage' },
{ path: '/alert-center', title: '预警中心', icon: Bell },
{ path: '/alert-rule', title: '预警规则', icon: Bell },
{ path: '/attachment', title: '附件中心', icon: Folder, code: 'attachment:view' },
{ path: '/data-archive', title: '数据归档', icon: Tools, code: 'backup:manage' },
{ path: '/settings', title: '基础设置', icon: Setting, code: 'sys.settings:view' }
]
}
]
// 按当前用户权限码过滤(无 code 常驻;user:manage 仅管理员可见)
const showTopMenu = computed(() => !topMenu.code || permissionCodes.value.includes(topMenu.code))
const menus = computed(() =>
menuGroups
.map((g) => ({
...g,
children: g.children.filter((m) => !m.code || permissionCodes.value.includes(m.code))
}))
.filter((g) => g.children.length > 0)
)
// 默认展开的分组:除「系统管理」外全部展开(用户偏好:一进系统即可见全部菜单)
const defaultOpeneds = computed(() =>
menus.value
.filter((g) => g.title !== '系统管理')
.map((g) => 'group:' + g.title)
)
// 折叠 → 展开时重挂载菜单,使 default-openeds 重新生效。
// Element Plus 折叠时会清空内部 openedMenus 且展开时不恢复(menu 源码 watch(collapse) 只做清空),
// 而 default-openeds 仅在菜单实例初始化时读取一次——故用 key 变化强制重建实例,必达默认展开态。
const menuKey = ref(0)
watch(isCollapse, (collapsed) => {
if (!collapsed) menuKey.value++
})
// 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
})
// 打开当前页面帮助(各页面 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()
}
}
function onLogout() {
// 尽力通知后端记录"退出登录"操作日志,失败不阻塞本地退出
request.post('/user/logout').catch(() => {})
logout()
ElMessage.success('已退出登录')
router.push('/login')
}
// 免登录大屏:新标签页打开,不覆盖当前窗口
function openDisplay() {
window.open('/display', '_blank')
}
</script>
<template>
<el-container class="layout">
<!-- 移动端遮罩 -->
<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="brand">
<el-icon :size="22"><Box /></el-icon>
<span v-show="!isCollapse">WMS库房管理</span>
</div>
<el-menu :key="menuKey" :default-active="route.path" :default-openeds="defaultOpeneds" class="menu"
background-color="#001529" text-color="#a6adb4" active-text-color="#409eff" router
:collapse="isCollapse && !isMobile">
<el-menu-item v-if="showTopMenu" :index="topMenu.path">
<el-icon style="margin-right:8px"><component :is="topMenu.icon" /></el-icon>
<span>{{ topMenu.title }}</span>
</el-menu-item>
<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.title }}</span>
</el-menu-item>
</el-sub-menu>
</el-menu>
</el-aside>
<el-container>
<el-header height="56px" 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="title">{{ pageTitle }}</span>
</div>
<div class="spacer"></div>
<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 text type="primary" @click="openDisplay">
<el-icon style="margin-right:4px"><Monitor /></el-icon>免登录大屏
</el-button>
<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>
</el-header>
<el-main class="main">
<router-view v-slot="{ Component, route }">
<keep-alive :include="cachedNames">
<component :is="Component" :key="route.name" />
</keep-alive>
</router-view>
</el-main>
</el-container>
</el-container>
</template>
<style scoped>
.layout { height: 100vh; }
.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; }
.brand {
display: flex; align-items: center; justify-content: center; gap: 8px;
height: 60px;
color: #fff; font-weight: 600; font-size: 17px;
white-space: nowrap;
}
.menu { border-right: none; }
.header {
display: flex; align-items: center; gap: 10px;
background: #fff; border-bottom: 1px solid #ebeef5;
}
.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; }
.spacer { flex: 1; }
.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; }
.main { background: #f0f2f5; padding: 14px; overflow: auto; }
</style>