出库逻辑添加,扫码识别编码成功,后续对应逻辑没有完成

This commit is contained in:
dxc
2026-02-04 17:22:20 +08:00
parent 596f366fc4
commit 797b611530
12 changed files with 919 additions and 28 deletions

View File

@ -42,11 +42,11 @@ const routes: Array<RouteRecordRaw> = [
]
},
// 4. 库存管理
// 4. 库存管理 (入库)
{
path: '/inventory',
component: Layout,
meta: { title: '库管理', icon: 'Shop' },
meta: { title: '库管理', icon: 'Shop' }, // 修改标题以区分出库
redirect: '/inventory/buy',
children: [
{
@ -76,11 +76,33 @@ const routes: Array<RouteRecordRaw> = [
]
},
// 5. 业务操作
// 5. ★ [新增] 出库管理
{
path: '/outbound', // 注意:这里使用了和你提供的文件路径一致的顶级路径
component: Layout,
meta: { title: '出库管理', icon: 'Van' }, // 推荐使用 Van 图标
redirect: '/outbound/index',
children: [
{
path: 'create',
name: 'OutboundCreate',
component: () => import('@/views/outbound/create.vue'),
meta: { title: '扫码出库' }
},
{
path: 'index',
name: 'OutboundList',
component: () => import('@/views/outbound/index.vue'),
meta: { title: '出库记录' }
}
]
},
// 6. 业务操作
{
path: '/operation',
component: Layout,
meta: { title: '业务操作', icon: 'Operation' },
meta: { title: '其他业务', icon: 'Operation' },
redirect: '/operation/borrow',
children: [
{
@ -104,7 +126,7 @@ const routes: Array<RouteRecordRaw> = [
]
},
// 6. 系统管理
// 7. 系统管理
{
path: '/system',
component: Layout,
@ -137,45 +159,35 @@ const router = createRouter({
})
// ==========================================
// [关键修改] 全局路由守卫
// 全局路由守卫
// ==========================================
router.beforeEach((to, from, next) => {
const userStore = useUserStore()
// 1. 实时获取 Token (优先取 store防止 store 未初始化取 localStorage)
const token = userStore.token || localStorage.getItem('token')
const userRole = userStore.role || localStorage.getItem('role') || 'user'
// 2. 如果要去的是登录页
if (to.path === '/login') {
// 如果有 Token说明已登录踢回首页 (防止重复登录)
if (token) {
next('/')
} else {
// 没有 Token允许访问登录页
next()
}
return
}
// 3. 如果去的不是登录页,但没有 Token
if (!token) {
// 强制重定向到登录页
// 使用 replace 防止用户点击浏览器“返回”按钮时进入死循环
next({ path: '/login', replace: true })
return
}
// 4. 权限判断 (已有 Token)
if (to.meta.roles && Array.isArray(to.meta.roles)) {
if (to.meta.roles.includes(userRole)) {
next()
} else {
// 权限不足,跳回首页
next('/dashboard')
}
} else {
// 无特殊权限要求,放行
next()
}
})