MCPcopy Create free account
hub / github.com/dataease/SQLBot / copyData

Function copyData

frontend/src/views/chat/component/charts/Table.ts:261–317  ·  view source on GitHub ↗
(event: any, s2?: TableSheet)

Source from the content-addressed store, hash-verified

259}
260
261function copyData(event: any, s2?: TableSheet) {
262 event.preventDefault()
263 if (!s2) {
264 return
265 }
266 const cells = s2.interaction.getCells()
267
268 if (cells.length == 0) {
269 return
270 } else if (cells.length == 1) {
271 const c = cells[0]
272 const cellMeta = s2.facet.getCellMeta(c.rowIndex, c.colIndex)
273 if (cellMeta) {
274 let value = cellMeta.fieldValue
275 if (value === null || value === undefined) {
276 value = '-'
277 }
278 value = value + ''
279 copyToClipboard(value).finally(() => {
280 ElMessage.success(t('qa.copied'))
281 console.debug('copied:', cellMeta.fieldValue)
282 })
283 }
284 return
285 } else {
286 let currentRowIndex = -1
287 let currentRowData: Array<string> = []
288 const rowData: Array<string> = []
289 for (let i = 0; i < cells.length; i++) {
290 const c = cells[i]
291 const cellMeta = s2.facet.getCellMeta(c.rowIndex, c.colIndex)
292 if (!cellMeta) {
293 continue
294 }
295 if (currentRowIndex == -1) {
296 currentRowIndex = c.rowIndex
297 }
298 if (c.rowIndex !== currentRowIndex) {
299 rowData.push(currentRowData.join('\t'))
300 currentRowData = []
301 currentRowIndex = c.rowIndex
302 }
303 let value = cellMeta.fieldValue
304 if (value === null || value === undefined) {
305 value = '-'
306 }
307 value = value + ''
308 currentRowData.push(value)
309 }
310 rowData.push(currentRowData.join('\t'))
311 const finalValue = rowData.join('\n')
312 copyToClipboard(finalValue).finally(() => {
313 ElMessage.success(t('qa.copied'))
314 console.debug('copied:\n', finalValue)
315 })
316 }
317}

Callers 1

initMethod · 0.85

Calls 3

tFunction · 0.50
debugMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected