From 4b20c1fe39f61e874fcb4dab8b78da61d6f25b48 Mon Sep 17 00:00:00 2001 From: XingQue Date: Mon, 6 Jul 2026 18:44:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=95=86=E5=AE=B6=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E4=BB=A5API=E4=B8=BA=E5=87=86=EF=BC=8C=E8=8F=9C=E5=8D=95?= =?UTF-8?q?=E4=B8=8Epermission=5Fcodes=E5=AF=B9=E9=BD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- src/router/index.js | 2 +- src/utils/club-context.js | 36 +++++++++++++++++++++++++------ src/views/order/MerchantOrder.vue | 27 +---------------------- 3 files changed, 32 insertions(+), 33 deletions(-) diff --git a/src/router/index.js b/src/router/index.js index 4dd254f..0448a69 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -365,7 +365,7 @@ router.beforeEach(async (to, from, next) => { await ensureMenuAccess(async () => { const res = await request.get(JITUAN_API.menuAccess) return res.code === 0 ? res.data : null - }) + }, { force: true }) } catch (e) { console.error('路由加载菜单权限失败:', e) } diff --git a/src/utils/club-context.js b/src/utils/club-context.js index 51e8374..509bc92 100644 --- a/src/utils/club-context.js +++ b/src/utils/club-context.js @@ -3,7 +3,7 @@ const CLUB_SCOPE_KEY = 'admin_club_scope'; const CLUB_CONTEXT_KEY = 'admin_club_context'; const MENU_ACCESS_KEY = 'kefu_menu_access'; const MENU_SESSION_KEY = 'kefu_menu_session_v'; -const MENU_SESSION_VERSION = '16'; +const MENU_SESSION_VERSION = '17'; const DEFAULT_CLUB_ID = 'xq'; let menuAccessInflight = null; @@ -196,17 +196,41 @@ function pageAllowedByCodes(pageId, codes) { export function getEffectiveVisiblePaths(access = null) { const a = access || getMenuAccess(); const paths = a?.visible_paths; - return Array.isArray(paths) ? paths : []; + if (Array.isArray(paths) && paths.length > 0) { + return paths; + } + if (Array.isArray(a?.visible_page_ids) && a.visible_page_ids.length === 0) { + return []; + } + return pathsFromPermissionCodes(a?.permission_codes || []); +} + +export function hasPermCode(access, ...codes) { + if (!access || !codes.length) return false; + const list = access.permission_codes || []; + return codes.some((c) => list.includes(c)); } export function canShowMenuPage(pageId) { const access = getMenuAccess(); if (!access) return false; const ids = access?.visible_page_ids; - if (!Array.isArray(ids) || ids.length === 0) return false; - if (ids.includes(pageId)) return true; - const children = KEFU_MENU_PARENT_IDS[pageId]; - return children ? children.some((id) => ids.includes(id)) : false; + if (Array.isArray(ids) && ids.length > 0) { + if (ids.includes(pageId)) return true; + const children = KEFU_MENU_PARENT_IDS[pageId]; + return children ? children.some((id) => ids.includes(id)) : false; + } + const paths = access?.visible_paths; + if (Array.isArray(paths) && paths.length > 0) { + const row = KEFU_MENU_ROWS.find((r) => r.page_id === pageId); + if (row?.path && paths.includes(row.path)) return true; + } + if (Array.isArray(ids) && ids.length === 0) return false; + const row = KEFU_MENU_ROWS.find((r) => r.page_id === pageId); + if (row?.perm_codes?.length) { + return hasPermCode(access, ...row.perm_codes); + } + return false; } export function getFirstVisiblePath() { diff --git a/src/views/order/MerchantOrder.vue b/src/views/order/MerchantOrder.vue index 3b98267..8c71c93 100644 --- a/src/views/order/MerchantOrder.vue +++ b/src/views/order/MerchantOrder.vue @@ -143,18 +143,11 @@ import { ElMessage } from 'element-plus' import { Refresh } from '@element-plus/icons-vue' import request from '@/utils/request' import ClubScopeHint from '@/components/ClubScopeHint.vue' -import { - canShowMenuPage, - clearMenuAccess, - ensureMenuAccess, - JITUAN_API, -} from '@/utils/club-context' const route = useRoute() const router = useRouter() const loading = ref(false) const hasPermission = ref(true) -const menuRetried = ref(false) const PAGE_SIZE = 20 const pageNum = ref(1) @@ -223,12 +216,8 @@ const fetchOrderTypes = async () => { } } -// 商家订单列表接口 +// 商家订单列表:以 API 权限为准,不用前端菜单缓存拦截 const fetchOrders = async () => { - if (!canShowMenuPage('order.merchant')) { - hasPermission.value = false - return - } loading.value = true try { const phone = localStorage.getItem('username') @@ -270,18 +259,6 @@ const fetchOrders = async () => { ] } } else if (res.code === 403) { - if (!menuRetried.value) { - menuRetried.value = true - clearMenuAccess() - await ensureMenuAccess(async () => { - const r = await request.get(JITUAN_API.menuAccess) - return r.code === 0 ? r.data : null - }) - if (canShowMenuPage('order.merchant')) { - await fetchOrders() - return - } - } hasPermission.value = false } else { ElMessage.error(res.msg || '获取订单列表失败') @@ -385,8 +362,6 @@ const getStatusType = (code) => { watch(() => route.query, () => { restoreFromQuery(); fetchOrders() }, { deep: true }) onMounted(() => { - hasPermission.value = canShowMenuPage('order.merchant') - if (!hasPermission.value) return restoreFromQuery() fetchOrderTypes() fetchOrders()