refactor: #I7G9UB 重构ssh-file 文件数更新部分代码

This commit is contained in:
a20070322 2024-01-31 10:57:58 +08:00
parent d552cfd076
commit 79ed1b2f06

View File

@ -507,7 +507,7 @@ export default {
getRootFileList(this.baseUrl, this.reqDataId).then((res) => {
if (res.code === 200) {
this.treeList = res.data
.map((element) => {
.map((element, index) => {
return {
key: element.id,
name: element.allowPathParent,
@ -516,7 +516,8 @@ export default {
isLeaf: false,
//
disabled: !!element.error,
modifyTime: element.modifyTime
modifyTime: element.modifyTime,
activeKey: [index]
}
})
.sort((a, b) => {
@ -527,7 +528,50 @@ export default {
}
this.loading = false
})
}, //
},
/**
* 更新树节点的方法抽离封装
* @param keys
* @param value
*/
updateTreeChildren(keys, value) {
let node = this.treeList[keys[0]]
for (let key of keys.slice(1)) {
if (key >= 0 && key < node.children.length) {
node = node.children[key]
} else {
throw new Error('Invalid key: ' + key)
}
}
node.children = value
},
/**
* 文件列表转树结构
* @param data
*/
fileList2TreeData(data) {
const node = this.tempNode
const children = data
.filter((element) => element.dir)
.map((element) => ({
key: element.id,
name: element.name,
allowPathParent: node.allowPathParent,
nextPath: (element.nextPath + '/' + element.name).replace(new RegExp('//+', 'gm'), '/'),
isLeaf: !element.dir,
//
disabled: !!element.error,
modifyTime: element.modifyTime
}))
.sort((a, b) => {
const aV = a[this.sortMethod.key] || ''
const bV = b[this.sortMethod.key] || ''
return this.sortMethod.asc ? bV.localeCompare(aV) : aV.localeCompare(bV)
})
.map((element, index) => ({ ...element, activeKey: node.activeKey.concat(index) }))
this.updateTreeChildren(node.activeKey, children)
},
//
onSelect(selectedKeys, { node }) {
if (node.dataRef.disabled) {
return
@ -558,16 +602,6 @@ export default {
...element
})
}
children.push({
key: element.id,
name: element.name,
allowPathParent: node.dataRef.allowPathParent,
nextPath: (element.nextPath + '/' + element.name).replace(new RegExp('//+', 'gm'), '/'),
isLeaf: !element.dir,
//
disabled: !!element.error,
modifyTime: element.modifyTime
})
} else {
//
this.fileList.push({
@ -576,13 +610,8 @@ export default {
})
}
})
//
node.dataRef.children = children.sort((a, b) => {
const aV = a[this.sortMethod.key] || ''
const bV = b[this.sortMethod.key] || ''
return this.sortMethod.asc ? bV.localeCompare(aV) : aV.localeCompare(bV)
})
this.treeList = [...this.treeList]
// tree
this.fileList2TreeData(res.data)
}
this.loading = false
})
@ -625,6 +654,8 @@ export default {
...element
}
})
// tree
this.fileList2TreeData(res.data)
}
this.loading = false
})