fix: 商家订单以API为准,菜单与permission_codes对齐
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user