新增fieldType='link'类型

This commit is contained in:
huayj 2019-08-23 13:41:40 +08:00
parent f7bfad825a
commit 3a7d33cdc0
4 changed files with 66 additions and 3 deletions

View File

@ -17,7 +17,8 @@ const propTypes = {
]),
render: PropTypes.func,
onCellClick: PropTypes.func,
ifshow:PropTypes.bool
ifshow:PropTypes.bool,
fieldType: PropTypes.string, // 类型
}
class Column extends Component {

View File

@ -32,7 +32,9 @@ export default class ColumnManager {
// 向数据列中添加一列:序号
addOrderColumn = (columns, showRowNum) => {
if(!showRowNum)return columns;
if(!showRowNum){
return columns
}
let order = {
dataIndex: showRowNum.key || '_index',
key:'_index',

View File

@ -711,6 +711,13 @@ $icon-color:#505F79;
height: 40px;
}
.u-table-link{
cursor: pointer;
color: #0073E1;
}
.u-table-link-underline:hover{
text-decoration:underline;
}
}
.u-table:focus{

View File

@ -28,10 +28,51 @@ class TableCell extends Component{
onCellClick(record, e);
}
}
// 渲染链接类型
renderLinkType = ( data, record, config={}, index) => {
const { url, urlIndex, linkType, className, underline, descIndex, desc, linkColor } = config;
let linkUrl = '';
if(url){
linkUrl = url(data, record, index);
}
else if(urlIndex){
linkUrl = record[urlIndex];
}
if(linkUrl){
let link = () => {
window.open(linkUrl,linkType || '_blank');
}
let cls = 'u-table-link ';
if(className){
cls += `${className} `;
}
if(underline){
cls += 'u-table-link-underline ';
}
let title = '';
if(desc === true){
title = linkUrl;
}
else if( typeof desc === 'string'){
title = desc;
}
else if( typeof desc === 'function'){
title = desc(data, record, index);
}
else if(descIndex){
title = record[descIndex];
}
return <span onClick={link} className={cls} style={{color:linkColor || ''}} title={title}>{data}</span>
}
return data;
}
render() {
const { record, indentSize, clsPrefix, indent,
index, expandIcon, column ,fixed,showSum, bodyDisplayInRow,lazyStartIndex,lazyEndIndex} = this.props;
const { dataIndex, render } = column;
const { dataIndex, render, fieldType, linkConfig } = column;
let {className = ''} = column;
let text = objectPath.get(record, dataIndex);
@ -49,6 +90,18 @@ class TableCell extends Component{
}
}
// 根据 fieldType 来渲染数据
if(!render){
switch(column.fieldType){
case 'link':{
text = this.renderLinkType(text, record, column.linkConfig, index);
break;
}
default : {
break;
}
}
}
if (this.isInvalidRenderCellText(text)) {
text = null;