diff --git a/src/utils/club-context.js b/src/utils/club-context.js index c07342f..51e8374 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 = '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) { diff --git a/src/views/Layout.vue b/src/views/Layout.vue index 3eefd4a..6be6514 100644 --- a/src/views/Layout.vue +++ b/src/views/Layout.vue @@ -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