权限遮罩
This commit is contained in:
@@ -51,3 +51,49 @@ export function setSerch(data) {
|
||||
export function getSerch() {
|
||||
return JSON.parse(localStorage.getItem('Serch'));
|
||||
}
|
||||
|
||||
// ==================== 权限管理 ====================
|
||||
|
||||
const PERMISSIONS_KEY = 'user_permissions';
|
||||
|
||||
/**
|
||||
* 存储权限信息
|
||||
* @param {Object} permissions - 权限对象 { bigBrother, crawl, webAi }
|
||||
*/
|
||||
export function setPermissions(permissions) {
|
||||
localStorage.setItem(PERMISSIONS_KEY, JSON.stringify({
|
||||
bigBrother: permissions.bigBrother ?? 0,
|
||||
crawl: permissions.crawl ?? 0,
|
||||
webAi: permissions.webAi ?? 0,
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取权限信息
|
||||
* @returns {Object} 权限对象 { bigBrother, crawl, webAi }
|
||||
*/
|
||||
export function getPermissions() {
|
||||
try {
|
||||
const permissions = JSON.parse(localStorage.getItem(PERMISSIONS_KEY));
|
||||
return permissions || { bigBrother: 0, crawl: 0, webAi: 0 };
|
||||
} catch {
|
||||
return { bigBrother: 0, crawl: 0, webAi: 0 };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除权限信息
|
||||
*/
|
||||
export function clearPermissions() {
|
||||
localStorage.removeItem(PERMISSIONS_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查特定权限
|
||||
* @param {string} permissionKey - 'bigBrother' | 'crawl' | 'webAi'
|
||||
* @returns {boolean} 是否有权限
|
||||
*/
|
||||
export function hasPermission(permissionKey) {
|
||||
const permissions = getPermissions();
|
||||
return permissions[permissionKey] === 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user