fix: 菜单严格按服务端visible_paths,切换俱乐部强制刷新
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -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 = '15';
|
||||
const MENU_SESSION_VERSION = '16';
|
||||
const DEFAULT_CLUB_ID = 'xq';
|
||||
|
||||
let menuAccessInflight = null;
|
||||
@@ -196,24 +196,17 @@ function pageAllowedByCodes(pageId, codes) {
|
||||
export function getEffectiveVisiblePaths(access = null) {
|
||||
const a = access || getMenuAccess();
|
||||
const paths = a?.visible_paths;
|
||||
if (Array.isArray(paths) && paths.length > 0) {
|
||||
return paths;
|
||||
}
|
||||
return pathsFromPermissionCodes(a?.permission_codes || []);
|
||||
return Array.isArray(paths) ? paths : [];
|
||||
}
|
||||
|
||||
export function canShowMenuPage(pageId) {
|
||||
const access = getMenuAccess();
|
||||
if (shouldShowAllMenus(access)) return true;
|
||||
if (!access) return false;
|
||||
const ids = access?.visible_page_ids;
|
||||
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 codes = access?.permission_codes || [];
|
||||
if (!codes.length) return false;
|
||||
return pageAllowedByCodes(pageId, codes);
|
||||
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;
|
||||
}
|
||||
|
||||
export function getFirstVisiblePath() {
|
||||
@@ -248,17 +241,15 @@ export function formatNoMenuAccessMessage(access) {
|
||||
}
|
||||
|
||||
export function canSwitchClubByMenu() {
|
||||
const ctx = getAdminClubContext();
|
||||
if (ctx?.can_switch_club) return true;
|
||||
const access = getMenuAccess();
|
||||
if (!access || !isMenuSessionFresh()) {
|
||||
const ctx = getAdminClubContext();
|
||||
return !!ctx?.can_switch_club;
|
||||
}
|
||||
return !!access.can_switch_club;
|
||||
return !!access?.can_switch_club;
|
||||
}
|
||||
|
||||
export async function ensureMenuAccess(fetcher) {
|
||||
export async function ensureMenuAccess(fetcher, { force = false } = {}) {
|
||||
if (!localStorage.getItem('token')) return getMenuAccess();
|
||||
if (isMenuSessionFresh() && getMenuAccess()) {
|
||||
if (!force && isMenuSessionFresh() && getMenuAccess()) {
|
||||
return getMenuAccess();
|
||||
}
|
||||
if (!menuAccessInflight) {
|
||||
|
||||
@@ -317,7 +317,7 @@ const loadMenuAccess = async () => {
|
||||
await ensureMenuAccess(async () => {
|
||||
const res = await request.get(JITUAN_API.menuAccess)
|
||||
return res.code === 0 ? res.data : null
|
||||
})
|
||||
}, { force: true })
|
||||
const data = getMenuAccess()
|
||||
if (data) {
|
||||
menuAccessState.value = data
|
||||
|
||||
Reference in New Issue
Block a user