fix(web): 切换账号残留上一账号的标签/菜单;审核按钮不再对已通过的行显示

问题 1(创作者登录后还能看到「工作台」)根因:tagsView.delAllVisitedViews() 会「保留 affix 标签」,
它判断的是 userInfo 是否还在,而 userStore.reset() 是先清标签、后清 userInfo —— 顺序反了,
写死路由表里 affix 的「工作台」标签就跨账号活了下来。整页刷新时不复现,所以只有"退出后不刷新直接登录"
才看得到(PM 复现不到就是这个原因)。修法与加固:

- userStore.reset():先清账号信息再清标签,并调 permissionStore.clearRoutes() 一并清菜单状态
- permissionStore 增加 routersOwner(当前菜单属于哪个账号)+ clearRoutes();守卫发现账号变了会先 resetRouter()
  摘掉上一个账号动态加的路由,再重建(避免两套菜单并存、也避免创作者还能直接进 /dashboard)
- 守卫里"菜单拉取失败沿用上次缓存"这条:换账号后不再沿用(宁可先给空菜单)

问题 2(创作者入驻/审核):真实 UI 全流程(新增→审核→开通→凭据→登录落地)本身能跑通,
但复现出「审核」按钮对**所有状态**都显示 —— 后端状态机是 通过可从 pending/rejected/frozen 发起、
驳回只允许 pending、冻结只允许 approved,对「已通过」的行点审核提交必然 200003 红错。修法:
- 已通过的行不再显示「审核」(保留 冻结/重置密码/开通账号)
- 审核弹窗里的「驳回」只对 pending 显示,其余状态只能通过

顺带修:views/common/DashboardView 取列表时 res 可能为 undefined(拦截器把业务错误吞成 undefined),
账号切换瞬间会抛 Cannot read properties of undefined,已加可选链。
This commit is contained in:
Vicky committed 2026-10-15 16:30:29 +08:00
1 parent 8ce43ccd4c
commit 4509323ba8
6 files changed
+57 -11

No files matched your search

+7 -1
View File
@@ -5,6 +5,7 @@ import { ElMessageBox } from 'element-plus'
import { useI18n } from '@/hooks/web/useI18n'
import { loginOutApi } from '@/api/login'
import { useTagsViewStore } from './tagsView'
import { usePermissionStore } from './permission'
import router from '@/router'
interface UserState {
@@ -78,10 +79,15 @@ export const useUserStore = defineStore('user', {
},
reset() {
const tagsViewStore = useTagsViewStore()
tagsViewStore.delAllViews()
const permissionStore = usePermissionStore()
// 顺序要紧:delAllVisitedViews() 会「保留 affix 标签」,而它判断的正是 userInfo 是否还在。
// 先清账号信息再清标签,否则写死路由表里 affix 的「工作台」会在切换账号后残留。
this.setToken('')
this.setUserInfo(undefined)
this.setRoleRouters([])
tagsViewStore.delAllViews()
// 菜单/路由一起清:否则换账号后 permissionStore 里还是上一个账号的路由表
permissionStore.clearRoutes()
router.replace('/login')
},
logout() {