11<script setup lang="ts">
2- import { computed } from ' vue'
3- import NodeRenderer from ' ../NodeRenderer'
2+ import { computed } from " vue" ;
3+ import NodeRenderer from " ../NodeRenderer" ;
44
55// 定义单元格节点
66interface TableCellNode {
7- type: ' table_cell'
8- header: boolean
7+ type: " table_cell" ;
8+ header: boolean ;
99 children: {
10- type: string
11- raw: string
12- }[]
13- raw: string
10+ type: string ;
11+ raw: string ;
12+ }[];
13+ raw: string ;
1414}
1515
1616// 定义行节点
1717interface TableRowNode {
18- type: ' table_row'
19- cells: TableCellNode []
20- raw: string
18+ type: " table_row" ;
19+ cells: TableCellNode [];
20+ raw: string ;
2121}
2222
2323// 定义表格节点
2424interface TableNode {
25- type: ' table'
26- header: TableRowNode
27- rows: TableRowNode []
28- raw: string
29- loading: boolean
25+ type: " table" ;
26+ header: TableRowNode ;
27+ rows: TableRowNode [];
28+ raw: string ;
29+ loading: boolean ;
3030}
3131
3232// 接收props
3333const props = defineProps <{
34- node: TableNode
35- indexKey: string | number
36- }>()
34+ node: TableNode ;
35+ indexKey: string | number ;
36+ }>();
3737
3838// 定义事件
39- defineEmits ([' copy' ])
39+ defineEmits ([" copy" ]);
4040
4141// 计算列宽,平均分配。如果需要更复杂的策略,可以在此扩展
42- const colCount = computed (() => props .node ?.header ?.cells ?.length ?? 0 )
42+ const colCount = computed (() => props .node ?.header ?.cells ?.length ?? 0 );
4343const colWidths = computed (() => {
44- const n = colCount .value || 1
45- const base = Math .floor (100 / n )
44+ const n = colCount .value || 1 ;
45+ const base = Math .floor (100 / n );
4646 // 为了保证总和为100%,最后一个列占剩余的百分比
4747 return Array .from ({ length: n }).map ((_ , i ) =>
48- i === n - 1 ? ` ${100 - base * (n - 1 )}% ` : ` ${base }% ` ,
49- )
50- })
48+ i === n - 1 ? ` ${100 - base * (n - 1 )}% ` : ` ${base }% `
49+ );
50+ });
5151
52- const isLoading = computed (() => props .node .loading ?? false )
53- const bodyRows = computed (() => props .node .rows ?? [])
52+ const isLoading = computed (() => props .node .loading ?? false );
53+ const bodyRows = computed (() => props .node .rows ?? []);
5454 </script >
5555
5656<template >
5757 <div class =" table-node-wrapper" >
5858 <table
59- class =" table-node table-fixed text-left my-8 text-sm w-full "
59+ class =" w-full my-8 text-sm text-left table-fixed table-node "
6060 :class =" { 'table-node--loading': isLoading }"
6161 :aria-busy =" isLoading"
6262 >
6363 <colgroup >
64- <col v-for =" (w, i) in colWidths" :key =" `col-${i}`" :style =" { width: w }" >
64+ <col
65+ v-for =" (w, i) in colWidths"
66+ :key =" `col-${i}`"
67+ :style =" { width: w }"
68+ />
6569 </colgroup >
6670 <thead class =" border-[var(--table-border,#cbd5e1)]" >
6771 <tr class =" border-b" >
6872 <th
6973 v-for =" (cell, index) in node.header.cells"
7074 :key =" `header-${index}`"
7175 dir =" auto"
72- class =" text-left font-semibold dark:text-white truncate p-[calc(4/7*1em)]"
73- :class =" [index === 0 ? '!pl-0' : '']"
76+ class =" text-left font-semibold dark:text-white truncate p-[calc(4/7*1em)]"
7477 >
7578 <NodeRenderer
7679 :nodes =" cell.children"
@@ -85,11 +88,7 @@ const bodyRows = computed(() => props.node.rows ?? [])
8588 v-for =" (row, rowIndex) in bodyRows"
8689 :key =" `row-${rowIndex}`"
8790 class =" border-[var(--table-border,#cbd5e1)]"
88- :class =" [
89- rowIndex < bodyRows.length - 1
90- ? 'border-b'
91- : '',
92- ]"
91+ :class =" [rowIndex < bodyRows.length - 1 ? 'border-b' : '']"
9392 >
9493 <td
9594 v-for =" (cell, cellIndex) in row.cells"
@@ -138,7 +137,7 @@ const bodyRows = computed(() => props.node.rows ?? [])
138137}
139138
140139.table-node--loading tbody td ::after {
141- content : ' ' ;
140+ content : " " ;
142141 position : absolute ;
143142 inset : 0 ;
144143 border-radius : 0.25rem ;
0 commit comments