完善动态菜单、设置角色等功能,修复登录问题
This commit is contained in:
@@ -27,3 +27,5 @@ export default {menuDic,btnDic};
|
||||
|
||||
|
||||
//如果查询找到的是user:*,可以先把*全部替换成get:list再进行比对即可
|
||||
|
||||
//等待持续更新中
|
||||
@@ -1,29 +1,26 @@
|
||||
export function setTreeMenu(menuList) {
|
||||
if (menuList != null && menuList.length > 0) {
|
||||
export function toTree(data) {
|
||||
// 删除 所有 children,以防止多次调用
|
||||
data.forEach(function (item) {
|
||||
delete item.children;
|
||||
});
|
||||
|
||||
//结果
|
||||
var res;
|
||||
//获取最小的parentId
|
||||
var minParentId = 0;
|
||||
//获取id=最小的parentId的菜单列表
|
||||
var menuList1=menuList.filter((item)=>{item.parentId==minParentId}) ;
|
||||
|
||||
menuList1.forEach(element=>{
|
||||
res.push(element)
|
||||
var children=menuList.filter((item)=>{item.parentId==element.id}) ;
|
||||
if (children.length > 0) {
|
||||
setTreeChildren(menuList, children,element)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function setTreeChildren(menuList, childrenList,model) {
|
||||
childrenList.forEach(element => {
|
||||
model.Childs.push(element);
|
||||
var childrenList2=menuList.filter((item)=>{item.parentId==element.id}) ;
|
||||
if (childrenList2.length > 0) {
|
||||
setTreeChildren(menuList, childrenList2,element)
|
||||
// 将数据存储为 以 id 为 KEY 的 map 索引数据列
|
||||
var map = {};
|
||||
data.forEach(function (item) {
|
||||
map[item.id] = item;
|
||||
});
|
||||
// console.log(map);
|
||||
var val = [];
|
||||
data.forEach(function (item) {
|
||||
// 以当前遍历项,的pid,去map对象中找到索引的id
|
||||
var parent = map[item.parentId];
|
||||
// 好绕啊,如果找到索引,那么说明此项不在顶级当中,那么需要把此项添加到,他对应的父级中
|
||||
if (parent) {
|
||||
(parent.children || ( parent.children = [] )).push(item);
|
||||
} else {
|
||||
//如果没有在map中找到对应的索引ID,那么直接把 当前的item添加到 val结果集中,作为顶级
|
||||
val.push(item);
|
||||
}
|
||||
});
|
||||
return val;
|
||||
}
|
||||
@@ -31,14 +31,14 @@ myaxios.interceptors.request.use(function(config) {
|
||||
// 响应拦截器
|
||||
myaxios.interceptors.response.use(async function(response) {
|
||||
const resp = response.data
|
||||
if (resp.code == undefined && resp.msg == undefined) {
|
||||
if (resp.code == undefined && resp.message == undefined) {
|
||||
vm.$dialog.notify.error("错误代码:无,原因:与服务器失去连接", {
|
||||
position: "top-right",
|
||||
timeout: 5000,
|
||||
});
|
||||
} else if (resp.code == 401) {
|
||||
const res = await vm.$dialog.error({
|
||||
text: `错误代码:${resp.code},原因:${resp.msg}<br>是否重新进行登录?`,
|
||||
text: `错误代码:${resp.code},原因:${resp.message}<br>是否重新进行登录?`,
|
||||
title: '错误',
|
||||
actions: {
|
||||
'false': '取消',
|
||||
@@ -50,7 +50,7 @@ myaxios.interceptors.response.use(async function(response) {
|
||||
}
|
||||
|
||||
} else if (resp.code !== 200) {
|
||||
vm.$dialog.notify.error(`错误代码:${resp.code},原因:${resp.msg}`, {
|
||||
vm.$dialog.notify.error(`错误代码:${resp.code},原因:${resp.message}`, {
|
||||
position: "top-right",
|
||||
timeout: 5000,
|
||||
});
|
||||
@@ -60,14 +60,14 @@ myaxios.interceptors.response.use(async function(response) {
|
||||
return resp;
|
||||
}, async function(error) {
|
||||
const resp = error.response.data
|
||||
if (resp.code == undefined && resp.msg == undefined) {
|
||||
if (resp.code == undefined && resp.message == undefined) {
|
||||
vm.$dialog.notify.error("错误代码:无,原因:与服务器失去连接", {
|
||||
position: "top-right",
|
||||
timeout: 5000,
|
||||
});
|
||||
} else if (resp.code == 401) {
|
||||
const res = await vm.$dialog.error({
|
||||
text: `错误代码:${resp.code},原因:${resp.msg}<br>是否重新进行登录?`,
|
||||
text: `错误代码:${resp.code},原因:${resp.message}<br>是否重新进行登录?`,
|
||||
title: '错误',
|
||||
actions: {
|
||||
'false': '取消',
|
||||
@@ -81,7 +81,7 @@ myaxios.interceptors.response.use(async function(response) {
|
||||
}
|
||||
|
||||
} else if (resp.code !== 200) {
|
||||
vm.$dialog.notify.error(`错误代码:${resp.code},原因:${resp.msg}`, {
|
||||
vm.$dialog.notify.error(`错误代码:${resp.code},原因:${resp.message}`, {
|
||||
position: "top-right",
|
||||
timeout: 5000,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user