This commit is contained in:
zhoutianchi
2026-03-04 18:22:46 +08:00
parent 1600b44440
commit 39bab0f1c2
4 changed files with 95 additions and 15 deletions

View File

@@ -42,7 +42,7 @@
<script setup lang="ts">
import { ref, computed, toRef } from 'vue'
import { listAllRole } from '/@/api/admin/role'
import { Local } from '/@/utils/storage'
import { Local, Session } from '/@/utils/storage'
import { useMessage } from '/@/hooks/message'
/** 弹框标题,如「角色切换」「登录角色选择」 */
@@ -108,9 +108,14 @@ const handleChangeRole = (label: string) => {
Local.set('roleName', obj.roleName)
Local.set('roleId', obj.roleId)
useMessage().success('操作成功')
// 清掉 tags 缓存,重载后只保留首页 tag
Session.remove('tagsViewList')
// 清除 pinia 持久化的 tagsView 路由,避免重载后先恢复旧角色菜单再被新路由覆盖前就初始化出“不存在的 tag”
try {
window.localStorage.removeItem('tagsViewRoutes')
} catch (_) {}
setTimeout(() => {
// 切换角色后统一回到首页,避免停留在诸如 jsonflow/run-job/do-job 等内部路由
window.location.hash = '#/'
window.location.hash = '#/home'
window.location.reload()
}, 500)
}