Commit 5312dc15 authored by 李苏's avatar 李苏 💬

同步 方法 /调整模块id

parent c32cf053
...@@ -5,12 +5,11 @@ export default [ ...@@ -5,12 +5,11 @@ export default [
mkmc: '考勤管理', mkmc: '考勤管理',
image: 'null', image: 'null',
children: [{ children: [{
mkid: '1804020000', mkid: '1804020200',
mkmc: '工作日报', mkmc: '工作日报',
image: '/static/icon/oa/gzrb.png', image: '/static/icon/oa/gzrb.png',
page: 'kqgl-gzrb' page: 'kqgl-gzrb'
}, }
] ]
} }
] ]
\ No newline at end of file
...@@ -85,29 +85,48 @@ ...@@ -85,29 +85,48 @@
key: 'mobile', key: 'mobile',
data: res.data, data: res.data,
}); });
/* 获取本地权限副本*/
const menuMap = res.data.menu.reduce((acc, item) => { let powerList =JSON.parse(JSON.stringify(this.powerList))
acc[item.mkid] = item.mkmc; // 创建一个以 mkid 为键,mkmc 为值的映射对象 /* 获取服务器权限mam*/
return acc; let menuMap=new Map(res.data.menu.map((item,index)=>[item.mkid,{...item,qz:index}]))
}, {}); /* 过滤本地权限数组 */
const filterPower = (powerList, menuMap) => {
// 递归函数,用于更新项及其子项的 mkmc let filteredList = [];
const updateItemMkmc = (item) => { powerList.forEach(item => {
const newMkmc = menuMap[item.mkid]; if (menuMap.has(item.mkid)) {
item.mkmc = newMkmc; // 更新当前项的 mkmc let menuValue = menuMap.get(item.mkid);
let updatedItem = { ...item }; // 创建item的浅拷贝以避免直接修改原对象
if (item.children && item.children.length > 0) { updatedItem.mkmc = menuValue.mkmc;
// 递归更新子项 updatedItem.qz = menuValue.qz;
item.children = item.children.map(updateItemMkmc); if (updatedItem.children && updatedItem.children.length > 0) {
} updatedItem.children = filterPower(updatedItem.children, menuMap);
}
return item; filteredList.push(updatedItem);
}; }
});
// 更新 powerList return filteredList;
this.powerList = this.powerList.map(updateItemMkmc); };
this.showList = this.powerList.filter(item => item.children && item.children.length > 0); /* 根据权重递归数据 */
this.showList = this.powerList; const sortByQz=(array)=>{
function compare(a, b) {
return a.qz - b.qz;
}
function recursiveSort(arr) {
// 对当前数组进行排序
arr.sort(compare);
arr.forEach(item => {
if (item.children && item.children.length > 0) {
recursiveSort(item.children);
}
});
}
recursiveSort(array);
return array;
}
powerList=filterPower(powerList,menuMap)
this.showList = sortByQz(powerList)
console.log(this.showList,'最终展示')
} else { } else {
this.$tip.alert(res.message || "请求失败"); this.$tip.alert(res.message || "请求失败");
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment