Files
tms-erp-web/src/utils/auth.js
T
b2894lxlx 50c1afe9c8 ✨ 列表导出补齐创建人创建时间,并修复组织类型提交
多模块列表与导出展示创建人、创建时间;组织类型强制提交数字编码,避免中文 dictKey 反序列化失败。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-30 14:22:39 +08:00

57 lines
1.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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);
}