✨ 新增管理员代登录功能

This commit is contained in:
caojia
2026-11-04 15:20:05 +08:00
parent 93da04fe5e
commit 5cccbf510f
17 changed files with 540 additions and 18 deletions
+4 -1
View File
@@ -1,10 +1,11 @@
import cache from '@/plugins/cache'
import useSettingsStore from '@/store/modules/settings'
import { getImpersonationToken } from '@/utils/auth'
const PERSIST_KEY = 'tags-view-visited'
function isPersistEnabled() {
return useSettingsStore().tagsViewPersist
return !getImpersonationToken() && useSettingsStore().tagsViewPersist
}
function saveVisitedViews(views) {
@@ -14,10 +15,12 @@ function saveVisitedViews(views) {
}
function loadVisitedViews() {
if (getImpersonationToken()) return []
return cache.local.getJSON(PERSIST_KEY) || []
}
function clearVisitedViews() {
if (getImpersonationToken()) return
cache.local.remove(PERSIST_KEY)
}
+17 -4
View File
@@ -2,7 +2,8 @@ import router from '@/router'
import cache from '@/plugins/cache'
import { ElMessageBox, } from 'element-plus'
import { login, logout, getInfo } from '@/api/login'
import { getToken, setToken, removeToken } from '@/utils/auth'
import { getToken, setToken, removeToken, getImpersonationToken, clearImpersonationToken } from '@/utils/auth'
import { exitImpersonation } from '@/api/system/user'
import { isHttp, isEmpty } from "@/utils/validate"
import useLockStore from '@/store/modules/lock'
import useDictStore from '@/store/modules/dict'
@@ -18,7 +19,8 @@ const useUserStore = defineStore(
nickName: '',
avatar: '',
roles: [],
permissions: []
permissions: [],
impersonating: false
}),
actions: {
// 登录
@@ -57,6 +59,7 @@ const useUserStore = defineStore(
this.name = user.userName
this.nickName = user.nickName
this.avatar = avatar
this.impersonating = !!res.impersonating
cache.session.set('pwrChrtype', res.pwdChrtype)
/* 改密提示展示标记:通知弹屏组件读取该标记,等改密框关闭后再弹通知,避免双框冲突 */
const showPwdPrompt = (msg) => {
@@ -68,11 +71,11 @@ const useUserStore = defineStore(
})
}
/* 初始密码提示 */
if(res.isDefaultModifyPwd) {
if(!this.impersonating && res.isDefaultModifyPwd) {
showPwdPrompt('您的密码还是初始密码,请修改密码!')
}
/* 过期密码提示 */
if(!res.isDefaultModifyPwd && res.isPasswordExpired) {
if(!this.impersonating && !res.isDefaultModifyPwd && res.isPasswordExpired) {
showPwdPrompt('您的密码已过期,请尽快修改密码!')
}
resolve(res)
@@ -83,6 +86,16 @@ const useUserStore = defineStore(
},
// 退出系统
logOut() {
if (getImpersonationToken()) {
return exitImpersonation().then(() => {
clearImpersonationToken()
this.token = getToken()
this.roles = []
this.permissions = []
this.impersonating = false
useDictStore().cleanDict()
})
}
return new Promise((resolve, reject) => {
logout(this.token).then(() => {
this.token = ''