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 | 368 +++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 316 insertions(+), 52 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 2260a2d..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}</> + } } } @@ -433,21 +564,31 @@ ) } 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.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) { console.info(content) console.warn(e) + content = '' } - content = '' } } @@ -462,7 +603,9 @@ 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, ' ') content = <span dangerouslySetInnerHTML={{__html: content}}></span> @@ -481,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}</> + } } } @@ -657,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 @@ -680,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 = (<> @@ -733,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}</> + } } } @@ -800,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}</> + } } } @@ -826,21 +1022,31 @@ ) } 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.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) { console.info(content) console.warn(e) + content = '' } - content = '' } } @@ -855,7 +1061,9 @@ 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, ' ') content = <span dangerouslySetInnerHTML={{__html: content}}></span> @@ -874,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}</> + } } } @@ -915,6 +1131,7 @@ pageSize: 10, // 姣忛〉鏁版嵁鏉℃暟 columns: null, // 鏄剧ず鍒� forms: [], + signForms: [], orderfields: {}, // 鎺掑簭id涓巉ield杞崲 loading: false, pageOptions: [], @@ -931,6 +1148,7 @@ let deForms = [] let _forms = {} let hasBid = false + let signForms = [] let getColumns = (cols) => { return cols.map(item => { @@ -942,6 +1160,8 @@ } else { if (item.editable === 'true') { _forms[item.field] = item + + signForms.push(item.field) if (item.ctrlField) { item.ctrlValue = item.ctrlValue.split(',') @@ -964,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' } } } @@ -998,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) } @@ -1014,6 +1250,7 @@ this.setState({ forms, + signForms, pageSize: setting.pageSize || 10, pageOptions, columns: _columns, @@ -1076,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) @@ -1127,7 +1382,7 @@ 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 @@ -1429,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 @@ -1449,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) } }) @@ -1557,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') { @@ -1642,22 +1911,12 @@ if (submit.intertype === 'system') { // 绯荤粺瀛樺偍杩囩▼ param.func = 'sPC_TableData_InUpDe' - if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺 - result.sql = result.sql.replace(/\$@/ig, '/*') - result.sql = result.sql.replace(/@\$/ig, '*/') - result.bottom = result.bottom.replace(/\$@/ig, '/*') - result.bottom = result.bottom.replace(/@\$/ig, '*/') - } else { - result.sql = result.sql.replace(/@\$|\$@/ig, '') - result.bottom = result.bottom.replace(/@\$|\$@/ig, '') - } - - param.excel_in_type = 'true' - param.LText1 = Utils.formatOptions(result.insert) - param.LText2 = Utils.formatOptions(result.bottom) + delete param.excel_in + + param.exec_type = 'y' param.LText = Utils.formatOptions(result.sql) param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') - param.secretkey = Utils.encrypt(param.LText, param.timestamp) + param.secretkey = Utils.encrypt('', param.timestamp) param.menuname = submit.logLabel @@ -1678,6 +1937,11 @@ }) } else if (submit.intertype === 'inner' && submit.innerFunc) { // 鑷畾涔夊瓨鍌ㄨ繃绋� param.func = submit.innerFunc + + if (submit.recordUser === 'true') { + param.username = sessionStorage.getItem('User_Name') || '' + param.fullname = sessionStorage.getItem('Full_Name') || '' + } Api.genericInterface(param).then((res) => { if (res.status) { @@ -1700,12 +1964,12 @@ if (res && res.ErrCode === 'S') { // 鎵ц鎴愬姛 notification.success({ top: 92, - message: res.ErrMesg || '鎵ц鎴愬姛', + message: res.message || '鎵ц鎴愬姛', duration: submit.stime ? submit.stime : 2 }) } else if (res && res.ErrCode === 'Y') { // 鎵ц鎴愬姛 Modal.success({ - title: res.ErrMesg || '鎵ц鎴愬姛' + title: res.message || '鎵ц鎴愬姛' }) } else if (res && res.ErrCode === '-1') { // 瀹屾垚鍚庝笉鎻愮ず @@ -1741,23 +2005,23 @@ if (res.ErrCode === 'E') { Modal.error({ - title: res.message || res.ErrMesg, + title: res.message || '鎵ц澶辫触锛�', }) } else if (res.ErrCode === 'N') { notification.error({ top: 92, - message: res.message || res.ErrMesg, + message: res.message || '鎵ц澶辫触锛�', 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 || '鎵ц澶辫触锛�', duration: submit.ftime ? submit.ftime : 10 }) } else if (res.ErrCode === 'NM') { - message.error(res.message || res.ErrMesg) + message.error(res.message || '鎵ц澶辫触锛�') } this.setState({ -- Gitblit v1.8.0