| | |
| | | import React, {Component} from 'react' |
| | | import PropTypes from 'prop-types' |
| | | import { is, fromJS } from 'immutable' |
| | | import { Table, Typography, Icon, Switch, Input, InputNumber, Tooltip } from 'antd' |
| | | import { Table, Typography, Modal, Input, InputNumber, Button, notification, message, Select } from 'antd' |
| | | import { EditOutlined, QuestionCircleOutlined } from '@ant-design/icons' |
| | | import moment from 'moment' |
| | | |
| | | import Api from '@/api' |
| | | import asyncComponent from '@/utils/asyncComponent' |
| | | import Utils, { getEditTableSql, getMark } from '@/utils/utils.js' |
| | | import MKEmitter from '@/utils/events.js' |
| | | import zhCN from '@/locales/zh-CN/main.js' |
| | | import enUS from '@/locales/en-US/main.js' |
| | | import '@/assets/css/table.scss' |
| | | import CusSwitch from './cusSwitch' |
| | | import Encrypts from '@/components/encrypts' |
| | | import './index.scss' |
| | | |
| | | const { Paragraph } = Typography |
| | | const MkIcon = asyncComponent(() => import('@/components/mk-icon')) |
| | | const CardCellComponent = asyncComponent(() => import('@/tabviews/custom/components/card/cardcellList')) |
| | | |
| | | class BodyRow extends React.Component { |
| | |
| | | class BodyCell extends React.Component { |
| | | state = { |
| | | editing: false, |
| | | err: null |
| | | } |
| | | |
| | | getMark = (record, marks, style, content) => { |
| | | marks.some(mark => { |
| | | let originVal = record[mark.field[0]] + '' |
| | | let contrastVal = '' |
| | | let result = false |
| | | |
| | | if (mark.field[1] === 'static') { |
| | | contrastVal = mark.contrastValue + '' |
| | | } else { |
| | | contrastVal = record[mark.field[2]] + '' |
| | | } |
| | | |
| | | if (mark.match === '=') { |
| | | result = originVal === contrastVal |
| | | } else if (mark.match === '!=') { |
| | | result = originVal !== contrastVal |
| | | } else if (mark.match === 'like') { |
| | | result = originVal.indexOf(contrastVal) > -1 |
| | | } else if (mark.match === '>') { |
| | | try { |
| | | originVal = parseFloat(originVal) |
| | | contrastVal = parseFloat(contrastVal) |
| | | } catch (e) { |
| | | originVal = NaN |
| | | } |
| | | |
| | | if (!isNaN(originVal) && !isNaN(contrastVal) && originVal > contrastVal) { |
| | | result = true |
| | | } |
| | | } else if (mark.match === '<') { |
| | | try { |
| | | originVal = parseFloat(originVal) |
| | | contrastVal = parseFloat(contrastVal) |
| | | } catch (e) { |
| | | originVal = NaN |
| | | } |
| | | |
| | | if (!isNaN(originVal) && !isNaN(contrastVal) && originVal < contrastVal) { |
| | | result = true |
| | | } |
| | | } |
| | | |
| | | if (result) { |
| | | if (mark.signType[0] === 'font') { |
| | | style.color = mark.color |
| | | } else if (mark.signType[0] === 'background') { |
| | | style.background = mark.color |
| | | if (mark.fontColor) { |
| | | style.color = mark.fontColor |
| | | } |
| | | } else if (mark.signType[0] === 'underline') { |
| | | style.textDecoration = 'underline' |
| | | style.color = mark.color |
| | | } else if (mark.signType[0] === 'line-through') { |
| | | style.textDecoration = 'line-through' |
| | | style.color = mark.color |
| | | } else if (mark.signType[0] === 'icon') { |
| | | let icon = (<Icon style={{color: mark.color}} type={mark.signType[3]} />) |
| | | if (mark.signType[1] === 'front') { |
| | | content = <span>{icon} {content}</span> |
| | | } else { |
| | | content = <span>{content} {icon}</span> |
| | | } |
| | | } |
| | | } |
| | | return result |
| | | }) |
| | | |
| | | return content |
| | | err: null, |
| | | value: '' |
| | | } |
| | | |
| | | shouldComponentUpdate (nextProps, nextState) { |
| | | return !is(fromJS(this.props.record), fromJS(nextProps.record)) || |
| | | nextState.editing !== this.state.editing || |
| | | nextState.err !== this.state.err |
| | | } |
| | | |
| | | componentDidMount () { |
| | | MKEmitter.addListener('tdFocus', this.tdFocus) |
| | | return !is(fromJS(this.props.record), fromJS(nextProps.record)) || !is(fromJS(this.state), fromJS(nextState)) |
| | | } |
| | | |
| | | /** |
| | |
| | | this.setState = () => { |
| | | return |
| | | } |
| | | MKEmitter.removeListener('tdFocus', this.tdFocus) |
| | | } |
| | | |
| | | tdFocus = (id) => { |
| | | const { col, record } = this.props |
| | | if (id !== col.uuid + record.$Index) return |
| | | this.focus() |
| | | } |
| | | |
| | | enterPress = () => { |
| | |
| | | const { value } = this.state |
| | | |
| | | this.setState({editing: false}) |
| | | if (col.enter === '$next') { |
| | | MKEmitter.emit('nextLine', col, record.$Index) |
| | | } else { |
| | | MKEmitter.emit('tdFocus', col.enter + record.$Index) |
| | | } |
| | | setTimeout(() => { |
| | | if (/\$next/.test(col.enter)) { |
| | | MKEmitter.emit('nextLine', col, record.$$uuid) |
| | | } else if (col.enter === '$sub') { |
| | | MKEmitter.emit('subLine', col, record) |
| | | } else if (col.enter !== '$noAct') { |
| | | let node = document.getElementById(col.enter + record.$$uuid) |
| | | node && node.click() |
| | | } |
| | | }, 50) |
| | | |
| | | let _record = {...record, [col.field]: value} |
| | | MKEmitter.emit('changeRecord', _record) |
| | | if (value !== record[col.field]) { |
| | | MKEmitter.emit('changeRecord', col.tableId, {...record, [col.field]: value}) |
| | | } |
| | | } |
| | | |
| | | focus = () => { |
| | | const { col, record } = this.props |
| | | |
| | | let err = null |
| | | let val = record[col.field] !== undefined ? record[col.field] : '' |
| | | if (col.ctrlField && col.ctrlValue.includes(record[col.ctrlField])) return |
| | | |
| | | if (col.type === 'number') { |
| | | val = +val |
| | | if (isNaN(val)) { |
| | | val = 0 |
| | | if (col.editType === 'switch' || col.editType === 'select') { |
| | | this.setState({editing: true}, () => { |
| | | let node = document.getElementById(col.uuid + record.$$uuid) |
| | | node && node.click() |
| | | }) |
| | | } else { |
| | | let err = null |
| | | let val = record[col.field] !== undefined ? record[col.field] : '' |
| | | |
| | | if (col.type === 'number') { |
| | | val = +val |
| | | if (isNaN(val)) { |
| | | val = 0 |
| | | } |
| | | if (typeof(col.max) === 'number' && val > col.max) { |
| | | err = col.label + '最大为' + col.max |
| | | } else if (typeof(col.min) === 'number' && val < col.min) { |
| | | err = col.label + '最小为' + col.min |
| | | } |
| | | } else if (col.required === 'true' && !val) { |
| | | err = '请填写' + col.label |
| | | } |
| | | if (typeof(col.max) === 'number' && val > col.max) { |
| | | err = col.label + '最大为' + col.max |
| | | } else if (typeof(col.min) === 'number' && val < col.min) { |
| | | err = col.label + '最小为' + col.min |
| | | } |
| | | } else if (col.required === 'true' && !val) { |
| | | err = '请填写' + col.label |
| | | |
| | | this.setState({editing: true, value: val, err}, () => { |
| | | let node = document.getElementById(col.uuid + record.$$uuid) |
| | | node && node.select() |
| | | }) |
| | | } |
| | | |
| | | this.setState({editing: true, value: val, err}, () => { |
| | | let node = document.getElementById(col.uuid + record.$Index) |
| | | node && node.select() |
| | | }) |
| | | } |
| | | |
| | | onBlur = () => { |
| | |
| | | |
| | | this.setState({editing: false}) |
| | | |
| | | let _record = {...record, [col.field]: value} |
| | | MKEmitter.emit('changeRecord', _record) |
| | | if (value !== record[col.field]) { |
| | | MKEmitter.emit('changeRecord', col.tableId, {...record, [col.field]: value}) |
| | | } |
| | | } |
| | | |
| | | onChange = (val) => { |
| | |
| | | } else if (col.required === 'true' && !val) { |
| | | err = '请填写' + col.label |
| | | } |
| | | |
| | | this.setState({value: val, err}) |
| | | } |
| | | |
| | | onSwitchChange = (val, label) => { |
| | | const { col, record } = this.props |
| | | |
| | | this.setState({editing: false}) |
| | | |
| | | setTimeout(() => { |
| | | if (/\$next/.test(col.enter)) { |
| | | MKEmitter.emit('nextLine', col, record.$$uuid) |
| | | } else if (col.enter === '$sub') { |
| | | MKEmitter.emit('subLine', col, record) |
| | | } else if (col.enter !== '$noAct') { |
| | | let node = document.getElementById(col.enter + record.$$uuid) |
| | | node && node.click() |
| | | } |
| | | }, 50) |
| | | |
| | | MKEmitter.emit('changeRecord', col.tableId, {...record, [col.field]: val}) |
| | | } |
| | | |
| | | onSelectChange = (val, option) => { |
| | | const { col, record } = this.props |
| | | |
| | | let values = {} |
| | | let _option = col.options.filter(m => m.key === option.key)[0] |
| | | |
| | | if (_option) { |
| | | if (col.linkSubField) { |
| | | col.linkSubField.forEach(m => { |
| | | values[m] = _option[m] !== undefined ? _option[m] : '' |
| | | }) |
| | | } |
| | | |
| | | values[col.field] = val |
| | | } |
| | | |
| | | this.setState({editing: false}) |
| | | |
| | | setTimeout(() => { |
| | | if (/\$next/.test(col.enter)) { |
| | | MKEmitter.emit('nextLine', col, record.$$uuid) |
| | | } else if (col.enter === '$sub') { |
| | | MKEmitter.emit('subLine', col, record) |
| | | } else if (col.enter !== '$noAct') { |
| | | let node = document.getElementById(col.enter + record.$$uuid) |
| | | node && node.click() |
| | | } |
| | | }, 50) |
| | | |
| | | MKEmitter.emit('changeRecord', col.tableId, {...record, ...values}) |
| | | } |
| | | |
| | | switchBlur = () => { |
| | | setTimeout(() => { |
| | | this.setState({editing: false}) |
| | | }, 10) |
| | | } |
| | | |
| | | render() { |
| | | let { col, config, record, style, className } = this.props |
| | | let { col, config, record, style, className, ...resProps } = this.props |
| | | const { editing, value, err } = this.state |
| | | |
| | | if (!col) return (<td {...resProps} className={className} style={style}/>) |
| | | |
| | | let disabled = false |
| | | if (col.ctrlField) { |
| | | disabled = col.ctrlValue.includes(record[col.ctrlField]) |
| | | } |
| | | |
| | | let children = null |
| | | if (col.type === 'text') { |
| | |
| | | content = `${record[col.field]}` |
| | | } |
| | | |
| | | if (col.editType === 'select' && col.options.length > 0) { |
| | | content = col.map.get(content) || content |
| | | } |
| | | |
| | | 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)}` |
| | | } else if (col.textFormat === 'encryption') { |
| | | content = <span>{col.prefix || ''}<Encrypts value={content} />{col.postfix || ''}</span> |
| | | } |
| | | |
| | | content = (col.prefix || '') + content + (col.postfix || '') |
| | | if (col.textFormat !== 'encryption') { |
| | | content = (col.prefix || '') + content + (col.postfix || '') |
| | | } |
| | | } |
| | | |
| | | if (col.marks) { |
| | | style = style || {} |
| | | content = this.getMark(record, col.marks, style, content) |
| | | let mark = getMark(col.marks, record, style) |
| | | |
| | | style = mark.style |
| | | |
| | | if (mark.icon) { |
| | | if (mark.position === 'front') { |
| | | content = <span><MkIcon style={mark.innerStyle} type={mark.icon} /> {content}</span> |
| | | } else { |
| | | content = <span>{content} <MkIcon style={mark.innerStyle} type={mark.icon} /></span> |
| | | } |
| | | } else if (mark.innerStyle) { |
| | | content = <span style={mark.innerStyle}>{content}</span> |
| | | } |
| | | } |
| | | |
| | | if (col.editable === 'true') { |
| | | if (col.editable === 'true' && !disabled) { |
| | | if (editing) { |
| | | return (<td className="editing_table_cell"> |
| | | <Input id={col.uuid + record.$Index} defaultValue={value} onChange={(e) => this.onChange(e.target.value)} onPressEnter={this.enterPress} onBlur={this.onBlur}/> |
| | | {err ? <Tooltip title={err}><Icon type="exclamation-circle" /></Tooltip> : null} |
| | | </td>) |
| | | if (!col.editType || col.editType === 'text') { |
| | | return (<td className="editing_table_cell"> |
| | | <Input className={err ? 'has-error' : ''} title={err} id={col.uuid + record.$$uuid} defaultValue={value} onChange={(e) => this.onChange(e.target.value)} onPressEnter={this.enterPress} onBlur={this.onBlur}/> |
| | | </td>) |
| | | } else if (col.editType === 'switch') { |
| | | let _value = record[col.field] !== undefined ? record[col.field] : '' |
| | | |
| | | return (<td className="editing_table_cell"> |
| | | <CusSwitch config={col} defaultValue={_value} autoFocus={true} onChange={this.onSwitchChange} onBlur={this.switchBlur}/> |
| | | </td>) |
| | | } else { |
| | | let _value = record[col.field] !== undefined ? record[col.field] : '' |
| | | |
| | | return (<td className="editing_table_cell"> |
| | | <Select |
| | | showSearch |
| | | defaultValue={_value} |
| | | dropdownClassName="edit-table-dropdown" |
| | | dropdownMatchSelectWidth={col.dropdown === 'fixed'} |
| | | id={col.uuid + record.$$uuid} |
| | | onBlur={() => this.setState({editing: false})} |
| | | filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0} |
| | | onSelect={this.onSelectChange} |
| | | > |
| | | {col.options.map((item, i) => (<Select.Option key={item.key} disabled={item.$disabled} value={item.value}>{item.label}</Select.Option>))} |
| | | </Select> |
| | | </td>) |
| | | } |
| | | } else { |
| | | return (<td className={className + ' pointer'} style={style}><div className="mk-mask" onClick={this.focus}></div>{content}</td>) |
| | | return (<td className={className + ' pointer'} style={style}> |
| | | <div className="mk-mask" id={col.uuid + record.$$uuid} onClick={this.focus}></div>{content} |
| | | </td>) |
| | | } |
| | | } else { |
| | | children = content |
| | |
| | | if (isNaN(content)) { |
| | | content = '' |
| | | } |
| | | if (col.noValue === 'hide' && content === 0) { |
| | | content = '' |
| | | } |
| | | } catch (e) { |
| | | content = '' |
| | | } |
| | | |
| | | if (content !== '') { |
| | | let decimal = col.decimal || 0 |
| | | if (col.round) { |
| | | content = Math.round(content * col.round) / col.round |
| | | } |
| | | if (col.format === 'percent') { |
| | | content = content * 100 |
| | | decimal = decimal > 2 ? decimal - 2 : 0 |
| | | } else if (col.format === 'abs') { |
| | | content = Math.abs(content) |
| | | } |
| | | |
| | | content = content.toFixed(decimal) |
| | | if (col.round) { |
| | | content = content.toFixed(col.decimal) |
| | | } |
| | | |
| | | if (col.format === 'thdSeparator') { |
| | | content = content.replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,') |
| | | } |
| | | |
| | | content = col.prefix + content + col.postfix |
| | | content = (col.prefix || '') + content + (col.postfix || '') |
| | | } |
| | | |
| | | if (col.marks) { |
| | | style = style || {} |
| | | content = this.getMark(record, col.marks, style, content) |
| | | let mark = getMark(col.marks, record, style) |
| | | |
| | | style = mark.style |
| | | |
| | | if (mark.icon) { |
| | | if (mark.position === 'front') { |
| | | content = <span><MkIcon style={mark.innerStyle} type={mark.icon} /> {content}</span> |
| | | } else { |
| | | content = <span>{content} <MkIcon style={mark.innerStyle} type={mark.icon} /></span> |
| | | } |
| | | } else if (mark.innerStyle) { |
| | | content = <span style={mark.innerStyle}>{content}</span> |
| | | } |
| | | } |
| | | |
| | | if (col.editable === 'true') { |
| | | if (col.editable === 'true' && !disabled) { |
| | | if (editing) { |
| | | let val = value |
| | | if (col.noValue === 'hide' && value === 0) { |
| | | val = '' |
| | | } |
| | | return (<td className="editing_table_cell"> |
| | | <InputNumber id={col.uuid + record.$Index} defaultValue={value} onChange={(val) => this.onChange(val)} onPressEnter={this.enterPress} onBlur={this.onBlur}/> |
| | | {err ? <Tooltip title={err}><Icon type="exclamation-circle" /></Tooltip> : null} |
| | | <InputNumber className={err ? 'has-error' : ''} precision={col.decimal || 0} title={err} id={col.uuid + record.$$uuid} defaultValue={val} onChange={(val) => this.onChange(val)} onPressEnter={this.enterPress} onBlur={this.onBlur}/> |
| | | </td>) |
| | | } else { |
| | | return (<td className={className + ' pointer'} style={style}><div className="mk-mask" onClick={this.focus}></div>{content}</td>) |
| | | return (<td className={className + ' pointer'} style={style}> |
| | | <div className="mk-mask" id={col.uuid + record.$$uuid} onClick={this.focus}></div>{content} |
| | | </td>) |
| | | } |
| | | } else { |
| | | children = content |
| | |
| | | } |
| | | |
| | | if (content) { |
| | | content = col.prefix + content + col.postfix |
| | | content = (col.prefix || '') + content + (col.postfix || '') |
| | | } |
| | | |
| | | children = ( |
| | |
| | | {content ? <Paragraph copyable ellipsis={{ rows: 3, expandable: true }}>{content}</Paragraph> : null } |
| | | </div> |
| | | ) |
| | | } else if (col.type === 'formula') { |
| | | let content = col.formula |
| | | Object.keys(record).forEach(key => { |
| | | let reg = new RegExp('@' + key + '@', 'ig') |
| | | content = content.replace(reg, record[key]) |
| | | }) |
| | | |
| | | if (col.eval !== 'false') { |
| | | try { |
| | | // eslint-disable-next-line |
| | | content = eval(content) |
| | | } catch (e) { |
| | | if (window.debugger) { |
| | | console.info(content) |
| | | console.warn(e) |
| | | } |
| | | content = '' |
| | | } |
| | | } |
| | | |
| | | content = content === undefined ? '' : content |
| | | |
| | | if (col.noValue === 'hide' && content === 0) { |
| | | content = '' |
| | | } |
| | | |
| | | if (col.round && typeof(content) === 'number') { |
| | | content = Math.round(content * col.round) / col.round |
| | | content = content.toFixed(col.decimal) |
| | | } |
| | | |
| | | if (content !== '') { |
| | | content = `${col.prefix || ''}${content}${col.postfix || ''}` |
| | | content = content.replace(/\n/ig, '<br/>').replace(/\s/ig, ' ') |
| | | content = <span dangerouslySetInnerHTML={{__html: content}}></span> |
| | | } |
| | | |
| | | if (col.marks) { |
| | | let mark = getMark(col.marks, record, style) |
| | | |
| | | style = mark.style |
| | | |
| | | if (mark.icon) { |
| | | if (mark.position === 'front') { |
| | | content = <span><MkIcon style={mark.innerStyle} type={mark.icon} /> {content}</span> |
| | | } else { |
| | | content = <span>{content} <MkIcon style={mark.innerStyle} type={mark.icon} /></span> |
| | | } |
| | | } else if (mark.innerStyle) { |
| | | content = <span style={mark.innerStyle}>{content}</span> |
| | | } |
| | | } |
| | | |
| | | children = content |
| | | } else if (col.type === 'custom') { |
| | | style.padding = '0px' |
| | | if (col.style) { |
| | |
| | | children = ( |
| | | <CardCellComponent data={record} cards={config} elements={col.elements}/> |
| | | ) |
| | | } else if (col.type === 'action') { |
| | | style.padding = '0px 5px' |
| | | children = ( |
| | | <CardCellComponent data={record} cards={config} elements={col.elements}/> |
| | | ) |
| | | } |
| | | |
| | | return (<td className={className} style={style}>{children}</td>) |
| | | } |
| | | } |
| | | |
| | | class BodyAllCell extends React.Component { |
| | | state = { |
| | | err: null, |
| | | value: '' |
| | | } |
| | | |
| | | shouldComponentUpdate (nextProps, nextState) { |
| | | return !is(fromJS(this.props.record), fromJS(nextProps.record)) || !is(fromJS(this.state), fromJS(nextState)) |
| | | } |
| | | |
| | | UNSAFE_componentWillMount() { |
| | | const { col } = this.props |
| | | |
| | | if (col && col.editable === 'true') { |
| | | this.setState({value: this.props.record[col.field]}) |
| | | } |
| | | } |
| | | |
| | | UNSAFE_componentWillReceiveProps(nextProps) { |
| | | const { col } = this.props |
| | | const { value } = this.state |
| | | |
| | | if (col && col.editable === 'true' && nextProps.record[col.field] !== value) { |
| | | this.setState({value: nextProps.record[col.field]}) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @description 组件销毁,清除state更新,清除快捷键设置 |
| | | */ |
| | | componentWillUnmount () { |
| | | this.setState = () => { |
| | | return |
| | | } |
| | | } |
| | | |
| | | enterPress = () => { |
| | | const { col, record } = this.props |
| | | |
| | | this.onBlur() |
| | | |
| | | setTimeout(() => { |
| | | if (/\$next/.test(col.enter)) { |
| | | MKEmitter.emit('nextLine', col, record.$$uuid) |
| | | } else if (col.enter === '$sub') { |
| | | MKEmitter.emit('subLine', col, record) |
| | | } else if (col.enter !== '$noAct') { |
| | | let node = document.getElementById(col.enter + record.$$uuid) |
| | | |
| | | if (node) { |
| | | if (col.triType === 'click') { |
| | | node.click() |
| | | } else { |
| | | node.select && node.select() |
| | | } |
| | | } |
| | | } |
| | | }, 50) |
| | | } |
| | | |
| | | onChange = (val) => { |
| | | const { col } = this.props |
| | | |
| | | if (col.noValue === 'hide' && val === null) { |
| | | this.setState({value: 0}) |
| | | } else { |
| | | this.setState({value: val}) |
| | | } |
| | | } |
| | | |
| | | onBlur = () => { |
| | | const { col, record } = this.props |
| | | const { value } = this.state |
| | | |
| | | let err = null |
| | | let val = value |
| | | |
| | | if (col.type === 'number') { |
| | | val = +val |
| | | if (isNaN(val)) { |
| | | val = 0 |
| | | } |
| | | if (typeof(col.max) === 'number' && val > col.max) { |
| | | err = col.label + '最大为' + col.max |
| | | } else if (typeof(col.min) === 'number' && val < col.min) { |
| | | err = col.label + '最小为' + col.min |
| | | } |
| | | } else if (col.required === 'true' && !val) { |
| | | err = '请填写' + col.label |
| | | } |
| | | |
| | | this.setState({err}) |
| | | |
| | | if (value !== record[col.field]) { |
| | | MKEmitter.emit('changeRecord', col.tableId, {...record, [col.field]: val}) |
| | | } |
| | | } |
| | | |
| | | onSwitchChange = (val, label) => { |
| | | const { col, record } = this.props |
| | | |
| | | setTimeout(() => { |
| | | if (/\$next/.test(col.enter)) { |
| | | MKEmitter.emit('nextLine', col, record.$$uuid) |
| | | } else if (col.enter === '$sub') { |
| | | MKEmitter.emit('subLine', col, record) |
| | | } else if (col.enter !== '$noAct') { |
| | | let node = document.getElementById(col.enter + record.$$uuid) |
| | | if (node) { |
| | | if (col.triType === 'click') { |
| | | node.click() |
| | | } else { |
| | | node.select && node.select() |
| | | } |
| | | } |
| | | } |
| | | }, 50) |
| | | |
| | | MKEmitter.emit('changeRecord', col.tableId, {...record, [col.field]: val}) |
| | | } |
| | | |
| | | onSelectChange = (val, option) => { |
| | | const { col, record } = this.props |
| | | |
| | | let values = {} |
| | | let _option = col.options.filter(m => m.key === option.key)[0] |
| | | |
| | | if (_option) { |
| | | if (col.linkSubField) { |
| | | col.linkSubField.forEach(m => { |
| | | values[m] = _option[m] !== undefined ? _option[m] : '' |
| | | }) |
| | | } |
| | | |
| | | values[col.field] = val |
| | | } |
| | | |
| | | setTimeout(() => { |
| | | if (/\$next/.test(col.enter)) { |
| | | MKEmitter.emit('nextLine', col, record.$$uuid) |
| | | } else if (col.enter === '$sub') { |
| | | MKEmitter.emit('subLine', col, record) |
| | | } else if (col.enter !== '$noAct') { |
| | | let node = document.getElementById(col.enter + record.$$uuid) |
| | | if (node) { |
| | | if (col.triType === 'click') { |
| | | node.click() |
| | | } else { |
| | | node.select && node.select() |
| | | } |
| | | } |
| | | } |
| | | }, 50) |
| | | |
| | | MKEmitter.emit('changeRecord', col.tableId, {...record, ...values}) |
| | | } |
| | | |
| | | render() { |
| | | let { col, config, record, style, className, ...resProps } = this.props |
| | | const { err } = this.state |
| | | |
| | | if (!col) return (<td {...resProps} className={className} style={style}/>) |
| | | |
| | | let disabled = false |
| | | if (col.ctrlField) { |
| | | disabled = col.ctrlValue.includes(record[col.ctrlField]) |
| | | } |
| | | |
| | | let children = null |
| | | if (col.type === 'text') { |
| | | if (col.editable === 'true' && !disabled) { |
| | | let _value = record[col.field] !== undefined ? record[col.field] : '' |
| | | |
| | | if (!col.editType || col.editType === 'text') { |
| | | children = (<> |
| | | <Input className={err ? 'has-error' : ''} title={err} id={col.uuid + record.$$uuid} defaultValue={_value} onChange={(e) => this.onChange(e.target.value)} onPressEnter={this.enterPress} onBlur={this.onBlur}/> |
| | | </>) |
| | | } else if (col.editType === 'switch') { |
| | | children = ( |
| | | <CusSwitch config={col} autoFocus={false} defaultValue={_value} onChange={this.onSwitchChange} onBlur={() => {}}/> |
| | | ) |
| | | } else { |
| | | children = (<> |
| | | <Select |
| | | showSearch |
| | | dropdownClassName="edit-table-dropdown" |
| | | dropdownMatchSelectWidth={col.dropdown === 'fixed'} |
| | | defaultValue={_value} |
| | | id={col.uuid + record.$$uuid} |
| | | filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0} |
| | | onSelect={this.onSelectChange} |
| | | > |
| | | {col.options.map((item, i) => (<Select.Option key={item.key} disabled={item.$disabled} value={item.value}>{item.label}</Select.Option>))} |
| | | </Select> |
| | | </>) |
| | | } |
| | | } else { |
| | | let content = '' |
| | | if (record[col.field] !== undefined) { |
| | | content = `${record[col.field]}` |
| | | } |
| | | |
| | | if (col.editType === 'select' && col.options.length > 0) { |
| | | content = col.map.get(content) || content |
| | | } |
| | | |
| | | 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)}` |
| | | } else if (col.textFormat === 'encryption') { |
| | | content = <span>{col.prefix || ''}<Encrypts value={content} />{col.postfix || ''}</span> |
| | | } |
| | | |
| | | if (col.textFormat !== 'encryption') { |
| | | content = (col.prefix || '') + content + (col.postfix || '') |
| | | } |
| | | } |
| | | |
| | | if (col.marks) { |
| | | let mark = getMark(col.marks, record, style) |
| | | |
| | | style = mark.style |
| | | |
| | | if (mark.icon) { |
| | | if (mark.position === 'front') { |
| | | content = <span><MkIcon style={mark.innerStyle} type={mark.icon} /> {content}</span> |
| | | } else { |
| | | content = <span>{content} <MkIcon style={mark.innerStyle} type={mark.icon} /></span> |
| | | } |
| | | } else if (mark.innerStyle) { |
| | | content = <span style={mark.innerStyle}>{content}</span> |
| | | } |
| | | } |
| | | |
| | | if (col.editable === 'true' && disabled) { |
| | | content = <span style={{display: 'inline-block', padding: '0 6px'}}>{content}</span> |
| | | } |
| | | |
| | | children = content |
| | | } |
| | | } else if (col.type === 'number') { |
| | | if (col.editable === 'true' && !disabled) { |
| | | let _value = record[col.field] !== undefined ? record[col.field] : '' |
| | | |
| | | if (col.noValue === 'hide' && _value === 0) { |
| | | _value = '' |
| | | } |
| | | |
| | | children = (<> |
| | | <InputNumber className={err ? 'has-error' : ''} title={err} precision={col.decimal || 0} id={col.uuid + record.$$uuid} defaultValue={_value} onChange={(val) => this.onChange(val)} onPressEnter={this.enterPress} onBlur={this.onBlur}/> |
| | | </>) |
| | | } else { |
| | | let content = '' |
| | | try { |
| | | content = parseFloat(record[col.field]) |
| | | if (isNaN(content)) { |
| | | content = '' |
| | | } |
| | | if (col.noValue === 'hide' && content === 0) { |
| | | content = '' |
| | | } |
| | | } catch (e) { |
| | | content = '' |
| | | } |
| | | |
| | | if (content !== '') { |
| | | if (col.round) { |
| | | content = Math.round(content * col.round) / col.round |
| | | } |
| | | if (col.format === 'percent') { |
| | | content = content * 100 |
| | | } else if (col.format === 'abs') { |
| | | content = Math.abs(content) |
| | | } |
| | | if (col.round) { |
| | | content = content.toFixed(col.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 mark = getMark(col.marks, record, style) |
| | | |
| | | style = mark.style |
| | | |
| | | if (mark.icon) { |
| | | if (mark.position === 'front') { |
| | | content = <span><MkIcon style={mark.innerStyle} type={mark.icon} /> {content}</span> |
| | | } else { |
| | | content = <span>{content} <MkIcon style={mark.innerStyle} type={mark.icon} /></span> |
| | | } |
| | | } else if (mark.innerStyle) { |
| | | content = <span style={mark.innerStyle}>{content}</span> |
| | | } |
| | | } |
| | | |
| | | if (col.editable === 'true' && disabled) { |
| | | content = <span style={{display: 'inline-block', padding: '0 6px'}}>{content}</span> |
| | | } |
| | | |
| | | children = content |
| | | } |
| | | } else if (col.type === 'textarea') { |
| | | let content = '' |
| | | if (record[col.field] !== undefined) { |
| | | content = `${record[col.field]}` |
| | | } |
| | | |
| | | if (content) { |
| | | content = (col.prefix || '') + content + (col.postfix || '') |
| | | } |
| | | |
| | | children = ( |
| | | <div> |
| | | {content ? <Paragraph copyable ellipsis={{ rows: 3, expandable: true }}>{content}</Paragraph> : null } |
| | | </div> |
| | | ) |
| | | } else if (col.type === 'formula') { |
| | | let content = col.formula |
| | | Object.keys(record).forEach(key => { |
| | | let reg = new RegExp('@' + key + '@', 'ig') |
| | | content = content.replace(reg, record[key]) |
| | | }) |
| | | |
| | | if (col.eval !== 'false') { |
| | | try { |
| | | // eslint-disable-next-line |
| | | content = eval(content) |
| | | } catch (e) { |
| | | if (window.debugger) { |
| | | console.info(content) |
| | | console.warn(e) |
| | | } |
| | | content = '' |
| | | } |
| | | } |
| | | |
| | | content = content === undefined ? '' : content |
| | | |
| | | if (col.noValue === 'hide' && content === 0) { |
| | | content = '' |
| | | } |
| | | |
| | | if (col.round && typeof(content) === 'number') { |
| | | content = Math.round(content * col.round) / col.round |
| | | content = content.toFixed(col.decimal) |
| | | } |
| | | |
| | | if (content !== '') { |
| | | content = `${col.prefix || ''}${content}${col.postfix || ''}` |
| | | content = content.replace(/\n/ig, '<br/>').replace(/\s/ig, ' ') |
| | | content = <span dangerouslySetInnerHTML={{__html: content}}></span> |
| | | } |
| | | |
| | | if (col.marks) { |
| | | let mark = getMark(col.marks, record, style) |
| | | |
| | | style = mark.style |
| | | |
| | | if (mark.icon) { |
| | | if (mark.position === 'front') { |
| | | content = <span><MkIcon style={mark.innerStyle} type={mark.icon} /> {content}</span> |
| | | } else { |
| | | content = <span>{content} <MkIcon style={mark.innerStyle} type={mark.icon} /></span> |
| | | } |
| | | } else if (mark.innerStyle) { |
| | | content = <span style={mark.innerStyle}>{content}</span> |
| | | } |
| | | } |
| | | |
| | | children = content |
| | | } else if (col.type === 'custom') { |
| | | style.padding = '0px' |
| | | if (col.style) { |
| | | style = {...style, ...col.style} |
| | | } |
| | | |
| | | children = ( |
| | | <CardCellComponent data={record} cards={config} elements={col.elements}/> |
| | | ) |
| | | } |
| | | |
| | | return (<td className={'editing_all_table_cell ' + className} style={style}>{children}</td>) |
| | | } |
| | | } |
| | | |
| | | class NormalTable extends Component { |
| | | static propTpyes = { |
| | | statFValue: PropTypes.any, // 合计字段数据 |
| | | MenuID: PropTypes.string, // 菜单Id |
| | | setting: PropTypes.object, // 表格全局设置:tableType(表格是否可选、单选、多选)、columnfixed(列固定)、actionfixed(按钮固定) |
| | | setting: PropTypes.object, // 表格全局设置:tableType(表格是否可选、单选、多选)、actionfixed(按钮固定) |
| | | columns: PropTypes.array, // 表格列 |
| | | lineMarks: PropTypes.any, // 行标记 |
| | | fields: PropTypes.array, // 组件字段集 |
| | | BData: PropTypes.any, // 主表数据 |
| | | data: PropTypes.any, // 表格数据 |
| | | BID: PropTypes.any, // 主表ID |
| | | total: PropTypes.any, // 总数 |
| | | loading: PropTypes.bool, // 表格加载中 |
| | | refreshdata: PropTypes.func, // 表格中排序列、页码的变化时刷新 |
| | | chgSelectData: PropTypes.func, |
| | | } |
| | | |
| | | state = { |
| | | dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, |
| | | data: [], |
| | | edData: [], |
| | | selectedRowKeys: [], // 表格中选中行 |
| | | tableId: '', // 表格ID |
| | | pageIndex: 1, // 初始页面索引 |
| | | pageSize: 10, // 每页数据条数 |
| | | columns: null, // 显示列 |
| | | pickup: false, // 收起未选择项 |
| | | orderfields: {} // 排序id与field转换 |
| | | forms: [], |
| | | orderfields: {}, // 排序id与field转换 |
| | | loading: false, |
| | | pageOptions: [], |
| | | deForms: null, |
| | | visible: false, |
| | | midData: null |
| | | } |
| | | |
| | | UNSAFE_componentWillMount () { |
| | | const { setting, fields, columns, data } = this.props |
| | | const { setting, fields, columns, BID } = this.props |
| | | let orderfields = {} |
| | | let initEditLine = null |
| | | |
| | | let _columns = columns.map(item => { |
| | | if (item.type === 'index') { |
| | | item.field = '$Index' |
| | | item.type = 'text' |
| | | } |
| | | if (!initEditLine && item.editable === 'true') { |
| | | initEditLine = item |
| | | } |
| | | let _columns = [] |
| | | let deForms = [] |
| | | let _forms = {} |
| | | let hasBid = false |
| | | |
| | | if (item.marks && item.marks.length === 0) { |
| | | item.marks = '' |
| | | } |
| | | let getColumns = (cols) => { |
| | | return cols.map(item => { |
| | | let cell = null |
| | | |
| | | if (item.type === 'colspan') { |
| | | cell = { title: item.label, align: item.Align } |
| | | cell.children = getColumns(item.subcols) |
| | | } else { |
| | | if (item.editable === 'true') { |
| | | _forms[item.field] = item |
| | | |
| | | if (item.field) { |
| | | orderfields[item.uuid] = item.field |
| | | } |
| | | if (item.ctrlField) { |
| | | item.ctrlValue = item.ctrlValue.split(',') |
| | | } |
| | | |
| | | if (item.type === 'text' && item.editType === 'select') { |
| | | item.map = new Map() |
| | | if (item.resourceType === '1') { |
| | | let _option = Utils.getSelectQueryOptions(item) |
| | | |
| | | if (/@BID@/ig.test(_option.sql)) { |
| | | hasBid = true |
| | | } |
| | | |
| | | item.base_sql = _option.sql |
| | | item.arr_field = _option.field |
| | | |
| | | deForms.push(item) |
| | | } else { |
| | | item.options.forEach(cell => { |
| | | item.map.set(cell.value, cell.label) |
| | | }) |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (item.field) { |
| | | orderfields[item.uuid] = item.field |
| | | } |
| | | |
| | | return { |
| | | align: item.Align, |
| | | dataIndex: item.uuid, |
| | | title: item.label, |
| | | sorter: item.field && item.IsSort === 'true', |
| | | width: item.Width || 120, |
| | | onCell: record => ({ |
| | | record, |
| | | col: item, |
| | | config: item.type === 'custom' || item.type === 'action' ? {setting, columns: fields} : null, |
| | | }) |
| | | cell = { |
| | | align: item.Align, |
| | | dataIndex: item.uuid, |
| | | title: item.editable === 'true' ? <span>{item.label}<EditOutlined className="system-color mk-edit-sign"/></span> : item.label, |
| | | sorter: !!(item.field && item.IsSort === 'true'), |
| | | width: item.Width || 120, |
| | | $type: item.type, |
| | | onCell: record => ({ |
| | | record, |
| | | col: item, |
| | | config: item.type === 'custom' ? {setting, columns: fields} : null, |
| | | }) |
| | | } |
| | | } |
| | | |
| | | return cell |
| | | }) |
| | | } |
| | | |
| | | _columns = getColumns(columns) |
| | | |
| | | let forms = [] |
| | | fields.forEach(item => { |
| | | if (item.field === setting.primaryKey) return |
| | | |
| | | if (_forms[item.field]) { |
| | | forms.push({..._forms[item.field], datatype: item.datatype}) |
| | | } else { |
| | | forms.push(item) |
| | | } |
| | | }) |
| | | |
| | | let tableId = (() => { |
| | | let uuid = [] |
| | | let _options = 'abcdefghigklmnopqrstuv' |
| | | for (let i = 0; i < 19; i++) { |
| | | uuid.push(_options.substr(Math.floor(Math.random() * 0x20), 1)) |
| | | } |
| | | return uuid.join('') |
| | | }) () |
| | | let size = (setting.pageSize || 10) + '' |
| | | let pageOptions = ['10', '25', '50', '100', '500', '1000'] |
| | | |
| | | if (setting.borderColor) { // 边框颜色 |
| | | let style = `#${tableId} table, #${tableId} tr, #${tableId} th, #${tableId} td {border-color: ${setting.borderColor}}` |
| | | let ele = document.createElement('style') |
| | | ele.innerHTML = style |
| | | document.getElementsByTagName('head')[0].appendChild(ele) |
| | | if (!pageOptions.includes(size)) { |
| | | pageOptions.push(size) |
| | | pageOptions = pageOptions.sort((a, b) => a - b) |
| | | } |
| | | |
| | | this.setState({ |
| | | data, |
| | | forms, |
| | | pageSize: setting.pageSize || 10, |
| | | pageOptions, |
| | | columns: _columns, |
| | | tableId, |
| | | orderfields, |
| | | initEditLine |
| | | tableId: setting.tableId, |
| | | orderfields |
| | | }, () => { |
| | | if (deForms.length > 0) { |
| | | if (hasBid && setting.supModule && !BID) { |
| | | this.setState({ deForms }) |
| | | } else { |
| | | this.improveActionForm(deForms, BID) |
| | | } |
| | | } |
| | | |
| | | const element = document.getElementById(setting.tableId) |
| | | element && element.style.setProperty('--mk-table-border-color', setting.borderColor || '#e8e8e8') |
| | | element && element.style.setProperty('--mk-table-color', setting.color || 'rgba(0, 0, 0, 0.65)') |
| | | element && element.style.setProperty('--mk-table-font-size', setting.fontSize || '14px') |
| | | element && element.style.setProperty('--mk-table-font-weight', setting.fontWeight || 'normal') |
| | | }) |
| | | } |
| | | |
| | |
| | | return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState)) |
| | | } |
| | | |
| | | UNSAFE_componentWillReceiveProps(nextProps) { |
| | | const { BID } = this.props |
| | | const { deForms } = this.state |
| | | |
| | | if (deForms && nextProps.BID !== BID) { |
| | | this.improveActionForm(deForms, nextProps.BID) |
| | | } |
| | | } |
| | | |
| | | componentDidMount () { |
| | | MKEmitter.addListener('resetTable', this.resetTable) |
| | | MKEmitter.addListener('subLine', this.subLine) |
| | | MKEmitter.addListener('nextLine', this.nextLine) |
| | | MKEmitter.addListener('addRecord', this.addRecord) |
| | | MKEmitter.addListener('delRecord', this.delRecord) |
| | | MKEmitter.addListener('resetTable', this.resetTable) |
| | | MKEmitter.addListener('transferData', this.transferData) |
| | | MKEmitter.addListener('changeRecord', this.changeRecord) |
| | | } |
| | | |
| | |
| | | this.setState = () => { |
| | | return |
| | | } |
| | | MKEmitter.removeListener('resetTable', this.resetTable) |
| | | MKEmitter.removeListener('subLine', this.subLine) |
| | | MKEmitter.removeListener('nextLine', this.nextLine) |
| | | MKEmitter.removeListener('addRecord', this.addRecord) |
| | | MKEmitter.removeListener('delRecord', this.delRecord) |
| | | MKEmitter.removeListener('resetTable', this.resetTable) |
| | | MKEmitter.removeListener('transferData', this.transferData) |
| | | MKEmitter.removeListener('changeRecord', this.changeRecord) |
| | | } |
| | | |
| | | UNSAFE_componentWillReceiveProps(nextProps) { |
| | | if (!is(fromJS(this.props.data), fromJS(nextProps.data))) { |
| | | this.setState({data: nextProps.data || []}) |
| | | transferData = (menuid, data, type) => { |
| | | const { MenuID } = this.props |
| | | const { edData } = this.state |
| | | |
| | | if (menuid !== MenuID) return |
| | | |
| | | if (type !== 'line') { |
| | | let index = edData.findIndex(item => !item.$origin && !item.$forbid) |
| | | |
| | | if (index > -1) { |
| | | this.setState({visible: true, midData: data}) |
| | | } else { |
| | | this.updateMutil(data) |
| | | } |
| | | } else if (type === 'line') { |
| | | let _edData = this.state.edData.map(item => { |
| | | if (item.$$uuid === data.$$uuid) { |
| | | return data |
| | | } else { |
| | | return item |
| | | } |
| | | }) |
| | | |
| | | this.setState({edData: _edData}) |
| | | } |
| | | } |
| | | |
| | | updateMutil = (data) => { |
| | | const { setting } = this.props |
| | | |
| | | if (setting.editType === 'multi' && data.length > 0) { |
| | | this.setState({edData: []}, () => { |
| | | this.setState({edData: data, visible: false, midData: null}) |
| | | }) |
| | | } else { |
| | | this.setState({edData: data, visible: false, midData: null}) |
| | | } |
| | | |
| | | if (setting.addable && data.length === 0) { |
| | | setTimeout(() => { |
| | | this.plusLine(true) |
| | | }, 10) |
| | | } |
| | | } |
| | | |
| | | improveActionForm = (deForms, BID) => { |
| | | const { setting } = this.props |
| | | |
| | | let deffers = [] |
| | | let mainItems = [] // 云端或单点数据 |
| | | let localItems = [] // 本地数据 |
| | | let cache = setting.cache !== 'false' |
| | | let debug = window.GLOB.debugger === true || window.debugger === true |
| | | let _sql = `Declare @mk_departmentcode nvarchar(512),@mk_organization nvarchar(512),@mk_user_type nvarchar(20) select @mk_departmentcode='${sessionStorage.getItem('departmentcode') || ''}',@mk_organization='${sessionStorage.getItem('organization') || ''}',@mk_user_type='${sessionStorage.getItem('mk_user_type') || ''}'\n` |
| | | let _sso = _sql |
| | | |
| | | deForms.forEach(item => { |
| | | if (item.database === 'sso') { |
| | | let sql = _sso + item.base_sql |
| | | _sso = '' |
| | | |
| | | sql = sql.replace(/@BID@/ig, `'${BID}'`) |
| | | |
| | | if (debug) { |
| | | console.info(sql) |
| | | } |
| | | |
| | | sql = sql.replace(/%/ig, ' mpercent ') |
| | | |
| | | mainItems.push(`select '${item.uuid}' as obj_name,'${item.arr_field}' as arr_field,'${window.btoa(window.encodeURIComponent(sql))}' as LText`) |
| | | } else { |
| | | let sql = _sql + item.base_sql |
| | | _sql = '' |
| | | |
| | | sql = sql.replace(/@BID@/ig, `'${BID}'`) |
| | | |
| | | if (debug) { |
| | | console.info(sql) |
| | | } |
| | | |
| | | sql = sql.replace(/%/ig, ' mpercent ') |
| | | |
| | | localItems.push(`select '${item.uuid}' as obj_name,'${item.arr_field}' as arr_field,'${window.btoa(window.encodeURIComponent(sql))}' as LText`) |
| | | } |
| | | }) |
| | | |
| | | // 本地请求 |
| | | let param = { |
| | | func: 'sPC_Get_SelectedList', |
| | | LText: localItems.join(' union all '), |
| | | obj_name: '', |
| | | arr_field: '', |
| | | table_type: 'Y', |
| | | BID: BID || '' |
| | | } |
| | | |
| | | if (param.LText) { |
| | | param.LText = Utils.formatOptions(param.LText) |
| | | param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') |
| | | param.secretkey = Utils.encrypt(param.LText, param.timestamp) |
| | | |
| | | deffers.push( |
| | | new Promise(resolve => { |
| | | Api.getSystemCacheConfig(param, cache).then(res => { |
| | | if (!res.status) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: res.message, |
| | | duration: 5 |
| | | }) |
| | | } |
| | | resolve(res) |
| | | }) |
| | | }) |
| | | ) |
| | | } |
| | | |
| | | // 系统请求 |
| | | let mainparam = { |
| | | func: 'sPC_Get_SelectedList', |
| | | LText: mainItems.join(' union all '), |
| | | obj_name: '', |
| | | arr_field: '', |
| | | table_type: 'Y', |
| | | BID: BID || '' |
| | | } |
| | | |
| | | if (mainparam.LText) { |
| | | mainparam.LText = Utils.formatOptions(mainparam.LText) |
| | | mainparam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') |
| | | mainparam.secretkey = Utils.encrypt(mainparam.LText, mainparam.timestamp) |
| | | |
| | | if (window.GLOB.mainSystemApi) { |
| | | mainparam.rduri = window.GLOB.mainSystemApi |
| | | } |
| | | |
| | | deffers.push( |
| | | new Promise(resolve => { |
| | | Api.getSystemCacheConfig(mainparam, cache).then(res => { |
| | | if (!res.status) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: res.message, |
| | | duration: 5 |
| | | }) |
| | | } |
| | | resolve(res) |
| | | }) |
| | | }) |
| | | ) |
| | | } |
| | | |
| | | Promise.all(deffers).then(response => { |
| | | let result = {...response[0], ...(response[1] || {})} |
| | | |
| | | delete result.ErrCode |
| | | delete result.ErrMesg |
| | | delete result.message |
| | | delete result.status |
| | | |
| | | this.resetFormList(result) |
| | | }) |
| | | } |
| | | |
| | | resetFormList = (result) => { |
| | | const { columns, edData } = this.state |
| | | |
| | | let _edColumns = [] |
| | | |
| | | let reCols = {} |
| | | this.props.columns.forEach(item => { |
| | | if (item.resourceType === '1' && result[item.uuid] && result[item.uuid].length > 0) { |
| | | let options = [] |
| | | let all = false |
| | | result[item.uuid].forEach(cell => { |
| | | let _cell = {key: Utils.getuuid()} |
| | | |
| | | _cell.value = cell[item.valueField] |
| | | _cell.label = cell[item.valueText] |
| | | |
| | | if (!_cell.label && _cell.label !== 0) { |
| | | if (!all) { |
| | | _cell.label = '全部' |
| | | all = true |
| | | } else { |
| | | return |
| | | } |
| | | } |
| | | |
| | | if (item.map.has(_cell.value)) return |
| | | item.map.set(_cell.value, _cell.label) |
| | | |
| | | if (item.linkSubField) { |
| | | item.linkSubField.forEach(m => { |
| | | _cell[m] = cell[m] === undefined ? '' : cell[m] |
| | | }) |
| | | } |
| | | |
| | | if (item.disableField && cell[item.disableField] && /^true$/ig.test(cell[item.disableField])) { |
| | | _cell.$disabled = true |
| | | } |
| | | |
| | | options.push(_cell) |
| | | }) |
| | | |
| | | item.options = options |
| | | |
| | | reCols[item.uuid] = fromJS(item).toJS() |
| | | } |
| | | }) |
| | | |
| | | _edColumns = columns.map(item => { |
| | | if (reCols[item.dataIndex]) { |
| | | item.onCell = record => ({ |
| | | record, |
| | | col: reCols[item.dataIndex] |
| | | }) |
| | | } |
| | | |
| | | return item |
| | | }) |
| | | |
| | | this.setState({columns: [], edData: []}, () => { |
| | | this.setState({columns: _edColumns, edData: edData}) |
| | | }) |
| | | } |
| | | |
| | | nextLine = (col, index) => { |
| | | const { data, initEditLine } = this.state |
| | | index = +index |
| | | nextLine = (col, uuid) => { |
| | | const { setting } = this.props |
| | | const { edData, tableId } = this.state |
| | | |
| | | if (index < data.length && initEditLine) { |
| | | MKEmitter.emit('tdFocus', initEditLine.uuid + (index + 1)) |
| | | if (col.tableId !== tableId) return |
| | | |
| | | let index = edData.findIndex(item => item.$$uuid === uuid) |
| | | let next = edData[index + 1] || null |
| | | |
| | | if (next) { |
| | | let nextId = setting.initId + next.$$uuid |
| | | if (/^\$next_/.test(col.enter)) { |
| | | nextId = col.enter.split('_')[1] + next.$$uuid |
| | | } |
| | | |
| | | let node = document.getElementById(nextId) |
| | | if (node) { |
| | | if (setting.editType === 'multi') { |
| | | if (setting.triType === 'click') { |
| | | node.click() |
| | | } else { |
| | | node.select && node.select() |
| | | } |
| | | } else { |
| | | node.click() |
| | | } |
| | | } |
| | | } else if (setting.addable) { |
| | | setTimeout(() => { |
| | | this.plusLine() |
| | | }, 10) |
| | | } else if (edData[index]) { |
| | | setTimeout(() => { |
| | | this.subLine(col, edData[index]) |
| | | }, 10) |
| | | } |
| | | } |
| | | |
| | | changeRecord = (record) => { |
| | | let _data = this.state.data.map(item => { |
| | | if (item.$Index === record.$Index) { |
| | | subLine = (col, record) => { |
| | | const { tableId, edData } = this.state |
| | | |
| | | if (col && col.tableId !== tableId) return |
| | | |
| | | let _data = edData.map(item => { |
| | | if (item.$$uuid === record.$$uuid) { |
| | | item.$origin = false |
| | | } |
| | | return item |
| | | }) |
| | | |
| | | this.setState({edData: _data}, () => { |
| | | this.submit() |
| | | }) |
| | | } |
| | | |
| | | plusLine = (auto) => { |
| | | const { setting } = this.props |
| | | const { edData, forms } = this.state |
| | | |
| | | let item = edData.length > 0 ? {...edData[edData.length - 1]} : {} |
| | | |
| | | item.$$uuid = Utils.getguid() |
| | | item.$type = 'add' |
| | | item.$forbid = true |
| | | item.$Index = '' |
| | | |
| | | forms.forEach(col => { |
| | | if (col.initval !== '$copy') { |
| | | item[col.field] = col.initval |
| | | } |
| | | if (col.type === 'number') { |
| | | item[col.field] = +item[col.field] |
| | | if (isNaN(item[col.field])) { |
| | | item[col.field] = 0 |
| | | } |
| | | } |
| | | if (item[col.field] === undefined) { |
| | | item[col.field] = '' |
| | | } |
| | | }) |
| | | |
| | | this.setState({edData: [...edData, item]}, () => { |
| | | let node = document.getElementById(setting.initId + item.$$uuid) |
| | | if (node && !auto) { |
| | | if (setting.editType === 'multi') { |
| | | if (setting.triType === 'click') { |
| | | node.click() |
| | | } else { |
| | | node.select && node.select() |
| | | } |
| | | } else { |
| | | node.click() |
| | | } |
| | | } |
| | | }) |
| | | } |
| | | |
| | | delRecord = (id, record) => { |
| | | const { setting } = this.props |
| | | const { tableId, edData } = this.state |
| | | |
| | | if (id !== tableId) return |
| | | |
| | | if (record.$type === 'add') { |
| | | let _data = edData.filter(item => item.$$uuid !== record.$$uuid) |
| | | this.setState({edData: _data}) |
| | | } else { |
| | | let _data = fromJS(edData).toJS().map(item => { |
| | | if (item.$$uuid === record.$$uuid) { |
| | | item.$deleted = true |
| | | item.$origin = false |
| | | item.$type = 'del' |
| | | } |
| | | |
| | | return item |
| | | }) |
| | | |
| | | this.setState({edData: _data}, () => { |
| | | if (setting.commit === 'simple') { |
| | | this.submit() |
| | | } |
| | | }) |
| | | } |
| | | } |
| | | |
| | | changeRecord = (id, record) => { |
| | | const { setting } = this.props |
| | | const { tableId } = this.state |
| | | |
| | | if (id !== tableId) return |
| | | |
| | | let lock = record.$lock |
| | | |
| | | let _data = this.state.edData.map(item => { |
| | | if (item.$$uuid === record.$$uuid) { |
| | | record.$origin = false |
| | | record.$lock = true |
| | | |
| | | delete record.$forbid |
| | | |
| | | return record |
| | | } else { |
| | | return item |
| | | } |
| | | }) |
| | | |
| | | this.setState({data: _data}) |
| | | this.setState({edData: _data}, () => { |
| | | if (setting.tableType && setting.hasAction && !lock && this.state.selectedRowKeys.includes(record.$$uuid)) { |
| | | this.selectdata(this.state.selectedRowKeys) |
| | | } |
| | | }) |
| | | } |
| | | |
| | | addRecord = (id, record) => { |
| | | const { BID } = this.props |
| | | const { edData, forms, tableId } = this.state |
| | | |
| | | if (id !== tableId) return |
| | | |
| | | let _edData = fromJS(edData).toJS() |
| | | let item = {} |
| | | let index = null |
| | | let copy = edData.length > 0 ? {...edData[edData.length - 1]} : null |
| | | |
| | | if (record) { |
| | | index = _edData.findIndex(item => record.$$uuid === item.$$uuid) |
| | | index = index === -1 ? null : index |
| | | |
| | | copy = {...record} |
| | | } |
| | | |
| | | if (copy) { |
| | | item = {...copy} |
| | | } |
| | | |
| | | item.$$uuid = Utils.getguid() |
| | | item.$type = 'add' |
| | | item.$Index = '' |
| | | item.$forbid = true |
| | | item.$$BID = BID || '' |
| | | |
| | | forms.forEach(col => { |
| | | if (col.initval !== '$copy') { |
| | | item[col.field] = col.initval |
| | | } |
| | | if (col.type === 'number') { |
| | | item[col.field] = +item[col.field] |
| | | if (isNaN(item[col.field])) { |
| | | item[col.field] = 0 |
| | | } |
| | | } |
| | | |
| | | if (item[col.field] === undefined) { |
| | | item[col.field] = '' |
| | | } |
| | | }) |
| | | |
| | | if (index === null) { |
| | | _edData.push(item) |
| | | } else { |
| | | _edData.splice(index, 0, item) |
| | | } |
| | | |
| | | this.setState({edData: _edData}) |
| | | } |
| | | |
| | | checkData = () => { |
| | | const { setting } = this.props |
| | | const { edData, forms } = this.state |
| | | |
| | | if (edData.length === 0) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '提交数据不可为空!', |
| | | duration: 5 |
| | | }) |
| | | return null |
| | | } |
| | | |
| | | let data = fromJS(edData).toJS() |
| | | |
| | | data = data.filter(item => !item.$forbid) |
| | | if (setting.commit === 'change' || setting.commit === 'simple') { |
| | | data = data.filter(item => !item.$origin) |
| | | } |
| | | |
| | | if (data.length === 0) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '数据未修改,不可提交!', |
| | | duration: 5 |
| | | }) |
| | | return null |
| | | } |
| | | |
| | | let err = '' |
| | | let Index = 1 |
| | | data = data.map(item => { |
| | | let line = [] |
| | | forms.forEach(col => { |
| | | if (col.editable !== 'true' || item.$deleted) { |
| | | if (col.type === 'number') { |
| | | item[col.field] = +item[col.field] |
| | | if (isNaN(item[col.field])) { |
| | | item[col.field] = 0 |
| | | } |
| | | } else { |
| | | item[col.field] = item[col.field] !== undefined ? (item[col.field] + '') : '' |
| | | } |
| | | return |
| | | } |
| | | if (col.type === 'text') { |
| | | let val = item[col.field] !== undefined ? (item[col.field] + '') : '' |
| | | if (col.required === 'true' && !val) { |
| | | line.push(`${col.label}不可为空`) |
| | | } |
| | | item[col.field] = val |
| | | } else if (col.type === 'number') { |
| | | let val = item[col.field] |
| | | if (col.noValue === 'hide' && !val) { |
| | | val = 0 |
| | | } else if (!val && val !== 0) { |
| | | line.push(`${col.label}不可为空`) |
| | | return |
| | | } |
| | | val = +val |
| | | if (isNaN(val)) { |
| | | line.push(`${col.label}数据格式错误`) |
| | | return |
| | | } |
| | | |
| | | val = +val.toFixed(col.decimal || 0) |
| | | |
| | | if (typeof(col.max) === 'number' && val > col.max) { |
| | | line.push(`${col.label}不可大于${col.max}`) |
| | | } else if (typeof(col.min) === 'number' && val < col.min) { |
| | | line.push(`${col.label}不可小于${col.min}`) |
| | | } |
| | | |
| | | item[col.field] = val |
| | | } |
| | | }) |
| | | |
| | | if (line.length > 0) { |
| | | err += `第${Index}行:` + line.join(',') + ';' |
| | | } |
| | | if (!item.$deleted) { |
| | | Index++ |
| | | } |
| | | |
| | | return item |
| | | }) |
| | | |
| | | if (err) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: err, |
| | | duration: 5 |
| | | }) |
| | | |
| | | return null |
| | | } |
| | | |
| | | return data |
| | | } |
| | | |
| | | submit = () => { |
| | | const { submit, BID, setting } = this.props |
| | | const { forms } = this.state |
| | | |
| | | this.setState({visible: false, midData: null}) |
| | | |
| | | if (setting.supModule && !BID) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '需要上级主键值!', |
| | | duration: 5 |
| | | }) |
| | | |
| | | return |
| | | } |
| | | |
| | | let data = this.checkData() |
| | | |
| | | if (!data) return |
| | | |
| | | let result = getEditTableSql(submit, data, forms) |
| | | |
| | | let param = { |
| | | excel_in: result.lines, |
| | | BID: BID || '' |
| | | } |
| | | |
| | | this.setState({ |
| | | loading: true |
| | | }) |
| | | |
| | | if (submit.intertype === 'system') { // 系统存储过程 |
| | | param.func = 'sPC_TableData_InUpDe' |
| | | |
| | | if (sessionStorage.getItem('dataM') === 'true') { // 数据权限 |
| | | result.sql = result.sql.replace(/\$@/ig, '/*') |
| | | result.sql = result.sql.replace(/@\$/ig, '*/') |
| | | result.bottom = result.bottom.replace(/\$@/ig, '/*') |
| | | result.bottom = result.bottom.replace(/@\$/ig, '*/') |
| | | } else { |
| | | result.sql = result.sql.replace(/@\$|\$@/ig, '') |
| | | result.bottom = result.bottom.replace(/@\$|\$@/ig, '') |
| | | } |
| | | |
| | | param.excel_in_type = 'true' |
| | | param.LText1 = Utils.formatOptions(result.insert) |
| | | param.LText2 = Utils.formatOptions(result.bottom) |
| | | param.LText = Utils.formatOptions(result.sql) |
| | | param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') |
| | | param.secretkey = Utils.encrypt(param.LText, param.timestamp) |
| | | |
| | | param.menuname = submit.logLabel |
| | | |
| | | if (window.GLOB.probation) { |
| | | param.s_debug_type = 'Y' |
| | | } |
| | | |
| | | Api.genericInterface(param).then((res) => { |
| | | if (res.status) { |
| | | this.execSuccess(res) |
| | | } else { |
| | | this.execError(res) |
| | | } |
| | | }, (error) => { |
| | | if (error && error.ErrCode === 'LoginError') return |
| | | |
| | | this.execError({}) |
| | | }) |
| | | } else if (submit.intertype === 'inner' && submit.innerFunc) { // 自定义存储过程 |
| | | param.func = submit.innerFunc |
| | | |
| | | Api.genericInterface(param).then((res) => { |
| | | if (res.status) { |
| | | this.execSuccess(res) |
| | | } else { |
| | | this.execError(res) |
| | | } |
| | | }, (error) => { |
| | | if (error && error.ErrCode === 'LoginError') return |
| | | |
| | | this.execError({}) |
| | | }) |
| | | } |
| | | } |
| | | |
| | | execSuccess = (res) => { |
| | | const { submit } = this.props |
| | | const { edData } = this.state |
| | | |
| | | if (res && res.ErrCode === 'S') { // 执行成功 |
| | | notification.success({ |
| | | top: 92, |
| | | message: res.ErrMesg || '执行成功', |
| | | duration: submit.stime ? submit.stime : 2 |
| | | }) |
| | | } else if (res && res.ErrCode === 'Y') { // 执行成功 |
| | | Modal.success({ |
| | | title: res.ErrMesg || '执行成功' |
| | | }) |
| | | } else if (res && res.ErrCode === '-1') { // 完成后不提示 |
| | | |
| | | } |
| | | |
| | | let _edData = fromJS(edData).toJS() |
| | | |
| | | _edData = _edData.map(item => { |
| | | if (!item.$forbid) { |
| | | item.$origin = true |
| | | } |
| | | return item |
| | | }) |
| | | |
| | | this.setState({ |
| | | loading: false, |
| | | edData: _edData |
| | | }) |
| | | |
| | | if (submit.closetab === 'true') { |
| | | MKEmitter.emit('popclose') |
| | | } |
| | | |
| | | if (submit.execSuccess !== 'never') { |
| | | MKEmitter.emit('refreshByButtonResult', submit.$menuId, submit.execSuccess, submit) |
| | | } |
| | | |
| | | submit.syncComponentId && MKEmitter.emit('reloadData', submit.syncComponentId) |
| | | } |
| | | |
| | | execError = (res) => { |
| | | const { submit } = this.props |
| | | |
| | | if (res.ErrCode === 'E') { |
| | | Modal.error({ |
| | | title: res.message || res.ErrMesg, |
| | | }) |
| | | } else if (res.ErrCode === 'N') { |
| | | notification.error({ |
| | | top: 92, |
| | | message: res.message || res.ErrMesg, |
| | | duration: submit.ntime ? submit.ntime : 10 |
| | | }) |
| | | } else if (res.ErrCode === 'F') { |
| | | notification.error({ |
| | | className: 'notification-custom-error', |
| | | top: 92, |
| | | message: res.message || res.ErrMesg, |
| | | duration: submit.ftime ? submit.ftime : 10 |
| | | }) |
| | | } else if (res.ErrCode === 'NM') { |
| | | message.error(res.message || res.ErrMesg) |
| | | } |
| | | |
| | | this.setState({ |
| | | loading: false |
| | | }) |
| | | |
| | | if (submit.execError !== 'never') { |
| | | MKEmitter.emit('refreshByButtonResult', submit.$menuId, submit.execError, submit) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @description 选中行 |
| | | */ |
| | | onSelectChange = selectedRowKeys => { |
| | | this.setState({ selectedRowKeys }) |
| | | |
| | | let activeId = '' |
| | | if (selectedRowKeys.length > 0) { |
| | | activeId = selectedRowKeys.slice(-1)[0] |
| | | } |
| | | this.changedata(activeId) |
| | | this.selectdata(selectedRowKeys) |
| | | } |
| | | |
| | | /** |
| | | * @description 点击整行,触发切换, 判断是否可选,单选或多选,进行对应操作 |
| | | */ |
| | | changeRow = (id) => { |
| | | const { setting } = this.props |
| | | |
| | | if (!setting.tableType) return |
| | | |
| | | let newkeys = fromJS(this.state.selectedRowKeys).toJS() |
| | | |
| | | let activeId = '' |
| | | if (setting.tableType === 'radio') { |
| | | activeId = id |
| | | newkeys = [id] |
| | | this.setState({ selectedRowKeys: newkeys }) |
| | | } else { |
| | | if (newkeys.includes(id)) { |
| | | newkeys = newkeys.filter(item => item !== id) |
| | | |
| | | if (newkeys.length > 0) { |
| | | activeId = newkeys.slice(-1)[0] |
| | | } |
| | | } else { |
| | | activeId = id |
| | | newkeys.push(id) |
| | | } |
| | | |
| | | this.setState({ selectedRowKeys: newkeys }) |
| | | } |
| | | |
| | | this.changedata(activeId) |
| | | this.selectdata(newkeys) |
| | | } |
| | | |
| | | changedata = (id) => { |
| | | const { MenuID } = this.props |
| | | const { edData } = this.state |
| | | |
| | | let _data = '' |
| | | |
| | | if (id) { |
| | | _data = edData.filter(item => item.$$uuid === id)[0] || '' |
| | | } |
| | | |
| | | MKEmitter.emit('resetSelectLine', MenuID, id, _data) |
| | | } |
| | | |
| | | selectdata = (keys) => { |
| | | const { edData } = this.state |
| | | |
| | | let _data = edData.filter(item => keys.includes(item.$$uuid)) |
| | | |
| | | this.props.chgSelectData(_data) |
| | | } |
| | | |
| | | changeTable = (pagination, filters, sorter) => { |
| | |
| | | this.setState({ |
| | | pageIndex: pagination.current, |
| | | pageSize: pagination.pageSize, |
| | | pickup: false |
| | | selectedRowKeys: [], |
| | | }) |
| | | |
| | | sorter.field = orderfields[sorter.field] || '' |
| | |
| | | |
| | | if (repage === 'false') { |
| | | this.setState({ |
| | | pickup: false |
| | | selectedRowKeys: [], |
| | | }) |
| | | } else { |
| | | this.setState({ |
| | | pageIndex: 1, |
| | | pickup: false |
| | | selectedRowKeys: [], |
| | | }) |
| | | } |
| | | } |
| | | |
| | | pickupChange = () => { |
| | | this.setState({ |
| | | pickup: !this.state.pickup |
| | | }) |
| | | } |
| | | |
| | | render() { |
| | | const { setting, statFValue, lineMarks } = this.props |
| | | const { pickup, tableId, data } = this.state |
| | | const { setting, lineMarks, submit } = this.props |
| | | const { tableId, edData, columns, loading, pageOptions, selectedRowKeys, visible, midData } = this.state |
| | | |
| | | const components = { |
| | | body: { |
| | | row: BodyRow, |
| | | cell: BodyCell |
| | | cell: setting.editType !== 'multi' ? BodyCell : BodyAllCell |
| | | } |
| | | } |
| | | |
| | | // 数据收起时,过滤已选数据 |
| | | let _data = data || [] |
| | | let _data = edData.filter(item => !item.$deleted) |
| | | |
| | | if (pickup) { |
| | | _data = _data.filter(item => !item.$deleted) |
| | | // 设置表格选择属性:单选、多选、不可选 |
| | | let rowSelection = null |
| | | if (setting.tableType) { |
| | | rowSelection = { |
| | | selectedRowKeys, |
| | | type: (setting.tableType === 'radio') ? 'radio' : 'checkbox', |
| | | onChange: this.onSelectChange |
| | | } |
| | | } |
| | | |
| | | |
| | | let _pagination = false |
| | | if (setting.laypage !== 'false' && setting.laypage !== false) { |
| | | if (setting.laypage) { |
| | | _pagination = { |
| | | current: this.state.pageIndex, |
| | | pageSize: this.state.pageSize, |
| | | pageSizeOptions: ['10', '25', '50', '100', '500', '1000'], |
| | | pageSizeOptions: pageOptions, |
| | | showSizeChanger: true, |
| | | total: this.props.total || 0, |
| | | showTotal: (total, range) => `${range[0]}-${range[1]} ${this.state.dict['main.pagination.of']} ${total} ${this.state.dict['main.pagination.items']}` |
| | | showTotal: (total, range) => `${range[0]}-${range[1]} 共 ${total} 条` |
| | | } |
| | | } |
| | | |
| | | let _footer = '' |
| | | |
| | | if (statFValue && statFValue.length > 0) { |
| | | _footer = statFValue.map(f => `${f.label}(合计):${f.value}`).join(';') |
| | | let height = setting.height || false |
| | | if (height && height <= 100) { |
| | | height = height + 'vh' |
| | | } |
| | | |
| | | let height = setting.height || false |
| | | |
| | | return ( |
| | | <div className={`edit-custom-table ${pickup ? 'editable' : ''} ${setting.tableHeader || ''} ${height ? 'fixed-height' : ''} ${setting.mode || ''}`} id={tableId}> |
| | | <Switch title="编辑" className="main-pickup" checkedChildren="开" unCheckedChildren="关" checked={pickup} onChange={this.pickupChange} /> |
| | | <Table |
| | | components={components} |
| | | style={setting.style} |
| | | size={setting.size || 'middle'} |
| | | bordered={setting.bordered !== 'false'} |
| | | columns={this.state.columns} |
| | | dataSource={_data} |
| | | loading={this.props.loading} |
| | | scroll={{ x: '100%', y: height }} |
| | | onRow={(record, index) => { |
| | | return { |
| | | lineMarks, |
| | | data: record |
| | | } |
| | | }} |
| | | onChange={this.changeTable} |
| | | pagination={_pagination} |
| | | /> |
| | | {_footer ? <div className={'normal-table-footer ' + (_pagination ? 'pagination' : '')}>{_footer}</div> : null} |
| | | </div> |
| | | <> |
| | | {setting.hasSubmit ? <div className="edit-custom-table-btn-wrap" style={submit.wrapStyle}> |
| | | <Button style={submit.style} onClick={() => setTimeout(() => {this.submit()}, 10)} loading={loading} className="submit-table" type="link">提交</Button> |
| | | </div> : null} |
| | | <div className={`edit-custom-table ${setting.tableHeader || ''} ${height ? 'fixed-height' : ''} ${setting.mode || ''} table-vertical-${setting.vertical || ''} mk-edit-${setting.editType || 'simple'}`} id={tableId}> |
| | | <Table |
| | | rowKey="$$uuid" |
| | | components={components} |
| | | size={setting.size || 'middle'} |
| | | bordered={setting.bordered !== 'false'} |
| | | rowSelection={rowSelection} |
| | | columns={columns} |
| | | dataSource={_data} |
| | | loading={this.props.loading} |
| | | scroll={{ x: '100%', y: height }} |
| | | onRow={(record, index) => { |
| | | return { |
| | | lineMarks, |
| | | title: setting.tipField ? record[setting.tipField] : '', |
| | | data: record, |
| | | onClick: () => {this.changeRow(record.$$uuid)}, |
| | | } |
| | | }} |
| | | onChange={this.changeTable} |
| | | pagination={_pagination} |
| | | /> |
| | | {setting.hasSubmit && _data.length > 10 ? <Button style={submit.style} onClick={() => setTimeout(() => {this.submit()}, 10)} loading={loading} className="submit-footer-table" type="link">提交</Button> : null} |
| | | </div> |
| | | <Modal |
| | | className="mk-user-confirm" |
| | | visible={visible} |
| | | width={450} |
| | | maskClosable={false} |
| | | closable={false} |
| | | footer={[ |
| | | <Button key="cancel" onClick={() => { this.setState({ visible: false, midData: null }) }}>取消</Button>, |
| | | <Button key="refresh" className="table-refresh" onClick={() => { midData && this.updateMutil(midData) }}>刷新表格</Button>, |
| | | <Button key="confirm" type="primary" onClick={() => setTimeout(() => {this.submit()}, 10)}>提交数据</Button> |
| | | ]} |
| | | destroyOnClose |
| | | > |
| | | <div><QuestionCircleOutlined />表格中有数据尚未提交</div> |
| | | </Modal> |
| | | </> |
| | | ) |
| | | } |
| | | } |