| | |
| | | }, |
| | | |
| | | // 扁平化数据转换tree |
| | | getTreeList(rootList, pathLength, newArr, path) { |
| | | 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 |
| | |
| | | } |
| | | } |
| | | //给数组里面再添加一个children的空数组 |
| | | // let addnum1 = pathLength - path.length == 6 ? 6 : 7 |
| | | for (const i of newArr) { |
| | | i.children = [] |
| | | let addnum1 = i.productLinkPath.length - path.length == 6 ? 6 : 7 |
| | | this.getTreeList(rootList, pathLength + addnum1, i.children, i.productLinkPath) |
| | | this.getTreeList(rootList, i.children, i.productLinkPath) |
| | | if (i.children.length == 0) { |
| | | delete i.children |
| | | } |
| | |
| | | // 排序数组 按照productLinkPath |
| | | insertAndSortObjectsByProductLinkPath(array, newObj) { |
| | | // 查找新对象应该插入的位置 |
| | | let insertIndex = array.findIndex(obj => Number(newObj.productLinkPath.substring(newObj.productLinkPath.lastIndexOf('\\') + 1, newObj.productLinkPath.length)) < Number(obj.productLinkPath.substring(obj.productLinkPath.lastIndexOf('\\') + 1, 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.lastIndexOf('\\') + 1, a.productLinkPath.length)) < Number(b.productLinkPath.substring(b.productLinkPath.lastIndexOf('\\') + 1, b.productLinkPath.length))) { |
| | | return -1; |
| | | } |
| | | if (Number(a.productLinkPath.substring(a.productLinkPath.lastIndexOf('\\') + 1, a.productLinkPath.length)) > Number(b.productLinkPath.substring(b.productLinkPath.lastIndexOf('\\') + 1, 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; |
| | | }, |
| | |
| | | }) |
| | | } |
| | | } |
| | | const addNum = query.cmsPath.length > 10 ? 7 : query.cmsPath.length > 13 ? 8 : 6 |
| | | const num = query.cmsPath.length + addNum |
| | | this.getTreeList(res.datas.cmsDatas[0].datas, num, list, '\\') |
| | | this.getTreeList(res.datas.cmsDatas[0].datas, list, query.cmsPath) |
| | | list = this.ensureTreeConsistency(list) |
| | | list = this.changeResourceChildren(list) |
| | | let result = []; |
| | |
| | | } |
| | | if (data.length > 0) { |
| | | let list = [] |
| | | // 测试 6位// 正式 5位// 测试调用传20,内部7 正式调用传17 内部传6 |
| | | |
| | | const addNum = query.cmsPath.length > 10 ? 7 : query.cmsPath.length > 13 ? 8 : 6 |
| | | const num = query.cmsPath.length + addNum |
| | | that.getTreeList(data, num, list, '\\') |
| | | that.getTreeList(data, list, query.cmsPath) |
| | | list = that.ensureTreeConsistency(list) |
| | | that.findChildIds(list[0].children, result); |
| | | that.setData({ |