| | |
| | | import React, {Component} from 'react' |
| | | import PropTypes from 'prop-types' |
| | | import { is, fromJS } from 'immutable' |
| | | import { Table, Typography, Modal, Input, InputNumber, Button, notification, message, Select } from 'antd' |
| | | import { Table, Typography, Modal, Input, InputNumber, Switch, Button, notification, message, Select, DatePicker } from 'antd' |
| | | import { EditOutlined, QuestionCircleOutlined } from '@ant-design/icons' |
| | | import moment from 'moment' |
| | | import md5 from 'md5' |
| | | |
| | | import Api from '@/api' |
| | | import asyncComponent from '@/utils/asyncComponent' |
| | | import Utils, { getEditTableSql, getMark } from '@/utils/utils.js' |
| | | import MKEmitter from '@/utils/events.js' |
| | | import CusSwitch from './cusSwitch' |
| | | import Encrypts from '@/components/encrypts' |
| | | import './index.scss' |
| | | |
| | | const { Paragraph } = Typography |
| | | const MkIcon = asyncComponent(() => import('@/components/mk-icon')) |
| | | const MKPopSelect = asyncComponent(() => import('./mkPopSelect')) |
| | | const CardCellComponent = asyncComponent(() => import('@/tabviews/custom/components/card/cardcellList')) |
| | | |
| | | class MkSwitch extends Component { |
| | | static propTpyes = { |
| | | autoFocus: PropTypes.bool, |
| | | defaultValue: PropTypes.any, |
| | | config: PropTypes.object, |
| | | onChange: PropTypes.func |
| | | } |
| | | |
| | | state = { |
| | | status: false |
| | | } |
| | | |
| | | node = null |
| | | |
| | | UNSAFE_componentWillMount () { |
| | | const { defaultValue, config } = this.props |
| | | |
| | | let status = false |
| | | |
| | | if (defaultValue === config.openVal) { |
| | | status = true |
| | | } |
| | | |
| | | this.setState({status}) |
| | | } |
| | | |
| | | changeStatus = (val) => { |
| | | const { config, lineId } = this.props |
| | | |
| | | this.setState({ status: val }) |
| | | |
| | | let values = {[config.field]: val ? config.openVal : config.closeVal} |
| | | |
| | | this.props.onChange(values, '') |
| | | |
| | | this.node.blur() |
| | | |
| | | if (/\$noAct/.test(config.enter)) return |
| | | |
| | | if (/\$next/.test(config.enter)) { |
| | | MKEmitter.emit('nextLine' + config.tableId, lineId, config.enter.replace('$next_', '')) |
| | | } else { |
| | | MKEmitter.emit('setFocus' + config.tableId, lineId, config.enter) |
| | | } |
| | | } |
| | | |
| | | onFocus = () => { |
| | | const { config, lineId } = this.props |
| | | |
| | | if (!config.$ctrl) return |
| | | |
| | | MKEmitter.emit('colFocus' + config.tableId, lineId, config.uuid) |
| | | } |
| | | |
| | | onBlur = () => { |
| | | const { config, lineId } = this.props |
| | | |
| | | if (config.$ctrl) { |
| | | MKEmitter.emit('colBlur' + config.tableId, lineId, config.uuid) |
| | | } |
| | | |
| | | this.props.onBlur && this.props.onBlur() |
| | | } |
| | | |
| | | render() { |
| | | const { config, autoFocus } = this.props |
| | | const { status } = this.state |
| | | |
| | | return ( |
| | | <Switch |
| | | ref={ref => this.node = ref} |
| | | checkedChildren={config.openText} |
| | | checked={status} |
| | | autoFocus={autoFocus} |
| | | onFocus={this.onFocus} |
| | | onBlur={this.onBlur} |
| | | unCheckedChildren={config.closeText} |
| | | onChange={this.changeStatus} |
| | | /> |
| | | ) |
| | | } |
| | | } |
| | | |
| | | class MkDatePicker extends Component { |
| | | static propTpyes = { |
| | | defaultValue: PropTypes.any, |
| | | config: PropTypes.object, |
| | | onChange: PropTypes.func |
| | | } |
| | | |
| | | state = { |
| | | value: null, |
| | | open: false |
| | | } |
| | | |
| | | UNSAFE_componentWillMount () { |
| | | const { defaultValue } = this.props |
| | | |
| | | let _value = defaultValue || null |
| | | if (_value) { |
| | | _value = moment(_value, 'YYYY-MM-DD HH:mm:ss') |
| | | } |
| | | |
| | | this.setState({value: _value}) |
| | | } |
| | | |
| | | componentDidMount() { |
| | | const { config, autoFocus, lineId } = this.props |
| | | |
| | | if (autoFocus === true) { |
| | | this.setState({open: true}) |
| | | |
| | | if (config.$ctrl) { |
| | | MKEmitter.emit('colFocus' + config.tableId, lineId, config.uuid) |
| | | } |
| | | } |
| | | |
| | | MKEmitter.addListener('setFocus' + config.tableId, this.setFocus) |
| | | } |
| | | |
| | | componentWillUnmount () { |
| | | this.setState = () => { |
| | | return |
| | | } |
| | | |
| | | MKEmitter.removeListener('setFocus' + this.props.config.tableId, this.setFocus) |
| | | } |
| | | |
| | | setFocus = (lId, colId) => { |
| | | const { config, lineId } = this.props |
| | | |
| | | if (lId !== lineId || config.uuid !== colId) return |
| | | |
| | | this.setState({open: true}) |
| | | |
| | | if (config.$ctrl) { |
| | | MKEmitter.emit('colFocus' + config.tableId, lineId, config.uuid) |
| | | } |
| | | } |
| | | |
| | | onOpenChange = (open) => { |
| | | const { config, lineId } = this.props |
| | | |
| | | this.setState({open}) |
| | | |
| | | if (!open) { |
| | | this.props.onBlur && this.props.onBlur() |
| | | } |
| | | |
| | | if (!config.$ctrl) return |
| | | |
| | | if (open) { |
| | | MKEmitter.emit('colFocus' + config.tableId, lineId, config.uuid) |
| | | } else { |
| | | MKEmitter.emit('colBlur' + config.tableId, lineId, config.uuid) |
| | | } |
| | | } |
| | | |
| | | onChange = (val) => { |
| | | const { config, lineId } = this.props |
| | | |
| | | let _val = val ? moment(val).format(config.format) : '' |
| | | |
| | | if (config.precision === 'hour') { |
| | | _val = _val + ':00:00' |
| | | } else if (config.precision === 'minute') { |
| | | _val = _val + ':00' |
| | | } |
| | | |
| | | let values = {[config.field]: _val} |
| | | |
| | | this.props.onChange(values) |
| | | |
| | | if (/\$noAct/.test(config.enter)) return |
| | | |
| | | if (/\$next/.test(config.enter)) { |
| | | MKEmitter.emit('nextLine' + config.tableId, lineId, config.enter.replace('$next_', '')) |
| | | } else { |
| | | MKEmitter.emit('setFocus' + config.tableId, lineId, config.enter) |
| | | } |
| | | } |
| | | |
| | | render() { |
| | | const { config } = this.props |
| | | const { value, open } = this.state |
| | | |
| | | return ( |
| | | <DatePicker dropdownClassName={'mk-date-picker ' + config.precision} showTime={config.format !== 'YYYY-MM-DD'} format={config.format} open={open} defaultValue={value} onChange={this.onChange} onOpenChange={this.onOpenChange}/> |
| | | ) |
| | | } |
| | | } |
| | | |
| | | class MkSelect extends Component { |
| | | static propTpyes = { |
| | | defaultValue: PropTypes.any, |
| | | lineId: PropTypes.string, |
| | | config: PropTypes.object, |
| | | onChange: PropTypes.func, |
| | | } |
| | | |
| | | state = { |
| | | value: '' |
| | | } |
| | | |
| | | node = null |
| | | |
| | | UNSAFE_componentWillMount() { |
| | | const { defaultValue } = this.props |
| | | |
| | | this.setState({value: defaultValue}) |
| | | } |
| | | |
| | | componentDidMount() { |
| | | const { config, autoFocus, lineId } = this.props |
| | | |
| | | if (autoFocus) { |
| | | let node = document.getElementById(config.uuid + lineId) |
| | | node && node.click() |
| | | } |
| | | MKEmitter.addListener('setFocus' + config.tableId, this.setFocus) |
| | | } |
| | | |
| | | UNSAFE_componentWillReceiveProps(nextProps) { |
| | | if (nextProps.defaultValue !== this.props.defaultValue) { |
| | | this.setState({value: nextProps.defaultValue}) |
| | | } |
| | | } |
| | | |
| | | componentWillUnmount () { |
| | | this.setState = () => { |
| | | return |
| | | } |
| | | |
| | | MKEmitter.removeListener('setFocus' + this.props.config.tableId, this.setFocus) |
| | | } |
| | | |
| | | setFocus = (lId, colId) => { |
| | | const { config, lineId } = this.props |
| | | |
| | | if (lId !== lineId || config.uuid !== colId) return |
| | | |
| | | let node = document.getElementById(config.uuid + lineId) |
| | | node && node.click() |
| | | } |
| | | |
| | | onSelectChange = (val, option) => { |
| | | const { config, lineId } = this.props |
| | | |
| | | let values = {} |
| | | let _option = config.options.filter(m => m.key === option.key)[0] |
| | | |
| | | if (_option) { |
| | | if (config.linkSubField) { |
| | | config.linkSubField.forEach((m, i) => { |
| | | values[m] = _option[m] !== undefined ? _option[m] : '' |
| | | }) |
| | | } |
| | | |
| | | values[config.field] = val |
| | | } |
| | | |
| | | this.setState({value: val}) |
| | | |
| | | this.props.onChange(values, val) |
| | | |
| | | if (config.enter === '$noActX') return |
| | | |
| | | this.node.blur() |
| | | |
| | | if (/\$noAct/.test(config.enter)) return |
| | | |
| | | setTimeout(() => { |
| | | if (/\$next/.test(config.enter)) { |
| | | MKEmitter.emit('nextLine' + config.tableId, lineId, config.enter.replace('$next_', '')) |
| | | } else { |
| | | MKEmitter.emit('setFocus' + config.tableId, lineId, config.enter) |
| | | } |
| | | }, 100) |
| | | } |
| | | |
| | | onFocus = () => { |
| | | const { config, lineId } = this.props |
| | | |
| | | if (!config.$ctrl) return |
| | | |
| | | MKEmitter.emit('colFocus' + config.tableId, lineId, config.uuid) |
| | | } |
| | | |
| | | onBlur = () => { |
| | | const { config, lineId } = this.props |
| | | |
| | | if (config.$ctrl) { |
| | | MKEmitter.emit('colBlur' + config.tableId, lineId, config.uuid, true) |
| | | } |
| | | |
| | | setTimeout(() => { |
| | | this.props.onBlur && this.props.onBlur() |
| | | }, 10) |
| | | } |
| | | |
| | | render() { |
| | | const { config, lineId } = this.props |
| | | const { value } = this.state |
| | | |
| | | return ( |
| | | <Select |
| | | showSearch |
| | | dropdownClassName="edit-table-dropdown" |
| | | dropdownMatchSelectWidth={config.dropdown === 'fixed'} |
| | | value={value} |
| | | id={config.uuid + lineId} |
| | | ref={ref => this.node = ref} |
| | | onFocus={this.onFocus} |
| | | onBlur={this.onBlur} |
| | | filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0} |
| | | onSelect={this.onSelectChange} |
| | | > |
| | | {config.options.map(item => (<Select.Option key={item.key} disabled={item.$disabled} value={item.value}>{item.label}</Select.Option>))} |
| | | </Select> |
| | | ) |
| | | } |
| | | } |
| | | |
| | | class MkInput extends Component { |
| | | static propTpyes = { |
| | | defaultValue: PropTypes.any, |
| | | lineId: PropTypes.string, |
| | | config: PropTypes.object, |
| | | onChange: PropTypes.func |
| | | } |
| | | |
| | | state = { |
| | | value: null, |
| | | err: null |
| | | } |
| | | |
| | | node = null |
| | | |
| | | UNSAFE_componentWillMount() { |
| | | const { defaultValue } = this.props |
| | | |
| | | this.setState({value: defaultValue}) |
| | | } |
| | | |
| | | componentDidMount() { |
| | | const { config, autoFocus } = this.props |
| | | |
| | | if (autoFocus) { |
| | | this.node.select() |
| | | } |
| | | MKEmitter.addListener('setFocus' + config.tableId, this.setFocus) |
| | | } |
| | | |
| | | UNSAFE_componentWillReceiveProps(nextProps) { |
| | | if (nextProps.defaultValue !== this.props.defaultValue) { |
| | | this.setState({value: nextProps.defaultValue}) |
| | | } |
| | | } |
| | | |
| | | componentWillUnmount () { |
| | | this.setState = () => { |
| | | return |
| | | } |
| | | |
| | | MKEmitter.removeListener('setFocus' + this.props.config.tableId, this.setFocus) |
| | | } |
| | | |
| | | setFocus = (lId, colId) => { |
| | | const { config, lineId } = this.props |
| | | |
| | | if (lId !== lineId || config.uuid !== colId) return |
| | | |
| | | this.node.select() |
| | | } |
| | | |
| | | onChange = (val) => { |
| | | this.setState({value: val}) |
| | | } |
| | | |
| | | onFocus = () => { |
| | | const { config, lineId } = this.props |
| | | |
| | | if (!config.$ctrl) return |
| | | |
| | | MKEmitter.emit('colFocus' + config.tableId, lineId, config.uuid) |
| | | } |
| | | |
| | | enterPress = () => { |
| | | const { config, lineId } = this.props |
| | | |
| | | this.node.blur() |
| | | |
| | | if (/\$noAct/.test(config.enter)) return |
| | | |
| | | if (/\$next/.test(config.enter)) { |
| | | MKEmitter.emit('nextLine' + config.tableId, lineId, config.enter.replace('$next_', '')) |
| | | } else { |
| | | MKEmitter.emit('setFocus' + config.tableId, lineId, config.enter) |
| | | } |
| | | } |
| | | |
| | | onBlur = () => { |
| | | const { config, lineId } = this.props |
| | | const { value } = this.state |
| | | |
| | | let err = null |
| | | |
| | | if (config.required === 'true' && !value) { |
| | | err = '请填写' + config.label |
| | | } |
| | | |
| | | this.setState({err}) |
| | | |
| | | this.props.onChange({[config.field]: value}) |
| | | |
| | | if (config.$ctrl) { |
| | | MKEmitter.emit('colBlur' + config.tableId, lineId, config.uuid) |
| | | } |
| | | |
| | | this.props.onBlur && this.props.onBlur() |
| | | } |
| | | |
| | | render() { |
| | | const { value, err } = this.state |
| | | |
| | | return ( |
| | | <Input |
| | | title={err} |
| | | className={err ? 'has-error' : ''} |
| | | ref={ref => this.node = ref} |
| | | value={value} |
| | | onChange={(e) => this.onChange(e.target.value)} |
| | | onPressEnter={this.enterPress} |
| | | onFocus={this.onFocus} |
| | | onBlur={this.onBlur} |
| | | /> |
| | | ) |
| | | } |
| | | } |
| | | |
| | | class MkInputNumber extends Component { |
| | | static propTpyes = { |
| | | defaultValue: PropTypes.any, |
| | | lineId: PropTypes.string, |
| | | config: PropTypes.object, |
| | | onChange: PropTypes.func |
| | | } |
| | | |
| | | state = { |
| | | value: null, |
| | | err: null, |
| | | clear: false |
| | | } |
| | | |
| | | node = null |
| | | |
| | | UNSAFE_componentWillMount() { |
| | | const { defaultValue } = this.props |
| | | |
| | | this.setState({value: defaultValue}) |
| | | } |
| | | |
| | | componentDidMount() { |
| | | const { config, autoFocus } = this.props |
| | | |
| | | if (autoFocus) { |
| | | this.node.focus() |
| | | } |
| | | MKEmitter.addListener('setFocus' + config.tableId, this.setFocus) |
| | | } |
| | | |
| | | UNSAFE_componentWillReceiveProps(nextProps) { |
| | | if (nextProps.defaultValue !== this.props.defaultValue) { |
| | | this.setState({value: nextProps.defaultValue}) |
| | | } |
| | | } |
| | | |
| | | componentWillUnmount () { |
| | | this.setState = () => { |
| | | return |
| | | } |
| | | |
| | | MKEmitter.removeListener('setFocus' + this.props.config.tableId, this.setFocus) |
| | | } |
| | | |
| | | setFocus = (lId, colId) => { |
| | | const { config, lineId } = this.props |
| | | |
| | | if (lId !== lineId || config.uuid !== colId) return |
| | | |
| | | this.node.focus() |
| | | } |
| | | |
| | | onChange = (val) => { |
| | | const { config } = this.props |
| | | |
| | | this.setState({value: val}) |
| | | |
| | | if (config.clearField && val && !this.state.clear) { |
| | | this.setState({clear: true}) |
| | | |
| | | this.props.onChange({[config.clearField]: ''}) |
| | | } |
| | | } |
| | | |
| | | onFocus = () => { |
| | | const { config, lineId } = this.props |
| | | |
| | | this.setState({clear: false}) |
| | | |
| | | if (!config.$ctrl) return |
| | | |
| | | MKEmitter.emit('colFocus' + config.tableId, lineId, config.uuid) |
| | | } |
| | | |
| | | enterPress = () => { |
| | | const { config, lineId } = this.props |
| | | |
| | | this.node.blur() |
| | | |
| | | if (/\$noAct/.test(config.enter)) return |
| | | |
| | | setTimeout(() => { |
| | | if (/\$next/.test(config.enter)) { |
| | | MKEmitter.emit('nextLine' + config.tableId, lineId, config.enter.replace('$next_', '')) |
| | | } else { |
| | | MKEmitter.emit('setFocus' + config.tableId, lineId, config.enter) |
| | | } |
| | | }, 10) |
| | | } |
| | | |
| | | onBlur = () => { |
| | | const { config, lineId } = this.props |
| | | |
| | | if (config.$ctrl) { |
| | | MKEmitter.emit('colBlur' + config.tableId, lineId, config.uuid) |
| | | } |
| | | |
| | | setTimeout(() => { |
| | | let err = null |
| | | let value = this.state.value |
| | | |
| | | if (config.noValue === 'hide' && !value) { |
| | | value = 0 |
| | | } |
| | | |
| | | if (config.required === 'true' && !value) { |
| | | err = `${config.label}不可为${config.noValue === 'hide' ? '空' : '0'}` |
| | | } else { |
| | | if (typeof(config.max) === 'number' && value > config.max) { |
| | | err = config.label + '最大为' + config.max |
| | | } else if (typeof(config.min) === 'number' && value < config.min) { |
| | | err = config.label + '最小为' + config.min |
| | | } |
| | | } |
| | | |
| | | this.setState({err}) |
| | | |
| | | this.props.onChange({[config.field]: value}) |
| | | |
| | | this.props.onBlur && this.props.onBlur() |
| | | }, 5) |
| | | } |
| | | |
| | | render() { |
| | | const { config } = this.props |
| | | const { value, err } = this.state |
| | | |
| | | if (!config.decimal && config.decimal !== 0) { |
| | | return ( |
| | | <InputNumber |
| | | title={err} |
| | | className={err ? 'has-error' : ''} |
| | | ref={ref => this.node = ref} |
| | | value={value} |
| | | onChange={(value) => this.onChange(value)} |
| | | onPressEnter={this.enterPress} |
| | | onFocus={this.onFocus} |
| | | onBlur={this.onBlur} |
| | | /> |
| | | ) |
| | | } else { |
| | | return ( |
| | | <InputNumber |
| | | title={err} |
| | | className={err ? 'has-error' : ''} |
| | | ref={ref => this.node = ref} |
| | | precision={config.decimal} |
| | | value={value} |
| | | onChange={(value) => this.onChange(value)} |
| | | onPressEnter={this.enterPress} |
| | | onFocus={this.onFocus} |
| | | onBlur={this.onBlur} |
| | | /> |
| | | ) |
| | | } |
| | | } |
| | | } |
| | | |
| | | class BodyRow extends React.Component { |
| | | shouldComponentUpdate (nextProps, nextState) { |
| | |
| | | |
| | | class BodyCell extends React.Component { |
| | | state = { |
| | | editing: false, |
| | | err: null, |
| | | value: '' |
| | | editing: false |
| | | } |
| | | |
| | | componentDidMount() { |
| | | const { col } = this.props |
| | | |
| | | if (col && col.editable === 'true') { |
| | | MKEmitter.addListener('setFocus' + col.tableId, this.setFocus) |
| | | } |
| | | } |
| | | |
| | | shouldComponentUpdate (nextProps, nextState) { |
| | |
| | | this.setState = () => { |
| | | return |
| | | } |
| | | if (this.props.col) { |
| | | MKEmitter.removeListener('setFocus' + this.props.col.tableId, this.setFocus) |
| | | } |
| | | } |
| | | |
| | | enterPress = () => { |
| | | setFocus = (lId, colId) => { |
| | | const { col, record } = this.props |
| | | const { value } = this.state |
| | | |
| | | 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) |
| | | if (lId !== record.$$uuid || col.uuid !== colId) return |
| | | if (col.ctrlField && col.ctrlValue.includes(record[col.ctrlField] + '')) return |
| | | |
| | | if (value !== record[col.field]) { |
| | | MKEmitter.emit('changeRecord', col.tableId, {...record, [col.field]: value}) |
| | | } |
| | | this.setState({editing: true}) |
| | | } |
| | | |
| | | focus = () => { |
| | | const { col, record } = this.props |
| | | |
| | | if (col.ctrlField && col.ctrlValue.includes(record[col.ctrlField])) return |
| | | if (col.ctrlField && col.ctrlValue.includes(record[col.ctrlField] + '')) return |
| | | |
| | | 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 |
| | | } |
| | | |
| | | this.setState({editing: true, value: val, err}, () => { |
| | | let node = document.getElementById(col.uuid + record.$$uuid) |
| | | node && node.select() |
| | | }) |
| | | } |
| | | this.setState({editing: true}) |
| | | } |
| | | |
| | | onBlur = () => { |
| | | const { col, record } = this.props |
| | | const { value } = this.state |
| | | |
| | | this.setState({editing: false}) |
| | | |
| | | if (value !== record[col.field]) { |
| | | MKEmitter.emit('changeRecord', col.tableId, {...record, [col.field]: value}) |
| | | } |
| | | } |
| | | |
| | | onChange = (val) => { |
| | | const { col } = this.props |
| | | |
| | | let err = null |
| | | |
| | | 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({value: val, err}) |
| | | } |
| | | |
| | | onSwitchChange = (val, label) => { |
| | | onColChange = (values) => { |
| | | 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) |
| | | MKEmitter.emit('changeRecord' + col.tableId, {...record, ...values}) |
| | | } |
| | | |
| | | render() { |
| | | let { col, config, record, style, className, ...resProps } = this.props |
| | | const { editing, value, err } = this.state |
| | | let { col, record, style, className, ...resProps } = this.props |
| | | const { editing } = this.state |
| | | |
| | | if (!col) return (<td {...resProps} className={className} style={style}/>) |
| | | |
| | | let disabled = false |
| | | if (col.ctrlField) { |
| | | disabled = col.ctrlValue.includes(record[col.ctrlField]) |
| | | disabled = col.ctrlValue.includes(record[col.ctrlField] + '') |
| | | } |
| | | |
| | | let children = null |
| | |
| | | |
| | | if (col.editType === 'select' && col.options.length > 0) { |
| | | content = col.map.get(content) || content |
| | | } else if (col.editType === 'switch') { |
| | | if (content === col.openVal) { |
| | | content = col.openText |
| | | } else if (content === col.closeVal) { |
| | | content = col.closeText |
| | | } |
| | | } else if (col.editType === 'popSelect') { |
| | | if (col.showField) { |
| | | content = record[col.showField] || content |
| | | } |
| | | } |
| | | |
| | | if (content !== '') { |
| | |
| | | content = <span>{col.prefix || ''}<Encrypts value={content} />{col.postfix || ''}</span> |
| | | } |
| | | |
| | | if (col.noValue === 'hide' && content < '1949-10-02') { |
| | | content = '' |
| | | } |
| | | |
| | | if (col.textFormat !== 'encryption') { |
| | | content = (col.prefix || '') + content + (col.postfix || '') |
| | | } |
| | | } |
| | | |
| | | if (col.marks) { |
| | | let mark = getMark(col.marks, record, style) |
| | | style = style ? {...style} : {} |
| | | |
| | | style = mark.style |
| | | let mark = getMark(col.marks, record, style) |
| | | |
| | | if (mark.icon) { |
| | | if (mark.position === 'front') { |
| | |
| | | } |
| | | } else if (mark.innerStyle) { |
| | | content = <span style={mark.innerStyle}>{content}</span> |
| | | } else if (mark.space) { |
| | | content = <><span dangerouslySetInnerHTML={{__html: mark.space}}></span>{content}</> |
| | | } else if (mark.point) { |
| | | if (mark.position === 'front') { |
| | | content = <>{mark.point}{content}</> |
| | | } else { |
| | | content = <>{content}{mark.point}</> |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (col.editable === 'true' && !disabled) { |
| | | if (editing) { |
| | | let _value = record[col.field] !== undefined ? record[col.field] : '' |
| | | |
| | | 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}/> |
| | | return (<td onClick={(e) => e.stopPropagation()} className="editing_table_cell"> |
| | | <MkInput config={col} lineId={record.$$uuid} defaultValue={_value} autoFocus={true} onChange={this.onColChange} onBlur={() => this.setState({editing: false})}/> |
| | | </td>) |
| | | } else if (col.editType === 'switch') { |
| | | let _value = record[col.field] !== undefined ? record[col.field] : '' |
| | | return (<td onClick={(e) => e.stopPropagation()} className="editing_table_cell"> |
| | | <MkSwitch config={col} lineId={record.$$uuid} defaultValue={_value} autoFocus={true} onChange={this.onColChange} onBlur={() => this.setState({editing: false})}/> |
| | | </td>) |
| | | } else if (col.editType === 'date') { |
| | | return (<td onClick={(e) => e.stopPropagation()} className="editing_table_cell"> |
| | | <MkDatePicker config={col} lineId={record.$$uuid} defaultValue={_value || null} autoFocus={true} onChange={this.onColChange} onBlur={() => this.setState({editing: false})}/> |
| | | </td>) |
| | | } else if (col.editType === 'popSelect') { |
| | | let showValue = '' |
| | | if (col.showField) { |
| | | showValue = record[col.showField] || '' |
| | | } |
| | | |
| | | return (<td className="editing_table_cell"> |
| | | <CusSwitch config={col} defaultValue={_value} autoFocus={true} onChange={this.onSwitchChange} onBlur={this.switchBlur}/> |
| | | return (<td onClick={(e) => e.stopPropagation()} className="editing_table_cell"> |
| | | <MKPopSelect config={col} lineId={record.$$uuid} defaultValue={_value} showValue={showValue} BID={record.$$BID} autoFocus={true} onChange={this.onColChange} onBlur={() => this.setState({editing: false})}/> |
| | | </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> |
| | | return (<td onClick={(e) => e.stopPropagation()} className="editing_table_cell"> |
| | | <MkSelect config={col} lineId={record.$$uuid} defaultValue={_value} autoFocus={true} onChange={this.onColChange} onBlur={() => this.setState({editing: false})}/> |
| | | </td>) |
| | | } |
| | | } else { |
| | | return (<td className={className + ' pointer'} style={style}> |
| | | return (<td onClick={(e) => e.stopPropagation()} className={className + ' pointer'} style={style}> |
| | | <div className="mk-mask" id={col.uuid + record.$$uuid} onClick={this.focus}></div>{content} |
| | | </td>) |
| | | } |
| | |
| | | } |
| | | |
| | | if (col.format === 'thdSeparator') { |
| | | content = content + '' |
| | | content = content.replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,') |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | if (col.marks) { |
| | | let mark = getMark(col.marks, record, style) |
| | | style = style ? {...style} : {} |
| | | |
| | | style = mark.style |
| | | let mark = getMark(col.marks, record, style) |
| | | |
| | | if (mark.icon) { |
| | | if (mark.position === 'front') { |
| | |
| | | } |
| | | } else if (mark.innerStyle) { |
| | | content = <span style={mark.innerStyle}>{content}</span> |
| | | } else if (mark.space) { |
| | | content = <><span dangerouslySetInnerHTML={{__html: mark.space}}></span>{content}</> |
| | | } else if (mark.point) { |
| | | if (mark.position === 'front') { |
| | | content = <>{mark.point}{content}</> |
| | | } else { |
| | | content = <>{content}{mark.point}</> |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (col.editable === 'true' && !disabled) { |
| | | if (editing) { |
| | | let val = value |
| | | if (col.noValue === 'hide' && value === 0) { |
| | | let val = record[col.field] !== undefined ? record[col.field] : '' |
| | | if (col.noValue === 'hide' && val === 0) { |
| | | val = '' |
| | | } |
| | | return (<td className="editing_table_cell"> |
| | | <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}/> |
| | | return (<td onClick={(e) => e.stopPropagation()} className="editing_table_cell"> |
| | | <MkInputNumber config={col} lineId={record.$$uuid} defaultValue={val} autoFocus={true} onChange={this.onColChange} onBlur={() => this.setState({editing: false})}/> |
| | | </td>) |
| | | } else { |
| | | return (<td className={className + ' pointer'} style={style}> |
| | | return (<td onClick={(e) => e.stopPropagation()} className={className + ' pointer'} style={style}> |
| | | <div className="mk-mask" id={col.uuid + record.$$uuid} onClick={this.focus}></div>{content} |
| | | </td>) |
| | | } |
| | |
| | | ) |
| | | } 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') { |
| | | if (col.eval === 'func') { |
| | | try { |
| | | // eslint-disable-next-line |
| | | content = eval(content) |
| | | let func = new Function('data', col.formula) |
| | | content = func([record]) |
| | | } catch (e) { |
| | | if (window.debugger) { |
| | | console.info(content) |
| | | console.warn(e) |
| | | } |
| | | console.warn(e) |
| | | content = '' |
| | | } |
| | | } else { |
| | | 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) { |
| | | window.mkInfo(content) |
| | | console.warn(e) |
| | | content = '' |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | content = content.toFixed(col.decimal) |
| | | } |
| | | |
| | | if (content !== '') { |
| | | if (col.eval === 'func') { |
| | | content = <span dangerouslySetInnerHTML={{__html: content}}></span> |
| | | } else if (content !== '') { |
| | | content = `${col.prefix || ''}${content}${col.postfix || ''}` |
| | | content = content.replace(/\n/ig, '<br/>').replace(/\s/ig, ' ') |
| | | if (!col.evalchars || col.evalchars.includes('enter')) { |
| | | content = content.replace(/\n/ig, '<br/>') |
| | | } |
| | | if (!col.evalchars || col.evalchars.includes('space')) { |
| | | content = content.replace(/\s/ig, ' ') |
| | | } |
| | | content = <span dangerouslySetInnerHTML={{__html: content}}></span> |
| | | } |
| | | |
| | | if (col.marks) { |
| | | let mark = getMark(col.marks, record, style) |
| | | style = style ? {...style} : {} |
| | | |
| | | style = mark.style |
| | | let mark = getMark(col.marks, record, style) |
| | | |
| | | if (mark.icon) { |
| | | if (mark.position === 'front') { |
| | |
| | | } |
| | | } else if (mark.innerStyle) { |
| | | content = <span style={mark.innerStyle}>{content}</span> |
| | | } else if (mark.space) { |
| | | content = <><span dangerouslySetInnerHTML={{__html: mark.space}}></span>{content}</> |
| | | } else if (mark.point) { |
| | | if (mark.position === 'front') { |
| | | content = <>{mark.point}{content}</> |
| | | } else { |
| | | content = <>{content}{mark.point}</> |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | children = ( |
| | | <CardCellComponent data={record} cards={config} elements={col.elements}/> |
| | | <CardCellComponent data={record} cards={col.config} elements={col.elements}/> |
| | | ) |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | class BodyAllCell extends React.Component { |
| | | state = { |
| | | err: null, |
| | | value: '' |
| | | } |
| | | state = {} |
| | | |
| | | 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]}) |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | } |
| | | |
| | | enterPress = () => { |
| | | onColChange = (values) => { |
| | | 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}) |
| | | MKEmitter.emit('changeRecord' + col.tableId, {...record, ...values}) |
| | | } |
| | | |
| | | render() { |
| | | let { col, config, record, style, className, ...resProps } = this.props |
| | | const { err } = this.state |
| | | let { col, record, style, className, ...resProps } = this.props |
| | | |
| | | if (!col) return (<td {...resProps} className={className} style={style}/>) |
| | | |
| | | let disabled = false |
| | | let editable = false |
| | | if (col.ctrlField) { |
| | | disabled = col.ctrlValue.includes(record[col.ctrlField]) |
| | | disabled = col.ctrlValue.includes(record[col.ctrlField] + '') |
| | | } |
| | | |
| | | let children = null |
| | | if (col.type === 'text') { |
| | | if (col.editable === 'true' && !disabled) { |
| | | editable = true |
| | | 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}/> |
| | | </>) |
| | | children = ( |
| | | <MkInput config={col} lineId={record.$$uuid} defaultValue={_value} autoFocus={false} onChange={this.onColChange}/> |
| | | ) |
| | | } else if (col.editType === 'switch') { |
| | | children = ( |
| | | <CusSwitch config={col} autoFocus={false} defaultValue={_value} onChange={this.onSwitchChange} onBlur={() => {}}/> |
| | | <MkSwitch config={col} lineId={record.$$uuid} defaultValue={_value} autoFocus={false} onChange={this.onColChange}/> |
| | | ) |
| | | } else if (col.editType === 'date') { |
| | | children = ( |
| | | <MkDatePicker config={col} lineId={record.$$uuid} defaultValue={_value || null} autoFocus={false} onChange={this.onColChange}/> |
| | | ) |
| | | } else if (col.editType === 'popSelect') { |
| | | let showValue = '' |
| | | if (col.showField) { |
| | | showValue = record[col.showField] || '' |
| | | } |
| | | |
| | | children = ( |
| | | <MKPopSelect config={col} lineId={record.$$uuid} defaultValue={_value} showValue={showValue} BID={record.$$BID} autoFocus={false} onChange={this.onColChange}/> |
| | | ) |
| | | } 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> |
| | | </>) |
| | | children = ( |
| | | <MkSelect config={col} lineId={record.$$uuid} defaultValue={_value} autoFocus={false} onChange={this.onColChange} /> |
| | | ) |
| | | } |
| | | } else { |
| | | let content = '' |
| | |
| | | |
| | | if (col.editType === 'select' && col.options.length > 0) { |
| | | content = col.map.get(content) || content |
| | | } else if (col.editType === 'switch') { |
| | | if (content === col.openVal) { |
| | | content = col.openText |
| | | } else if (content === col.closeVal) { |
| | | content = col.closeText |
| | | } |
| | | } else if (col.editType === 'popSelect') { |
| | | if (col.showField) { |
| | | content = record[col.showField] || content |
| | | } |
| | | } |
| | | |
| | | if (content !== '') { |
| | |
| | | content = <span>{col.prefix || ''}<Encrypts value={content} />{col.postfix || ''}</span> |
| | | } |
| | | |
| | | if (col.noValue === 'hide' && content < '1949-10-02') { |
| | | content = '' |
| | | } |
| | | |
| | | if (col.textFormat !== 'encryption') { |
| | | content = (col.prefix || '') + content + (col.postfix || '') |
| | | } |
| | | } |
| | | |
| | | if (col.marks) { |
| | | let mark = getMark(col.marks, record, style) |
| | | style = style ? {...style} : {} |
| | | |
| | | style = mark.style |
| | | let mark = getMark(col.marks, record, style) |
| | | |
| | | if (mark.icon) { |
| | | if (mark.position === 'front') { |
| | |
| | | } |
| | | } else if (mark.innerStyle) { |
| | | content = <span style={mark.innerStyle}>{content}</span> |
| | | } else if (mark.space) { |
| | | content = <><span dangerouslySetInnerHTML={{__html: mark.space}}></span>{content}</> |
| | | } else if (mark.point) { |
| | | if (mark.position === 'front') { |
| | | content = <>{mark.point}{content}</> |
| | | } else { |
| | | content = <>{content}{mark.point}</> |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | } else if (col.type === 'number') { |
| | | if (col.editable === 'true' && !disabled) { |
| | | editable = true |
| | | 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}/> |
| | | </>) |
| | | children = ( |
| | | <MkInputNumber config={col} lineId={record.$$uuid} defaultValue={_value} autoFocus={false} onChange={this.onColChange}/> |
| | | ) |
| | | } else { |
| | | let content = '' |
| | | try { |
| | |
| | | } |
| | | |
| | | if (col.format === 'thdSeparator') { |
| | | content = content + '' |
| | | content = content.replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,') |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | if (col.marks) { |
| | | let mark = getMark(col.marks, record, style) |
| | | style = style ? {...style} : {} |
| | | |
| | | style = mark.style |
| | | let mark = getMark(col.marks, record, style) |
| | | |
| | | if (mark.icon) { |
| | | if (mark.position === 'front') { |
| | |
| | | } |
| | | } else if (mark.innerStyle) { |
| | | content = <span style={mark.innerStyle}>{content}</span> |
| | | } else if (mark.space) { |
| | | content = <><span dangerouslySetInnerHTML={{__html: mark.space}}></span>{content}</> |
| | | } else if (mark.point) { |
| | | if (mark.position === 'front') { |
| | | content = <>{mark.point}{content}</> |
| | | } else { |
| | | content = <>{content}{mark.point}</> |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | ) |
| | | } 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') { |
| | | if (col.eval === 'func') { |
| | | try { |
| | | // eslint-disable-next-line |
| | | content = eval(content) |
| | | let func = new Function('data', col.formula) |
| | | content = func([record]) |
| | | } catch (e) { |
| | | if (window.debugger) { |
| | | console.info(content) |
| | | console.warn(e) |
| | | } |
| | | console.warn(e) |
| | | content = '' |
| | | } |
| | | } else { |
| | | 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) { |
| | | window.mkInfo(content) |
| | | console.warn(e) |
| | | content = '' |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | content = content.toFixed(col.decimal) |
| | | } |
| | | |
| | | if (content !== '') { |
| | | if (col.eval === 'func') { |
| | | content = <span dangerouslySetInnerHTML={{__html: content}}></span> |
| | | } else if (content !== '') { |
| | | content = `${col.prefix || ''}${content}${col.postfix || ''}` |
| | | content = content.replace(/\n/ig, '<br/>').replace(/\s/ig, ' ') |
| | | if (!col.evalchars || col.evalchars.includes('enter')) { |
| | | content = content.replace(/\n/ig, '<br/>') |
| | | } |
| | | if (!col.evalchars || col.evalchars.includes('space')) { |
| | | content = content.replace(/\s/ig, ' ') |
| | | } |
| | | content = <span dangerouslySetInnerHTML={{__html: content}}></span> |
| | | } |
| | | |
| | | if (col.marks) { |
| | | let mark = getMark(col.marks, record, style) |
| | | style = style ? {...style} : {} |
| | | |
| | | style = mark.style |
| | | let mark = getMark(col.marks, record, style) |
| | | |
| | | if (mark.icon) { |
| | | if (mark.position === 'front') { |
| | |
| | | } |
| | | } else if (mark.innerStyle) { |
| | | content = <span style={mark.innerStyle}>{content}</span> |
| | | } else if (mark.space) { |
| | | content = <><span dangerouslySetInnerHTML={{__html: mark.space}}></span>{content}</> |
| | | } else if (mark.point) { |
| | | if (mark.position === 'front') { |
| | | content = <>{mark.point}{content}</> |
| | | } else { |
| | | content = <>{content}{mark.point}</> |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | children = ( |
| | | <CardCellComponent data={record} cards={config} elements={col.elements}/> |
| | | <CardCellComponent data={record} cards={col.config} elements={col.elements}/> |
| | | ) |
| | | } |
| | | |
| | | if (editable) { |
| | | return (<td onClick={(e) => e.stopPropagation()} className={'editing_all_table_cell ' + className} style={style}>{children}</td>) |
| | | } |
| | | |
| | | return (<td className={'editing_all_table_cell ' + className} style={style}>{children}</td>) |
| | |
| | | loading: PropTypes.bool, // 表格加载中 |
| | | refreshdata: PropTypes.func, // 表格中排序列、页码的变化时刷新 |
| | | chgSelectData: PropTypes.func, |
| | | allSearch: PropTypes.any, |
| | | colsCtrls: PropTypes.any |
| | | } |
| | | |
| | | state = { |
| | |
| | | pageOptions: [], |
| | | deForms: null, |
| | | visible: false, |
| | | midData: null |
| | | midData: null, |
| | | allColumns: null, |
| | | checkForms: [], |
| | | allForms: [], |
| | | reseting: false, |
| | | dict: window.GLOB.dict |
| | | } |
| | | |
| | | timer = null |
| | | focusId = '' |
| | | blurId = '' |
| | | colId = '' |
| | | |
| | | UNSAFE_componentWillMount () { |
| | | const { setting, fields, columns, BID } = this.props |
| | | const { setting, fields, columns, BID, colsCtrls } = this.props |
| | | let orderfields = {} |
| | | |
| | | let _columns = [] |
| | | let deForms = [] |
| | | let _forms = {} |
| | | let hasBid = false |
| | | let checkForms = [] |
| | | let allForms = [] |
| | | |
| | | let getColumns = (cols) => { |
| | | let getColumns = (cols, sk) => { |
| | | return cols.map(item => { |
| | | let cell = null |
| | | |
| | | if (item.type === 'colspan') { |
| | | cell = { title: item.label, align: item.Align } |
| | | cell.children = getColumns(item.subcols) |
| | | cell = { title: item.label, align: item.Align, $key: item.uuid } |
| | | cell.children = getColumns(item.subcols, sk || item.uuid) |
| | | } else { |
| | | if (item.editable === 'true') { |
| | | _forms[item.field] = item |
| | | |
| | | if (item.ctrlField) { |
| | | item.ctrlValue = item.ctrlValue.split(',') |
| | | } |
| | | |
| | | allForms.push({uuid: sk || item.uuid, field: item.field}) |
| | | checkForms.push(item.field) |
| | | |
| | | 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)) { |
| | | if (/@BID@/ig.test(_option.sql) && setting.supModule) { |
| | | hasBid = true |
| | | } |
| | | |
| | |
| | | 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 |
| | | } else if (item.sortField) { |
| | | orderfields[item.uuid] = item.sortField |
| | | } |
| | | |
| | | 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'), |
| | | sorter: (item.field || item.sortField) && item.IsSort === 'true', |
| | | width: item.Width || 120, |
| | | $type: item.type, |
| | | $key: item.uuid, |
| | | onCell: record => ({ |
| | | record, |
| | | col: item, |
| | | config: item.type === 'custom' ? {setting, columns: fields} : null, |
| | | col: item |
| | | }) |
| | | } |
| | | } |
| | |
| | | if (item.field === setting.primaryKey) return |
| | | |
| | | if (_forms[item.field]) { |
| | | forms.push({..._forms[item.field], datatype: item.datatype}) |
| | | let _item = {..._forms[item.field]} |
| | | if (_item.editType === 'date') { |
| | | _item.datatype = _item.declareType || 'datetime' |
| | | } else { |
| | | _item.datatype = item.datatype |
| | | } |
| | | if (_item.type === 'number' && item.type === 'number') { |
| | | _item.decimal = item.decimal || 0 |
| | | } |
| | | |
| | | forms.push(_item) |
| | | } else { |
| | | forms.push(item) |
| | | forms.push({...item, $sort: 999}) |
| | | } |
| | | }) |
| | | |
| | | forms.sort((a, b) => a.$sort - b.$sort) |
| | | |
| | | let size = (setting.pageSize || 10) + '' |
| | | let pageOptions = ['10', '25', '50', '100', '500', '1000'] |
| | |
| | | pageOptions = pageOptions.sort((a, b) => a - b) |
| | | } |
| | | |
| | | if (setting.maxPageSize) { |
| | | pageOptions = pageOptions.filter(item => item <= setting.maxPageSize) |
| | | } |
| | | |
| | | let allColumns = null |
| | | if (colsCtrls) { |
| | | allColumns = [..._columns] |
| | | checkForms = [] |
| | | _columns = this.getCurColumns(_columns, this.props.allSearch, allForms, checkForms) |
| | | } else { |
| | | allForms = null |
| | | } |
| | | |
| | | checkForms = Array.from(new Set(checkForms)) |
| | | |
| | | this.setState({ |
| | | forms, |
| | | allForms, |
| | | allColumns, |
| | | checkForms, |
| | | pageSize: setting.pageSize || 10, |
| | | pageOptions, |
| | | columns: _columns, |
| | | tableId: setting.tableId, |
| | | orderfields |
| | | orderfields, |
| | | deForms: hasBid ? deForms : null |
| | | }, () => { |
| | | if (deForms.length > 0) { |
| | | if (hasBid && setting.supModule && !BID) { |
| | | this.setState({ deForms }) |
| | | if (deForms.length > 0 && (!hasBid || BID)) { |
| | | if (window.backend && window.GLOB.CacheData.has('sql_' + deForms[0].uuid)) { |
| | | this.improveBackActionForm(deForms, BID) |
| | | } 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') |
| | | }) |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | UNSAFE_componentWillReceiveProps(nextProps) { |
| | | const { BID } = this.props |
| | | const { BID, parCtrl } = this.props |
| | | const { deForms } = this.state |
| | | |
| | | if (deForms && nextProps.BID !== BID) { |
| | | this.improveActionForm(deForms, nextProps.BID) |
| | | if (window.backend && window.GLOB.CacheData.has('sql_' + deForms[0].uuid)) { |
| | | this.improveBackActionForm(deForms, nextProps.BID) |
| | | } else { |
| | | this.improveActionForm(deForms, nextProps.BID) |
| | | } |
| | | } |
| | | if (parCtrl && !is(fromJS(this.props.columns), fromJS(nextProps.columns))) { |
| | | let getColumns = (cols, sk) => { |
| | | return cols.map(item => { |
| | | let cell = null |
| | | |
| | | if (item.type === 'colspan') { |
| | | cell = { title: item.label, align: item.Align, $key: item.uuid } |
| | | cell.children = getColumns(item.subcols, sk || item.uuid) |
| | | } else { |
| | | 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.sortField) && item.IsSort === 'true', |
| | | width: item.Width || 120, |
| | | $key: item.uuid, |
| | | onCell: record => ({ |
| | | record, |
| | | col: item |
| | | }) |
| | | } |
| | | } |
| | | |
| | | return cell |
| | | }) |
| | | } |
| | | |
| | | let _columns = getColumns(nextProps.columns) |
| | | |
| | | this.setState({ |
| | | columns: _columns |
| | | }) |
| | | } |
| | | } |
| | | |
| | | componentDidMount () { |
| | | MKEmitter.addListener('subLine', this.subLine) |
| | | MKEmitter.addListener('nextLine', this.nextLine) |
| | | MKEmitter.addListener('addRecord', this.addRecord) |
| | | MKEmitter.addListener('delRecord', this.delRecord) |
| | | const { setting } = this.props |
| | | const { tableId } = this.state |
| | | |
| | | if (setting.commit === 'change') { |
| | | MKEmitter.addListener('colBlur' + tableId, this.colBlur) |
| | | MKEmitter.addListener('colFocus' + tableId, this.colFocus) |
| | | } |
| | | |
| | | MKEmitter.addListener('resetTable', this.resetTable) |
| | | MKEmitter.addListener('transferData', this.transferData) |
| | | MKEmitter.addListener('changeRecord', this.changeRecord) |
| | | MKEmitter.addListener('nextLine' + tableId, this.nextLine) |
| | | MKEmitter.addListener('addRecord' + tableId, this.plusLine) |
| | | MKEmitter.addListener('delRecord' + tableId, this.delRecord) |
| | | MKEmitter.addListener('transferData' + tableId, this.transferData) |
| | | MKEmitter.addListener('changeRecord' + tableId, this.changeRecord) |
| | | } |
| | | |
| | | /** |
| | | * @description 组件销毁,清除state更新 |
| | | */ |
| | | componentWillUnmount () { |
| | | const { tableId } = this.state |
| | | |
| | | this.setState = () => { |
| | | return |
| | | } |
| | | 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) |
| | | MKEmitter.removeListener('colBlur' + tableId, this.colBlur) |
| | | MKEmitter.removeListener('colFocus' + tableId, this.colFocus) |
| | | MKEmitter.removeListener('nextLine' + tableId, this.nextLine) |
| | | MKEmitter.removeListener('addRecord' + tableId, this.plusLine) |
| | | MKEmitter.removeListener('delRecord' + tableId, this.delRecord) |
| | | MKEmitter.removeListener('transferData' + tableId, this.transferData) |
| | | MKEmitter.removeListener('changeRecord' + tableId, this.changeRecord) |
| | | } |
| | | |
| | | transferData = (menuid, data, type) => { |
| | | const { MenuID } = this.props |
| | | const { edData } = this.state |
| | | colBlur = (lineId, colId, defer) => { |
| | | if (defer && this.focusId === lineId && this.colId !== colId) { |
| | | return |
| | | } |
| | | |
| | | this.blurId = lineId |
| | | this.focusId = '' |
| | | |
| | | if (menuid !== MenuID) return |
| | | this.timer && clearTimeout(this.timer) |
| | | |
| | | 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) |
| | | this.timer = setTimeout(() => { |
| | | if (!this.focusId || this.focusId !== this.blurId) { |
| | | this.checkLine() |
| | | } |
| | | }, 150) |
| | | } |
| | | |
| | | colFocus = (lineId, colId) => { |
| | | this.focusId = lineId |
| | | this.colId = colId |
| | | } |
| | | |
| | | checkLine = () => { |
| | | const { edData, forms, checkForms, dict } = this.state |
| | | |
| | | let data = edData.filter(item => item.$$uuid === this.blurId)[0] |
| | | |
| | | if (!data) return |
| | | |
| | | let record = fromJS(data).toJS() |
| | | |
| | | let value = '' |
| | | Object.keys(record).sort().forEach(key => { |
| | | if (/^\$/.test(key)) return |
| | | value += record[key] |
| | | }) |
| | | |
| | | if (record.$sign === md5(value)) return |
| | | |
| | | let err = '' |
| | | forms.forEach(col => { |
| | | let check = true |
| | | if (col.editable !== 'true' || !checkForms.includes(col.field)) { |
| | | check = false |
| | | } |
| | | if (col.ctrlField && col.ctrlValue.includes(record[col.ctrlField] + '')) { |
| | | check = false |
| | | } |
| | | |
| | | if (!check) { |
| | | if (col.type === 'number') { |
| | | record[col.field] = +record[col.field] |
| | | if (isNaN(record[col.field])) { |
| | | record[col.field] = 0 |
| | | } |
| | | } else { |
| | | record[col.field] = record[col.field] !== undefined ? (record[col.field] + '') : '' |
| | | } |
| | | return |
| | | } |
| | | |
| | | if (err) return |
| | | |
| | | if (col.type === 'text') { |
| | | let val = record[col.field] !== undefined ? (record[col.field] + '') : '' |
| | | if (col.required === 'true' && !val) { |
| | | err = `${col.label}${dict['not_empty'] || '不可为空'}` |
| | | } else if (col.datatype === 'datetime' && !val) { |
| | | val = '1949-10-01' |
| | | } |
| | | record[col.field] = val |
| | | } else if (col.type === 'number') { |
| | | let val = record[col.field] |
| | | |
| | | if (col.required === 'true' && !val) { |
| | | err = `${col.label}${col.noValue === 'hide' ? (dict['not_empty'] || '不可为空') : dict['not_zero'] || '不可为0'}` |
| | | } else if (col.noValue === 'hide' && !val) { |
| | | if (col.clearField && checkForms.includes(col.clearField) && !record[col.clearField]) { |
| | | err = `${dict['input_tip'] || '请填写 '}${col.label} ${dict['or'] || '或'} ${col.clearName}` |
| | | } |
| | | val = 0 |
| | | } else if (!val && val !== 0) { |
| | | err = `${col.label}${dict['not_empty'] || '不可为空'}` |
| | | } else { |
| | | val = +val |
| | | if (isNaN(val)) { |
| | | err = `${col.label} ${dict['data_format'] || '数据格式错误'}` |
| | | return |
| | | } |
| | | |
| | | val = +val.toFixed(col.decimal || 0) |
| | | |
| | | if (typeof(col.max) === 'number' && val > col.max) { |
| | | err = `${col.label}${dict['max_limit'] || ' 不可大于 '}${col.max}` |
| | | } else if (typeof(col.min) === 'number' && val < col.min) { |
| | | err = `${col.label}${dict['less_limit'] || ' 不可小于 '}${col.min}` |
| | | } |
| | | } |
| | | |
| | | record[col.field] = val |
| | | } |
| | | }) |
| | | |
| | | if (err) { |
| | | message.warning(err) |
| | | return |
| | | } |
| | | |
| | | this.submit(record) |
| | | } |
| | | |
| | | getCurColumns = (columns, allSearch, allForms, checkForms) => { |
| | | const { colsCtrls } = this.props |
| | | |
| | | let values = {} |
| | | allSearch.forEach(item => { |
| | | values[item.key] = item.value |
| | | }) |
| | | let cols = null |
| | | colsCtrls.some(item => { |
| | | let originVal = item.field.map(f => values[f] || '').join('') |
| | | let contrastVal = item.contrastValue |
| | | let result = false |
| | | |
| | | if (item.match === '=') { |
| | | result = originVal === contrastVal |
| | | } else if (item.match === '!=') { |
| | | result = originVal !== contrastVal |
| | | } else if (item.match === 'regexp') { |
| | | let reg = new RegExp(item.contrastValue, 'ig') |
| | | result = reg.test(originVal) |
| | | } else { |
| | | originVal = isNaN(originVal) ? originVal : +originVal |
| | | contrastVal = isNaN(contrastVal) ? contrastVal : +contrastVal |
| | | if (item.match === '>') { |
| | | result = originVal > contrastVal |
| | | } else if (item.match === '<') { |
| | | result = originVal < contrastVal |
| | | } |
| | | } |
| | | |
| | | if (!result) return false |
| | | |
| | | cols = item.cols |
| | | |
| | | return true |
| | | }) |
| | | |
| | | if (cols) { |
| | | allForms.forEach(item => { |
| | | if (cols.includes(item.uuid)) { |
| | | checkForms.push(item.field) |
| | | } |
| | | }) |
| | | |
| | | return columns.filter(col => cols.includes(col.$key)) |
| | | } |
| | | |
| | | allForms.forEach(item => { |
| | | checkForms.push(item.field) |
| | | }) |
| | | |
| | | return columns |
| | | } |
| | | |
| | | transferData = (data, type) => { |
| | | const { edData, tableId } = this.state |
| | | |
| | | if (type === 'clear') { |
| | | this.setState({edData: [], midData: []}) |
| | | return |
| | | } else if (type === 'delete') { |
| | | |
| | | } else if (type === 'line') { |
| | | let value = '' |
| | | Object.keys(data).sort().forEach(key => { |
| | | if (/^\$/.test(key)) return |
| | | value += data[key] |
| | | }) |
| | | data.$sign = md5(value) |
| | | } else { |
| | | data.forEach(item => { |
| | | let value = '' |
| | | Object.keys(item).sort().forEach(key => { |
| | | if (/^\$/.test(key)) return |
| | | value += item[key] |
| | | }) |
| | | item.$sign = md5(value) |
| | | }) |
| | | } |
| | | |
| | | if (type === 'delete') { |
| | | let _edData = this.state.edData.filter(item => item.$$uuid !== data) |
| | | |
| | | this.setState({edData: _edData, reseting: true}, () => { |
| | | this.setState({reseting: false}) |
| | | |
| | | if (this.focusId) { |
| | | setTimeout(() => { |
| | | MKEmitter.emit('setFocus' + tableId, this.focusId, this.colId) |
| | | }, 10) |
| | | } |
| | | }) |
| | | } else if (type === 'line') { |
| | | let _edData = this.state.edData.map(item => { |
| | | if (item.$$uuid === data.$$uuid) { |
| | |
| | | } |
| | | }) |
| | | |
| | | this.setState({edData: _edData}) |
| | | this.setState({edData: _edData, reseting: true}, () => { |
| | | this.setState({reseting: false}) |
| | | |
| | | if (this.focusId) { |
| | | setTimeout(() => { |
| | | MKEmitter.emit('setFocus' + tableId, this.focusId, this.colId) |
| | | }, 10) |
| | | } |
| | | }) |
| | | } else { |
| | | let index = edData.findIndex(item => !item.$origin && !item.$forbid) |
| | | |
| | | if (index > -1) { |
| | | this.setState({visible: true, midData: data}) |
| | | } else { |
| | | this.updateMutil(data) |
| | | } |
| | | } |
| | | } |
| | | |
| | | updateMutil = (data) => { |
| | | const { setting } = this.props |
| | | const { setting, colsCtrls, allSearch } = this.props |
| | | const { allColumns, allForms } = this.state |
| | | |
| | | if (colsCtrls) { |
| | | let checkForms = [] |
| | | let columns = this.getCurColumns(allColumns, allSearch, allForms, checkForms) |
| | | |
| | | checkForms = Array.from(new Set(checkForms)) |
| | | |
| | | this.setState({ |
| | | checkForms, |
| | | columns: columns, |
| | | reseting: true, |
| | | edData: data, |
| | | visible: false, |
| | | midData: null |
| | | }, () => { |
| | | this.setState({ |
| | | reseting: false |
| | | }) |
| | | }) |
| | | |
| | | return |
| | | } |
| | | |
| | | if (setting.editType === 'multi' && data.length > 0) { |
| | | this.setState({edData: []}, () => { |
| | | this.setState({edData: data, visible: false, midData: null}) |
| | | this.setState({edData: data, visible: false, midData: null, reseting: true}, () => { |
| | | this.setState({reseting: false}) |
| | | }) |
| | | } else { |
| | | this.setState({edData: data, visible: false, midData: null}) |
| | |
| | | |
| | | if (setting.addable && data.length === 0) { |
| | | setTimeout(() => { |
| | | this.plusLine(true) |
| | | this.plusLine() |
| | | }, 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 debug = window.GLOB.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 |
| | | |
| | |
| | | sql = sql.replace(/@BID@/ig, `'${BID}'`) |
| | | |
| | | if (debug) { |
| | | console.info(sql) |
| | | window.mkInfo(sql) |
| | | } |
| | | |
| | | sql = sql.replace(/%/ig, ' mpercent ') |
| | |
| | | sql = sql.replace(/@BID@/ig, `'${BID}'`) |
| | | |
| | | if (debug) { |
| | | console.info(sql) |
| | | window.mkInfo(sql) |
| | | } |
| | | |
| | | sql = sql.replace(/%/ig, ' mpercent ') |
| | |
| | | } |
| | | |
| | | if (param.LText) { |
| | | param.LText = Utils.formatOptions(param.LText) |
| | | if (window.GLOB.execType === 'x') { |
| | | param.exec_type = 'x' |
| | | } |
| | | |
| | | param.LText = Utils.formatOptions(param.LText, param.exec_type) |
| | | param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') |
| | | param.secretkey = Utils.encrypt(param.LText, param.timestamp) |
| | | param.secretkey = Utils.encrypt(window.GLOB.execType === 'x' ? '' : param.LText, param.timestamp) |
| | | |
| | | deffers.push( |
| | | new Promise(resolve => { |
| | | Api.getSystemCacheConfig(param, cache).then(res => { |
| | | Api.getSystemCacheConfig(param, false).then(res => { |
| | | if (!res.status) { |
| | | notification.warning({ |
| | | top: 92, |
| | |
| | | } |
| | | |
| | | if (mainparam.LText) { |
| | | mainparam.LText = Utils.formatOptions(mainparam.LText) |
| | | if (window.GLOB.execType === 'x') { |
| | | mainparam.exec_type = 'x' |
| | | } |
| | | |
| | | mainparam.LText = Utils.formatOptions(mainparam.LText, mainparam.exec_type) |
| | | mainparam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') |
| | | mainparam.secretkey = Utils.encrypt(mainparam.LText, mainparam.timestamp) |
| | | mainparam.secretkey = Utils.encrypt(window.GLOB.execType === 'x' ? '' : mainparam.LText, mainparam.timestamp) |
| | | |
| | | if (window.GLOB.mainSystemApi) { |
| | | mainparam.rduri = window.GLOB.mainSystemApi |
| | |
| | | |
| | | deffers.push( |
| | | new Promise(resolve => { |
| | | Api.getSystemCacheConfig(mainparam, cache).then(res => { |
| | | Api.getSystemCacheConfig(mainparam, false).then(res => { |
| | | if (!res.status) { |
| | | notification.warning({ |
| | | top: 92, |
| | |
| | | }) |
| | | ) |
| | | } |
| | | |
| | | 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) |
| | | }) |
| | | } |
| | | |
| | | improveBackActionForm = (deForms, BID) => { |
| | | let sysvals = { |
| | | mk_departmentcode: sessionStorage.getItem('departmentcode') || '', |
| | | mk_organization: sessionStorage.getItem('organization') || '', |
| | | mk_user_type: sessionStorage.getItem('mk_user_type') || '', |
| | | bid: BID || '', |
| | | datam: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '', |
| | | datam_begin: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '', |
| | | datam_end: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '' |
| | | } |
| | | if (window.GLOB.externalDatabase !== null) { |
| | | sysvals.db = window.GLOB.externalDatabase |
| | | } |
| | | |
| | | let deffers = [] |
| | | let mainItems = [] // 云端或单点数据 |
| | | let localItems = [] // 本地数据 |
| | | |
| | | deForms.forEach(item => { |
| | | let ex = window.GLOB.CacheData.get('sql_' + item.uuid) |
| | | |
| | | if (!ex) return |
| | | |
| | | let exps = [] |
| | | ex.reps.forEach(n => { |
| | | let key = n.toLowerCase() |
| | | if (sysvals.hasOwnProperty(key)) { |
| | | exps.push({ |
| | | key: n, |
| | | value: sysvals[key] |
| | | }) |
| | | } |
| | | }) |
| | | |
| | | let cell = { |
| | | id: ex.id, |
| | | exps: exps, |
| | | menuname: item.label + '(表单)', |
| | | md5_id: '' |
| | | } |
| | | |
| | | if (item.database === 'sso' && window.GLOB.mainSystemApi) { |
| | | mainItems.push(cell) |
| | | } else { |
| | | localItems.push(cell) |
| | | } |
| | | }) |
| | | |
| | | if (localItems.length) { |
| | | deffers.push({ |
| | | $backend: true, |
| | | data: localItems |
| | | }) |
| | | } |
| | | |
| | | if (mainItems.length) { |
| | | deffers.push({ |
| | | $backend: true, |
| | | data: mainItems, |
| | | rduri: window.GLOB.mainSystemApi |
| | | }) |
| | | } |
| | | |
| | | if (!deffers.length) return |
| | | |
| | | deffers = deffers.map(item => { |
| | | return new Promise(resolve => { |
| | | Api.getSystemCacheConfig(item, false).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] || {})} |
| | |
| | | return item |
| | | }) |
| | | |
| | | this.setState({columns: [], edData: []}, () => { |
| | | let _cols = this.state.allColumns |
| | | if (_cols) { |
| | | _cols = _cols.map(item => { |
| | | if (reCols[item.dataIndex]) { |
| | | item.onCell = record => ({ |
| | | record, |
| | | col: reCols[item.dataIndex] |
| | | }) |
| | | } |
| | | |
| | | return item |
| | | }) |
| | | } |
| | | |
| | | this.setState({columns: [], edData: [], allColumns: _cols}, () => { |
| | | this.setState({columns: _edColumns, edData: edData}) |
| | | }) |
| | | } |
| | | |
| | | nextLine = (col, uuid) => { |
| | | nextLine = (lineId, colId) => { |
| | | const { setting } = this.props |
| | | const { edData, tableId } = this.state |
| | | |
| | | if (col.tableId !== tableId) return |
| | | |
| | | let index = edData.findIndex(item => item.$$uuid === uuid) |
| | | let index = edData.findIndex(item => item.$$uuid === lineId) |
| | | 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() |
| | | } |
| | | } |
| | | MKEmitter.emit('setFocus' + tableId, next.$$uuid, colId) |
| | | } else if (setting.addable) { |
| | | setTimeout(() => { |
| | | this.plusLine() |
| | | this.plusLine(colId) |
| | | }, 10) |
| | | } else if (edData[index]) { |
| | | } else if (edData[index] && (setting.commit === 'all' || setting.commit === 'amend')) { |
| | | setTimeout(() => { |
| | | this.subLine(col, edData[index]) |
| | | this.submit() |
| | | }, 10) |
| | | } |
| | | } |
| | | |
| | | 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({edData: _data}, () => { |
| | | if (setting.tableType && setting.hasAction && !lock && this.state.selectedRowKeys.includes(record.$$uuid)) { |
| | | this.selectdata(this.state.selectedRowKeys) |
| | | } |
| | | }) |
| | | } |
| | | |
| | | addRecord = (id, record) => { |
| | | plusLine = (colId, lineId) => { |
| | | const { BID } = this.props |
| | | const { edData, forms, tableId } = this.state |
| | | const { forms, tableId } = this.state |
| | | |
| | | if (id !== tableId) return |
| | | |
| | | let _edData = fromJS(edData).toJS() |
| | | let item = {} |
| | | let edData = fromJS(this.state.edData).toJS() |
| | | let item = edData.length > 0 ? {...edData[edData.length - 1]} : {} |
| | | let index = null |
| | | let copy = edData.length > 0 ? {...edData[edData.length - 1]} : null |
| | | |
| | | if (record) { |
| | | index = _edData.findIndex(item => record.$$uuid === item.$$uuid) |
| | | |
| | | if (lineId) { |
| | | index = edData.findIndex(item => lineId === item.$$uuid) |
| | | index = index === -1 ? null : index |
| | | |
| | | copy = {...record} |
| | | |
| | | if (index !== null) { |
| | | item = {...edData[index]} |
| | | } |
| | | } |
| | | |
| | | if (copy) { |
| | | item = {...copy} |
| | | } |
| | | |
| | | item.key = edData.length |
| | | item.$$uuid = Utils.getguid() |
| | | item.$type = 'add' |
| | | item.$Index = '' |
| | | item.$forbid = true |
| | | item.$Index = '' |
| | | item.$$BID = BID || '' |
| | | |
| | | forms.forEach(col => { |
| | |
| | | item[col.field] = 0 |
| | | } |
| | | } |
| | | |
| | | if (item[col.field] === undefined) { |
| | | item[col.field] = '' |
| | | } |
| | | }) |
| | | |
| | | let value = '' |
| | | Object.keys(item).sort().forEach(key => { |
| | | if (/^\$/.test(key)) return |
| | | value += item[key] |
| | | }) |
| | | item.$sign = md5(value) |
| | | |
| | | if (index === null) { |
| | | _edData.push(item) |
| | | edData.push(item) |
| | | } else { |
| | | _edData.splice(index, 0, item) |
| | | edData.splice(index, 0, item) |
| | | } |
| | | |
| | | this.setState({edData: _edData}) |
| | | this.setState({edData: edData}, () => { |
| | | if (colId) { |
| | | MKEmitter.emit('setFocus' + tableId, item.$$uuid, colId) |
| | | } |
| | | }) |
| | | } |
| | | |
| | | delRecord = (record) => { |
| | | const { setting } = this.props |
| | | const { edData } = this.state |
| | | |
| | | 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' |
| | | |
| | | record.$deleted = true |
| | | record.$origin = false |
| | | record.$type = 'del' |
| | | } |
| | | |
| | | return item |
| | | }) |
| | | |
| | | this.setState({edData: _data}, () => { |
| | | if (setting.commit === 'change') { |
| | | this.submit(record) |
| | | } |
| | | }) |
| | | } |
| | | } |
| | | |
| | | changeRecord = (record) => { |
| | | const { setting } = this.props |
| | | const { edData } = this.state |
| | | |
| | | let data = edData.filter(item => item.$$uuid === record.$$uuid)[0] |
| | | |
| | | if (!data) return |
| | | |
| | | if (is(fromJS(data), fromJS(record))) return |
| | | |
| | | delete record.$forbid |
| | | |
| | | let value = '' |
| | | Object.keys(record).sort().forEach(key => { |
| | | if (/^\$/.test(key)) return |
| | | value += record[key] |
| | | }) |
| | | |
| | | let sign = md5(value) |
| | | |
| | | if (record.$sign === sign) { |
| | | record.$origin = true |
| | | record.$lock = false |
| | | } else { |
| | | record.$origin = false |
| | | record.$lock = true |
| | | } |
| | | |
| | | let _data = edData.map(item => { |
| | | if (item.$$uuid === record.$$uuid) { |
| | | return record |
| | | } else { |
| | | return item |
| | | } |
| | | }) |
| | | |
| | | this.setState({edData: _data}, () => { |
| | | if (setting.tableType && setting.hasAction && this.state.selectedRowKeys.includes(record.$$uuid)) { |
| | | this.selectdata(this.state.selectedRowKeys) |
| | | } |
| | | }) |
| | | } |
| | | |
| | | checkData = () => { |
| | | const { setting } = this.props |
| | | const { edData, forms } = this.state |
| | | |
| | | if (edData.length === 0) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '提交数据不可为空!', |
| | | duration: 5 |
| | | }) |
| | | return null |
| | | } |
| | | const { edData, forms, checkForms, selectedRowKeys, dict } = this.state |
| | | |
| | | let data = fromJS(edData).toJS() |
| | | |
| | | data = data.filter(item => !item.$forbid) |
| | | if (setting.commit === 'change' || setting.commit === 'simple') { |
| | | |
| | | if (setting.commit === 'amend') { |
| | | data = data.filter(item => !item.$origin) |
| | | } else if (setting.commit === 'check') { |
| | | data = data.filter(item => selectedRowKeys.includes(item.$$uuid)) |
| | | |
| | | if (data.length === 0) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: dict['select_row'] || '请选择需要提交的数据!', |
| | | duration: 5 |
| | | }) |
| | | return null |
| | | } |
| | | } |
| | | |
| | | if (data.length === 0) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '数据未修改,不可提交!', |
| | | message: dict['un_modified'] || '数据未修改,不可提交!', |
| | | duration: 5 |
| | | }) |
| | | return null |
| | |
| | | data = data.map(item => { |
| | | let line = [] |
| | | forms.forEach(col => { |
| | | if (col.editable !== 'true' || item.$deleted) { |
| | | let check = true |
| | | if (col.editable !== 'true' || item.$deleted || !checkForms.includes(col.field)) { |
| | | check = false |
| | | } |
| | | if (col.ctrlField && col.ctrlValue.includes(item[col.ctrlField] + '')) { |
| | | check = false |
| | | } |
| | | |
| | | if (!check) { |
| | | if (col.type === 'number') { |
| | | item[col.field] = +item[col.field] |
| | | if (isNaN(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}不可为空`) |
| | | line.push(`${col.label}${dict['not_empty'] || '不可为空'}`) |
| | | } else if (col.datatype === 'datetime' && !val) { |
| | | val = '1949-10-01' |
| | | } |
| | | item[col.field] = val |
| | | } else if (col.type === 'number') { |
| | | let val = item[col.field] |
| | | if (col.noValue === 'hide' && !val) { |
| | | if (col.required === 'true' && !val) { |
| | | err = `${col.label}${col.noValue === 'hide' ? (dict['not_empty'] || '不可为空') : dict['not_zero'] || '不可为0'}` |
| | | } else if (col.noValue === 'hide' && !val) { |
| | | if (col.clearField && checkForms.includes(col.clearField) && !item[col.clearField]) { |
| | | let msg = `${dict['input_tip'] || '请填写 '}${col.label} ${dict['or'] || '或'} ${col.clearName}` |
| | | if (!line.includes(msg)) { |
| | | line.push(msg) |
| | | } |
| | | } |
| | | val = 0 |
| | | } else if (!val && val !== 0) { |
| | | line.push(`${col.label}不可为空`) |
| | | line.push(`${col.label}${dict['not_empty'] || '不可为空'}`) |
| | | 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}`) |
| | | } else { |
| | | val = +val |
| | | if (isNaN(val)) { |
| | | line.push(`${col.label} ${dict['data_format'] || '数据格式错误'}`) |
| | | return |
| | | } |
| | | |
| | | val = +val.toFixed(col.decimal || 0) |
| | | |
| | | if (typeof(col.max) === 'number' && val > col.max) { |
| | | line.push(`${col.label}${dict['max_limit'] || ' 不可大于 '}${col.max}`) |
| | | } else if (typeof(col.min) === 'number' && val < col.min) { |
| | | line.push(`${col.label}${dict['less_limit'] || ' 不可小于 '}${col.min}`) |
| | | } |
| | | } |
| | | |
| | | item[col.field] = val |
| | |
| | | }) |
| | | |
| | | if (line.length > 0) { |
| | | err += `第${Index}行:` + line.join(',') + ';' |
| | | err += (dict['line'] ? `${dict['line']} ${Index}:` : `第${Index}行:`) + line.join(',') + ';' |
| | | } |
| | | if (!item.$deleted) { |
| | | Index++ |
| | |
| | | return data |
| | | } |
| | | |
| | | submit = () => { |
| | | submit = (record) => { |
| | | const { submit, BID, setting } = this.props |
| | | const { forms } = this.state |
| | | const { forms, dict } = this.state |
| | | |
| | | this.setState({visible: false, midData: null}) |
| | | |
| | | if (setting.supModule && !BID) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '需要上级主键值!', |
| | | message: dict['sup_key_req'] || '需要上级主键值!', |
| | | duration: 5 |
| | | }) |
| | | |
| | | return |
| | | } |
| | | |
| | | let data = this.checkData() |
| | | let data = null |
| | | if (record) { |
| | | data = [record] |
| | | } else { |
| | | 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') { // 系统存储过程 |
| | | if (submit.intertype === 'system' && window.backend && window.GLOB.CacheData.has('sql_submit_' + submit.$menuId)) { |
| | | let ex = window.GLOB.CacheData.get('sql_submit_' + submit.$menuId) |
| | | let param = this.getExps(ex, submit, data, forms) |
| | | |
| | | Api.genericInterface(param).then((res) => { |
| | | if (res.status) { |
| | | this.execSuccess(res, record) |
| | | } else { |
| | | this.execError(res, record) |
| | | } |
| | | }, (error) => { |
| | | if (error && error.ErrCode === 'LoginError') return |
| | | |
| | | this.execError({}) |
| | | }) |
| | | } else if (submit.intertype === 'system') { // 系统存储过程 |
| | | let result = getEditTableSql(submit, data, forms) |
| | | let param = {} |
| | | |
| | | param.func = 'sPC_TableData_InUpDe' |
| | | param.BID = BID || '' |
| | | |
| | | 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.exec_type = window.GLOB.execType || 'y' |
| | | param.LText = Utils.formatOptions(result.sql, param.exec_type) |
| | | param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') |
| | | param.secretkey = Utils.encrypt(param.LText, param.timestamp) |
| | | param.secretkey = Utils.encrypt('', param.timestamp) |
| | | |
| | | param.menuname = submit.logLabel |
| | | |
| | |
| | | |
| | | Api.genericInterface(param).then((res) => { |
| | | if (res.status) { |
| | | this.execSuccess(res) |
| | | this.execSuccess(res, record) |
| | | } else { |
| | | this.execError(res) |
| | | this.execError(res, record) |
| | | } |
| | | }, (error) => { |
| | | if (error && error.ErrCode === 'LoginError') return |
| | |
| | | this.execError({}) |
| | | }) |
| | | } else if (submit.intertype === 'inner' && submit.innerFunc) { // 自定义存储过程 |
| | | let result = getEditTableSql(submit, data, forms) |
| | | let param = {} |
| | | |
| | | param.func = submit.innerFunc |
| | | param.BID = BID || '' |
| | | param.excel_in = result.lines |
| | | |
| | | if (submit.recordUser === 'true') { |
| | | param.username = sessionStorage.getItem('User_Name') || '' |
| | | param.fullname = sessionStorage.getItem('Full_Name') || '' |
| | | } |
| | | |
| | | Api.genericInterface(param).then((res) => { |
| | | if (res.status) { |
| | | this.execSuccess(res) |
| | | this.execSuccess(res, record) |
| | | } else { |
| | | this.execError(res) |
| | | this.execError(res, record) |
| | | } |
| | | }, (error) => { |
| | | if (error && error.ErrCode === 'LoginError') return |
| | |
| | | } |
| | | } |
| | | |
| | | execSuccess = (res) => { |
| | | getExps = (ex, btn, data, forms) => { |
| | | const { BID } = this.props |
| | | |
| | | let exps = [] |
| | | let values = { |
| | | time_id: Utils.getguid(), |
| | | roleid: sessionStorage.getItem('role_id') || '', |
| | | mk_departmentcode: sessionStorage.getItem('departmentcode') || '', |
| | | mk_organization: sessionStorage.getItem('organization') || '', |
| | | mk_user_type: sessionStorage.getItem('mk_user_type') || '', |
| | | mk_nation: sessionStorage.getItem('nation') || '', |
| | | mk_province: sessionStorage.getItem('province') || '', |
| | | mk_city: sessionStorage.getItem('city') || '', |
| | | mk_district: sessionStorage.getItem('district') || '', |
| | | mk_address: sessionStorage.getItem('address') || '', |
| | | bid: BID || '', |
| | | typename: 'admin', |
| | | datam: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '', |
| | | datam_begin: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '', |
| | | datam_end: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '', |
| | | } |
| | | |
| | | if (window.GLOB.externalDatabase !== null) { |
| | | values.db = window.GLOB.externalDatabase |
| | | } |
| | | |
| | | let lines = data.map(item => { |
| | | let vals = [] |
| | | forms.forEach(col => { |
| | | vals.push(item[col.field]) |
| | | }) |
| | | |
| | | vals.push(item.$$uuid) |
| | | vals.push(item.$type || 'upt') |
| | | vals.push(BID) |
| | | |
| | | return vals |
| | | }) |
| | | |
| | | ex.reps.forEach(n => { |
| | | let key = n.toLowerCase() |
| | | if (values.hasOwnProperty(key)) { |
| | | exps.push({ |
| | | key: n, |
| | | value: values[key] |
| | | }) |
| | | } |
| | | }) |
| | | |
| | | exps.push({ |
| | | key: 'mk_excel_data', |
| | | value: lines |
| | | }) |
| | | |
| | | let md5_id = '' |
| | | if (window.GLOB.probation) { |
| | | md5_id = md5(ex.id + JSON.stringify(exps) + Math.floor(new Date().getTime() / 600000)) |
| | | md5_id = moment().format('YYYYMMDDHHmmss') + md5_id.slice(-18) |
| | | } |
| | | |
| | | return { |
| | | $backend: true, |
| | | data: [{ |
| | | id: ex.id, |
| | | exps: exps, |
| | | menuname: btn.logLabel || '', |
| | | md5_id: md5_id |
| | | }] |
| | | } |
| | | } |
| | | |
| | | execSuccess = (res, record) => { |
| | | const { submit } = this.props |
| | | const { edData } = this.state |
| | | const { edData, dict } = this.state |
| | | |
| | | if (res && res.ErrCode === 'S') { // 执行成功 |
| | | notification.success({ |
| | | top: 92, |
| | | message: res.ErrMesg || '执行成功', |
| | | message: res.message || dict['exc_success'] || '执行成功', |
| | | duration: submit.stime ? submit.stime : 2 |
| | | }) |
| | | } else if (res && res.ErrCode === 'Y') { // 执行成功 |
| | | Modal.success({ |
| | | title: res.ErrMesg || '执行成功' |
| | | title: res.message || dict['exc_success'] || '执行成功', |
| | | okText: dict['got_it'] || '知道了' |
| | | }) |
| | | } else if (res && res.ErrCode === '-1') { // 完成后不提示 |
| | | |
| | |
| | | |
| | | let _edData = fromJS(edData).toJS() |
| | | |
| | | _edData = _edData.map(item => { |
| | | _edData = _edData.filter(item => { |
| | | if (item.$deleted) return false |
| | | |
| | | if (!item.$forbid) { |
| | | item.$type = 'upt' |
| | | item.$origin = true |
| | | item.$lock = false |
| | | } |
| | | return item |
| | | |
| | | let value = '' |
| | | Object.keys(item).sort().forEach(key => { |
| | | if (/^\$/.test(key)) return |
| | | value += item[key] |
| | | }) |
| | | |
| | | item.$sign = md5(value) |
| | | |
| | | return true |
| | | }) |
| | | |
| | | this.setState({ |
| | |
| | | } |
| | | |
| | | if (submit.execSuccess !== 'never') { |
| | | MKEmitter.emit('refreshByButtonResult', submit.$menuId, submit.execSuccess, submit) |
| | | MKEmitter.emit('refreshByButtonResult', submit.$menuId, submit.execSuccess, submit, '', record ? [record] : null) |
| | | } |
| | | |
| | | submit.syncComponentId && MKEmitter.emit('reloadData', submit.syncComponentId) |
| | | } |
| | | |
| | | execError = (res) => { |
| | | execError = (res, record) => { |
| | | const { submit } = this.props |
| | | const { dict } = this.state |
| | | |
| | | if (res.ErrCode === 'E') { |
| | | Modal.error({ |
| | | title: res.message || res.ErrMesg, |
| | | title: res.message || dict['exc_fail'] || '执行失败!', |
| | | okText: dict['got_it'] || '知道了' |
| | | }) |
| | | } else if (res.ErrCode === 'N') { |
| | | notification.error({ |
| | | top: 92, |
| | | message: res.message || res.ErrMesg, |
| | | message: res.message || dict['exc_fail'] || '执行失败!', |
| | | duration: submit.ntime ? submit.ntime : 10 |
| | | }) |
| | | } else if (res.ErrCode === 'F') { |
| | | notification.error({ |
| | | className: 'notification-custom-error', |
| | | top: 92, |
| | | message: res.message || res.ErrMesg, |
| | | message: res.message || dict['exc_fail'] || '执行失败!', |
| | | duration: submit.ftime ? submit.ftime : 10 |
| | | }) |
| | | } else if (res.ErrCode === 'NM') { |
| | | message.error(res.message || res.ErrMesg) |
| | | message.error(res.message || dict['exc_fail'] || '执行失败!') |
| | | } |
| | | |
| | | this.setState({ |
| | |
| | | }) |
| | | |
| | | if (submit.execError !== 'never') { |
| | | MKEmitter.emit('refreshByButtonResult', submit.$menuId, submit.execError, submit) |
| | | MKEmitter.emit('refreshByButtonResult', submit.$menuId, submit.execError, submit, '', record ? [record] : null) |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | render() { |
| | | const { setting, lineMarks, submit } = this.props |
| | | const { tableId, edData, columns, loading, pageOptions, selectedRowKeys, visible, midData } = this.state |
| | | const { edData, columns, loading, pageOptions, selectedRowKeys, visible, midData, reseting, dict } = this.state |
| | | |
| | | if (reseting) return null |
| | | |
| | | const components = { |
| | | body: { |
| | |
| | | pageSizeOptions: pageOptions, |
| | | showSizeChanger: true, |
| | | total: this.props.total || 0, |
| | | showTotal: (total, range) => `${range[0]}-${range[1]} 共 ${total} 条` |
| | | showTotal: (total, range) => `${range[0]}-${range[1]} ${dict['of'] || '共'} ${total} ${dict['items'] || '条'}` |
| | | } |
| | | } |
| | | |
| | | let height = setting.height || false |
| | | if (height && height <= 100) { |
| | | height = height + 'vh' |
| | | if (height) { |
| | | if (height <= 100) { |
| | | if (height < 0) { |
| | | height = `calc(100vh - ${-height}px)` |
| | | } else { |
| | | height = height + 'vh' |
| | | } |
| | | } |
| | | } |
| | | |
| | | let style = { |
| | | '--mk-table-border-color': setting.borderColor || '#e8e8e8', |
| | | '--mk-table-color': setting.color || 'rgba(0, 0, 0, 0.65)', |
| | | '--mk-table-font-size': setting.fontSize || '14px', |
| | | '--mk-table-font-weight': setting.fontWeight || 'normal' |
| | | } |
| | | |
| | | return ( |
| | | <> |
| | | {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> |
| | | {setting.hasSubmit && edData.length > 0 ? <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">{dict['submit'] || '提交'}</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}> |
| | | <div className={`edit-custom-table ${setting.tableHeader || ''} ${setting.parity === 'true' ? 'mk-parity' : ''} ${height ? 'fixed-table-height' : ''} ${setting.mode || ''} table-vertical-${setting.vertical || ''} mk-edit-${setting.editType || 'simple'}`} style={style}> |
| | | <Table |
| | | rowKey="$$uuid" |
| | | components={components} |
| | |
| | | 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} |
| | | {setting.hasSubmit && _data.length > 10 ? <Button style={submit.style} onClick={() => setTimeout(() => {this.submit()}, 10)} loading={loading} className="submit-footer-table" type="link">{dict['submit'] || '提交'}</Button> : null} |
| | | </div> |
| | | <Modal |
| | | className="mk-user-confirm" |
| | |
| | | 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> |
| | | <Button key="cancel" onClick={() => { this.setState({ visible: false, midData: null }) }}>{dict['cancel'] || '取消'}</Button>, |
| | | <Button key="refresh" className="table-refresh" onClick={() => { midData && this.updateMutil(midData) }}>{dict['refresh'] || '刷新表格'}</Button>, |
| | | <Button key="confirm" type="primary" onClick={() => setTimeout(() => {this.submit()}, 10)}>{dict['submit'] || '提交数据'}</Button> |
| | | ]} |
| | | destroyOnClose |
| | | > |
| | | <div><QuestionCircleOutlined />表格中有数据尚未提交</div> |
| | | <div><QuestionCircleOutlined />{dict['data_not_sub'] || '表格中有数据尚未提交'}</div> |
| | | </Modal> |
| | | </> |
| | | ) |