mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-27 01:15:10 +08:00
前端 Token、账号、密码等信息,统一使用 LocalStorage 替代 Cookie 存储
This commit is contained in:
@ -1,22 +1,96 @@
|
||||
import Cookies from 'js-cookie'
|
||||
import {decrypt, encrypt} from "@/utils/jsencrypt";
|
||||
|
||||
const AccessTokenKey = 'ACCESS_TOKEN'
|
||||
const RefreshTokenKey = 'REFRESH_TOKEN'
|
||||
|
||||
// ========== Token 相关 ==========
|
||||
|
||||
export function getAccessToken() {
|
||||
return Cookies.get(AccessTokenKey)
|
||||
return localStorage.getItem(AccessTokenKey)
|
||||
}
|
||||
|
||||
export function getRefreshToken() {
|
||||
return Cookies.get(RefreshTokenKey)
|
||||
return localStorage.getItem(RefreshTokenKey)
|
||||
}
|
||||
|
||||
export function setToken(token) {
|
||||
Cookies.set(AccessTokenKey, token.accessToken)
|
||||
Cookies.set(RefreshTokenKey, token.refreshToken)
|
||||
localStorage.setItem(AccessTokenKey, token.accessToken)
|
||||
localStorage.setItem(RefreshTokenKey, token.refreshToken)
|
||||
}
|
||||
|
||||
export function removeToken() {
|
||||
Cookies.remove(AccessTokenKey)
|
||||
Cookies.remove(RefreshTokenKey)
|
||||
localStorage.removeItem(AccessTokenKey)
|
||||
localStorage.removeItem(RefreshTokenKey)
|
||||
}
|
||||
|
||||
// ========== 账号相关 ==========
|
||||
|
||||
const UsernameKey = 'USERNAME'
|
||||
const PasswordKey = 'PASSWORD'
|
||||
const RememberMeKey = 'REMEMBER_ME'
|
||||
|
||||
export function getUsername() {
|
||||
return localStorage.getItem(UsernameKey)
|
||||
}
|
||||
|
||||
export function setUsername(username) {
|
||||
localStorage.setItem(UsernameKey, username)
|
||||
}
|
||||
|
||||
export function removeUsername() {
|
||||
localStorage.removeItem(UsernameKey)
|
||||
}
|
||||
|
||||
export function getPassword() {
|
||||
const password = localStorage.getItem(PasswordKey)
|
||||
return password ? decrypt(password) : undefined
|
||||
}
|
||||
|
||||
export function setPassword(password) {
|
||||
localStorage.setItem(PasswordKey, encrypt(password))
|
||||
}
|
||||
|
||||
export function removePassword() {
|
||||
localStorage.removeItem(PasswordKey)
|
||||
}
|
||||
|
||||
export function getRememberMe() {
|
||||
return localStorage.getItem(RememberMeKey) === 'true'
|
||||
}
|
||||
|
||||
export function setRememberMe(rememberMe) {
|
||||
localStorage.setItem(RememberMeKey, rememberMe)
|
||||
}
|
||||
|
||||
export function removeRememberMe() {
|
||||
localStorage.removeItem(RememberMeKey)
|
||||
}
|
||||
|
||||
// ========== 租户相关 ==========
|
||||
|
||||
const TenantIdKey = 'TENANT_ID'
|
||||
const TenantNameKey = 'TENANT_NAME'
|
||||
|
||||
export function getTenantName() {
|
||||
return localStorage.getItem(TenantNameKey)
|
||||
}
|
||||
|
||||
export function setTenantName(username) {
|
||||
localStorage.setItem(TenantNameKey, username)
|
||||
}
|
||||
|
||||
export function removeTenantName() {
|
||||
localStorage.removeItem(TenantNameKey)
|
||||
}
|
||||
|
||||
export function getTenantId() {
|
||||
return localStorage.getItem(TenantIdKey)
|
||||
}
|
||||
|
||||
export function setTenantId(username) {
|
||||
localStorage.setItem(TenantIdKey, username)
|
||||
}
|
||||
|
||||
export function removeTenantId() {
|
||||
localStorage.removeItem(TenantIdKey)
|
||||
}
|
||||
|
Reference in New Issue
Block a user