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 >
@@ -61,11 +61,7 @@ const bodyRows = computed(() => props.node.rows ?? []);
6161 :aria-busy =" isLoading"
6262 >
6363 <colgroup >
64- <col
65- v-for =" (w, i) in colWidths"
66- :key =" `col-${i}`"
67- :style =" { width: w }"
68- />
64+ <col v-for =" (w, i) in colWidths" :key =" `col-${i}`" :style =" { width: w }" >
6965 </colgroup >
7066 <thead class =" border-[var(--table-border,#cbd5e1)]" >
7167 <tr class =" border-b" >
@@ -107,12 +103,7 @@ const bodyRows = computed(() => props.node.rows ?? []);
107103 </tbody >
108104 </table >
109105 <transition name =" table-node-fade" >
110- <div
111- v-if =" isLoading"
112- class =" table-node__loading"
113- role =" status"
114- aria-live =" polite"
115- >
106+ <div v-if =" isLoading" class =" table-node__loading" role =" status" aria-live =" polite" >
116107 <slot name =" loading" :is-loading =" isLoading" >
117108 <span class =" table-node__spinner animate-spin" aria-hidden =" true" />
118109 <span class =" sr-only" >Loading</span >
@@ -137,7 +128,7 @@ const bodyRows = computed(() => props.node.rows ?? []);
137128}
138129
139130.table-node--loading tbody td ::after {
140- content : " " ;
131+ content : ' ' ;
141132 position : absolute ;
142133 inset : 0 ;
143134 border-radius : 0.25rem ;
0 commit comments