column新增bool类型

This commit is contained in:
huayj 2019-08-24 17:34:34 +08:00
parent a84313109a
commit 90e108c735
2 changed files with 28 additions and 3 deletions

View File

@ -1,7 +1,8 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import objectPath from 'object-path'; import objectPath from 'object-path';
import i18n from './lib/i18n';
import { getComponentLocale } from 'bee-locale/build/tool';
const propTypes = { const propTypes = {
record: PropTypes.object, record: PropTypes.object,
clsPrefix: PropTypes.string, clsPrefix: PropTypes.string,
@ -30,7 +31,7 @@ class TableCell extends Component{
} }
// 渲染链接类型 // 渲染链接类型
renderLinkType = ( data, record, config={}, index) => { renderLinkType = ( data, record, index, config={}) => {
const { url, urlIndex, linkType, className, underline, descIndex, desc, linkColor } = config; const { url, urlIndex, linkType, className, underline, descIndex, desc, linkColor } = config;
let linkUrl = ''; let linkUrl = '';
if(url){ if(url){
@ -69,6 +70,20 @@ class TableCell extends Component{
return data; return data;
} }
renderBoolType = ( data, record, index, 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'){
if(data === 'false' || data === '0'){
return boolConfig.falseText;
}
}
else if(!data){
return boolConfig.falseText;
}
return boolConfig.trueText;
}
render() { render() {
const { record, indentSize, clsPrefix, indent, const { record, indentSize, clsPrefix, indent,
index, expandIcon, column ,fixed,showSum, bodyDisplayInRow,lazyStartIndex,lazyEndIndex} = this.props; index, expandIcon, column ,fixed,showSum, bodyDisplayInRow,lazyStartIndex,lazyEndIndex} = this.props;
@ -94,7 +109,11 @@ class TableCell extends Component{
if(!render){ if(!render){
switch(column.fieldType){ switch(column.fieldType){
case 'link':{ case 'link':{
text = this.renderLinkType(text, record, column.linkConfig, index); text = this.renderLinkType(text, record, index, column.linkConfig);
break;
}
case 'bool':{
text = this.renderBoolType(text, record, index, column.boolConfig);
break; break;
} }
default : { default : {

View File

@ -14,6 +14,8 @@ module.exports = {
'be_equal_to':'等于', 'be_equal_to':'等于',
'not_equal_to':'不等于', 'not_equal_to':'不等于',
"no_data":'暂无数据', "no_data":'暂无数据',
"bool_true":"是",
"bool_false":"否",
'en-us': { 'en-us': {
'resetSettings': 'reset settings', 'resetSettings': 'reset settings',
'include': 'include', 'include': 'include',
@ -29,6 +31,8 @@ module.exports = {
'be_equal_to':'be equal to', 'be_equal_to':'be equal to',
'not_equal_to':'not equal to', 'not_equal_to':'not equal to',
"no_data":'no data', "no_data":'no data',
"bool_true":"true",
"bool_false":"false",
}, },
'zh-tw': { 'zh-tw': {
'resetSettings': '還原設置', 'resetSettings': '還原設置',
@ -45,5 +49,7 @@ module.exports = {
'be_equal_to':'等於', 'be_equal_to':'等於',
'not_equal_to':'不等於', 'not_equal_to':'不等於',
"no_data":'暫無數據', "no_data":'暫無數據',
"bool_true":"是",
"bool_false":"否",
} }
} }