auth-service.ts 2.9 KB
Newer Older
1
import store from '@/store';
2 3 4 5 6 7 8 9 10 11 12
/**
 * 实体权限服务
 *
 * @export
 * @class AuthService
 */
export default class AuthService {

    /**
     * Vue 状态管理器
     *
13
     * @public
14 15 16
     * @type {(any | null)}
     * @memberof AuthService
     */
17 18 19 20 21 22 23 24 25 26
    public $store: any;

    /**
     * 系统操作标识映射统一资源Map
     *
     * @public
     * @type {Map<string,any>}
     * @memberof AuthService
     */
    public sysOPPrivsMap:Map<string,any> = new  Map();
27 28

    /**
29
     * 默认操作标识
30 31 32 33 34
     *
     * @public
     * @type {(any)}
     * @memberof AuthService
     */
35
    public defaultOPPrivs: any = {CREATE: 1,DELETE: 1,DENY: 1,NONE: 1,READ: 1,TEST1: 1,UPDATE: 1,WFSTART: 1}; 
36 37 38 39 40 41 42 43

    /**
     * Creates an instance of AuthService.
     * 
     * @param {*} [opts={}]
     * @memberof AuthService
     */
    constructor(opts: any = {}) {
44 45
        this.$store = store;
        this.registerSysOPPrivs();
46 47 48 49 50 51 52 53
    }

    /**
     * 获取状态管理器
     *
     * @returns {(any | null)}
     * @memberof AuthService
     */
54
    public getStore(): any {
55 56 57
        return this.$store;
    }

58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
    /**
     * 获取计算统一资源之后的系统操作标识
     *
     * @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;
    }

75 76 77 78 79 80 81 82 83 84 85
    /**
     * 获取实体权限服务
     *
     * @param {string} name 实体名称
     * @returns {Promise<any>}
     * @memberof AuthService
     */
    public getService(name: string): Promise<any> {
        return (window as any)['authServiceRegister'].getService(name);
    }

86 87 88 89 90 91 92 93 94 95
    /**
     * 注册系统操作标识统一资源
     *
     * @param {string} name 实体名称
     * @returns {Promise<any>}
     * @memberof AuthService
     */ 
    public registerSysOPPrivs(){
    }

96 97 98 99
    /**
     * 根据当前数据获取实体操作标识
     *
     * @param {string} name 实体名称
100
     * @returns {any}
101 102
     * @memberof AuthService
     */
103
    public getOPPrivs(data: any): any {
104 105 106 107 108 109 110 111 112 113
        return null;
    }

    /**
     * 根据菜单项获取菜单权限
     *
     * @param {*} item 菜单标识
     * @returns {boolean}
     * @memberof AuthService
     */
114
    public getMenusPermission(item: any): boolean {
115
        return this.$store.getters['authresource/getAuthMenu'](item);
116 117 118 119 120 121 122 123 124
    }

    /**
     * 根据统一资源标识获取统一资源权限
     *
     * @param {*} tag 统一资源标识
     * @returns {boolean}
     * @memberof AuthService
     */
125
    public getResourcePermission(tag: any): boolean {
126
        return this.$store.getters['authresource/getResourceData'](tag);
127 128 129
    }

}