From 5e1ff4dc1c6d384af39cac1d3fbe6bf4b58566f2 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期四, 19 十月 2023 17:59:22 +0800 Subject: [PATCH] 2023-10-19 --- src/tabviews/custom/components/table/edit-table/normalTable/index.jsx | 291 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 264 insertions(+), 27 deletions(-) diff --git a/src/tabviews/custom/components/table/edit-table/normalTable/index.jsx b/src/tabviews/custom/components/table/edit-table/normalTable/index.jsx index 71db29c..95e8350 100644 --- a/src/tabviews/custom/components/table/edit-table/normalTable/index.jsx +++ b/src/tabviews/custom/components/table/edit-table/normalTable/index.jsx @@ -1,21 +1,105 @@ 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 CardCellComponent = asyncComponent(() => import('@/tabviews/custom/components/card/cardcellList')) + +class CusSwitch extends Component { + static propTpyes = { + defaultValue: PropTypes.any, + autoFocus: PropTypes.any, + config: PropTypes.object, + onChange: PropTypes.func + } + + state = { + status: false + } + + UNSAFE_componentWillMount () { + const { defaultValue, config } = this.props + + let status = false + + if (defaultValue === config.openVal) { + status = true + } + + this.setState({status}) + } + + changeStatus = (val) => { + const { config } = this.props + this.setState({ status: val }, () => { + let _val = val ? config.openVal : config.closeVal + let _text = val ? config.openText : config.closeText + this.props.onChange(_val, _text) + }) + } + + render() { + const { config, autoFocus } = this.props + const { status } = this.state + return ( + <Switch checkedChildren={config.openText} autoFocus={autoFocus} onBlur={this.props.onBlur} unCheckedChildren={config.closeText} checked={status} onChange={this.changeStatus} /> + ) + } +} + +class CusDatePicker extends Component { + static propTpyes = { + defaultValue: PropTypes.any, + config: PropTypes.object, + onChange: PropTypes.func, + blur: PropTypes.func + } + + state = { + value: null, + open: false + } + + UNSAFE_componentWillMount () { + const { value, open } = this.props + + let _value = value || null + if (_value) { + _value = moment(_value, 'YYYY-MM-DD HH:mm:ss') + } + + this.setState({value: _value, open: open === true}) + } + + onOpenChange = (open) => { + this.setState({open}) + + if (open === false) { + this.props.blur() + } + } + + 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.props.onChange} onOpenChange={this.onOpenChange}/> + ) + } +} class BodyRow extends React.Component { shouldComponentUpdate (nextProps, nextState) { @@ -253,6 +337,33 @@ MKEmitter.emit('changeRecord', col.tableId, {...record, ...values}) } + onDateChange = (val) => { + const { col, record } = this.props + + let _val = val ? moment(val).format(col.format) : '' + + if (col.precision === 'hour') { + _val = _val + ':00:00' + } else if (col.precision === 'minute') { + _val = _val + ':00' + } + + 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}) + } + switchBlur = () => { setTimeout(() => { this.setState({editing: false}) @@ -308,6 +419,14 @@ } } 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}</> + } } } @@ -316,6 +435,10 @@ if (!col.editType || col.editType === 'text') { return (<td className="editing_table_cell"> <Input className={err ? 'has-error' : ''} title={err} id={col.uuid + record.$$uuid} defaultValue={value} onChange={(e) => this.onChange(e.target.value)} onPressEnter={this.enterPress} onBlur={this.onBlur}/> + </td>) + } else if (col.editType === 'date') { + return (<td className="editing_table_cell"> + <CusDatePicker config={col} value={record[col.field] || null} open={true} onChange={this.onDateChange} blur={() => this.setState({editing: false})}/> </td>) } else if (col.editType === 'switch') { let _value = record[col.field] !== undefined ? record[col.field] : '' @@ -396,6 +519,14 @@ } } 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}</> + } } } @@ -440,9 +571,7 @@ let func = new Function('data', col.formula) content = func([record]) } catch (e) { - if (window.GLOB.debugger === true) { - console.warn(e) - } + console.warn(e) content = '' } } else { @@ -456,10 +585,8 @@ // eslint-disable-next-line content = eval(content) } catch (e) { - if (window.GLOB.debugger === true) { - console.info(content) - console.warn(e) - } + console.info(content) + console.warn(e) content = '' } } @@ -497,6 +624,14 @@ } } 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}</> + } } } @@ -673,6 +808,31 @@ MKEmitter.emit('changeRecord', col.tableId, {...record, ...values}) } + onDateChange = (val) => { + const { col, record } = this.props + + let _val = val ? moment(val).format(col.format) : '' + + if (col.precision === 'hour') { + _val = _val + ':00:00' + } else if (col.precision === 'minute') { + _val = _val + ':00' + } + + 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}) + } + render() { let { col, config, record, style, className, ...resProps } = this.props const { err } = this.state @@ -696,6 +856,10 @@ } else if (col.editType === 'switch') { children = ( <CusSwitch config={col} autoFocus={false} defaultValue={_value} onChange={this.onSwitchChange} onBlur={() => {}}/> + ) + } else if (col.editType === 'date') { + children = ( + <CusDatePicker config={col} value={record[col.field] || null} onChange={this.onDateChange} blur={() => {}}/> ) } else { children = (<> @@ -749,6 +913,14 @@ } } 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}</> + } } } @@ -816,6 +988,14 @@ } } 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}</> + } } } @@ -849,9 +1029,7 @@ let func = new Function('data', col.formula) content = func([record]) } catch (e) { - if (window.GLOB.debugger === true) { - console.warn(e) - } + console.warn(e) content = '' } } else { @@ -865,10 +1043,8 @@ // eslint-disable-next-line content = eval(content) } catch (e) { - if (window.GLOB.debugger === true) { - console.info(content) - console.warn(e) - } + console.info(content) + console.warn(e) content = '' } } @@ -906,6 +1082,14 @@ } } 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}</> + } } } @@ -947,6 +1131,7 @@ pageSize: 10, // 姣忛〉鏁版嵁鏉℃暟 columns: null, // 鏄剧ず鍒� forms: [], + signForms: [], orderfields: {}, // 鎺掑簭id涓巉ield杞崲 loading: false, pageOptions: [], @@ -963,6 +1148,7 @@ let deForms = [] let _forms = {} let hasBid = false + let signForms = [] let getColumns = (cols) => { return cols.map(item => { @@ -974,6 +1160,8 @@ } else { if (item.editable === 'true') { _forms[item.field] = item + + signForms.push(item.field) if (item.ctrlField) { item.ctrlValue = item.ctrlValue.split(',') @@ -996,6 +1184,16 @@ item.options.forEach(cell => { item.map.set(cell.value, cell.label) }) + } + } else if (item.type === 'text' && item.editType === 'date') { + item.format = 'YYYY-MM-DD' + + if (item.precision === 'hour') { + item.format = 'YYYY-MM-DD HH' + } else if (item.precision === 'minute') { + item.format = 'YYYY-MM-DD HH:mm' + } else if (item.precision === 'second') { + item.format = 'YYYY-MM-DD HH:mm:ss' } } } @@ -1030,7 +1228,13 @@ 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 + } + forms.push(_item) } else { forms.push(item) } @@ -1046,6 +1250,7 @@ this.setState({ forms, + signForms, pageSize: setting.pageSize || 10, pageOptions, columns: _columns, @@ -1108,10 +1313,28 @@ } transferData = (menuid, data, type) => { - const { MenuID } = this.props - const { edData } = this.state + const { MenuID, setting } = this.props + const { edData, signForms } = this.state if (menuid !== MenuID) return + + if (setting.commit !== 'all' && setting.standard !== 'change') { + if (type !== 'line') { + data.forEach(item => { + let value = '' + signForms.forEach(field => { + value += item[field] + }) + item.$sign = md5(value) + }) + } else { + let value = '' + signForms.forEach(field => { + value += data[field] + }) + data.$sign = md5(value) + } + } if (type !== 'line') { let index = edData.findIndex(item => !item.$origin && !item.$forbid) @@ -1461,19 +1684,31 @@ changeRecord = (id, record) => { const { setting } = this.props - const { tableId } = this.state + const { tableId, signForms } = this.state if (id !== tableId) return - let lock = record.$lock + if (!record.$sign) { + record.$origin = false + record.$lock = true + delete record.$forbid + } else { + let value = '' + signForms.forEach(field => { + value += record[field] + }) + + if (record.$sign !== md5(value)) { + record.$origin = false + record.$lock = true + } else { + record.$origin = true + record.$lock = false + } + } 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 @@ -1481,7 +1716,7 @@ }) this.setState({edData: _data}, () => { - if (setting.tableType && setting.hasAction && !lock && this.state.selectedRowKeys.includes(record.$$uuid)) { + if (setting.tableType && setting.hasAction && this.state.selectedRowKeys.includes(record.$$uuid)) { this.selectdata(this.state.selectedRowKeys) } }) @@ -1589,6 +1824,8 @@ let val = item[col.field] !== undefined ? (item[col.field] + '') : '' if (col.required === 'true' && !val) { line.push(`${col.label}涓嶅彲涓虹┖`) + } else if (col.datatype === 'datetime' && !val) { + val = '1949-10-01' } item[col.field] = val } else if (col.type === 'number') { -- Gitblit v1.8.0