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

同步 方法 /调整模块id

parent c32cf053
......@@ -5,12 +5,11 @@ export default [
mkmc: '考勤管理',
image: 'null',
children: [{
mkid: '1804020000',
mkid: '1804020200',
mkmc: '工作日报',
image: '/static/icon/oa/gzrb.png',
page: 'kqgl-gzrb'
},
}
]
}
]
\ No newline at end of file
......@@ -85,29 +85,48 @@
key: 'mobile',
data: res.data,
});
const menuMap = res.data.menu.reduce((acc, item) => {
acc[item.mkid] = item.mkmc; // 创建一个以 mkid 为键,mkmc 为值的映射对象
return acc;
}, {});
// 递归函数,用于更新项及其子项的 mkmc
const updateItemMkmc = (item) => {
const newMkmc = menuMap[item.mkid];
item.mkmc = newMkmc; // 更新当前项的 mkmc
if (item.children && item.children.length > 0) {
// 递归更新子项
item.children = item.children.map(updateItemMkmc);
/* 获取本地权限副本*/
let powerList =JSON.parse(JSON.stringify(this.powerList))
/* 获取服务器权限mam*/
let menuMap=new Map(res.data.menu.map((item,index)=>[item.mkid,{...item,qz:index}]))
/* 过滤本地权限数组 */
const filterPower = (powerList, menuMap) => {
let filteredList = [];
powerList.forEach(item => {
if (menuMap.has(item.mkid)) {
let menuValue = menuMap.get(item.mkid);
let updatedItem = { ...item }; // 创建item的浅拷贝以避免直接修改原对象
updatedItem.mkmc = menuValue.mkmc;
updatedItem.qz = menuValue.qz;
if (updatedItem.children && updatedItem.children.length > 0) {
updatedItem.children = filterPower(updatedItem.children, menuMap);
}
return item;
filteredList.push(updatedItem);
}
});
return filteredList;
};
/* 根据权重递归数据 */
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,'最终展示')
// 更新 powerList
this.powerList = this.powerList.map(updateItemMkmc);
this.showList = this.powerList.filter(item => item.children && item.children.length > 0);
this.showList = this.powerList;
} else {
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