| | |
| | | if (this.data.selectActive === 'learn') { |
| | | let list = [] |
| | | // 测试 6位// 正式 5位// 测试调用传20,内部7 正式调用传17 内部传6 |
| | | let addNum = query.cmsPath.length > 5 ? 7 : query.cmsPath.length > 6 ? 8 : 6 |
| | | const num = query.cmsPath.length + addNum |
| | | if (learn.some((item) => item.sysType == 'CmsFolder')) { |
| | | this.getTreeList(learn, num, list, '\\', addNum) |
| | | list = this.ensureTreeConsistency(list) |
| | | // 1.只有目录,没有资源 |
| | | if (!learn.some((item) => item.sysType == 'CmsItem')) { |
| | | list = learn |
| | | } else { |
| | | // 2.目录和资源都有 |
| | | this.getTreeList(learn, list, query.cmsPath) |
| | | list = this.ensureTreeConsistency(list) |
| | | } |
| | | } else { |
| | | // 3.只有资源,没有目录 |
| | | list = learn |
| | | } |
| | | let result = []; |
| | |
| | | ) |
| | | if (data.length > 0) { |
| | | let list = [] |
| | | let addNum = query.cmsPath.length > 5 ? 7 : query.cmsPath.length > 6 ? 8 : 6 |
| | | const num = query.cmsPath.length + addNum |
| | | this.getTreeList(data, num, list, '\\', addNum) |
| | | this.getTreeList(data, list, query.cmsPath) |
| | | list = this.ensureTreeConsistency(list) |
| | | let result = []; |
| | | this.findChildIds(list[0]?.children, result) |
| | |
| | | }) |
| | | }, |
| | | // 扁平化数据转换tree |
| | | getTreeList(rootList, pathLength, newArr, path, addNum) { |
| | | getTreeList(rootList, newArr, path) { |
| | | for (const item of rootList) { |
| | | // 此处原本 item.productLinkPath.length == pathLength 但 productLinkPath 长度个别书存在4、5位交错 |
| | | if ((pathLength - item.productLinkPath.length >= 0 && pathLength - item.productLinkPath.length <= 3) && item.productLinkPath.includes(path)) { |
| | | if (path == item.productLinkPath.replace('\\' + item.id, '')) { |
| | | if (item.sysType == 'CmsItem') { |
| | | if (item.selectType == 'webpage') { |
| | | item.disabled = true |
| | |
| | | } |
| | | // newArr.push(item) |
| | | // 在插入过程中对数据进行排序 |
| | | newArr = this.insertAndSortObjectsByProductLinkPath(newArr, item, addNum) |
| | | newArr = this.insertAndSortObjectsByProductLinkPath(newArr, item) |
| | | // 插进数组后 从原数据中删除 |
| | | rootList = rootList.filter(nitem => nitem.id != item.id) |
| | | } |
| | | } |
| | | //给数组里面再添加一个children的空数组 |
| | | for (const i of newArr) { |
| | | i.children = [] |
| | | this.getTreeList(rootList, pathLength + addNum, i.children, i.productLinkPath, addNum) |
| | | this.getTreeList(rootList, i.children, i.productLinkPath) |
| | | if (i.children.length == 0) { |
| | | newArr[0].istry = true |
| | | delete i.children |
| | | } |
| | | } |
| | |
| | | }, |
| | | |
| | | // 排序数组 按照productLinkPath |
| | | insertAndSortObjectsByProductLinkPath(array, newObj, addNum) { |
| | | insertAndSortObjectsByProductLinkPath(array, newObj) { |
| | | // 查找新对象应该插入的位置 |
| | | let insertIndex = array.findIndex(obj => Number(newObj.productLinkPath.substring(newObj.productLinkPath.length - addNum, newObj.productLinkPath.length)) < Number(obj.productLinkPath.substring(obj.productLinkPath.length - addNum, obj.productLinkPath.length))); |
| | | |
| | | let insertIndex = array.findIndex(obj => newObj.id < obj.id); |
| | | // 如果没有找到合适的位置,则放在数组末尾 |
| | | if (insertIndex === -1) { |
| | | insertIndex = array.length; |
| | | } |
| | | // 插入新对象到数组 |
| | | array.splice(insertIndex, 0, newObj); |
| | | // 测试6 正式5 |
| | | // 对数组进行排序 |
| | | array.sort((a, b) => { |
| | | if (Number(a.productLinkPath.substring(a.productLinkPath.length - addNum, a.productLinkPath.length)) < Number(b.productLinkPath.substring(b.productLinkPath.length - addNum, b.productLinkPath.length))) { |
| | | return -1; |
| | | } |
| | | if (Number(a.productLinkPath.substring(a.productLinkPath.length - addNum, a.productLinkPath.length)) > Number(b.productLinkPath.substring(b.productLinkPath.length - addNum, b.productLinkPath.length))) { |
| | | return 1; |
| | | } |
| | | // a must be equal to b |
| | | if (a.id < b.id) return -1; |
| | | if (a.id > b.id) return 1; |
| | | return 0; |
| | | }); |
| | | |
| | | // 返回更新后的数组 |
| | | return array; |
| | | }, |