11import { BaseChart , type ChartAxis , type ChartData } from '@/views/chat/component/BaseChart.ts'
22import {
3- TableSheet ,
4- S2Event ,
53 copyToClipboard ,
6- type S2Options ,
4+ type Node ,
75 type S2DataConfig ,
6+ S2Event ,
87 type S2MountContainer ,
8+ type S2Options ,
99 type SortMethod ,
10- type Node ,
11- type CellTextWordWrapStyle ,
10+ TableSheet ,
1211} from '@antv/s2'
1312import { debounce , filter } from 'lodash-es'
1413import { i18n } from '@/i18n'
14+ import '@antv/s2/dist/s2.min.css'
1515
1616const { t } = i18n . global
1717
@@ -71,30 +71,42 @@ export class Table extends BaseChart {
7171 data : this . data ,
7272 }
7373
74- const cellTextWordWrapStyle : CellTextWordWrapStyle = {
75- // 最大行数,文本超出后将被截断
76- maxLines : 3 ,
77- // 文本是否换行
78- wordWrap : true ,
79- // 可选项见:https://g.antv.antgroup.com/api/basic/text#textoverflow
80- textOverflow : 'ellipsis' ,
81- }
82-
8374 const s2Options : S2Options = {
8475 width : 600 ,
8576 height : 360 ,
8677 showDefaultHeaderActionIcon : true ,
8778 tooltip : {
88- enable : true ,
8979 operation : {
9080 // 开启组内排序
9181 sort : true ,
9282 } ,
83+ dataCell : {
84+ enable : true ,
85+ content : ( cell ) => {
86+ const meta = cell . getMeta ( )
87+ const container = document . createElement ( 'div' )
88+ container . style . padding = '8px 0'
89+ container . style . minWidth = '100px'
90+ container . style . maxWidth = '400px'
91+ container . style . display = 'flex'
92+ container . style . alignItems = 'center'
93+ container . style . padding = '8px 16px'
94+ container . style . cursor = 'pointer'
95+ container . style . color = '#606266'
96+ container . style . fontSize = '14px'
97+ container . style . whiteSpace = 'pre-wrap'
98+
99+ const text = document . createTextNode ( meta . fieldValue )
100+ container . appendChild ( text )
101+
102+ return container
103+ } ,
104+ } ,
93105 colCell : {
106+ enable : true ,
94107 content : ( cell ) => {
95108 const meta = cell . getMeta ( )
96109 const { spreadsheet : s2 } = meta
97-
98110 if ( ! meta . isLeaf ) {
99111 return null
100112 }
@@ -169,11 +181,6 @@ export class Table extends BaseChart {
169181 colCell : true ,
170182 } ,
171183 } ,
172- style : {
173- colCell : cellTextWordWrapStyle ,
174- // 如果是数值不建议换行, 容易产生歧义
175- dataCell : cellTextWordWrapStyle ,
176- } ,
177184 placeholder : {
178185 cell : '-' ,
179186 empty : {
@@ -185,7 +192,6 @@ export class Table extends BaseChart {
185192
186193 if ( this . container ) {
187194 this . table = new TableSheet ( this . container , s2DataConfig , s2Options )
188- console . log ( this . table )
189195 // right click
190196 this . table . on ( S2Event . GLOBAL_COPIED , ( data ) => {
191197 ElMessage . success ( t ( 'qa.copied' ) )
0 commit comments