import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import md5 from 'md5'
|
import { connect } from 'react-redux'
|
import { is, fromJS } from 'immutable'
|
import { Table, Affix, Typography } from 'antd'
|
|
import asyncComponent from '@/utils/asyncComponent'
|
import MKEmitter from '@/utils/events.js'
|
import MkIcon from '@/components/mk-icon'
|
import '@/assets/css/table.scss'
|
import './index.scss'
|
|
const { Paragraph } = Typography
|
|
const NormalButton = asyncComponent(() => import('@/tabviews/zshare/actionList/normalbutton'))
|
const PopupButton = asyncComponent(() => import('@/tabviews/zshare/actionList/popupbutton'))
|
const TabButton = asyncComponent(() => import('@/tabviews/zshare/actionList/tabbutton'))
|
const NewPageButton = asyncComponent(() => import('@/tabviews/zshare/actionList/newpagebutton'))
|
|
class BodyRow extends React.Component {
|
shouldComponentUpdate (nextProps) {
|
return !is(fromJS(this.props.record), fromJS(nextProps.record)) || this.props.className !== nextProps.className
|
}
|
|
render() {
|
const { record, ...resProps } = this.props
|
return <tr {...resProps}/>
|
}
|
}
|
|
class NormalTable extends Component {
|
static propTpyes = {
|
tableId: PropTypes.string, // 列表Id
|
statFValue: PropTypes.any, // 合计字段数据
|
pageSize: PropTypes.any, // 每页数据
|
dict: PropTypes.object, // 字典项
|
MenuID: PropTypes.string, // 菜单Id
|
setting: PropTypes.object, // 表格全局设置:tableType(表格是否可选、单选、多选)、columnfixed(列固定)、actionfixed(按钮固定)
|
pickup: PropTypes.any, // 数据收起
|
columns: PropTypes.array, // 表格列
|
fields: PropTypes.array, // 组件字段集
|
ContainerId: PropTypes.any, // 标签页外层Id
|
BData: PropTypes.any, // 主表数据
|
data: PropTypes.any, // 表格数据
|
total: PropTypes.any, // 总数
|
loading: PropTypes.bool, // 表格加载中
|
refreshdata: PropTypes.func, // 表格中排序列、页码的变化时刷新
|
chgSelectData: PropTypes.func, // 数据切换
|
}
|
|
state = {
|
selectedRowKeys: [], // 表格中选中行
|
pageIndex: 1, // 初始页面索引
|
pageSize: 10, // 每页数据条数
|
columns: null, // 显示列
|
lineMarks: null, // 行标记
|
activeIndex: null, // 标记当前选中行
|
rowspans: null, // 行合并字段信息
|
pageOptions: []
|
}
|
|
UNSAFE_componentWillMount () {
|
const { menuType, memberLevel, pageSize, setting } = this.props
|
let columns = fromJS(this.props.columns).toJS()
|
let lineMarks = []
|
let _columns = []
|
let radio = 5 // 虚化比例
|
let _format = false // 是否虚化处理
|
let rowspans = []
|
|
if (setting.tableMode === 'fast') {
|
rowspans = null
|
columns.forEach(item => {
|
if (item.hidden === true || item.Hide === 'true') return
|
let cell = null
|
|
if (item.type === 'colspan' || item.type === 'old_colspan') {
|
cell = {title: item.label, children: []}
|
|
item.subcols.forEach(col => {
|
cell.children.push({
|
align: col.Align,
|
title: col.label,
|
dataIndex: col.field || col.uuid,
|
key: col.uuid,
|
width: col.Width || 120
|
})
|
})
|
} else {
|
if (item.type === 'index') {
|
item.field = '$Index'
|
item.type = 'text'
|
}
|
|
cell = {
|
align: item.Align,
|
dataIndex: item.field || item.uuid,
|
title: item.label,
|
sorter: item.field && item.IsSort === 'true',
|
width: item.Width || 120
|
}
|
}
|
|
_columns.push(cell)
|
})
|
} else {
|
if (window.GLOB.dataFormat && menuType !== 'HS' && memberLevel) {
|
_format = true
|
|
if (memberLevel >= 30) {
|
radio = 20
|
} else if (memberLevel >= 20) {
|
radio = 10
|
}
|
}
|
|
columns.forEach((item, index) => {
|
if (item.hidden === true || item.Hide === 'true') return
|
let cell = null
|
|
if (item.type === 'colspan') {
|
cell = {title: item.label, children: []}
|
|
item.subcols.forEach(col => {
|
if (col.rowspan === 'true') {
|
rowspans.push(col.field)
|
}
|
if (_format && !Math.floor(Math.random() * radio)) {
|
col.blur = true
|
}
|
|
if (col.marks) { // 过滤行和卡片标记
|
col.marks = col.marks.filter(mark => {
|
if (mark.signType === 'line') {
|
lineMarks.push(mark)
|
}
|
return mark.signType !== 'line' && mark.signType !== 'card'
|
})
|
|
if (col.marks.length === 0) {
|
col.marks = ''
|
}
|
}
|
|
cell.children.push({
|
align: col.Align,
|
title: col.label,
|
dataIndex: col.field || col.uuid,
|
key: col.uuid,
|
width: col.Width || 120,
|
render: (text, record) => {
|
return this.getContent(col, record)
|
}
|
})
|
})
|
} else if (item.type === 'old_colspan') {
|
item.subcols.forEach(col => {
|
if (col.marks) { // 过滤行和卡片标记
|
col.marks = col.marks.filter(mark => {
|
if (mark.signType === 'line') {
|
lineMarks.push(mark)
|
}
|
return mark.signType !== 'line' && mark.signType !== 'card'
|
})
|
|
if (col.marks.length === 0) {
|
col.marks = ''
|
}
|
}
|
})
|
|
cell = {
|
align: item.Align,
|
dataIndex: item.field || item.uuid,
|
title: item.label,
|
sorter: item.field && item.IsSort === 'true',
|
width: item.Width || 120,
|
render: (text, record) => {
|
return this.getContent(item, record)
|
}
|
}
|
} else {
|
if (item.rowspan === 'true') {
|
rowspans.push(item.field)
|
}
|
if (item.type === 'index') {
|
item.field = '$Index'
|
item.type = 'text'
|
} else if (_format && !Math.floor(Math.random() * radio)) {
|
item.blur = true
|
}
|
|
if (item.marks) { // 过滤行和卡片标记
|
item.marks = item.marks.filter(mark => {
|
if (mark.signType === 'line') {
|
lineMarks.push(mark)
|
}
|
return mark.signType !== 'line' && mark.signType !== 'card'
|
})
|
|
if (item.marks.length === 0) {
|
item.marks = ''
|
}
|
}
|
|
cell = {
|
align: item.Align,
|
dataIndex: item.field || item.uuid,
|
title: item.label,
|
sorter: item.field && item.IsSort === 'true',
|
width: item.Width || 120,
|
render: (text, record) => {
|
return this.getContent(item, record)
|
}
|
}
|
}
|
|
_columns.push(cell)
|
})
|
|
if (rowspans.length === 0) {
|
rowspans = null
|
}
|
}
|
|
let size = (setting.pageSize || 10) + ''
|
let pageOptions = ['10', '25', '50', '100', '500', '1000']
|
|
if (!pageOptions.includes(size)) {
|
pageOptions.push(size)
|
pageOptions = pageOptions.sort((a, b) => a - b)
|
}
|
|
this.setState({
|
pageOptions,
|
columns: _columns,
|
pageSize: pageSize ? pageSize : 10,
|
lineMarks,
|
rowspans
|
})
|
}
|
|
shouldComponentUpdate (nextProps, nextState) {
|
return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
|
}
|
|
componentDidMount () {
|
MKEmitter.addListener('resetTable', this.resetTable)
|
MKEmitter.addListener('autoQueryData', this.autoQueryData)
|
MKEmitter.addListener('autoSelectData', this.autoSelectData)
|
MKEmitter.addListener('mkTableCheckTopLine', this.mkTableCheckTopLine)
|
}
|
|
/**
|
* @description 组件销毁,清除state更新
|
*/
|
componentWillUnmount () {
|
this.setState = () => {
|
return
|
}
|
MKEmitter.removeListener('resetTable', this.resetTable)
|
MKEmitter.removeListener('autoQueryData', this.autoQueryData)
|
MKEmitter.removeListener('autoSelectData', this.autoSelectData)
|
MKEmitter.removeListener('mkTableCheckTopLine', this.mkTableCheckTopLine)
|
}
|
|
mkTableCheckTopLine = (id) => {
|
if (id !== this.props.MenuID) return
|
|
if (this.props.data.length > 0) {
|
this.changeRow(this.props.data[0], 0)
|
}
|
}
|
|
autoSelectData = (id, index) => {
|
if (id !== this.props.MenuID) return
|
|
const { pageSize, pageIndex } = this.state
|
|
let i = index - (pageIndex - 1) * pageSize - 1
|
|
if (this.props.data[i]) {
|
this.changeRow(this.props.data[i], i)
|
MKEmitter.emit('autoTransSelectData', this.props.MenuID, this.props.data[i])
|
} else {
|
MKEmitter.emit('autoMaticOver', this.props.MenuID)
|
}
|
}
|
|
autoQueryData = (id, index) => {
|
if (id !== this.props.MenuID) return
|
|
const { total } = this.props
|
const { pageSize } = this.state
|
|
if (index !== 1 && (!total || index > total)) {
|
MKEmitter.emit('autoMaticOver', this.props.MenuID)
|
return
|
}
|
|
console.clear()
|
|
let pageIndex = Math.ceil(index / pageSize)
|
|
this.setState({
|
pageIndex: pageIndex,
|
selectedRowKeys: [],
|
activeIndex: null
|
})
|
|
this.props.refreshdata({pageIndex})
|
}
|
|
// 字段透视
|
triggerLink = (e, item, record) => {
|
e.stopPropagation()
|
|
let __param = {
|
$searchkey: item.field,
|
$searchval: record[item.field] || '',
|
$BID: record.$$uuid
|
}
|
|
if (item.linkfields && item.linkfields.length > 0) {
|
item.linkfields.forEach(field => {
|
__param[field] = record[field] || ''
|
})
|
}
|
|
if (item.linkThdMenu) {
|
let tabmenu = item.linkThdMenu
|
tabmenu.param = __param
|
|
if (['linkage_navigation', 'linkage', 'menu_board'].includes(window.GLOB.navBar)) {
|
MKEmitter.emit('modifyTabs', tabmenu, 'replace')
|
} else {
|
MKEmitter.emit('modifyTabs', tabmenu, 'plus', true)
|
}
|
} else if (item.linkurl) {
|
let src = item.linkurl
|
|
if (src.indexOf('paramsmain/') > -1) {
|
try {
|
let _url = item.linkurl.split('paramsmain/')[0] + 'paramsmain/'
|
let _param = JSON.parse(window.decodeURIComponent(window.atob(item.linkurl.split('paramsmain/')[1])))
|
_param.UserID = sessionStorage.getItem('UserID')
|
_param.LoginUID = sessionStorage.getItem('LoginUID')
|
_param.User_Name = sessionStorage.getItem('User_Name')
|
_param.param = __param
|
src = _url + window.btoa(window.encodeURIComponent(JSON.stringify(_param)))
|
} catch (e) {
|
console.warn('菜单参数解析错误!')
|
}
|
} else {
|
let con = '?'
|
|
if (/\?/ig.test(src)) {
|
con = '&'
|
}
|
|
if (item.linkfields && item.linkfields.length > 0) {
|
item.linkfields.forEach(field => {
|
if (field.toLowerCase() === 'id') return
|
con += `${field}=${record[field] || ''}&`
|
})
|
}
|
|
src = src + `${con}id=${record.$$uuid}&appkey=${window.GLOB.appkey}&userid=${sessionStorage.getItem('UserID')}&LoginUID=${sessionStorage.getItem('LoginUID') || ''}`
|
}
|
|
window.open(src)
|
}
|
}
|
|
getMark = (record, marks) => {
|
let className = ''
|
let isIcon = false
|
let position = 'back'
|
let icon = ''
|
|
marks.some(mark => {
|
let originVal = record[mark.field] + ''
|
let contrastVal = ''
|
if (mark.contrastType === 'static') {
|
contrastVal = mark.contrastValue + ''
|
} else {
|
contrastVal = record[mark.contrastField] + ''
|
}
|
|
if (mark.match === '=') {
|
className = originVal === contrastVal ? mark.color[1] : ''
|
} else if (mark.match === '!=') {
|
className = originVal !== contrastVal ? mark.color[1] : ''
|
} else if (mark.match === 'like') {
|
className = originVal.indexOf(contrastVal) > -1 ? mark.color[1] : ''
|
} else if (mark.match === '>') {
|
try {
|
originVal = parseFloat(originVal)
|
contrastVal = parseFloat(contrastVal)
|
} catch (e) {
|
originVal = NaN
|
}
|
|
if (!isNaN(originVal) && !isNaN(contrastVal) && originVal > contrastVal) {
|
className = mark.color[1]
|
}
|
} else if (mark.match === '<') {
|
try {
|
originVal = parseFloat(originVal)
|
contrastVal = parseFloat(contrastVal)
|
} catch (e) {
|
originVal = NaN
|
}
|
|
if (!isNaN(originVal) && !isNaN(contrastVal) && originVal < contrastVal) {
|
className = mark.color[1]
|
}
|
}
|
|
if (!className) return false
|
|
if (mark.signType === 'font') {
|
className = 'font ' + className
|
} else if (mark.signType === 'background') {
|
className = 'background ' + className
|
} else if (mark.signType === 'icon') {
|
isIcon = true
|
if (mark.position === 'front') {
|
position = 'front'
|
}
|
icon = <MkIcon className={'font ' + className} type={mark.icon} />
|
className = ''
|
}
|
|
return true
|
})
|
|
return {
|
className: className,
|
isIcon: isIcon,
|
position: position,
|
icon: icon
|
}
|
}
|
|
getContent = (item, record) => {
|
if (item.type === 'text') {
|
let content = ''
|
let className = ''
|
if (item.field && record.hasOwnProperty(item.field)) {
|
content = `${record[item.field]}`
|
}
|
|
if (content !== '') {
|
if (item.textFormat === 'YYYY-MM-DD' && /^[1-9]\d{3}(-|\/)(0[1-9]|1[0-2])(-|\/)(0[1-9]|[1-2][0-9]|3[0-1])/.test(content)) {
|
content = `${content.substr(0, 4)}-${content.substr(5, 2)}-${content.substr(8, 2)}`
|
} else if (item.textFormat === 'YYYY-MM-DD HH:mm:ss' && /^[1-9]\d{3}(-|\/)(0[1-9]|1[0-2])(-|\/)(0[1-9]|[1-2][0-9]|3[0-1]).([0-1][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]/.test(content)) {
|
content = `${content.substr(0, 4)}-${content.substr(5, 2)}-${content.substr(8, 2)} ${content.substr(11, 2)}:${content.substr(14, 2)}:${content.substr(17, 2)}`
|
}
|
|
content = (item.prefix || '') + content + (item.postfix || '')
|
}
|
|
if (item.marks) {
|
let result = this.getMark(record, item.marks)
|
|
if (result.className) {
|
className = result.className
|
} else if (result.isIcon) {
|
if (result.position === 'front') {
|
content = <span>{result.icon} {content}</span>
|
} else {
|
content = <span>{content} {result.icon}</span>
|
}
|
}
|
}
|
|
if (item.blur) {
|
className = ''
|
content = md5(content)
|
}
|
|
if (!record.$disabled && (item.linkThdMenu || item.linkurl)) {
|
if (item.rowspan === 'true') {
|
return {
|
children: (
|
<div className={className}>
|
<div className="baseboard link-menu" onDoubleClick={(e) => this.triggerLink(e, item, record)}></div>
|
<div className="content link-menu" onDoubleClick={(e) => this.triggerLink(e, item, record)}>
|
{content}
|
</div>
|
</div>
|
),
|
props: {
|
rowSpan: record['$$' + item.field],
|
}
|
}
|
}
|
return (
|
<div className={className}>
|
<div className="baseboard link-menu" onDoubleClick={(e) => this.triggerLink(e, item, record)}></div>
|
<div className="content link-menu" onDoubleClick={(e) => this.triggerLink(e, item, record)}>
|
{content}
|
</div>
|
</div>
|
)
|
} else {
|
if (item.rowspan === 'true') {
|
return {
|
children: (
|
<div className={className}>
|
<div className="baseboard"></div>
|
<div className="content">
|
{content}
|
</div>
|
</div>
|
),
|
props: {
|
rowSpan: record['$$' + item.field],
|
}
|
}
|
}
|
return (
|
<div className={className}>
|
<div className="baseboard"></div>
|
<div className="content">
|
{content}
|
</div>
|
</div>
|
)
|
}
|
} else if (item.type === 'number') {
|
let content = ''
|
let className = ''
|
|
if (item.field && record.hasOwnProperty(item.field)) {
|
try {
|
content = parseFloat(record[item.field])
|
if (isNaN(content)) {
|
content = ''
|
}
|
} catch (e) {
|
content = ''
|
}
|
}
|
|
if (content !== '') {
|
let decimal = item.decimal || 0
|
if (item.format === 'percent') {
|
content = content * 100
|
decimal = decimal > 2 ? decimal - 2 : 0
|
}
|
|
content = content.toFixed(decimal)
|
|
if (item.format === 'thdSeparator') {
|
content = content.replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,')
|
}
|
|
content = (item.prefix || '') + content + (item.postfix || '')
|
}
|
|
if (item.marks) {
|
let result = this.getMark(record, item.marks)
|
|
if (result.className) {
|
className = result.className
|
} else if (result.isIcon) {
|
if (result.position === 'front') {
|
content = <span>{result.icon} {content}</span>
|
} else {
|
content = <span>{content} {result.icon}</span>
|
}
|
}
|
}
|
|
if (item.blur) {
|
className = ''
|
content = md5(content)
|
}
|
|
if (!record.$disabled && (item.linkThdMenu || item.linkurl)) {
|
if (item.rowspan === 'true') {
|
return {
|
children: (
|
<div className={className}>
|
<div className="baseboard link-menu" onDoubleClick={(e) => this.triggerLink(e, item, record)}></div>
|
<div className="content link-menu" onDoubleClick={(e) => this.triggerLink(e, item, record)}>
|
{content}
|
</div>
|
</div>
|
),
|
props: {
|
rowSpan: record['$$' + item.field],
|
}
|
}
|
}
|
return (
|
<div className={className}>
|
<div className="baseboard link-menu" onDoubleClick={(e) => this.triggerLink(e, item, record)}></div>
|
<div className="content link-menu" onDoubleClick={(e) => this.triggerLink(e, item, record)}>
|
{content}
|
</div>
|
</div>
|
)
|
} else {
|
if (item.rowspan === 'true') {
|
return {
|
children: (
|
<div className={className}>
|
<div className="baseboard"></div>
|
<div className="content">
|
{content}
|
</div>
|
</div>
|
),
|
props: {
|
rowSpan: record['$$' + item.field],
|
}
|
}
|
}
|
return (
|
<div className={className}>
|
<div className="baseboard"></div>
|
<div className="content">
|
{content}
|
</div>
|
</div>
|
)
|
}
|
} else if (item.type === 'picture') {
|
let photos = ''
|
if (item.field && record.hasOwnProperty(item.field)) {
|
photos = record[item.field] + ''
|
photos = photos.split(',').filter(Boolean)
|
} else {
|
photos = ''
|
}
|
|
let maxHeight = item.maxHeight || 128
|
return (
|
<div className="picture-col">
|
{photos && photos.map((url, i) => {
|
if (item.scale === 'true') {
|
return <img style={{maxHeight: maxHeight}} className="image-scale" onClick={(e) => {
|
e.stopPropagation()
|
MKEmitter.emit('mkImageScale', url, photos)
|
}} key={`${i}`} src={url} alt=""/>
|
} else {
|
return <img style={{maxHeight: maxHeight}} key={`${i}`} src={url} alt=""/>
|
}
|
})}
|
</div>
|
)
|
} else if (item.type === 'textarea') {
|
let content = ''
|
|
if (item.field && record.hasOwnProperty(item.field)) {
|
content = `${record[item.field]}`
|
}
|
|
content = content ? (item.prefix || '') + content + (item.postfix || '') : ''
|
|
if (item.blur) {
|
content = md5(content)
|
}
|
|
return (
|
<div>
|
<div className="content">
|
{content ? <Paragraph copyable ellipsis={{ rows: 3, expandable: true }}>{content}</Paragraph> : null }
|
</div>
|
</div>
|
)
|
} else if (item.type === 'link') {
|
let content = ''
|
let _href = record[item.field] || ''
|
|
if (item.nameField && record.hasOwnProperty(item.nameField)) {
|
content = record[item.nameField]
|
}
|
|
if (!content && _href) {
|
content = _href
|
} else if (!_href) {
|
content = ''
|
}
|
|
if (item.joint === 'true' && _href) {
|
let _quary = `id=${record[this.props.setting.primaryKey]}&userid=${sessionStorage.getItem('UserID')}&appkey=${window.GLOB.appkey}&LoginUID=${sessionStorage.getItem('LoginUID')}`
|
let _param = ''
|
|
try {
|
_param = window.btoa(_quary)
|
} catch (e) {
|
_param = window.btoa(window.encodeURIComponent(_quary))
|
}
|
|
_href += '?' + _param
|
}
|
|
if (_href && /^https/.test(window.location.protocol)) { // https转换
|
_href = _href.replace(/^http:/ig, 'https:')
|
}
|
|
if (item.blur) {
|
content = md5(content)
|
}
|
|
return (
|
<div>
|
<div className="content">
|
{content ? <a href={_href} target="_blank" rel="noopener noreferrer">{content}</a> : null }
|
</div>
|
</div>
|
)
|
} else if (item.type === 'action') {
|
return (
|
<div className="action-col">
|
{item.operations.map(btn => {
|
if (['exec', 'prompt', 'pop'].includes(btn.OpenType)) {
|
return (
|
<NormalButton
|
key={btn.uuid}
|
btn={btn}
|
BID={record.$$BID}
|
disabled={record.$disabled}
|
selectedData={[record]}
|
BData={this.props.BData}
|
setting={this.props.setting}
|
columns={this.props.fields || this.props.columns}
|
ContainerId={this.props.ContainerId}
|
/>
|
)
|
} else if (btn.OpenType === 'popview') {
|
return (
|
<PopupButton
|
key={btn.uuid}
|
btn={btn}
|
BID={record.$$BID}
|
disabled={record.$disabled}
|
selectedData={[record]}
|
BData={this.props.BData}
|
setting={this.props.setting}
|
/>
|
)
|
} else if (btn.OpenType === 'tab') {
|
return (
|
<TabButton
|
key={btn.uuid}
|
btn={btn}
|
disabled={record.$disabled}
|
selectedData={[record]}
|
BData={this.props.BData}
|
MenuID={this.props.MenuID}
|
setting={this.props.setting}
|
/>
|
)
|
} else if (btn.OpenType === 'innerpage' || btn.OpenType === 'outerpage') {
|
return (
|
<NewPageButton
|
key={btn.uuid}
|
btn={btn}
|
disabled={record.$disabled}
|
selectedData={[record]}
|
BData={this.props.BData}
|
setting={this.props.setting}
|
/>
|
)
|
}
|
return null
|
})}
|
</div>
|
)
|
} else if (item.type === 'old_colspan') {
|
if (item.subcols.length === 0) return ''
|
let ordertype = item.order
|
let contents = []
|
let images = []
|
|
item.subcols.forEach(col => {
|
if (!col.field || !record.hasOwnProperty(col.field)) return
|
|
if (col.type === 'number') {
|
let content = ''
|
try {
|
content = parseFloat(record[col.field])
|
if (isNaN(content)) {
|
content = ''
|
}
|
} catch (e) {
|
content = ''
|
}
|
|
if (content !== '') {
|
let decimal = col.decimal || 0
|
if (col.format === 'percent') {
|
content = content * 100
|
decimal = decimal > 2 ? decimal - 2 : 0
|
}
|
|
content = content.toFixed(decimal)
|
|
if (col.format === 'thdSeparator') {
|
content = content.replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,')
|
}
|
|
content = (col.prefix || '') + content + (col.postfix || '')
|
}
|
|
if (col.marks) {
|
let result = this.getMark(record, col.marks)
|
|
if (result.className && result.className.indexOf('font') > -1) {
|
content = <span className={result.className}>{content}</span>
|
} else if (result.isIcon) {
|
if (result.position === 'front') {
|
content = <span>{result.icon} {content}</span>
|
} else {
|
content = <span>{content} {result.icon}</span>
|
}
|
}
|
}
|
|
if (item.blur) {
|
content = md5(content)
|
}
|
|
contents.push({content, align: col.Align})
|
} else if (col.type === 'picture') {
|
let photos = []
|
try {
|
photos = record[col.field] + ''
|
photos = photos.split(',').filter(Boolean)
|
} catch (e) {
|
photos = []
|
}
|
|
photos.forEach(photo => {
|
images.push({url: photo, align: col.Align, scale: col.scale === 'true', maxHeight: col.maxHeight || 128})
|
})
|
} else if (col.type === 'text') {
|
let content = record[col.field]
|
|
if (content !== '') {
|
if (col.textFormat === 'YYYY-MM-DD' && /^[1-9]\d{3}(-|\/)(0[1-9]|1[0-2])(-|\/)(0[1-9]|[1-2][0-9]|3[0-1])/.test(content)) {
|
content = `${content.substr(0, 4)}-${content.substr(5, 2)}-${content.substr(8, 2)}`
|
} else if (col.textFormat === 'YYYY-MM-DD HH:mm:ss' && /^[1-9]\d{3}(-|\/)(0[1-9]|1[0-2])(-|\/)(0[1-9]|[1-2][0-9]|3[0-1]).([0-1][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]/.test(content)) {
|
content = `${content.substr(0, 4)}-${content.substr(5, 2)}-${content.substr(8, 2)} ${content.substr(11, 2)}:${content.substr(14, 2)}:${content.substr(17, 2)}`
|
}
|
|
content = (col.prefix || '') + content + (col.postfix || '')
|
}
|
|
if (col.marks) {
|
let result = this.getMark(record, col.marks)
|
|
if (result.className && result.className.indexOf('font') > -1) {
|
content = <span className={result.className}>{content}</span>
|
} else if (result.isIcon) {
|
if (result.position === 'front') {
|
content = <span>{result.icon} {content}</span>
|
} else {
|
content = <span>{content} {result.icon}</span>
|
}
|
}
|
}
|
|
if (item.blur) {
|
content = md5(content)
|
}
|
|
contents.push({content, align: col.Align})
|
} else if (col.type === 'link') {
|
let content = col.nameField ? record[col.nameField] : ''
|
let _href = record[col.field] || ''
|
|
if (!content && _href) {
|
content = _href
|
} else if (!_href) {
|
content = ''
|
}
|
|
if (col.joint === 'true' && _href) {
|
let _quary = `id=${record[this.props.setting.primaryKey]}&userid=${sessionStorage.getItem('UserID')}&appkey=${window.GLOB.appkey}&LoginUID=${sessionStorage.getItem('LoginUID')}`
|
let _param = ''
|
|
try {
|
_param = window.btoa(_quary)
|
} catch (e) {
|
_param = window.btoa(window.encodeURIComponent(_quary))
|
}
|
|
_href += '?' + _param
|
}
|
|
if (_href && /^https/.test(window.location.protocol)) { // https转换
|
_href = _href.replace(/^http:/ig, 'https:')
|
}
|
|
if (item.blur) {
|
content = md5(content)
|
}
|
|
content = _href ? <a href={_href} target="_blank" rel="noopener noreferrer">{content}</a> : null
|
|
contents.push({content, align: col.Align})
|
} else {
|
let content = record[col.field]
|
|
if (content !== '') {
|
content = (col.prefix || '') + record[col.field] + (col.postfix || '')
|
}
|
|
if (item.blur) {
|
content = md5(content)
|
}
|
|
contents.push({content, align: col.Align})
|
}
|
})
|
|
if (images.length > 0 && ['vertical2', 'horizontal', 'vertical'].includes(ordertype)) {
|
ordertype = 'topPicBottomText'
|
}
|
|
return (
|
<div>
|
<div className="content">
|
{this.getCospanContent(ordertype, contents, images)}
|
</div>
|
</div>
|
)
|
}
|
}
|
|
getCospanContent = (type, contents, images) => {
|
if (type === 'vertical') {
|
return contents.map((cont, index) => {
|
return (<p key={index} style={{textAlign: cont.align}}>{cont.content}</p>)
|
})
|
} else if (type === 'horizontal') {
|
return contents.map((cont, index) => {
|
return (<span key={index}>{cont.content}</span>)
|
})
|
} else if (type === 'vertical2') {
|
return (
|
<div className="content-fence">
|
<div className="content-fence-left">
|
{contents.map((cont, index) => {
|
if (index % 2 === 0) {
|
return (<p key={index} style={{textAlign: cont.align}}>{cont.content}</p>)
|
} else {
|
return ''
|
}
|
})}
|
</div>
|
<div className="content-fence-right">
|
{contents.map((cont, index) => {
|
if (index % 2 === 1) {
|
return (<p key={index} style={{textAlign: cont.align}}>{cont.content}</p>)
|
} else {
|
return ''
|
}
|
})}
|
</div>
|
</div>
|
)
|
} else if (type === 'topPicBottomText') {
|
return (
|
<div className="content-fence">
|
<div className="content-fence-top" style={images[0] ? {textAlign: images[0].align} : null}>
|
{images.map((_img, index) => {
|
if (_img.scale) {
|
return <img style={{maxHeight: _img.maxHeight}} className="image-scale" onClick={(e) => {
|
e.stopPropagation()
|
MKEmitter.emit('mkImageScale', _img.url, images.map(g => g.url))
|
}} key={`${index}`} src={_img.url} alt=""/>
|
} else {
|
return (<img style={{maxHeight: _img.maxHeight}} key={`${index}`} src={_img.url} alt=""/>)
|
}
|
})}
|
</div>
|
<div className="content-fence-bottom">
|
{contents.map((cont, index) => {
|
return (<p key={index} style={{textAlign: cont.align}}>{cont.content}</p>)
|
})}
|
</div>
|
</div>
|
)
|
} else if (type === 'leftPicRightText') {
|
return (
|
<div className="content-fence">
|
<div className="content-fence-left" style={images[0] ? {textAlign: images[0].align} : null}>
|
{images.map((_img, index) => {
|
if (_img.scale) {
|
return <img style={{maxHeight: _img.maxHeight}} className="image-scale" onClick={() => {
|
MKEmitter.emit('mkImageScale', _img.url, images.map(g => g.url))
|
}} key={`${index}`} src={_img.url} alt=""/>
|
} else {
|
return (<img style={{maxHeight: _img.maxHeight}} key={`${index}`} src={_img.url} alt=""/>)
|
}
|
})}
|
</div>
|
<div className="content-fence-right">
|
{contents.map((cont, index) => {
|
return (<p key={index} style={{textAlign: cont.align}}>{cont.content}</p>)
|
})}
|
</div>
|
</div>
|
)
|
}
|
}
|
|
/**
|
*
|
*/
|
onSelectChange = selectedRowKeys => {
|
const { setting } = this.props
|
|
let index = ''
|
let _activeIndex = null
|
if (selectedRowKeys.length > 0) {
|
index = selectedRowKeys.slice(-1)[0]
|
}
|
|
if (setting.tableType === 'checkbox' || setting.tableType === 'radio') {
|
_activeIndex = index === '' ? null : index
|
}
|
|
this.changedata(index)
|
|
this.setState({ selectedRowKeys, activeIndex: _activeIndex })
|
|
let selects = this.props.data.filter((item, _index) => selectedRowKeys.includes(_index) && !item.$disabled)
|
|
this.props.chgSelectData(selects)
|
}
|
|
/**
|
* @description 点击整行,触发切换, 判断是否可选,单选或多选,进行对应操作
|
*/
|
changeRow = (record, index) => {
|
if (!this.props.setting.tableType || this.props.pickup) return
|
if (record.$disabled) return
|
|
let newkeys = fromJS(this.state.selectedRowKeys).toJS()
|
|
if (this.props.setting.tableType === 'radio') {
|
newkeys = [index]
|
this.changedata(index)
|
this.setState({ selectedRowKeys: newkeys, activeIndex: index })
|
} else {
|
let _index = ''
|
if (newkeys.includes(index)) {
|
newkeys = newkeys.filter(item => item !== index)
|
if (newkeys.length > 0) {
|
_index = newkeys.slice(-1)[0]
|
}
|
this.changedata(_index)
|
} else {
|
_index = index
|
newkeys.push(index)
|
this.changedata(index)
|
}
|
|
this.setState({ selectedRowKeys: newkeys, activeIndex: _index !== '' ? _index : null })
|
}
|
|
let selects = this.props.data.filter((item, _index) => newkeys.includes(_index))
|
|
this.props.chgSelectData(selects)
|
}
|
|
changeTable = (pagination, filters, sorter) => {
|
this.setState({
|
pageIndex: pagination.current,
|
pageSize: pagination.pageSize,
|
selectedRowKeys: [],
|
activeIndex: null
|
})
|
this.props.refreshdata(pagination, filters, sorter)
|
}
|
|
changedata = (index) => {
|
const { data, setting, tableId, ContainerId } = this.props
|
|
if (!tableId || !ContainerId) return
|
|
let _id = ''
|
let _data = ''
|
|
if (data && data.length > 0 && index !== '') {
|
_id = data[index][setting.primaryKey] || ''
|
_data = data[index] || ''
|
}
|
|
MKEmitter.emit('changeTableLine', ContainerId, tableId, _id, _data)
|
}
|
|
resetTable = (id, repage) => {
|
const { tableId } = this.props
|
|
if (id !== tableId) return
|
|
if (repage === 'false') {
|
this.setState({
|
selectedRowKeys: [],
|
activeIndex: null
|
})
|
} else {
|
this.setState({
|
pageIndex: 1,
|
selectedRowKeys: [],
|
activeIndex: null
|
})
|
}
|
}
|
|
handleRowspan = (data) => {
|
const { rowspans } = this.state
|
|
if (!rowspans || data.length === 0) return data
|
|
data = fromJS(data).toJS()
|
data = data.reverse()
|
data.forEach((item, index) => {
|
if (index === 0) {
|
rowspans.forEach(cell => {
|
item['$' + cell] = 1
|
})
|
} else {
|
let preItem = data[index - 1]
|
rowspans.forEach((cell, i) => {
|
if (i === 0) {
|
if (preItem[cell] === item[cell]) {
|
item['$' + cell] = preItem['$' + cell] + 1
|
} else {
|
item['$' + cell] = 1
|
}
|
} else {
|
if (preItem[cell] === item[cell]) {
|
item['$' + cell] = preItem['$' + cell] + 1
|
} else {
|
item['$' + cell] = 1
|
}
|
if (item['$' + cell] > item['$' + rowspans[i - 1]]) {
|
item['$' + cell] = 1
|
}
|
}
|
})
|
}
|
})
|
data = data.reverse()
|
data.forEach((item, index) => {
|
if (index === 0) {
|
rowspans.forEach(cell => {
|
item['$$' + cell] = item['$' + cell]
|
})
|
} else {
|
let preItem = data[index - 1]
|
rowspans.forEach(cell => {
|
if (preItem['$' + cell] > 1) {
|
item['$$' + cell] = 0
|
} else {
|
item['$$' + cell] = item['$' + cell]
|
}
|
})
|
}
|
})
|
return data
|
}
|
|
doubleClickLine = (record) => {
|
const { setting } = this.props
|
|
if (!setting.doubleClick) return
|
if (record.$disabled) return
|
|
MKEmitter.emit('triggerBtnId', setting.doubleClick, [record])
|
}
|
|
render() {
|
const { setting, pickup, statFValue } = this.props
|
const { selectedRowKeys, lineMarks, activeIndex, pageOptions } = this.state
|
|
let components = {
|
body: {}
|
}
|
|
if (setting.tableMode === 'fast') {
|
components.body.row = BodyRow
|
}
|
|
// 设置表格选择属性:单选、多选、不可选
|
let rowSelection = null
|
if (setting.tableType) {
|
rowSelection = {
|
selectedRowKeys,
|
type: (setting.tableType === 'radio') ? 'radio' : 'checkbox',
|
onChange: this.onSelectChange
|
}
|
}
|
|
// 表格头部固定于顶部时,判断距顶部高度
|
let offset = null
|
if (this.props.tableId === 'mainTable' && setting.columnfixed) {
|
if (!setting.actionfixed) {
|
offset = 48
|
} else {
|
let box = document.getElementById(this.props.MenuID + 'mainaction')
|
if (box) {
|
offset = 48 + box.offsetHeight
|
} else {
|
offset = 105
|
}
|
}
|
}
|
|
// 数据收起时,过滤已选数据
|
let _data = this.props.data ? this.props.data : []
|
|
if (pickup) {
|
_data = _data.filter((item, index) => selectedRowKeys.includes(index))
|
}
|
|
_data = this.handleRowspan(_data)
|
|
let _pagination = false
|
if (setting.laypage !== 'false' && setting.laypage !== false) {
|
_pagination = {
|
current: this.state.pageIndex,
|
pageSize: this.state.pageSize,
|
pageSizeOptions: pageOptions,
|
showSizeChanger: true,
|
total: this.props.total || 0,
|
showTotal: (total, range) => `${range[0]}-${range[1]} ${this.props.dict['main.pagination.of']} ${total} ${this.props.dict['main.pagination.items']}`
|
}
|
}
|
|
let _footer = ''
|
|
if (statFValue && statFValue.length > 0) {
|
_footer = statFValue.map(f => `${f.label}(合计):${f.value}`).join(';')
|
}
|
|
let height = setting.height || false
|
let style = {}
|
if (setting.color) {
|
style.color = setting.color
|
}
|
if (setting.fontSize) {
|
style.fontSize = setting.fontSize
|
}
|
|
let loading = this.props.loading
|
if (setting.mask === 'hidden') {
|
loading = false
|
}
|
|
return (
|
<div className={'normal-data-table mingke-table ' + (height ? 'fixed-height' : '')}>
|
{offset && <Affix offsetTop={offset} className="fix-header">
|
<Table
|
size={setting.size || 'middle'}
|
style={style}
|
bordered={setting.bordered !== 'false'}
|
rowSelection={rowSelection}
|
columns={this.state.columns.map(column => {
|
return {
|
align: column.align,
|
dataIndex: column.dataIndex,
|
title: column.title,
|
width: column.width
|
}
|
})}
|
/>
|
</Affix>}
|
<Table
|
components={components}
|
size={setting.size || 'middle'}
|
style={style}
|
bordered={setting.bordered !== 'false'}
|
rowSelection={rowSelection}
|
columns={this.state.columns}
|
dataSource={_data}
|
rowClassName={(record) => {
|
let className = ''
|
if (record.$disabled) {
|
className = 'mk-disabled '
|
} else if ((setting.tableType === 'checkbox' || setting.tableType === 'radio') && record.key === activeIndex) {
|
className = 'mk-row-active '
|
}
|
|
if (lineMarks.length === 0) return className
|
|
lineMarks.some(mark => {
|
let originVal = record[mark.field] + ''
|
let contrastVal = ''
|
if (mark.contrastType === 'static') {
|
contrastVal = mark.contrastValue + ''
|
} else {
|
contrastVal = record[mark.contrastField] + ''
|
}
|
|
if (mark.match === '=') {
|
className = originVal === contrastVal ? 'background ' + mark.color[1] : ''
|
} else if (mark.match === '!=') {
|
className = originVal !== contrastVal ? 'background ' + mark.color[1] : ''
|
} else if (mark.match === 'like') {
|
className = originVal.indexOf(contrastVal) > -1 ? 'background ' + mark.color[1] : ''
|
} else if (mark.match === '>') {
|
try {
|
originVal = parseFloat(originVal)
|
contrastVal = parseFloat(contrastVal)
|
} catch (e) {
|
originVal = NaN
|
}
|
|
if (!isNaN(originVal) && !isNaN(contrastVal) && originVal > contrastVal) {
|
className = 'background ' + mark.color[1]
|
}
|
} else if (mark.match === '<') {
|
try {
|
originVal = parseFloat(originVal)
|
contrastVal = parseFloat(contrastVal)
|
} catch (e) {
|
originVal = NaN
|
}
|
|
if (!isNaN(originVal) && !isNaN(contrastVal) && originVal < contrastVal) {
|
className = 'background ' + mark.color[1]
|
}
|
}
|
|
if (!className) return false
|
return true
|
})
|
|
return className
|
}}
|
loading={loading}
|
scroll={{ x: '100%', y: height }}
|
onRow={(record, index) => {
|
if (setting.tableMode === 'fast') {
|
return {
|
record,
|
onClick: () => {this.changeRow(record, index)},
|
onDoubleClick: () => {this.doubleClickLine(record)}
|
}
|
} else {
|
return {
|
onClick: () => {this.changeRow(record, index)},
|
onDoubleClick: () => {this.doubleClickLine(record)}
|
}
|
}
|
}}
|
onChange={this.changeTable}
|
pagination={_pagination}
|
/>
|
{_footer ? <div className={'normal-table-footer ' + (_pagination ? 'pagination' : '')}>{_footer}</div> : null}
|
</div>
|
)
|
}
|
}
|
|
const mapStateToProps = (state) => {
|
return {
|
menuType: state.editLevel,
|
memberLevel: state.memberLevel
|
}
|
}
|
|
const mapDispatchToProps = () => {
|
return {}
|
}
|
|
export default connect(mapStateToProps, mapDispatchToProps)(NormalTable)
|