feat(bx-mobile): guard routes by portal menuCodes and drop bx admin IAM pages

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
zlwuandCursor committed 2026-08-09 16:07:23 +08:00
1 parent a4f04ff297
commit a0eebfdbd3
2 files changed
+158 -50

No files matched your search

+116 -25
View File
@@ -1,4 +1,5 @@
import { createRouter, createWebHistory } from 'vue-router' import { createRouter, createWebHistory } from 'vue-router'
import { showToast } from 'vant'
import { useAuthStore } from '@/stores/auth' import { useAuthStore } from '@/stores/auth'
const routes = [ const routes = [
@@ -13,29 +14,110 @@ const routes = [
component: () => import('@/views/home/HomeLayout.vue'), component: () => import('@/views/home/HomeLayout.vue'),
children: [ children: [
{ path: '', name: 'Home', component: () => import('@/views/home/HomePage.vue') }, { path: '', name: 'Home', component: () => import('@/views/home/HomePage.vue') },
{ path: 'mine', name: 'Mine', component: () => import('@/views/mine/MinePage.vue') }, {
{ path: 'approval', name: 'Approval', component: () => import('@/views/approval/ApprovalPage.vue') }, path: 'mine',
{ path: 'approval/:bizType/:id', name: 'ApprovalDetail', component: () => import('@/views/approval/ApprovalDetailPage.vue') }, name: 'Mine',
{ path: 'advance/list', name: 'AdvanceList', component: () => import('@/views/advance/AdvanceListPage.vue') }, component: () => import('@/views/mine/MinePage.vue'),
{ path: 'advance/apply', name: 'AdvanceApply', component: () => import('@/views/advance/AdvanceApplyPage.vue') }, meta: { menuCodes: ['bx:viewMine:list'] },
},
{
path: 'approval',
name: 'Approval',
component: () => import('@/views/approval/ApprovalPage.vue'),
meta: { menuCodes: ['bx:viewTodo:list'] },
},
{
path: 'approval/:bizType/:id',
name: 'ApprovalDetail',
component: () => import('@/views/approval/ApprovalDetailPage.vue'),
meta: { menuCodes: ['bx:viewTodo:list', 'bx:advanceApprove:list', 'bx:reimburseApprove:list'] },
},
{
path: 'advance/list',
name: 'AdvanceList',
component: () => import('@/views/advance/AdvanceListPage.vue'),
meta: { menuCodes: ['bx:advanceApply:list'] },
},
{
path: 'advance/apply',
name: 'AdvanceApply',
component: () => import('@/views/advance/AdvanceApplyPage.vue'),
meta: { menuCodes: ['bx:advanceApply:list'] },
},
/* 须放在 advance/:id 之前,否则 approve/issue 会被当成动态 id */ /* 须放在 advance/:id 之前,否则 approve/issue 会被当成动态 id */
{ path: 'advance/approve', name: 'AdvanceApprove', component: () => import('@/views/advance/AdvanceApprovePage.vue'), meta: { roles: ['ADMIN', 'FINANCE', 'GENERAL_MANAGER'] } }, {
/* 与 bx_menu_role 一致:ADMIN、FINANCE 均分配「备用金发放管理」 */ path: 'advance/approve',
{ path: 'advance/issue', name: 'AdvanceIssue', component: () => import('@/views/advance/AdvanceIssuePage.vue'), meta: { roles: ['ADMIN', 'FINANCE'] } }, name: 'AdvanceApprove',
{ path: 'advance/:id', name: 'AdvanceDetail', component: () => import('@/views/advance/AdvanceDetailPage.vue') }, component: () => import('@/views/advance/AdvanceApprovePage.vue'),
{ path: 'reimburse/list', name: 'ReimburseList', component: () => import('@/views/reimburse/ReimburseListPage.vue') }, meta: { menuCodes: ['bx:advanceApprove:list'] },
{ path: 'reimburse/apply', name: 'ReimburseApply', component: () => import('@/views/reimburse/ReimburseApplyPage.vue') }, },
{ path: 'reimburse/approve', name: 'ReimburseApprove', component: () => import('@/views/reimburse/ReimburseApprovePage.vue'), meta: { roles: ['ADMIN', 'FINANCE', 'GENERAL_MANAGER'] } }, {
{ path: 'reimburse/:id', name: 'ReimburseDetail', component: () => import('@/views/reimburse/ReimburseDetailPage.vue') }, path: 'advance/issue',
{ path: 'payment', name: 'Payment', component: () => import('@/views/payment/PaymentPage.vue'), meta: { roles: ['ADMIN', 'FINANCE'] } }, name: 'AdvanceIssue',
{ path: 'all', name: 'All', component: () => import('@/views/all/AllPage.vue'), meta: { roles: ['ADMIN', 'GENERAL_MANAGER'] } }, component: () => import('@/views/advance/AdvanceIssuePage.vue'),
{ path: 'admin', name: 'AdminIndex', component: () => import('@/views/admin/AdminIndexPage.vue'), meta: { roles: ['ADMIN'] } }, meta: { menuCodes: ['bx:advanceIssue:list'] },
{ path: 'admin/users', name: 'UserManage', component: () => import('@/views/admin/UserManagePage.vue'), meta: { roles: ['ADMIN'] } }, },
{ path: 'admin/roles', name: 'RoleManage', component: () => import('@/views/admin/RoleManagePage.vue'), meta: { roles: ['ADMIN'] } }, {
{ path: 'admin/menus', name: 'MenuManage', component: () => import('@/views/admin/MenuManagePage.vue'), meta: { roles: ['ADMIN'] } }, path: 'advance/:id',
{ path: 'admin/expenses', name: 'ExpenseProject', component: () => import('@/views/admin/ExpenseProjectPage.vue'), meta: { roles: ['ADMIN'] } }, name: 'AdvanceDetail',
{ path: 'admin/wf-advance', name: 'WfAdvance', component: () => import('@/views/admin/WfAdvancePage.vue'), meta: { roles: ['ADMIN'] } }, component: () => import('@/views/advance/AdvanceDetailPage.vue'),
{ path: 'admin/wf-reimburse', name: 'WfReimburse', component: () => import('@/views/admin/WfReimbursePage.vue'), meta: { roles: ['ADMIN'] } }, meta: {
menuCodes: [
'bx:advanceApply:list',
'bx:advanceApprove:list',
'bx:advanceIssue:list',
'bx:viewMine:list',
'bx:viewTodo:list',
'bx:viewAll:list',
],
},
},
{
path: 'reimburse/list',
name: 'ReimburseList',
component: () => import('@/views/reimburse/ReimburseListPage.vue'),
meta: { menuCodes: ['bx:reimburseApply:list'] },
},
{
path: 'reimburse/apply',
name: 'ReimburseApply',
component: () => import('@/views/reimburse/ReimburseApplyPage.vue'),
meta: { menuCodes: ['bx:reimburseApply:list'] },
},
{
path: 'reimburse/approve',
name: 'ReimburseApprove',
component: () => import('@/views/reimburse/ReimburseApprovePage.vue'),
meta: { menuCodes: ['bx:reimburseApprove:list'] },
},
{
path: 'reimburse/:id',
name: 'ReimburseDetail',
component: () => import('@/views/reimburse/ReimburseDetailPage.vue'),
meta: {
menuCodes: [
'bx:reimburseApply:list',
'bx:reimburseApprove:list',
'bx:payment:list',
'bx:viewMine:list',
'bx:viewTodo:list',
'bx:viewAll:list',
],
},
},
{
path: 'payment',
name: 'Payment',
component: () => import('@/views/payment/PaymentPage.vue'),
meta: { menuCodes: ['bx:payment:list'] },
},
{
path: 'all',
name: 'All',
component: () => import('@/views/all/AllPage.vue'),
meta: { menuCodes: ['bx:viewAll:list'] },
},
/* P1:不注册 invoice/*、admin 配置与 IAM(users/roles/menus) */
{ path: 'profile', name: 'Profile', component: () => import('@/views/profile/ProfilePage.vue') }, { path: 'profile', name: 'Profile', component: () => import('@/views/profile/ProfilePage.vue') },
], ],
}, },
@@ -50,9 +132,18 @@ router.beforeEach(async (to, _from, next) => {
const auth = useAuthStore() const auth = useAuthStore()
if (to.meta?.public) return next() if (to.meta?.public) return next()
if (!auth.isLoggedIn) return next('/login') if (!auth.isLoggedIn) return next('/login')
if (!auth.user) await auth.fetchUser() if (!auth.user) {
const roles = to.meta?.roles as string[] | undefined try {
if (roles?.length && !roles.some((r: string) => auth.roleCodes.includes(r))) { await auth.fetchUser()
} catch {
return next('/login')
}
}
if (!auth.isLoggedIn) return next('/login')
const codes = to.meta?.menuCodes as string[] | undefined
if (codes?.length && !codes.some((c) => auth.can(c))) {
showToast('无权限')
return next('/') return next('/')
} }
next() next()
+42 -25
View File
@@ -28,20 +28,37 @@
<van-cell title="修改密码" icon="lock" is-link @click="showPasswordDialog = true" /> <van-cell title="修改密码" icon="lock" is-link @click="showPasswordDialog = true" />
</van-cell-group> </van-cell-group>
<!-- Finance / approver actions --> <!-- 按门户 menuCode 显隐快捷入口 -->
<template v-if="isApprover"> <template v-if="showQuickNav">
<van-cell-group inset class="group-block" title="审批管理"> <van-cell-group inset class="group-block" title="快捷入口">
<van-cell title="备用金审批" icon="cash-back-record" is-link to="/advance/approve" /> <van-cell
<van-cell title="报销审批" icon="description" is-link to="/reimburse/approve" /> v-if="auth.can('bx:advanceApprove:list')"
<van-cell title="发放管理" icon="balance-list-o" is-link to="/advance/issue" /> title="备用金审批"
<van-cell title="全部记录" icon="records" is-link to="/all" /> icon="cash-back-record"
</van-cell-group> is-link
</template> to="/advance/approve"
/>
<!-- Admin section --> <van-cell
<template v-if="auth.isAdmin"> v-if="auth.can('bx:reimburseApprove:list')"
<van-cell-group inset class="group-block" title="系统"> title="报销审批"
<van-cell title="系统管理" icon="setting-o" is-link to="/admin" /> icon="description"
is-link
to="/reimburse/approve"
/>
<van-cell
v-if="auth.can('bx:advanceIssue:list')"
title="发放管理"
icon="balance-list-o"
is-link
to="/advance/issue"
/>
<van-cell
v-if="auth.can('bx:viewAll:list')"
title="全部记录"
icon="records"
is-link
to="/all"
/>
</van-cell-group> </van-cell-group>
</template> </template>
@@ -128,10 +145,12 @@ const passwordForm = reactive({
confirmPassword: '', confirmPassword: '',
}) })
const APPROVER_ROLES = ['ADMIN', 'FINANCE', 'GENERAL_MANAGER'] const showQuickNav = computed(
() =>
const isApprover = computed(() => auth.can('bx:advanceApprove:list') ||
APPROVER_ROLES.some((r) => auth.roleCodes.includes(r)), auth.can('bx:reimburseApprove:list') ||
auth.can('bx:advanceIssue:list') ||
auth.can('bx:viewAll:list'),
) )
const avatarChar = computed(() => { const avatarChar = computed(() => {
@@ -140,13 +159,11 @@ const avatarChar = computed(() => {
}) })
const roleText = computed(() => { const roleText = computed(() => {
const codes = auth.roleCodes if (auth.isSuperAdmin || auth.allMenus) return '超级管理员'
const parts: string[] = [] const role = auth.user?.role
if (codes.includes('ADMIN')) parts.push('管理员') if (role) return role
if (codes.includes('GENERAL_MANAGER')) parts.push('总经理') const roles = auth.user?.roles || []
if (codes.includes('FINANCE')) parts.push('财务人员') return roles.length ? roles.join('、') : '已登录'
if (codes.includes('EMPLOYEE')) parts.push('员工')
return parts.join('、') || '未分配角色'
}) })
async function handleLogout() { async function handleLogout() {