-
Notifications
You must be signed in to change notification settings - Fork 501
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
225 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import Vue from 'vue' | ||
import permission from './permission' | ||
|
||
const directives = [permission] | ||
directives.forEach(d => Vue.use(d)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import permission from './permission' | ||
|
||
const install = function(Vue) { | ||
Vue.directive('permission', permission) | ||
} | ||
|
||
if (window.Vue) { | ||
window['permission'] = permission | ||
Vue.use(install); // eslint-disable-line | ||
} | ||
|
||
permission.install = install | ||
export default permission |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import store from '@/store' | ||
|
||
export default { | ||
inserted(el, binding, vnode) { | ||
const { value } = binding | ||
|
||
if(store.getters.buttonMap.size == undefined) { | ||
// 初始加载的时候,还没有写入到vuex中,因此使用setInterval在下次dom更新时生效 | ||
let intervalID = setInterval(() => { | ||
// 得到按钮上的路径 | ||
const buttonMap = store.getters.buttonMap | ||
if (value && value.length > 0) { | ||
const path = value | ||
const hasPermission = buttonMap.get(path) | ||
|
||
// 没有权限时,是否显示按钮,取决于button管理的上 是否显示 的设置 | ||
if (!hasPermission) { | ||
el.parentNode && el.parentNode.removeChild(el) | ||
} | ||
} | ||
// 清空触发器 | ||
if(store.getters.buttonMap.size != undefined) { | ||
clearInterval(intervalID); | ||
} | ||
},100); | ||
} else { | ||
// 得到按钮上的路径 | ||
|
||
const buttonMap = store.getters.buttonMap | ||
if (value && value.length > 0) { | ||
const path = value | ||
const hasPermission = buttonMap.get(path) | ||
if (!hasPermission) { | ||
el.parentNode && el.parentNode.removeChild(el) | ||
} | ||
} else { | ||
throw new Error(`need roles! Like v-permission="'admin'"`) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.