50c1afe9c8
多模块列表与导出展示创建人、创建时间;组织类型强制提交数字编码,避免中文 dictKey 反序列化失败。 Co-authored-by: Cursor <cursoragent@cursor.com>
57 lines
1.5 KiB
JavaScript
57 lines
1.5 KiB
JavaScript
import Cookies from 'js-cookie';
|
||
import website from '@/config/website';
|
||
|
||
const TokenKey = website.tokenKey;
|
||
const RefreshTokenKey = website.refreshTokenKey;
|
||
const SessionId = 'JSESSIONID';
|
||
const UserId = 'b-user-id';
|
||
|
||
/** 超级管理员角色别名 */
|
||
export const ADMINISTRATOR_ROLE_ALIAS = 'administrator';
|
||
|
||
/**
|
||
* 是否超级管理员:角色别名中包含 administrator 即为超级管理员
|
||
*
|
||
* @param {object|string|string[]} [userInfoOrAuthority] 用户信息,或 authority / role_name 字符串/数组
|
||
* @returns {boolean}
|
||
*/
|
||
export function isAdministrator(userInfoOrAuthority) {
|
||
let authority = userInfoOrAuthority;
|
||
if (authority && typeof authority === 'object' && !Array.isArray(authority)) {
|
||
authority = authority.authority ?? authority.role_name ?? authority.roleName ?? '';
|
||
}
|
||
const roles = Array.isArray(authority)
|
||
? authority
|
||
: String(authority || '')
|
||
.split(/[,,]/)
|
||
.map(role => role.trim())
|
||
.filter(Boolean);
|
||
return roles.some(role => String(role).trim() === ADMINISTRATOR_ROLE_ALIAS);
|
||
}
|
||
|
||
export function getToken() {
|
||
return Cookies.get(TokenKey);
|
||
}
|
||
|
||
export function setToken(token) {
|
||
return Cookies.set(TokenKey, token);
|
||
}
|
||
|
||
export function getRefreshToken() {
|
||
return Cookies.get(RefreshTokenKey);
|
||
}
|
||
|
||
export function setRefreshToken(token) {
|
||
return Cookies.set(RefreshTokenKey, token);
|
||
}
|
||
|
||
export function removeToken() {
|
||
Cookies.remove(SessionId);
|
||
Cookies.remove(UserId);
|
||
return Cookies.remove(TokenKey);
|
||
}
|
||
|
||
export function removeRefreshToken() {
|
||
return Cookies.remove(RefreshTokenKey);
|
||
}
|