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 鉴权指令 |
||||
* 当传入的权限当前用户没有时,会移除该组件 |
||||
* 用例:<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 { |
||||
inserted(el, binding, vnode) { |
||||
let btnText = ""; |
||||
// 如果有传值,就取传的值,否则,就取页面路由和按钮名字拼接起来
|
||||
const route = vnode.context.$route.path |
||||
if (binding.value) { |
||||
btnText = route + ':' + binding.value |
||||
} else { |
||||
btnText = route + ':' + el.innerText |
||||
} |
||||
const btnPermissions = store.state.auth.btns; |
||||
|
||||
if (btnText && btnPermissions && btnPermissions.length) { |
||||
const isPermission = btnPermissions.includes(btnText); |
||||
// 如果按钮集合里没有该权限,就把该按钮给去除
|
||||
if (!isPermission) { |
||||
el.parentNode && el.parentNode.removeChild(el); |
||||
} |
||||
} |
||||
}, |
||||
|
||||
}; |
||||
inserted(el, binding, vnode) { |
||||
const val = binding.value |
||||
// 如果有传值,就取传的值,否则,就取按钮名字
|
||||
const text = vnode.context.$route.path + ':' + (val || el.innerText) |
||||
const { btns } = store.state.auth |
||||
if (text && btns && btns.length) { |
||||
// 如果按钮集合里没有该权限,就把该按钮给去除
|
||||
if (!btns.includes(text)) { |
||||
el.parentNode && el.parentNode.removeChild(el) |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue