You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
LiaoNingDangAn/src/store/modules/myselfPermission.js

95 lines
2.6 KiB

import { getselfInfo } from "@/api/external";
import { Message } from "element-ui";
import { getcarid } from "@/api/jcy";
import router from "@/router";
let staticRouter = router.options.routes.filter((item) => item.isDiy == true)[0]
.children;
const selfPermission = {
state: {
token: localStorage.getItem("MSSM-LIAONING__TOKEN"),
permissionList: [],
routerList: [],
userData: {},
inspectorId: "",
},
mutations: {
//动态按钮权限
SET_PERMISSIONLIST: (state, permissions) => {
permissions.forEach((item) => {
state.permissionList.push(item.menuPerms);
});
},
//动态路由
SET_ROUTER: (state, router) => {
state.routerList = router;
},
//用户信息
SET_USERDATA: (state, data) => {
state.userData = data;
},
//某个id
SET_INSPECTORID: (state, id) => {
state.inspectorId = id;
},
},
actions: {
//获取远程接口(路由、菜单、按钮权限)
GetPermission({ commit, state }) {
return new Promise((resolve, reject) => {
getselfInfo()
.then((res) => {
console.log(res);
let infoData = res.result;
// let query = {
// id: infoData.userDto.cardId,
// };
// getcarid(query).then((res) => {
// commit(
// "SET_INSPECTORID",
// res.result.length > 0 ? res.result[0].id : null
// );
// });
//存储用户信息
commit("SET_USERDATA", infoData.userDto);
//过滤出按钮权限字符
// let menuButton = infoData.menuButton.filter(
// (item) => item.appCode == "JCYGL"
// );
// commit("SET_PERMISSIONLIST", menuButton);
//过滤菜单
let menuTree = infoData.menuTree.filter(
(item) => item.appCode == "CPGL"
);
console.log(menuTree);
let fileTreeOut = filterTree(menuTree[0].childMenuList, []);
console.log(fileTreeOut);
commit("SET_ROUTER", fileTreeOut);
resolve(fileTreeOut.length > 0 ? fileTreeOut[0].path : []);
})
.catch((error) => {
reject(error);
});
});
},
},
};
function filterTree(tree, result) {
tree.forEach((item) => {
staticRouter.forEach((router, index) => {
if (item.menuUrl == router.path) {
result.push(router);
}
if (item.childMenuList != null) {
filterTree(tree[index].childMenuList, result[index].children);
}
});
});
return result;
}
export default selfPermission;