feat: 添加按钮权限

This commit is contained in:
xiaoxian521
2021-06-30 14:29:40 +08:00
parent a8bc76ed9c
commit ad1de9530a
11 changed files with 137 additions and 72 deletions

View File

@@ -8,12 +8,28 @@ export const usePermissionStore = defineStore({
state: () => ({
constantRoutes: constantRoutesArr, //静态路由
wholeRoutes: [],
buttonAuth: [],
}),
actions: {
asyncActionRoutes(routes) {
if (this.wholeRoutes.length > 0) return;
this.wholeRoutes = ascending(this.constantRoutes.concat(routes)).filter(
(v) => v.meta.showLink
);
const getButtonAuth = (arrRoutes: Array<string>) => {
if (!arrRoutes || !arrRoutes.length) return;
arrRoutes.forEach((v: any) => {
if (v.meta && v.meta.authority) {
this.buttonAuth.push(...v.meta.authority);
}
if (v.children) {
getButtonAuth(v.children);
}
});
};
getButtonAuth(this.wholeRoutes);
},
async changeSetting(routes) {
await this.asyncActionRoutes(routes);