From 98667870fb06d2cb4d5268e4e6b327f748517476 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E5=A4=9A=E7=9B=8A?= Date: Fri, 22 Jan 2021 14:13:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20Excel=20=E5=AF=BC=E5=87=BA?= =?UTF-8?q?=E4=B8=8D=E6=94=AF=E6=8C=81=E5=B5=8C=E5=A5=97=20name=20?= =?UTF-8?q?=E5=92=8C=20tpl=20=E9=97=AE=E9=A2=98=20(#1424)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/components/CRUD/ExportCSVExcel.jsx | 70 ++++++++++++++------- src/renderers/Table/index.tsx | 19 ++++-- 2 files changed, 61 insertions(+), 28 deletions(-) diff --git a/examples/components/CRUD/ExportCSVExcel.jsx b/examples/components/CRUD/ExportCSVExcel.jsx index f3bb7730e..0bbca1787 100644 --- a/examples/components/CRUD/ExportCSVExcel.jsx +++ b/examples/components/CRUD/ExportCSVExcel.jsx @@ -9,100 +9,121 @@ export default { { link: 'https://www.microsoft.com/', icon: __uri('../../static/ie.png'), - engine: 'Trident', browser: 'Internet Explorer 4.2', platform: 'Win 95+', - version: '4', notExport: '1', - grade: 'A' + grade: 'A', + engine: { + name: 'Trident', + version: '4' + } }, { link: 'https://www.microsoft.com/', icon: __uri('../../static/ie.png'), - engine: 'Trident', browser: 'Internet Explorer 4.2', platform: 'Win 95+', - version: '4', + + engine: { + name: 'Trident', + version: '4' + }, notExport: '1', grade: 'B' }, { link: 'https://www.microsoft.com/', icon: __uri('../../static/ie.png'), - engine: 'Trident', browser: 'AOL browser (AOL desktop)', platform: 'Win 95+', - version: '4', + engine: { + name: 'Trident', + version: '4' + }, notExport: '1', grade: 'C' }, { link: 'https://www.microsoft.com/', icon: __uri('../../static/ie.png'), - engine: 'Trident', + engine: { + name: 'Trident', + version: '3' + }, browser: 'AOL browser (AOL desktop)', platform: 'Win 98', - version: '3', notExport: '1', grade: 'A' }, { link: 'https://www.microsoft.com/', icon: __uri('../../static/ie.png'), - engine: 'Trident', + engine: { + name: 'Trident', + version: '4' + }, browser: 'AOL browser (AOL desktop)', platform: 'Win 98', - version: '4', notExport: '1', grade: 'A' }, { icon: __uri('../../static/firefox.png'), link: 'https://www.mozilla.org/', - engine: 'Gecko', browser: 'Firefox 1.0', platform: 'Win 98+ / OSX.2+', - version: '4', + engine: { + name: 'Gecko', + version: '4' + }, notExport: '1', grade: 'A' }, { icon: __uri('../../static/firefox.png'), link: 'https://www.mozilla.org/', - engine: 'Gecko', browser: 'Firefox 1.0', platform: 'Win 98+ / OSX.2+', - version: '5', + engine: { + name: 'Gecko', + version: '5' + }, notExport: '1', grade: 'A' }, { icon: __uri('../../static/firefox.png'), link: 'https://www.mozilla.org/', - engine: 'Gecko', + engine: { + name: 'Gecko', + version: '5' + }, browser: 'Firefox 2.0', platform: 'Win 98+ / OSX.2+', - version: '5', notExport: '1', grade: 'B' }, { icon: __uri('../../static/firefox.png'), link: 'https://www.mozilla.org/', - engine: 'Gecko', + engine: { + name: 'Gecko', + version: '5' + }, browser: 'Firefox 2.0', platform: 'Win 98+ / OSX.2+', - version: '5', notExport: '1', grade: 'C' }, { icon: __uri('../../static/firefox.png'), link: 'https://www.mozilla.org/', - engine: 'Gecko', + engine: { + name: 'Gecko', + version: '5' + }, browser: 'Firefox 2.0', platform: 'Win 98+ / OSX.2+', - version: '5', notExport: '1', grade: 'D' } @@ -121,7 +142,7 @@ export default { type: 'link' }, { - name: 'engine', + name: 'engine.name', label: '引擎' }, { @@ -133,8 +154,9 @@ export default { label: '操作系统' }, { - name: 'version', - label: '引擎版本' + name: 'engine.version', + label: 'CSS版本', + tpl: '${engine.version}' }, { name: 'grade', diff --git a/src/renderers/Table/index.tsx b/src/renderers/Table/index.tsx index 9d80d2bce..126ed0fa0 100644 --- a/src/renderers/Table/index.tsx +++ b/src/renderers/Table/index.tsx @@ -14,7 +14,8 @@ import { difference, noop, autobind, - isArrayChildrenModified + isArrayChildrenModified, + getVariable } from '../../utils/helper'; import {resolveVariable} from '../../utils/tpl-builtin'; import debounce from 'lodash/debounce'; @@ -1588,6 +1589,7 @@ export default class Table extends React.Component { render, data, translate, + locale, checkOnItemClick, buildItemProps, rowClassNameExpr, @@ -1653,6 +1655,7 @@ export default class Table extends React.Component { rowClassName={rowClassName} columns={columns} rows={rows} + locale={locale} translate={translate} rowsProps={{ regionPrefix: 'fixed/', @@ -1820,7 +1823,8 @@ export default class Table extends React.Component { let columIndex = 0; for (const key of firstRowKeys) { columIndex += 1; - if (!(key in row.data)) { + const value = getVariable(row.data, key); + if (typeof value === 'undefined' && !columnNameMap[key].tpl) { continue; } // 处理合并单元格 @@ -1837,7 +1841,7 @@ export default class Table extends React.Component { ); } } - const value = row.data[key]; + const type = columnNameMap[key].type || 'plain'; if (type === 'image') { const imageData = await toDataURL(value); @@ -1913,7 +1917,14 @@ export default class Table extends React.Component { sheetRow.getCell(columIndex).value = value; } } else { - sheetRow.getCell(columIndex).value = value; + if (columnNameMap[key].tpl) { + sheetRow.getCell(columIndex).value = filter( + columnNameMap[key].tpl, + row.data + ); + } else { + sheetRow.getCell(columIndex).value = value; + } } } }