diff --git a/web/src/views/testdata/fileSynchronization/index.vue b/web/src/views/testdata/fileSynchronization/index.vue index cf0344b..a365151 100644 --- a/web/src/views/testdata/fileSynchronization/index.vue +++ b/web/src/views/testdata/fileSynchronization/index.vue @@ -70,7 +70,7 @@ function diffFile() { comparearr.value = comparearr.value.filter(item => { return seen.has(item.id) ? false : seen.add(item.id); }); - tabs.value = 1 + tabs.value = 3 differential.value = true // getchayi() diffSure() @@ -132,7 +132,7 @@ const loading3 = ref(false) // }) // } //文件对比-新增内容 -const sureSize = ref(10) +const sureSize = ref(100) const sureTotal = ref() const sureCurrent = ref(1) function diffSure() { @@ -156,7 +156,7 @@ function diffSure() { sureSize.value = res.data.size sureTotal.value = res.data.total sureCurrent.value = res.data.current - diffColor() + // diffColor() }) } //文件对比-变更内容 @@ -184,11 +184,11 @@ function diffChange() { ChangeSize.value = res.data.size ChangeTotal.value = res.data.total ChangeCurrent.value = res.data.current - diffColor() + // diffColor() }) } //文件对比-缺失内容 -const MisseSize = ref(10) +const MisseSize = ref(100) const MissTotal = ref() const MissCurrent = ref(1) function diffMiss() { @@ -212,49 +212,62 @@ function diffMiss() { MisseSize.value = res.data.size MissTotal.value = res.data.total MissCurrent.value = res.data.current - diffColor() + // diffColor() }) } //差异染色 +// 优化后的diffColor方法 function diffColor() { - if (workdata.value.length > 0 && localOnlyFiles.value.length > 0) { - workdata.value = changeColor(workdata.value, localOnlyFiles.value, '1') - } - if (workdata.value.length > 0 && md5MismatchedFiles.value.length > 0) { - workdata.value = changeColor(workdata.value, md5MismatchedFiles.value, '2') - backupsdata.value = changeColor(backupsdata.value, md5MismatchedFiles.value, '2') - } - if (backupsdata.value.length > 0 && minioOnlyFiles.value.length > 0) { - backupsdata.value = changeColor(backupsdata.value, minioOnlyFiles.value, '3') - } - workref.value!.setCheckedKeys([], false) - beifentree.value!.setCheckedKeys([], false) -} -//状态改变递归 -function changeColor(data: any, data2: any, type: any) { - data.forEach((item: any) => { - data2.forEach((item2: any) => { - if (item.id == item2.id) { - item.station = type - } - if (item.children.length > 0) { - changeColor(item.children, data2, type) - } - }) - }) - return data + // 1. 使用Map优化查找性能 + const createMap = (arr: any[]) => new Map(arr.map(item => [item.id, item])); + + const localMap = createMap(localOnlyFiles.value); + const md5Map = createMap(md5MismatchedFiles.value); + const minioMap = createMap(minioOnlyFiles.value); -} -function gettabletable(){ - sureSize.value = 100 - ChangeSize.value = 100 - MisseSize.value = 100 - diffSure() - diffChange() - diffMiss() + // 2. 单次遍历优化 + const processTree = (tree: any[], location: 'local' | 'minio') => { + const stack = [...tree]; + + while (stack.length) { + const node = stack.pop(); + if (!node) continue; + + // 3. 使用位运算优化状态判断 + let status = 0; + if (location === 'local') { + status |= localMap.has(node.id) ? 1 : 0; + status |= md5Map.has(node.id) ? 2 : 0; + } else { + status |= minioMap.has(node.id) ? 3 : 0; + status |= md5Map.has(node.id) ? 2 : 0; + } + + // 4. 使用按位操作确定最终状态 + node.station = status.toString(10).split('').sort().reverse()[0]; + + // 5. 非递归方式处理子节点 + if (node.children?.length) { + stack.push(...node.children); + } + } + }; + + // 6. 避免重复处理相同数据 + if (workdata.value.length) { + processTree(workdata.value, 'local'); + } + if (backupsdata.value.length) { + processTree(backupsdata.value, 'minio'); + } + + // 7. 延迟更新UI + nextTick(() => { + workref.value?.setCheckedKeys([], false); + beifentree.value?.setCheckedKeys([], false); + }); } function diffClose() { - // gettabletable() differential.value = false getlocaltree() getminiotree()