Commit de398331 authored by tianhongyang's avatar tianhongyang

merge

parent 634f8fc5
<template> <template>
<div class="project-side-menu-container"> <div class="project-side-menu-container">
<el-menu mode="vertical" class="project-side-menu-instance"> <el-menu mode="vertical" class="project-side-menu-instance">
<project-menu-item></project-menu-item> <template v-for="(item,index) of tempMenuTree">
<project-menu-item :menuItem="item" :key="item.nodeValue"></project-menu-item>
</template>
</el-menu> </el-menu>
</div> </div>
</template> </template>
...@@ -75,6 +77,10 @@ export default { ...@@ -75,6 +77,10 @@ export default {
this.tempMenuOptions = _options; this.tempMenuOptions = _options;
// 映射配置 // 映射配置
const resultData = this.mapDataByMenuOptions(JSON.parse(JSON.stringify(this.comMenuTree)), _options); const resultData = this.mapDataByMenuOptions(JSON.parse(JSON.stringify(this.comMenuTree)), _options);
console.log(resultData);
if (resultData) {
this.tempMenuTree = resultData;
}
} }
}, },
mergeMenuOptions(options) { mergeMenuOptions(options) {
...@@ -86,10 +92,31 @@ export default { ...@@ -86,10 +92,31 @@ export default {
return options; return options;
}, },
mapDataByMenuOptions(menuList, options) { mapDataByMenuOptions(menuList, options) {
// 分组源数据
const _groupData = this.groupData(menuList, options);
// 映射过后的树 // 映射过后的树
const _mapedData = this.mapData(menuList, options); const _mapedData = this.mapData(_groupData, options);
// 处理层级 以及删除空children // 处理层级 以及删除空children
this.buildTree(_mapedData); return this.buildTree(_mapedData);
},
groupData(data, options, originData = []) {
if (data?.length) {
const { children } = options;
const len = data.length;
for (let index = 0; index < len; index++) {
const _item = data[index];
const _newItem = JSON.parse(JSON.stringify(_item));
originData.push({
originData: _newItem
});
if (_item[children] instanceof Array && _item[children].length) {
_newItem[children] = this.groupData(_item[children], options);
} else {
delete _newItem[children];
}
}
}
return originData;
}, },
mapData(data = [], mapOptions) { mapData(data = [], mapOptions) {
const keys = Object.keys(mapOptions); const keys = Object.keys(mapOptions);
...@@ -97,12 +124,13 @@ export default { ...@@ -97,12 +124,13 @@ export default {
data.forEach(item => { data.forEach(item => {
// 循环key映射到 树 // 循环key映射到 树
keys.forEach(key => { keys.forEach(key => {
const mapKey = mapOptions[key]; const _mapKey = mapOptions[key];
if (Object.hasOwnProperty.call(item, mapKey)) { const _origin = item["originData"];
item[key] = item[mapKey]; if (Object.hasOwnProperty.call(_origin, _mapKey)) {
item[key] = JSON.parse(JSON.stringify(_origin[_mapKey]));
} }
}); });
if (item?.children) { if (item?.children instanceof Array && item.children.length) {
// 递归映射 // 递归映射
this.mapData(item?.children, mapOptions); this.mapData(item?.children, mapOptions);
} }
...@@ -115,7 +143,7 @@ export default { ...@@ -115,7 +143,7 @@ export default {
// 添加层级 // 添加层级
addTreeLevel(mapedData); addTreeLevel(mapedData);
addNodeParent(mapedData); addNodeParent(mapedData);
console.log(mapedData); return mapedData;
} }
} }
}, },
......
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