1+ const PERMISSION_ENUM = {
2+ 'add' : { key : 'add' , label : '新增' } ,
3+ 'delete' : { key : 'delete' , label : '删除' } ,
4+ 'edit' : { key : 'edit' , label : '修改' } ,
5+ 'query' : { key : 'query' , label : '查询' } ,
6+ 'get' : { key : 'get' , label : '详情' } ,
7+ 'enable' : { key : 'enable' , label : '启用' } ,
8+ 'disable' : { key : 'disable' , label : '禁用' } ,
9+ 'import' : { key : 'import' , label : '导入' } ,
10+ 'export' : { key : 'import' , label : '导入' } ,
11+ } ;
12+
13+ function plugin ( Vue ) {
14+
15+ if ( plugin . installed ) {
16+ return ;
17+ }
18+
19+ ! Vue . prototype . $auth && Object . defineProperties ( Vue . prototype , {
20+ $auth : {
21+ get ( ) {
22+ const _this = this ;
23+ return ( permissions ) => {
24+ let [ permission , action ] = permissions . split ( '.' ) ;
25+ const permissionList = _this . $store . getters . roles . permissions ;
26+ permissionList . find ( ( val ) => {
27+ return val . permissionId === permission
28+ } ) . actionList . findIndex ( ( val ) => {
29+ return val === action
30+ } ) ;
31+ return false
32+ }
33+ }
34+ }
35+ } ) ;
36+
37+ ! Vue . prototype . $enum && Object . defineProperties ( Vue . prototype , {
38+ $enum : {
39+ get ( ) {
40+ // const _this = this;
41+ return ( val ) => {
42+ let result = PERMISSION_ENUM ;
43+ val && val . split ( '.' ) . forEach ( v => {
44+ result = result && result [ v ] || null
45+ } ) ;
46+ return result
47+ }
48+ }
49+ }
50+ } ) ;
51+ }
52+
53+ export default plugin
0 commit comments