提交 7e1a805d 编写于 作者: KK's avatar KK

权限服务基类

上级 d68ff382
<#ibiztemplate>
TARGET=PSSYSAPP
</#ibiztemplate>
import store from '@/store';
/**
* 实体权限服务基类
*
* @export
* @class AuthService
*/
export class AuthService {
/**
* Vue 状态管理器
*
* @public
* @type {(any | null)}
* @memberof AuthService
*/
public $store: any;
/**
* 系统操作标识映射统一资源Map
*
* @public
* @type {Map<string,any>}
* @memberof AuthService
*/
public sysOPPrivsMap:Map<string,any> = new Map();
/**
* 默认操作标识
*
* @public
* @type {(any)}
* @memberof AuthService
*/
public defaultOPPrivs: any = {<#if sys.getAllPSDEOPPrivs()??><#list sys.getAllPSDEOPPrivs() as sysOPPrivs>${sysOPPrivs.getName()}: 1<#if sysOPPrivs_has_next>,</#if></#list></#if>};
/**
* Creates an instance of AuthService.
*
* @param {*} [opts={}]
* @memberof AuthService
*/
constructor(opts: any = {}) {
this.$store = store;
this.registerSysOPPrivs();
}
/**
* 获取状态管理器
*
* @returns {(any | null)}
* @memberof AuthService
*/
public getStore(): any {
return this.$store;
}
/**
* 获取计算统一资源之后的系统操作标识
*
* @returns {}
* @memberof AuthService
*/
public getSysOPPrivs(){
let copySysOPPrivs:any = JSON.parse(JSON.stringify(this.defaultOPPrivs));
if(Object.keys(copySysOPPrivs).length === 0) return {};
Object.keys(copySysOPPrivs).forEach((name:any) =>{
if(this.sysOPPrivsMap.get(name)){
copySysOPPrivs[name] = this.getResourcePermission(this.sysOPPrivsMap.get(name))?1:0;
}
})
return copySysOPPrivs;
}
/**
* 获取实体权限服务
*
* @param {string} name 实体名称
* @returns {Promise<any>}
* @memberof AuthService
*/
public getService(name: string): Promise<any> {
return window.authServiceConstructor.getService(name);
}
/**
* 注册系统操作标识统一资源
*
* @param {string} name 实体名称
* @returns {Promise<any>}
* @memberof AuthService
*/
public registerSysOPPrivs(){
<#if sys.getAllPSDEOPPrivs()??>
<#list sys.getAllPSDEOPPrivs() as sysOPPrivs>
<#if sysOPPrivs.getMapPSSysUniRes()??>
this.sysOPPrivsMap.set('${sysOPPrivs.getName()}','${sysOPPrivs.getMapPSSysUniRes().getResCode()}');
</#if>
</#list>
</#if>
}
/**
* 根据当前数据获取实体操作标识
*
* @param {string} name 实体名称
* @returns {any}
* @memberof AuthService
*/
public getOPPrivs(data: any): any {
return null;
}
/**
* 根据菜单项获取菜单权限
*
* @param {*} item 菜单标识
* @returns {boolean}
* @memberof AuthService
*/
public getMenusPermission(item: any): boolean {
return this.$store.getters['authresource/getAuthMenu'](item);
}
/**
* 根据统一资源标识获取统一资源权限
*
* @param {*} tag 统一资源标识
* @returns {boolean}
* @memberof AuthService
*/
public getResourcePermission(tag: any): boolean {
return this.$store.getters['authresource/getResourceData'](tag);
}
/**
* 获取计算统一资源之后的系统操作标识
*
* @returns {}
* @memberof AuthService
*/
public getSysOPPrivs(){
let copySysOPPrivs:any = JSON.parse(JSON.stringify(this.defaultOPPrivs));
if(Object.keys(copySysOPPrivs).length === 0) return {};
Object.keys(copySysOPPrivs).forEach((name:any) =>{
if(this.sysOPPrivsMap.get(name)){
copySysOPPrivs[name] = this.getResourcePermission(this.sysOPPrivsMap.get(name))?1:0;
}
})
return copySysOPPrivs;
}
}
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册