fix
This commit is contained in:
24
src/App.vue
24
src/App.vue
@@ -58,7 +58,7 @@ onBeforeMount(() => {
|
||||
setIntroduction.jsCdn();
|
||||
});
|
||||
// 角色选择弹框是否已在本轮打开过(防止事件被触发两次)
|
||||
let roleDialogOpenedThisSession = false
|
||||
let roleDialogOpenedThisSession = false;
|
||||
|
||||
/** 校验缓存中的 roleId 是否仍在 listAllRole 结果中;若不存在则清除 roleId/roleCode/roleName 并返回 true(需要弹框) */
|
||||
async function validateCachedRoleId(): Promise<boolean> {
|
||||
@@ -67,14 +67,8 @@ async function validateCachedRoleId(): Promise<boolean> {
|
||||
try {
|
||||
const res = await listAllRole();
|
||||
const data = res?.data;
|
||||
const allRoles: any[] = Array.isArray(data)
|
||||
? data
|
||||
: data && typeof data === 'object'
|
||||
? (Object.values(data) as any[]).flat()
|
||||
: [];
|
||||
const exists = allRoles.some(
|
||||
(r: any) => r && String(r.roleId) === String(cachedRoleId)
|
||||
);
|
||||
const allRoles: any[] = Array.isArray(data) ? data : data && typeof data === 'object' ? (Object.values(data) as any[]).flat() : [];
|
||||
const exists = allRoles.some((r: any) => r && String(r.roleId) === String(cachedRoleId));
|
||||
if (!exists) {
|
||||
Local.remove('roleId');
|
||||
Local.remove('roleCode');
|
||||
@@ -90,12 +84,12 @@ async function validateCachedRoleId(): Promise<boolean> {
|
||||
onMounted(() => {
|
||||
// 唯一入口:只通过事件打开,且只打开一次;延迟打开以等待异步组件挂载
|
||||
mittBus.on('openRoleSelectDialog', () => {
|
||||
if (roleDialogOpenedThisSession) return
|
||||
roleDialogOpenedThisSession = true
|
||||
if (roleDialogOpenedThisSession) return;
|
||||
roleDialogOpenedThisSession = true;
|
||||
setTimeout(() => {
|
||||
changeRoleFirRef.value?.open()
|
||||
}, 300)
|
||||
})
|
||||
changeRoleFirRef.value?.open();
|
||||
}, 300);
|
||||
});
|
||||
nextTick(async () => {
|
||||
// 监听布局配置弹窗点击打开
|
||||
mittBus.on('openSettingsDrawer', () => {
|
||||
@@ -121,7 +115,7 @@ onMounted(() => {
|
||||
mittBus.emit('openRoleSelectDialog');
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
});
|
||||
// 页面销毁时,关闭监听
|
||||
onUnmounted(() => {
|
||||
|
||||
Reference in New Issue
Block a user