代码优化

This commit is contained in:
wangxk 2025-04-09 14:56:26 +08:00
parent aefba7c565
commit 557970fd87

View File

@ -272,6 +272,9 @@ function gettreedata() {
}
function handleNodeClick(data: any, node: any) {
pathid.value = data.nodeId
localOnlyFiles.value.length = 0
md5MismatchedFiles.value.length = 0
minioOnlyFiles.value.length = 0
getlocaltree()
getminiotree()
}
@ -297,9 +300,14 @@ const handleCheckChange = (
// 使
const updateCompare = debounce(() => {
comparearr.value = getclickdata(workall.value);
//
beifentree.value?.setCheckedNodes(comparearr.value, false);
const compareNodes = getclickdata(workall.value);
//
const checkedKeys = compareNodes
.map(node => node.id)
nextTick(() => {
beifentree.value?.setCheckedKeys(checkedKeys, false);
});
}, 50);
updateCompare();
@ -339,48 +347,78 @@ function getclickdata(nodes: any[]): any[] {
}
//
function getlocaltree() {
if (!projectId.value || !pathid.value) return;
if(projectId.value && pathid.value){
worktree.value = true
worktree.value = true;
listLocalTree({ taskId: projectId.value, nodeId: pathid.value }).then((res: any) => {
workdata.value = res.data.localTrees
if (workdata.value.length > 0) {
assignment(workdata.value, 'local')
}
worktree.value = false
diffColor()
})
const CHUNK_SIZE = 500; // 500
const rawData = res.data.localTrees;
// 使requestAnimationFrame
const processChunk = (index = 0) => {
const chunk = rawData.slice(index, index + CHUNK_SIZE);
if (chunk.length > 0) {
assignment(chunk, 'local');
workdata.value.push(...chunk); //
requestAnimationFrame(() => processChunk(index + CHUNK_SIZE));
} else {
worktree.value = false;
diffColor();
}
};
workdata.value = []; //
processChunk();
});
}
const worktree1 = ref(false)
//minio
function getminiotree() {
if(projectId.value && pathid.value){
worktree1.value = true
if (!projectId.value || !pathid.value) return;
worktree1.value = true;
listBackupTree({ taskId: projectId.value, nodeId: pathid.value }).then((res: any) => {
backupsdata.value = res.data.minioTrees
if (backupsdata.value.length > 0) {
assignment(backupsdata.value, 'minio')
}
worktree1.value = false
diffColor()
})
const CHUNK_SIZE = 500;
const rawData = res.data.minioTrees;
const processChunk = (index = 0) => {
const chunk = rawData.slice(index, index + CHUNK_SIZE);
if (chunk.length > 0) {
assignment(chunk, 'minio');
backupsdata.value.push(...chunk);
requestAnimationFrame(() => processChunk(index + CHUNK_SIZE));
} else {
worktree1.value = false;
diffColor();
}
};
backupsdata.value = [];
processChunk();
});
}
//
function assignment(data: any[], difference: 'local' | 'minio') {
// 使
const stack: any[] = [...data];
while (stack.length > 0) {
const node = stack.pop();
const queue = [...data]; // 使
while (queue.length > 0) {
const node = queue.shift();
if (!node) continue;
//
node.location = difference;
node.station = '0'; // 0: , 1: , 2: , 3:
//
// 使Object.definePropertyVue
Object.defineProperty(node, 'location', {
value: difference,
writable: true,
enumerable: true
});
Object.defineProperty(node, 'station', {
value: '0',
writable: true,
enumerable: true
});
if (node.children?.length) {
stack.push(...[...node.children].reverse());
queue.push(...node.children);
}
}
}
@ -409,12 +447,17 @@ const backupsChange = (
}
// 使
const updateCompare = debounce(() => {
comparearr.value = getclickdata(workall.value);
//
workref.value?.setCheckedNodes(comparearr.value, false);
}, 50);
const updateCompare = debounce(() => {
const compareNodes = getclickdata(workall.value);
//
const checkedKeys = compareNodes
.map(node => node.id)
nextTick(() => {
workref.value?.setCheckedKeys(checkedKeys, false);
});
}, 50);
updateCompare();
};
//
@ -929,8 +972,8 @@ const tabs = ref(1)
<div class="tree_left">
<div class="tree_title">工作空间:</div>
<div class="tree_content">
<el-scrollbar height="73vh">
<el-tree ref="workref" style="max-width: 600px" :props="props" :data="workdata"
<!-- <el-scrollbar height="73vh"> -->
<el-tree-v2 ref="workref" style="max-width: 600px" :props="props" :data="workdata" :height="700"
@node-click="workclick" @node-contextmenu="handleRightClick" default-expand-all
:expand-on-click-node="false" show-checkbox node-key="id" v-loading="worktree"
@check-change="handleCheckChange">
@ -946,7 +989,7 @@ const tabs = ref(1)
</span>
</span>
</template>
</el-tree>
</el-tree-v2>
<div v-show="contextMenuVisible" class="context-menu" :style="{
left: `${contextMenuPosition.x}px`,
top: `${contextMenuPosition.y}px`
@ -956,18 +999,18 @@ const tabs = ref(1)
<div v-if="currentNode && currentNode.isFile == 'FILE'" class="menu-item"
@click="handleMenuClick('preview', 'local')">预览</div>
</div>
</el-scrollbar>
<!-- </el-scrollbar> -->
</div>
</div>
<div class="tree_left">
<div class="tree_title">备份空间:</div>
<div class="tree_content">
<el-scrollbar height="73vh">
<el-tree ref="beifentree" style="max-width: 600px" :props="props" :data="backupsdata"
default-expand-all @node-click="workclick" @node-contextmenu="handleRightClick"
:expand-on-click-node="false" show-checkbox node-key="id" v-loading="worktree1"
@check-change="backupsChange">
<!-- <el-scrollbar height="73vh"> -->
<el-tree-v2 ref="beifentree" style="max-width: 600px" :props="props" :data="backupsdata"
:height="700" default-expand-all @node-click="workclick"
@node-contextmenu="handleRightClick" :expand-on-click-node="false" show-checkbox
node-key="id" v-loading="worktree1" @check-change="backupsChange">
<template #default="{ data }">
<span
:class="data.station == '0' ? 'custom-tree-node' : (data.station == '1' ? 'custom-tree-node1' : (data.station == '2' ? 'custom-tree-node2' : 'custom-tree-node3'))">
@ -980,7 +1023,7 @@ const tabs = ref(1)
== '2' ? '已变更' : '已删除') }})</span>
</span>
</template>
</el-tree>
</el-tree-v2>
<div v-show="contextMenuVisible2" class="context-menu" :style="{
left: `${contextMenuPosition.x}px`,
top: `${contextMenuPosition.y}px`
@ -990,7 +1033,7 @@ const tabs = ref(1)
<div v-if="currentNode && currentNode.isFile == 'FILE'" class="menu-item"
@click="handleMenuClick('preview', 'minio')">预览</div>
</div>
</el-scrollbar>
<!-- </el-scrollbar> -->
</div>
</div>