This commit is contained in:
zhoutianchi
2026-02-24 17:06:57 +08:00
parent 9699cdc849
commit b971e6de52
4 changed files with 76 additions and 107 deletions

View File

@@ -4,7 +4,7 @@
<LockScreen v-if="themeConfig.isLockScreen" />
<Settings ref="settingsRef" v-show="themeConfig.lockScreenTime > 1" />
<CloseFull v-if="!themeConfig.isLockScreen" />
<ChangeRoleFir ref="changeRoleFirRef" />
<ChangeRole ref="changeRoleFirRef" title="首次登录请选择角色" :require-select-to-close="true" />
</el-config-provider>
</template>
@@ -22,7 +22,7 @@ import setIntroduction from '/@/utils/setIconfont';
const LockScreen = defineAsyncComponent(() => import('/@/layout/lockScreen/index.vue'));
const Settings = defineAsyncComponent(() => import('./layout/navBars/breadcrumb/settings.vue'));
const CloseFull = defineAsyncComponent(() => import('/@/layout/navBars/breadcrumb/closeFull.vue'));
const ChangeRoleFir = defineAsyncComponent(() => import('/@/views/admin/system/role/changeRole-fir.vue'));
const ChangeRole = defineAsyncComponent(() => import('/@/views/admin/system/role/change-role.vue'));
// 定义变量内容
const { messages, locale } = useI18n();
@@ -56,10 +56,19 @@ onBeforeMount(() => {
// 设置批量第三方 js
setIntroduction.jsCdn();
});
// 页面加载时
// 角色选择弹框是否已在本轮打开过(防止事件被触发两次)
let roleDialogOpenedThisSession = false
onMounted(() => {
// 唯一入口:只通过事件打开,且只打开一次;延迟打开以等待异步组件挂载
mittBus.on('openRoleSelectDialog', () => {
if (roleDialogOpenedThisSession) return
roleDialogOpenedThisSession = true
setTimeout(() => {
changeRoleFirRef.value?.open()
}, 300)
})
nextTick(() => {
// 监听布局配'置弹窗点击打开
// 监听布局配置弹窗点击打开
mittBus.on('openSettingsDrawer', () => {
settingsRef.value.openDrawer();
});
@@ -72,18 +81,12 @@ onMounted(() => {
if (Session.get('isTagsViewCurrenFull')) {
stores.setCurrenFullscreen(Session.get('isTagsViewCurrenFull'));
}
// 全局判断:已登录但 Local 缺少角色信息时弹出角色选择;弹框已触发则不再重复弹出
// 与请求拦截器共用同一逻辑:先设标志再 emit由监听器统一打开监听器内会延迟 300ms 以等待异步组件挂载)
if (Session.getToken() && needRoleSelection() && !isRoleDialogTriggered()) {
setRoleDialogTriggered(true);
setTimeout(() => {
changeRoleFirRef.value?.open();
}, 300);
setRoleDialogTriggered(true)
mittBus.emit('openRoleSelectDialog')
}
// 请求拦截器里也会在发送请求时判断并 emit此处统一监听打开弹框
mittBus.on('openRoleSelectDialog', () => {
changeRoleFirRef.value?.open();
});
});
})
});
// 页面销毁时,关闭监听
onUnmounted(() => {