3.10 工程代码同步master
This commit is contained in:
@ -1,9 +1,10 @@
|
||||
import { reloadAuthorized } from './Authorized';
|
||||
//import { reloadAuthorized } from './Authorized';
|
||||
import { getRA, getPurchaseCanOperate } from './session';
|
||||
|
||||
// use localStorage to store the authority info, which might be sent from server in actual project.
|
||||
export function getAuthority(str?: string): string | string[] {
|
||||
const authorityString =
|
||||
typeof str === 'undefined' && localStorage ? localStorage.getItem('antd-pro-authority') : str;
|
||||
typeof str === 'undefined' && sessionStorage ? sessionStorage.getItem('roleAuthority') : str;
|
||||
// authorityString could be admin, "admin", ["admin"]
|
||||
let authority;
|
||||
try {
|
||||
@ -18,15 +19,36 @@ export function getAuthority(str?: string): string | string[] {
|
||||
}
|
||||
// preview.pro.ant.design only do not use in your production.
|
||||
// preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。
|
||||
if (!authority && ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site') {
|
||||
return ['admin'];
|
||||
}
|
||||
// if (!authority && ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site') {
|
||||
// return ['admin'];
|
||||
// }
|
||||
return authority;
|
||||
}
|
||||
|
||||
export function setAuthority(authority: string | string[]): void {
|
||||
const proAuthority = typeof authority === 'string' ? [authority] : authority;
|
||||
localStorage.setItem('antd-pro-authority', JSON.stringify(proAuthority));
|
||||
// auto reload
|
||||
reloadAuthorized();
|
||||
// export function setAuthority(authority: string | string[]): void {
|
||||
// const proAuthority = typeof authority === 'string' ? [authority] : authority;
|
||||
// sessionStorage.setItem('roleAuthority', JSON.stringify(proAuthority));
|
||||
// // auto reload
|
||||
// reloadAuthorized();
|
||||
// }
|
||||
//全局按钮控制 登陆角色是否显示功能 不显示:return true
|
||||
export function btnAuthority(allowedRoles: string[]) {
|
||||
const roles = getRA();//当前登陆账号的角色数组
|
||||
let control = true;
|
||||
//根据session中的 采购经理是否可操作 属性,返回控制值
|
||||
if (getPurchaseCanOperate() == null) {
|
||||
control = false;
|
||||
}
|
||||
//根据传入得可操作角色 返回控制值
|
||||
if (!control && allowedRoles?.length > 0 && roles != null) {
|
||||
for (let index = 0; index < allowedRoles.length; index++) {
|
||||
const element = allowedRoles[index];
|
||||
control = !roles.includes(element);//传入的角色有一个有权限就跳出,反false(显示)
|
||||
if (!control) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return control;
|
||||
}
|
||||
|
Reference in New Issue
Block a user