Skip to content

Commit 200e8cc

Browse files
committed
refactor: improve type safety and code clarity in App.vue
1 parent 98c6a13 commit 200e8cc

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

src/vue/projects/App.vue

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

2323
<script setup lang="ts">
24-
import { onMounted, ref, nextTick } from 'vue';
24+
import { onMounted, ref } from 'vue';
25+
import type { ElTable } from 'element-plus';
2526
import { imgUrl } from '../assets/img';
2627
import { sendCommand } from '../api/vscode';
2728
@@ -32,7 +33,7 @@ const collapseAll = () => {
3233
expandedRowKeys.value = []; // 清空展开的行
3334
};
3435
35-
const tableRef = ref(null);
36+
const tableRef = ref<InstanceType<typeof ElTable>>();
3637
const tableData = ref([
3738
{ id: "1", name: 'qemu-virt64-riscv', path: 'qemu-virt64-riscv'}
3839
]);
@@ -42,12 +43,10 @@ const reloadBSPProjects = () => {
4243
};
4344
4445
const saveBSPProjects = () => {
45-
let args:string[] = [];
46-
if (tableRef.value) {
47-
const selectedRows = (tableRef.value as any).getSelectionRows();
48-
if (selectedRows.length > 0) {
49-
args = selectedRows.map(row => row.path);
50-
}
46+
let args: string[] = [];
47+
const selectedRows = tableRef.value?.getSelectionRows();
48+
if (selectedRows && selectedRows.length > 0) {
49+
args = selectedRows.map((row: any) => row.path);
5150
}
5251
5352
sendCommand('saveBSPProjects', [args]);
@@ -63,17 +62,11 @@ onMounted(() => {
6362
switch (message.command) {
6463
case 'updateProjects':
6564
tableData.value = message.data.dirs;
66-
let stars:string[] = message.data.stars;
67-
68-
// 使用 nextTick 确保 DOM 更新完成后再执行选择操作
69-
nextTick(() => {
70-
tableData.value.forEach((item, index) => {
71-
if (stars.includes(item.path)) {
72-
if (tableRef.value) {
73-
(tableRef.value as any).toggleRowSelection(item, true);
74-
}
75-
}
76-
});
65+
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+
}
7770
});
7871
7972
loading.value = false; // 停止加载动画

0 commit comments

Comments
 (0)