inleft
2022-02-09 9bcb19959eeb9da9bde2561e7278f6d0a55eb151
commit | author | age
9bcb19 1 export const PERMISSION_ENUM = {
I 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: 'export', label: '导出' }
11 }
12
13 function plugin (Vue) {
14   if (plugin.installed) {
15     return
16   }
17
18   !Vue.prototype.$auth && Object.defineProperties(Vue.prototype, {
19     $auth: {
20       get () {
21         const _this = this
22         return (permissions) => {
23           const [permission, action] = permissions.split('.')
24           const permissionList = _this.$store.getters.roles.permissions
25           return permissionList.find((val) => {
26             return val.permissionId === permission
27           }).actionList.findIndex((val) => {
28             return val === action
29           }) > -1
30         }
31       }
32     }
33   })
34
35   !Vue.prototype.$enum && Object.defineProperties(Vue.prototype, {
36     $enum: {
37       get () {
38         // const _this = this;
39         return (val) => {
40           let result = PERMISSION_ENUM
41           val && val.split('.').forEach(v => {
42             result = result && result[v] || null
43           })
44           return result
45         }
46       }
47     }
48   })
49 }
50
51 export default plugin