From 5244834ce4a49559e66279299429a3d894a08964 Mon Sep 17 00:00:00 2001 From: huayj Date: Mon, 26 Aug 2019 13:55:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E6=95=B0=E5=92=8C=E7=B2=BE=E7=A1=AE?= =?UTF-8?q?=E6=95=B0=E5=80=BC=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Table.scss | 4 ++++ src/TableCell.js | 38 ++++++++++++++++++++++++++++++-------- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/Table.scss b/src/Table.scss index 4b8465e..2613fd3 100644 --- a/src/Table.scss +++ b/src/Table.scss @@ -722,6 +722,10 @@ $icon-color:#505F79; .u-table-link-underline:hover{ text-decoration:underline; } + .u-table-currency{ + display: inline-block; + text-align: right; + } } .u-table:focus{ diff --git a/src/TableCell.js b/src/TableCell.js index d9bc5a1..d8691ea 100644 --- a/src/TableCell.js +++ b/src/TableCell.js @@ -72,7 +72,7 @@ class TableCell extends Component{ } // 渲染布尔类型 - renderBoolType = ( data, record, index, config={} ) => { + renderBoolType = ( data, config={} ) => { let locale = getComponentLocale(this.props, this.context, 'Table', () => i18n); let boolConfig = {...{ trueText: locale['bool_true'], falseText: locale['bool_false']},...config}; if(typeof data === 'string'){ @@ -86,22 +86,26 @@ class TableCell extends Component{ return boolConfig.trueText; } - // 渲染货币类型 - renderCurrency = (data, record, index, config={}) => { - let number = formatMoney(data, config.precision || 2, config.thousand || true); + // 渲染整数/货币类型 + renderNumber = (data, config={}, width=200) => { + console.log(config); + let number = formatMoney(data, config.precision, config.thousand); if(config.makeUp === false && number !== '0') { number = number.replace(/0*$/,'').replace(/\.$/,''); } - let res = {number}; + let numberWidth = parseInt(width) - 16; // 减去默认的左右padding共计16px + let res = {number}; let pre = config.preSymbol ? {config.preSymbol} : null; let next = config.nextSymbol ? {config.nextSymbol} : null; - return + return {pre} {res} {next} ; } + + render() { const { record, indentSize, clsPrefix, indent, index, expandIcon, column ,fixed,showSum, bodyDisplayInRow,lazyStartIndex,lazyEndIndex} = this.props; @@ -131,11 +135,29 @@ class TableCell extends Component{ break; } case 'bool':{ - text = this.renderBoolType(text, record, index, column.boolConfig); + text = this.renderBoolType(text, column.boolConfig); break; } case 'currency':{ - text = this.renderCurrency(text, record, indent, column.currencyConfig); + let config = { + precision: 2, // 精度值,需要大于0 + thousand: true, // 是否显示千分符号 + makeUp: true, // 末位是否补零 + preSymbol: '', // 前置符号 + nextSymbol: '', // 后置符号 + } + text = this.renderNumber(text, {...config,...column.currencyConfig}, column.width); + break; + } + case 'number':{ + let config = { + precision: 2, // 精度值,需要大于0 + thousand: true, // 是否显示千分符号 + makeUp: false, // 末位是否补零 + preSymbol: '', // 前置符号 + nextSymbol: '', // 后置符号 + } + text = this.renderNumber(text, {...config,...column.numberConfig}, column.width); break; } default : {