自动填成当前登陆

This commit is contained in:
zhonghua.li
2026-05-02 17:52:09 +08:00
parent 421912174d
commit 7ba2bc6e4b
4 changed files with 84 additions and 4 deletions

View File

@@ -1,6 +1,7 @@
import Cookies from 'js-cookie'
const TokenKey = 'vue_admin_template_token'
const LoginAccountKey = 'vue_admin_template_login_account'
export function getToken() {
return Cookies.get(TokenKey)
@@ -13,3 +14,33 @@ export function setToken(token) {
export function removeToken() {
return Cookies.remove(TokenKey)
}
/** 当前登录账号(与 token 同步维护,刷新页面后仍可带给业务接口) */
export function getLoginAccount() {
try {
return (window.localStorage.getItem(LoginAccountKey) || '').trim()
} catch (e) {
return ''
}
}
export function setLoginAccount(account) {
const v = account == null ? '' : String(account).trim()
try {
if (v) {
window.localStorage.setItem(LoginAccountKey, v)
} else {
window.localStorage.removeItem(LoginAccountKey)
}
} catch (e) {
// ignore
}
}
export function removeLoginAccount() {
try {
window.localStorage.removeItem(LoginAccountKey)
} catch (e) {
// ignore
}
}