| | |
| | | }) |
| | | } |
| | | |
| | | if (type === 'editable') { |
| | | opentypes = [ |
| | | { |
| | | value: 'excelIn', |
| | | text: Formdict['model.form.excelIn'] |
| | | }, { |
| | | value: 'excelOut', |
| | | text: Formdict['model.form.excelOut'] |
| | | } |
| | | ] |
| | | } |
| | | // if (type === 'editable') { |
| | | // opentypes = [ |
| | | // { |
| | | // value: 'excelIn', |
| | | // text: Formdict['model.form.excelIn'] |
| | | // }, { |
| | | // value: 'excelOut', |
| | | // text: Formdict['model.form.excelOut'] |
| | | // } |
| | | // ] |
| | | // } |
| | | |
| | | let tabs = getTabs(JSON.parse(JSON.stringify(modules))) |
| | | |
| | |
| | | }, |
| | | { |
| | | type: 'radio', |
| | | field: 'editable', |
| | | label: '初始化', |
| | | initval: wrap.editable || 'false', |
| | | required: false, |
| | | options: [ |
| | | {value: 'true', label: '可编辑'}, |
| | | {value: 'false', label: '不可编辑'}, |
| | | ] |
| | | }, |
| | | { |
| | | type: 'radio', |
| | | field: 'commit', |
| | | label: '数据提交', |
| | | initval: wrap.commit || 'all', |
| | | required: false, |
| | | options: [ |
| | | {value: 'all', label: '全部'}, |
| | | {value: 'change', label: '修改项'}, |
| | | ] |
| | | }, |
| | | { |
| | | type: 'radio', |
| | | field: 'addable', |
| | | label: '可新增', |
| | | initval: wrap.addable || 'false', |
| | | required: false, |
| | | options: [ |
| | | {value: 'true', label: '是'}, |
| | | {value: 'false', label: '否'}, |
| | | ] |
| | | }, |
| | | { |
| | | type: 'radio', |
| | | field: 'delable', |
| | | label: '可删除', |
| | | initval: wrap.delable || 'true', |
| | | required: false, |
| | | options: [ |
| | | {value: 'true', label: '是'}, |
| | | {value: 'false', label: '否'}, |
| | | ] |
| | | }, |
| | | { |
| | | type: 'radio', |
| | | field: 'operType', |
| | | label: '编辑按钮', |
| | | initval: wrap.operType || 'btnMode', |
| | | tooltip: '编辑时的添加、删除按钮显示位置,注:使用浮标时表格横向滚动失效,表格设置高度时浮标无效。', |
| | | required: false, |
| | | options: [ |
| | | {value: 'btnMode', label: '按钮式'}, |
| | | {value: 'buoyMode', label: '浮标式'}, |
| | | ] |
| | | }, |
| | | { |
| | | type: 'radio', |
| | | field: 'cache', |
| | | label: '缓存', |
| | | initval: wrap.cache || 'true', |
| | | tooltip: '对于使用数据源的下拉菜单,下拉选项是否缓存到本地。', |
| | | required: false, |
| | | options: [ |
| | | {value: 'true', label: '使用'}, |
| | | {value: 'false', label: '不使用'}, |
| | | ] |
| | | }, |
| | | { |
| | | type: 'radio', |
| | | field: 'bordered', |
| | | label: '边框', |
| | | initval: wrap.bordered || 'true', |
| | |
| | | options: [ |
| | | {value: 'true', label: '显示'}, |
| | | {value: 'false', label: '隐藏'}, |
| | | ] |
| | | }, |
| | | { |
| | | type: 'radio', |
| | | field: 'addable', |
| | | label: '可新增', |
| | | initval: wrap.addable || 'false', |
| | | required: false, |
| | | options: [ |
| | | {value: 'true', label: '是'}, |
| | | {value: 'false', label: '否'}, |
| | | ] |
| | | }, |
| | | { |
| | | type: 'radio', |
| | | field: 'delable', |
| | | label: '可删除', |
| | | initval: wrap.delable || 'true', |
| | | required: false, |
| | | options: [ |
| | | {value: 'true', label: '是'}, |
| | | {value: 'false', label: '否'}, |
| | | ] |
| | | }, |
| | | { |
| | | type: 'radio', |
| | | field: 'editable', |
| | | label: '初始化', |
| | | initval: wrap.editable || 'false', |
| | | required: false, |
| | | options: [ |
| | | {value: 'true', label: '可编辑'}, |
| | | {value: 'false', label: '不可编辑'}, |
| | | ] |
| | | }, |
| | | { |
| | | type: 'radio', |
| | | field: 'cache', |
| | | label: '缓存', |
| | | initval: wrap.cache || 'true', |
| | | tooltip: '对于使用数据源的下拉菜单,下拉选项是否缓存到本地。', |
| | | required: false, |
| | | options: [ |
| | | {value: 'true', label: '使用'}, |
| | | {value: 'false', label: '不使用'}, |
| | | ] |
| | | }, |
| | | { |
| | |
| | | </Form.Item> |
| | | </Col> : null} |
| | | {/* 1、不分页且不存在上级模块 */} |
| | | {!['navbar'].includes(config.type) && (!config.pageable || (config.pageable && laypage === 'false')) && (!supModule || supModule.length === 0 || supModule[0] === 'empty') ? <Col span={8}> |
| | | {!['navbar'].includes(config.type) && !['editable'].includes(config.subtype) && (!config.pageable || (config.pageable && laypage === 'false')) && (!supModule || supModule.length === 0 || supModule[0] === 'empty') ? <Col span={8}> |
| | | <Form.Item label={ |
| | | <Tooltip placement="topLeft" title={'初始化加载时,是否与其他组件一同加载数据,注:仅在使用系统函数,且初始化加载数据时有效,分页请求时无效。'}> |
| | | <QuestionCircleOutlined className="mk-form-tip" /> |
| | |
| | | * 1、 initdata 为打印时使用的数据集 |
| | | */ |
| | | UNSAFE_componentWillMount () { |
| | | const { data, initdata, BID, BData } = this.props |
| | | const { BID, BData } = this.props |
| | | let _config = fromJS(this.props.config).toJS() |
| | | let _cols = new Map() |
| | | let _data = null |
| | | let _sync = _config.setting.sync === 'true' |
| | | let setting = {..._config.setting, ..._config.wrap, style: {}} |
| | | setting.tableId = Utils.getuuid() |
| | | |
| | | if (_config.setting.sync === 'true' && data) { |
| | | _data = data[_config.dataName] || [] |
| | | _sync = false |
| | | } else if (_config.setting.sync === 'true' && initdata) { |
| | | _data = initdata || [] |
| | | _sync = false |
| | | } |
| | | |
| | | if (_data) { |
| | | _data = _data.map((item, index) => { |
| | | item.key = index |
| | | item.$$uuid = item[_config.setting.primaryKey] || '' |
| | | item.$$BID = BID || '' |
| | | item.$$BData = BData || '' |
| | | item.$Index = index + 1 + '' |
| | | return item |
| | | }) |
| | | if (setting.height) { |
| | | setting.operType = 'btnMode' |
| | | } |
| | | |
| | | _config.columns.forEach(item => { |
| | |
| | | }) |
| | | |
| | | let _columns = [] |
| | | // let signAdd = false |
| | | let signAdd = false |
| | | _config.cols.forEach(column => { |
| | | if (column.Hide === 'true') return |
| | | if (column.type === 'index') { |
| | |
| | | column.type = 'text' |
| | | } |
| | | |
| | | // if (setting.addable === 'true' && column.type !== 'action' && !signAdd) { |
| | | // column.addable = true |
| | | // signAdd = true |
| | | // } |
| | | if (setting.addable === 'true' && setting.operType === 'buoyMode' && column.type !== 'action' && !signAdd) { |
| | | column.addable = true |
| | | signAdd = true |
| | | } |
| | | |
| | | if (column.marks && column.marks.length === 0) { |
| | | column.marks = '' |
| | |
| | | _columns.push(column) |
| | | }) |
| | | |
| | | // if (setting.delable !== 'false') { |
| | | // if (_columns[_columns.length - 1] && _columns[_columns.length - 1].type !== 'action') { |
| | | // _columns[_columns.length - 1].delable = true |
| | | // } else if (_columns[_columns.length - 2] && _columns[_columns.length - 2].type !== 'action') { |
| | | // _columns[_columns.length - 2].delable = true |
| | | // } |
| | | // } |
| | | if (setting.delable !== 'false' && setting.operType === 'buoyMode') { |
| | | if (_columns[_columns.length - 1] && _columns[_columns.length - 1].type !== 'action') { |
| | | _columns[_columns.length - 1].delable = true |
| | | } else if (_columns[_columns.length - 2] && _columns[_columns.length - 2].type !== 'action') { |
| | | _columns[_columns.length - 2].delable = true |
| | | } |
| | | } |
| | | |
| | | if (setting.color) { |
| | | setting.style.color = setting.color |
| | |
| | | BID: BID || '', |
| | | BData: BData || '', |
| | | title: _config.wrap.title, |
| | | sync: _sync, |
| | | data: _data, |
| | | config: _config, |
| | | setting: setting, |
| | | searchlist: _config.search, |
| | |
| | | arr_field: _config.columns.map(col => col.field).join(','), |
| | | search: Utils.initMainSearch(_config.search) // 搜索条件初始化(含有时间格式,需要转化) |
| | | }, () => { |
| | | if (_config.setting.sync !== 'true' && _config.setting.onload === 'true') { |
| | | if (_config.setting.onload === 'true') { |
| | | setTimeout(() => { |
| | | this.loadmaindata() |
| | | this.getStatFieldsValue() |
| | | }, _config.setting.delay || 0) |
| | | } else if (_config.setting.onload === 'true') { |
| | | this.getStatFieldsValue() |
| | | } |
| | | }) |
| | | } |
| | |
| | | item.$$BID = BID || '' |
| | | item.$$BData = BData || '' |
| | | item.$Index = start + index + '' |
| | | item.$type = 'upt' |
| | | item.$origin = true |
| | | return item |
| | | }), |
| | | total: result.total, |
| | |
| | | } |
| | | |
| | | UNSAFE_componentWillReceiveProps(nextProps) { |
| | | const { sync, config, BID, BData } = this.state |
| | | const { config } = this.state |
| | | |
| | | if (sync && !is(fromJS(this.props.data), fromJS(nextProps.data))) { |
| | | let _data = [] |
| | | if (nextProps.data && nextProps.data[config.dataName]) { |
| | | _data = nextProps.data[config.dataName] || [] |
| | | _data = _data.map((item, index) => { |
| | | item.key = index |
| | | item.$$uuid = item[config.setting.primaryKey] || '' |
| | | item.$$BID = BID || '' |
| | | item.$$BData = BData || '' |
| | | item.$Index = index + 1 + '' |
| | | return item |
| | | }) |
| | | } |
| | | |
| | | this.setState({sync: false, data: _data}) |
| | | } else if (config.setting.syncRefresh && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { |
| | | if (config.setting.syncRefresh && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { |
| | | this.setState({pageIndex: 1}, () => { |
| | | this.reloadtable() |
| | | }) |
| | |
| | | } |
| | | |
| | | render() { |
| | | const { BID, setting, searchlist, actions, config, columns, BData } = this.state |
| | | const { BID, setting, searchlist, actions, config, columns, BData, data } = this.state |
| | | |
| | | return ( |
| | | <div className="custom-edit-table" style={config.style}> |
| | |
| | | <div className={'main-table-box ' + (!actions || actions.length === 0 ? 'no-action' : '')}> |
| | | <MainTable |
| | | BID={BID} |
| | | data={data} |
| | | setting={setting} |
| | | columns={columns} |
| | | MenuID={config.uuid} |
| | | data={this.state.data} |
| | | submit={config.submit} |
| | | fields={config.columns} |
| | | total={this.state.total} |
| | |
| | | import PropTypes from 'prop-types' |
| | | import { is, fromJS } from 'immutable' |
| | | import { Table, Typography, Switch, Modal, Input, InputNumber, Tooltip, Button, notification, message, Select } from 'antd' |
| | | import { ExclamationCircleOutlined, EditOutlined, PlusOutlined } from '@ant-design/icons' |
| | | import { ExclamationCircleOutlined, EditOutlined, PlusOutlined, PlusCircleOutlined, DeleteOutlined } from '@ant-design/icons' |
| | | import moment from 'moment' |
| | | |
| | | import Api from '@/api' |
| | |
| | | tdFocus = (id) => { |
| | | const { col, record } = this.props |
| | | |
| | | if (id !== col.uuid + record.$Index) return |
| | | if (id !== col.uuid + record.$$uuid) return |
| | | this.focus() |
| | | } |
| | | |
| | |
| | | this.setState({editing: false}) |
| | | setTimeout(() => { |
| | | if (col.enter === '$next') { |
| | | MKEmitter.emit('nextLine', col, record.$Index) |
| | | MKEmitter.emit('nextLine', col, record.$$uuid) |
| | | } else { |
| | | MKEmitter.emit('tdFocus', col.enter + record.$Index) |
| | | MKEmitter.emit('tdFocus', col.enter + record.$$uuid) |
| | | } |
| | | }, 50) |
| | | |
| | |
| | | |
| | | if (col.editType === 'switch' || col.editType === 'select') { |
| | | this.setState({editing: true}, () => { |
| | | let node = document.getElementById(col.uuid + record.$Index) |
| | | let node = document.getElementById(col.uuid + record.$$uuid) |
| | | node && node.click() |
| | | }) |
| | | } else { |
| | |
| | | } |
| | | |
| | | this.setState({editing: true, value: val, err}, () => { |
| | | let node = document.getElementById(col.uuid + record.$Index) |
| | | let node = document.getElementById(col.uuid + record.$$uuid) |
| | | node && node.select() |
| | | }) |
| | | } |
| | |
| | | |
| | | setTimeout(() => { |
| | | if (col.enter === '$next') { |
| | | MKEmitter.emit('nextLine', col, record.$Index) |
| | | MKEmitter.emit('nextLine', col, record.$$uuid) |
| | | } else { |
| | | MKEmitter.emit('tdFocus', col.enter + record.$Index) |
| | | MKEmitter.emit('tdFocus', col.enter + record.$$uuid) |
| | | } |
| | | }, 50) |
| | | |
| | |
| | | |
| | | setTimeout(() => { |
| | | if (col.enter === '$next') { |
| | | MKEmitter.emit('nextLine', col, record.$Index) |
| | | MKEmitter.emit('nextLine', col, record.$$uuid) |
| | | } else { |
| | | MKEmitter.emit('tdFocus', col.enter + record.$Index) |
| | | MKEmitter.emit('tdFocus', col.enter + record.$$uuid) |
| | | } |
| | | }, 50) |
| | | |
| | |
| | | if (editing) { |
| | | if (!col.editType || col.editType === 'text') { |
| | | return (<td className="editing_table_cell"> |
| | | <Input id={col.uuid + record.$Index} defaultValue={value} onChange={(e) => this.onChange(e.target.value)} onPressEnter={this.enterPress} onBlur={this.onBlur}/> |
| | | <Input id={col.uuid + record.$$uuid} defaultValue={value} onChange={(e) => this.onChange(e.target.value)} onPressEnter={this.enterPress} onBlur={this.onBlur}/> |
| | | {err ? <Tooltip title={err}><ExclamationCircleOutlined /></Tooltip> : null} |
| | | </td>) |
| | | } else if (col.editType === 'switch') { |
| | |
| | | <Select |
| | | showSearch |
| | | defaultValue={_value} |
| | | id={col.uuid + record.$Index} |
| | | id={col.uuid + record.$$uuid} |
| | | onBlur={() => this.setState({editing: false})} |
| | | filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0} |
| | | onSelect={this.onSelectChange} |
| | |
| | | if (col.editable === 'true') { |
| | | if (editing) { |
| | | return (<td className="editing_table_cell"> |
| | | <InputNumber id={col.uuid + record.$Index} defaultValue={value} onChange={(val) => this.onChange(val)} onPressEnter={this.enterPress} onBlur={this.onBlur}/> |
| | | <InputNumber id={col.uuid + record.$$uuid} defaultValue={value} onChange={(val) => this.onChange(val)} onPressEnter={this.enterPress} onBlur={this.onBlur}/> |
| | | {err ? <Tooltip title={err}><ExclamationCircleOutlined /></Tooltip> : null} |
| | | </td>) |
| | | } else { |
| | |
| | | ) |
| | | } |
| | | |
| | | // return (<td className={className} style={style}>{col.addable ? <PlusCircleOutlined className="mk-editable mk-plus"/> : null}{children}{col.delable ? <DeleteOutlined className="mk-editable mk-del"/> : null}</td>) |
| | | return (<td className={className} style={style}>{children}</td>) |
| | | return (<td className={className} style={style}>{col.addable ? <PlusCircleOutlined onClick={() => MKEmitter.emit('addRecord', col.tableId, {...record})} className="mk-editable mk-plus"/> : null}{children}{col.delable ? <DeleteOutlined onClick={() => MKEmitter.emit('delRecord', col.tableId, {...record})} className="mk-editable mk-del"/> : null}</td>) |
| | | // return (<td className={className} style={style}>{children}</td>) |
| | | } |
| | | } |
| | | |
| | |
| | | _columns.push(_item) |
| | | }) |
| | | |
| | | // if (setting.delable !== 'false') { |
| | | // edColumns.push({ |
| | | // align: 'center', |
| | | // dataIndex: 'mkoperation', |
| | | // title: '操作', |
| | | // sorter: false, |
| | | // width: 100, |
| | | // onCell: record => ({ |
| | | // record, |
| | | // col: {type: 'operation', tableId: setting.tableId}, |
| | | // }) |
| | | // }) |
| | | // } |
| | | if (setting.delable !== 'false' && setting.operType !== 'buoyMode') { |
| | | edColumns.push({ |
| | | align: 'center', |
| | | dataIndex: 'mkoperation', |
| | | title: '操作', |
| | | sorter: false, |
| | | width: 100, |
| | | onCell: record => ({ |
| | | record, |
| | | col: {type: 'operation', tableId: setting.tableId}, |
| | | }) |
| | | }) |
| | | } |
| | | |
| | | if (setting.borderColor) { // 边框颜色 |
| | | let style = `#${setting.tableId} table, #${setting.tableId} tr, #${setting.tableId} th, #${setting.tableId} td {border-color: ${setting.borderColor}}` |
| | |
| | | } |
| | | |
| | | MKEmitter.addListener('nextLine', this.nextLine) |
| | | MKEmitter.addListener('addRecord', this.addLine) |
| | | MKEmitter.addListener('delRecord', this.delRecord) |
| | | MKEmitter.addListener('resetTable', this.resetTable) |
| | | MKEmitter.addListener('changeRecord', this.changeRecord) |
| | |
| | | return |
| | | } |
| | | MKEmitter.removeListener('nextLine', this.nextLine) |
| | | MKEmitter.removeListener('addRecord', this.addLine) |
| | | MKEmitter.removeListener('delRecord', this.delRecord) |
| | | MKEmitter.removeListener('resetTable', this.resetTable) |
| | | MKEmitter.removeListener('changeRecord', this.changeRecord) |
| | |
| | | UNSAFE_componentWillReceiveProps(nextProps) { |
| | | if (!is(fromJS(this.props.data), fromJS(nextProps.data))) { |
| | | this.setState({data: nextProps.data || []}) |
| | | if (this.state.editable === 'true') { |
| | | if (this.state.editable === 'true' && !this.state.pickup) { |
| | | setTimeout(() => { |
| | | this.pickupChange() |
| | | }, 200) |
| | |
| | | MKEmitter.emit('tdFocus', initEditLine.uuid + (index + 1)) |
| | | } else if (col.footEnter === 'add' && setting.addable === 'true') { |
| | | setTimeout(() => { |
| | | this.plusLine(initEditLine) |
| | | this.plusLine() |
| | | }, 10) |
| | | } else if (col.footEnter === 'sub') { |
| | | setTimeout(() => { |
| | |
| | | } |
| | | } |
| | | |
| | | plusLine = (initEditLine) => { |
| | | const { edData, fields } = this.state |
| | | plusLine = () => { |
| | | const { edData, fields, initEditLine } = this.state |
| | | |
| | | let item = {...edData[edData.length - 1]} |
| | | |
| | | item.key = item.key + 1 |
| | | item.$$uuid = '$new' |
| | | item.$Index = item.key + 1 + '' |
| | | item.$$uuid = Utils.getguid() |
| | | item.$type = 'add' |
| | | item.$Index = '' |
| | | |
| | | fields.forEach(col => { |
| | | if (col.initval !== '$copy') { |
| | |
| | | }) |
| | | |
| | | this.setState({edData: [...edData, item]}, () => { |
| | | MKEmitter.emit('tdFocus', initEditLine.uuid + item.$Index) |
| | | MKEmitter.emit('tdFocus', initEditLine.uuid + item.$$uuid) |
| | | }) |
| | | } |
| | | |
| | |
| | | |
| | | let _data = [] |
| | | |
| | | if (record.$$uuid === '$new') { |
| | | _data = edData.filter(item => item.$Index !== record.$Index) |
| | | _data = _data.map((item, index) => { |
| | | item.key = index |
| | | item.$Index = 1 + index + '' |
| | | return item |
| | | }) |
| | | if (record.$type === 'add') { |
| | | _data = edData.filter(item => item.$$uuid !== record.$$uuid) |
| | | } else { |
| | | _data = edData.map(item => { |
| | | if (item.$Index === record.$Index) { |
| | | if (item.$$uuid === record.$$uuid) { |
| | | record.$deleted = true |
| | | record.$origin = false |
| | | record.$type = 'del' |
| | | return record |
| | | } else { |
| | | return item |
| | |
| | | if (id !== tableId) return |
| | | |
| | | let _data = this.state.edData.map(item => { |
| | | if (item.$Index === record.$Index) { |
| | | if (item.$$uuid === record.$$uuid) { |
| | | record.$origin = false |
| | | return record |
| | | } else { |
| | | return item |
| | |
| | | this.setState({edData: _data}) |
| | | } |
| | | |
| | | addLine = () => { |
| | | addLine = (id, record) => { |
| | | const { BID } = this.props |
| | | const { edData, fields } = this.state |
| | | const { edData, fields, tableId } = this.state |
| | | |
| | | let item = {} |
| | | if (edData.length > 0) { |
| | | item = {...edData[edData.length - 1]} |
| | | item.key = item.key + 1 |
| | | item.$$uuid = '$new' |
| | | item.$Index = item.key + 1 + '' |
| | | } else { |
| | | item.key = 0 |
| | | item.$$uuid = '$new' |
| | | item.$Index = item.key + 1 + '' |
| | | if (id) { |
| | | if (id !== tableId) return |
| | | let _edData = fromJS(edData).toJS() |
| | | let index = _edData.findIndex(item => record.$$uuid === item.$$uuid) |
| | | |
| | | let item = {} |
| | | |
| | | item.$$uuid = Utils.getguid() |
| | | item.$type = 'add' |
| | | item.$Index = '' |
| | | item.$$BID = BID || '' |
| | | } |
| | | |
| | | fields.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 |
| | | |
| | | fields.forEach(col => { |
| | | if (col.initval !== '$copy') { |
| | | item[col.field] = col.initval |
| | | } |
| | | } |
| | | if (col.type === 'number') { |
| | | item[col.field] = +item[col.field] |
| | | if (isNaN(item[col.field])) { |
| | | item[col.field] = 0 |
| | | } |
| | | } |
| | | |
| | | if (item[col.field] === undefined) { |
| | | item[col.field] = '' |
| | | } |
| | | }) |
| | | |
| | | if (item[col.field] === undefined) { |
| | | item[col.field] = '' |
| | | } |
| | | }) |
| | | _edData.splice(index, 0, item) |
| | | |
| | | this.setState({edData: [...edData, item]}) |
| | | this.setState({edData: _edData}) |
| | | } else { |
| | | let item = {} |
| | | if (edData.length > 0) { |
| | | item = {...edData[edData.length - 1]} |
| | | item.$$uuid = Utils.getguid() |
| | | item.$type = 'add' |
| | | item.$Index = '' |
| | | } else { |
| | | item.$$uuid = Utils.getguid() |
| | | item.$type = 'add' |
| | | item.$Index = '' |
| | | item.$$BID = BID || '' |
| | | } |
| | | |
| | | fields.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]}) |
| | | } |
| | | } |
| | | |
| | | checkData = () => { |
| | |
| | | return |
| | | } |
| | | let err = '' |
| | | let Index = 1 |
| | | let data = fromJS(edData).toJS().map(item => { |
| | | let line = [] |
| | | fields.forEach(col => { |
| | |
| | | }) |
| | | |
| | | if (line.length > 0) { |
| | | err += `第${item.$Index}行:` + line.join(',') + ';' |
| | | err += `第${Index}行:` + line.join(',') + ';' |
| | | } |
| | | if (!item.$deleted) { |
| | | Index++ |
| | | } |
| | | |
| | | return item |
| | |
| | | } |
| | | |
| | | submit = (data) => { |
| | | const { submit, BID } = this.props |
| | | const { submit, BID, setting } = this.props |
| | | const { fields } = this.state |
| | | |
| | | if (setting.commit === 'change') { |
| | | data = data.filter(item => !item.$origin) |
| | | } |
| | | |
| | | if (data.length === 0) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '数据未修改,不可提交!', |
| | | duration: 5 |
| | | }) |
| | | return |
| | | } |
| | | |
| | | let result = getEditTableSql(submit, data, fields) |
| | | |
| | |
| | | let height = setting.height || false |
| | | |
| | | return ( |
| | | <div className={`edit-custom-table ${pickup ? 'editable' : ''} ${setting.tableHeader || ''} ${height ? 'fixed-height' : ''} ${setting.mode || ''}`} id={tableId}> |
| | | <Switch title="编辑" className="main-pickup" checkedChildren="开" unCheckedChildren="关" checked={pickup} onChange={this.pickupChange} /> |
| | | <div className={`edit-custom-table ${pickup ? 'editable' : ''} ${setting.tableHeader || ''} ${setting.operType || ''} ${height ? 'fixed-height' : ''} ${setting.mode || ''}`} id={tableId}> |
| | | <Switch title="编辑" className="main-pickup" checkedChildren="开" unCheckedChildren="关" disabled={loading || this.props.loading} checked={pickup} onChange={this.pickupChange} /> |
| | | {pickup ? <Button style={submit.style} onClick={() => setTimeout(() => {this.checkData()}, 10)} loading={loading} className="submit-table" type="link">提交</Button> : null} |
| | | <Table |
| | | rowKey="$$uuid" |
| | | components={components} |
| | | style={setting.style} |
| | | size={setting.size || 'middle'} |
| | |
| | | pagination={_pagination} |
| | | /> |
| | | {_footer ? <div className={'normal-table-footer ' + (_pagination ? 'pagination' : '')}>{_footer}</div> : null} |
| | | {pickup && setting.addable === 'true' ? <Button onClick={this.addLine} style={{display: 'block', width: '100%', color: '#26C281', border: '1px solid #dddddd', borderRadius: 0}} type="link"><PlusOutlined /></Button> : null} |
| | | {pickup && setting.addable === 'true' ? <Button className="mk-add-line" onClick={() => this.addLine()} disabled={this.props.loading} type="link"><PlusOutlined /></Button> : null} |
| | | </div> |
| | | ) |
| | | } |
| | |
| | | } |
| | | } |
| | | .mk-editable { |
| | | position: absolute; |
| | | display: inline-block; |
| | | top: calc(50% - 13px); |
| | | cursor: pointer; |
| | | padding: 10px 5px; |
| | | opacity: 0; |
| | | // transition: opacity 0.3s 0.1s, left 0.1s; |
| | | } |
| | | tr:hover { |
| | | .mk-editable { |
| | | opacity: 1; |
| | | } |
| | | .mk-plus { |
| | | left: -25px; |
| | | } |
| | | .mk-del { |
| | | right: -25px; |
| | | } |
| | | } |
| | | .mk-plus { |
| | | position: absolute; |
| | | top: 45%; |
| | | left: -20px; |
| | | color: #1890ff; |
| | | left: 0px; |
| | | // left: -25px; |
| | | color: rgb(38, 194, 129); |
| | | padding-right: 10px; |
| | | } |
| | | .mk-del { |
| | | right: 0px; |
| | | // right: -25px; |
| | | color: rgb(255, 77, 79); |
| | | padding-left: 10px; |
| | | } |
| | | .mk-add-line { |
| | | display: block; |
| | | width: 100%; |
| | | color: #26C281; |
| | | border: 1px solid #dddddd; |
| | | border-radius: 0; |
| | | font-size: 25px; |
| | | height: 40px; |
| | | } |
| | | .mk-add-line:disabled { |
| | | border-color: #fafafa!important; |
| | | } |
| | | } |
| | | .edit-custom-table.buoyMode { |
| | | .ant-table-scroll { |
| | | overflow: unset; |
| | | overflow-x: unset; |
| | | |
| | | .ant-table-body { |
| | | overflow-x: unset!important; |
| | | } |
| | | } |
| | | } |
| | | .edit-custom-table.editable { |
| | |
| | | |
| | | database = database ? (database[0] || '') : '' |
| | | |
| | | let getuuid = () => { |
| | | let uuid = [] |
| | | let timestamp = new Date().getTime() |
| | | let _options = '0123456789abcdefghigklmnopqrstuv' |
| | | for (let i = 0; i < 19; i++) { |
| | | uuid.push(_options.substr(Math.floor(Math.random() * 0x20), 1)) |
| | | } |
| | | uuid = timestamp + uuid.join('') |
| | | return uuid |
| | | } |
| | | |
| | | // let upId = getuuid() |
| | | |
| | | let _initCustomScript = '' // 初始化脚本 |
| | | let _prevCustomScript = '' // 默认sql前执行脚本 |
| | | let _backCustomScript = '' // 默认sql后执行脚本 |
| | |
| | | }) |
| | | |
| | | let key = item.$$uuid |
| | | let type = 'upt' |
| | | if (key === '$new') { |
| | | key = getuuid() |
| | | type = 'add' |
| | | } else if (item.$deleted) { |
| | | type = 'del' |
| | | } |
| | | let type = item.$type || 'upt' |
| | | |
| | | vals.push(`'${key}'`) |
| | | vals.push(`'${type}'`) |