Skip to content

Commit 176336c

Browse files
committed
refactor: enhance saveBSPProjects and updateProjects logic for better readability and performance
1 parent c1e097a commit 176336c

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/vue/projects/App.vue

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
</template>
2222

2323
<script setup lang="ts">
24-
import { onMounted, ref } from 'vue';
24+
import { onMounted, ref, nextTick } from 'vue';
2525
import type { ElTable } from 'element-plus';
2626
import { imgUrl } from '../assets/img';
2727
import { sendCommand } from '../api/vscode';
@@ -44,9 +44,11 @@ const reloadBSPProjects = () => {
4444
4545
const saveBSPProjects = () => {
4646
let args: string[] = [];
47-
const selectedRows = tableRef.value?.getSelectionRows();
48-
if (selectedRows && selectedRows.length > 0) {
49-
args = selectedRows.map((row: any) => row.path);
47+
if (tableRef.value) {
48+
const selectedRows = (tableRef.value as any).getSelectionRows();
49+
if (selectedRows.length > 0) {
50+
args = selectedRows.map(row => row.path);
51+
}
5052
}
5153
5254
sendCommand('saveBSPProjects', [args]);
@@ -63,12 +65,17 @@ onMounted(() => {
6365
case 'updateProjects':
6466
tableData.value = message.data.dirs;
6567
let stars: string[] = message.data.stars;
66-
tableData.value.forEach((item: any, index: number) => {
67-
if (stars.includes(item.path)) {
68-
tableRef.value?.toggleRowSelection(item, true);
69-
}
68+
69+
nextTick(() => {
70+
tableData.value.forEach((item: any, index: number) => {
71+
if (stars.includes(item.path)) {
72+
if (tableRef.value) {
73+
(tableRef.value as any).toggleRowSelection(item, true);
74+
}
75+
}
76+
});
7077
});
71-
78+
7279
loading.value = false; // 停止加载动画
7380
break;
7481

0 commit comments

Comments
 (0)