parent
ba933acf76
commit
cc375077da
7 changed files with 34 additions and 62 deletions
@ -1,26 +0,0 @@ |
|||||||
import store from "@/store"; |
|
||||||
import router from "@/router"; |
|
||||||
|
|
||||||
export default function() { |
|
||||||
setTimeout(() => { |
|
||||||
let routes = store.state.auth.routes; |
|
||||||
routes.forEach(e => { |
|
||||||
if (e.path == "/") { |
|
||||||
e.component = () => import("@/layouts/home/index.vue"); |
|
||||||
} else { |
|
||||||
e.component = () => import(`@/pages/${e.path}.vue`); |
|
||||||
} |
|
||||||
|
|
||||||
e.children && e.children.forEach(n => { |
|
||||||
n.path && (n.component = () => import(`@/pages/${n.path}.vue`)); |
|
||||||
}); |
|
||||||
}); |
|
||||||
|
|
||||||
routes.push({ |
|
||||||
path: "*", |
|
||||||
redirect: "404" |
|
||||||
}); |
|
||||||
|
|
||||||
router.addRoutes(routes); |
|
||||||
}, 500); |
|
||||||
} |
|
@ -1,29 +1,21 @@ |
|||||||
/** |
/** |
||||||
* @description 鉴权指令 |
* @description 鉴权指令 |
||||||
* 当传入的权限当前用户没有时,会移除该组件 |
* 当传入的权限当前用户没有时,会移除该组件 |
||||||
* 用例:<Tag v-auth>text</Tag> 或者:<Tag v-auth="'user:编辑'">text</Tag> |
* 用例:<Tag v-auth>text</Tag> 或者:<Tag v-auth="'编辑'">text</Tag> |
||||||
* */ |
* */ |
||||||
import store from "@/store"; |
import store from '@/store' |
||||||
|
|
||||||
export default { |
export default { |
||||||
inserted(el, binding, vnode) { |
inserted(el, binding, vnode) { |
||||||
let btnText = ""; |
const val = binding.value |
||||||
// 如果有传值,就取传的值,否则,就取页面路由和按钮名字拼接起来
|
// 如果有传值,就取传的值,否则,就取按钮名字
|
||||||
const route = vnode.context.$route.path |
const text = vnode.context.$route.path + ':' + (val || el.innerText) |
||||||
if (binding.value) { |
const { btns } = store.state.auth |
||||||
btnText = route + ':' + binding.value |
if (text && btns && btns.length) { |
||||||
} else { |
// 如果按钮集合里没有该权限,就把该按钮给去除
|
||||||
btnText = route + ':' + el.innerText |
if (!btns.includes(text)) { |
||||||
} |
el.parentNode && el.parentNode.removeChild(el) |
||||||
const btnPermissions = store.state.auth.btns; |
} |
||||||
|
} |
||||||
if (btnText && btnPermissions && btnPermissions.length) { |
} |
||||||
const isPermission = btnPermissions.includes(btnText); |
} |
||||||
// 如果按钮集合里没有该权限,就把该按钮给去除
|
|
||||||
if (!isPermission) { |
|
||||||
el.parentNode && el.parentNode.removeChild(el); |
|
||||||
} |
|
||||||
} |
|
||||||
}, |
|
||||||
|
|
||||||
}; |
|
||||||
|
Loading…
Reference in new issue