Skip to content

Commit 3c32cd7

Browse files
committed
fix: v-action
1 parent f61ba75 commit 3c32cd7

File tree

4 files changed

+60
-58
lines changed

4 files changed

+60
-58
lines changed

src/core/directives/action.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import Vue from 'vue'
2+
import store from '@/store'
3+
4+
/**
5+
* Action 权限指令
6+
* 指令用法:
7+
* - 在需要控制 action 级别权限的组件上使用 v-action:[method] , 如下:
8+
* <i-button v-action:add >添加用户</a-button>
9+
* <a-button v-action:delete>删除用户</a-button>
10+
* <a v-action:edit @click="edit(record)">修改</a>
11+
*
12+
* - 当前用户没有权限时,组件上使用了该指令则会被隐藏
13+
* - 当后台权限跟 pro 提供的模式不同时,只需要针对这里的权限过滤进行修改即可
14+
*
15+
* @see https://github.com/sendya/ant-design-pro-vue/pull/53
16+
*/
17+
const action = Vue.directive('action', {
18+
inserted: function (el, binding, vnode) {
19+
const actionName = binding.arg
20+
const roles = store.getters.roles
21+
const elVal = vnode.context.$route.meta.permission
22+
const permissionId = elVal instanceof String && [elVal] || elVal
23+
roles.permissions.forEach(p => {
24+
if (!permissionId.includes(p.permissionId)) {
25+
return
26+
}
27+
if (p.actionList && !p.actionList.includes(actionName)) {
28+
el.parentNode && el.parentNode.removeChild(el) || (el.style.display = 'none')
29+
}
30+
})
31+
}
32+
})
33+
34+
export default action

src/core/lazy_use.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Viser from 'viser-vue'
99
// ext library
1010
import VueClipboard from 'vue-clipboard2'
1111
import PermissionHelper from '@/utils/helper/permission'
12+
import './directives/action'
1213

1314
VueClipboard.config.autoSetContainer = true
1415

src/core/use.js

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
1-
import Vue from 'vue'
2-
import VueStorage from 'vue-ls'
3-
import config from '@/config/defaultSettings'
4-
5-
// base library
6-
import Antd from 'ant-design-vue'
7-
import Viser from 'viser-vue'
8-
import VueCropper from 'vue-cropper'
9-
import 'ant-design-vue/dist/antd.less'
10-
11-
// ext library
12-
import VueClipboard from 'vue-clipboard2'
13-
import PermissionHelper from '@/utils/helper/permission'
14-
// import '@/components/use'
15-
16-
VueClipboard.config.autoSetContainer = true
17-
18-
Vue.use(Antd)
19-
Vue.use(Viser)
20-
21-
Vue.use(VueStorage, config.storageOptions)
22-
Vue.use(VueClipboard)
23-
Vue.use(PermissionHelper)
24-
Vue.use(VueCropper)
1+
import Vue from 'vue'
2+
import VueStorage from 'vue-ls'
3+
import config from '@/config/defaultSettings'
4+
5+
// base library
6+
import Antd from 'ant-design-vue'
7+
import Viser from 'viser-vue'
8+
import VueCropper from 'vue-cropper'
9+
import 'ant-design-vue/dist/antd.less'
10+
11+
// ext library
12+
import VueClipboard from 'vue-clipboard2'
13+
import PermissionHelper from '@/utils/helper/permission'
14+
// import '@/components/use'
15+
import './directives/action'
16+
17+
VueClipboard.config.autoSetContainer = true
18+
19+
Vue.use(Antd)
20+
Vue.use(Viser)
21+
22+
Vue.use(VueStorage, config.storageOptions)
23+
Vue.use(VueClipboard)
24+
Vue.use(PermissionHelper)
25+
Vue.use(VueCropper)

src/permission.js

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -67,37 +67,3 @@ router.beforeEach((to, from, next) => {
6767
router.afterEach(() => {
6868
NProgress.done() // finish progress bar
6969
})
70-
71-
/**
72-
* Action 权限指令
73-
* 指令用法:
74-
* - 在需要控制 action 级别权限的组件上使用 v-action:[method] , 如下:
75-
* <i-button v-action:add >添加用户</a-button>
76-
* <a-button v-action:delete>删除用户</a-button>
77-
* <a v-action:edit @click="edit(record)">修改</a>
78-
*
79-
* - 当前用户没有权限时,组件上使用了该指令则会被隐藏
80-
* - 当后台权限跟 pro 提供的模式不同时,只需要针对这里的权限过滤进行修改即可
81-
*
82-
* @see https://github.com/sendya/ant-design-pro-vue/pull/53
83-
*/
84-
const action = Vue.directive('action', {
85-
bind: function (el, binding, vnode) {
86-
const actionName = binding.arg
87-
const roles = store.getters.roles
88-
const elVal = vnode.context.$route.meta.permission
89-
const permissionId = elVal instanceof String && [elVal] || elVal
90-
roles.permissions.forEach(p => {
91-
if (!permissionId.includes(p.permissionId)) {
92-
return
93-
}
94-
if (p.actionList && !p.actionList.includes(actionName)) {
95-
el.parentNode && el.parentNode.removeChild(el) || (el.style.display = 'none')
96-
}
97-
})
98-
}
99-
})
100-
101-
export {
102-
action
103-
}

0 commit comments

Comments
 (0)