From e6a6fb8d27b14581ae771325c1b99ee26d6618dd Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期四, 19 三月 2020 18:19:06 +0800 Subject: [PATCH] 2020-03-19 --- src/tabviews/zshare/normalTable/index.jsx | 129 ++++++++++++++++++++++++++++++------------ 1 files changed, 91 insertions(+), 38 deletions(-) diff --git a/src/tabviews/zshare/normalTable/index.jsx b/src/tabviews/zshare/normalTable/index.jsx index ec02ca6..47e52ca 100644 --- a/src/tabviews/zshare/normalTable/index.jsx +++ b/src/tabviews/zshare/normalTable/index.jsx @@ -165,60 +165,113 @@ ) } else if (item.type === 'colspan') { if (item.subColumn.length === 0) return '' + let ordertype = item.order + let contents = [] + let images = [] - let contents = item.subColumn.map(col => { - let content = '' - if (col.type === 'text' || col.type === 'textarea') { - if (col.field && record.hasOwnProperty(col.field)) { - content = `${record[col.field]}` - } + item.subColumn.forEach(col => { + if (!col.field || !record.hasOwnProperty(col.field)) return + + if (col.type === 'number' && typeof(record[col.field]) === 'number') { + let content = record[col.field] - content = (col.prefix || '') + content + (col.postfix || '') - } else if (col.type === 'number') { - if (col.field && record.hasOwnProperty(col.field)) { - content = +record[col.field] - } - if (content && col.format === 'thdSeparator') { + if (col.format === 'thdSeparator') { content = `${content}` content = content.replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,') } - content = (col.prefix || '') + content + (col.postfix || '') - } else if (col.type === 'picture') { - let photos = '' - if (col.field && record.hasOwnProperty(col.field)) { - photos = record[col.field].split(',') - } else { - photos = '' - } - content = <div className="picture-col"> - {photos && photos.map((url, i) => { - return <img key={`${i}`} src={url} alt=""/> - })} - </div> - } - return content + content = (col.prefix || '') + content + (col.postfix || '') + + contents.push(content) + } else if (col.type === 'picture') { + let photos = [] + try { + photos = record[col.field].split(',') + } catch { + photos = [] + } + + images.push(...photos) + } else { + contents.push((col.prefix || '') + record[col.field] + (col.postfix || '')) + } }) - if (contents && item.order === 'vertical2') { - let _contents = [] - for(let i = 0; i < contents.length; i += 2) { - _contents.push(contents.slice(i, i + 2).join(' ')) - } - contents = _contents + if (images.length > 0 && ['vertical2', 'horizontal', 'vertical'].includes(ordertype)) { + ordertype = 'topPicBottomText' } return ( <div> <div className="content" style={{ minWidth: (item.Width || 120) + 'px' }}> - {contents && item.order === 'vertical' && contents.map((content, index) => { + {this.getCospanContent(ordertype, contents, images)} + </div> + </div> + ) + } + } + + getCospanContent = (type, contents, images) => { + if (type === 'vertical') { + return contents.map((content, index) => { + return (<p key={index}>{content}</p>) + }) + } else if (type === 'horizontal') { + return contents.map((content, index) => { + return (<span key={index}>{content}</span>) + }) + } else if (type === 'vertical2') { + return ( + <div className="content-fence"> + <div className="content-fence-left"> + {contents.map((content, index) => { + if (index % 2 === 0) { + return (<p key={index}>{content}</p>) + } else { + return '' + } + })} + </div> + <div className="content-fence-right"> + {contents.map((content, index) => { + if (index % 2 === 1) { + return (<p key={index}>{content}</p>) + } else { + return '' + } + })} + </div> + </div> + ) + } else if (type === 'topPicBottomText') { + return ( + <div className="content-fence"> + <div className="content-fence-top"> + {images.map((url, index) => { + return (<img key={`${index}`} src={url} alt=""/>) + })} + {images.map((url, index) => { + return (<img key={`${index}`} src={url} alt=""/>) + })} + </div> + <div className="content-fence-bottom"> + {contents.map((content, index) => { return (<p key={index}>{content}</p>) })} - {contents && item.order === 'vertical2' && contents.map((content, index) => { - return (<p key={index}>{content}</p>) + </div> + </div> + ) + } else if (type === 'leftPicRightText') { + return ( + <div className="content-fence"> + <div className="content-fence-left"> + {images.map((url, index) => { + return (<img key={`${index}`} src={url} alt=""/>) })} - {contents && item.order === 'horizontal' && contents.map((content, index) => { - return (<span key={index}>{content}</span>) + </div> + <div className="content-fence-right"> + {contents.map((content, index) => { + return (<p key={index}>{content}</p>) })} </div> </div> -- Gitblit v1.8.0