diff --git a/web-admin/src/utils/list-excel-copy.test.ts b/web-admin/src/utils/list-excel-copy.test.ts index d4e5a7fd4..1f894f8c2 100644 --- a/web-admin/src/utils/list-excel-copy.test.ts +++ b/web-admin/src/utils/list-excel-copy.test.ts @@ -29,6 +29,7 @@ describe('excelCell', () => { it('trims and turns tabs and line breaks into spaces', () => { assert.equal(excelCell(' 合作中 \n'), '合作中') assert.equal(excelCell('重庆\t长寿\r\n区'), '重庆 长寿 区') + assert.equal(excelCell('重庆\r长寿'), '重庆 长寿') }) }) @@ -53,7 +54,10 @@ describe('toggleAxis', () => { it('shift-selects inclusive span and keeps earlier picks: start with set containing 0 and anchor 0, shift-click 3 yields 0,1,2,3 and anchor 3', () => { const selected = new Set([0]) const result = toggleAxis(selected, 3, true, 0) - assert.deepEqual([...result.selected].sort((a, b) => a - b), [0, 1, 2, 3]) + assert.deepEqual( + [...result.selected].sort((a, b) => a - b), + [0, 1, 2, 3] + ) assert.equal(result.anchor, 3) }) @@ -111,10 +115,13 @@ describe('resolveCopyAxes', () => { describe('buildExcelTsv', () => { it('builds CRLF-separated TSV with header row', () => { - const tsv = buildExcelTsv(['联系人', '状态'], [ - ['张三', '合作中'], - ['李四', '跟进中'] - ]) + const tsv = buildExcelTsv( + ['联系人', '状态'], + [ + ['张三', '合作中'], + ['李四', '跟进中'] + ] + ) assert.equal(tsv, '联系人\t状态\r\n张三\t合作中\r\n李四\t跟进中') }) }) diff --git a/web-admin/src/utils/list-excel-copy.ts b/web-admin/src/utils/list-excel-copy.ts index 8351343a5..c5d2f7979 100644 --- a/web-admin/src/utils/list-excel-copy.ts +++ b/web-admin/src/utils/list-excel-copy.ts @@ -16,7 +16,7 @@ export function isCopyableColumn(col: ListExcelColumn): boolean { export function excelCell(value: string): string { return String(value ?? '') .replace(/\t/g, ' ') - .replace(/\r?\n/g, ' ') + .replace(/\r\n|\r|\n/g, ' ') .trim() } @@ -46,7 +46,9 @@ export function resolveCopyAxes(input: { }): { cols: number[]; rows: number[] } | null { const { selectedCols, selectedRows, columnCount, rowCount } = input if (!selectedCols.length && !selectedRows.length) return null - const cols = (selectedCols.length ? selectedCols : range(columnCount)).slice().sort((a, b) => a - b) + const cols = (selectedCols.length ? selectedCols : range(columnCount)) + .slice() + .sort((a, b) => a - b) const rows = (selectedRows.length ? selectedRows : range(rowCount)).slice().sort((a, b) => a - b) return { cols, rows } }