From c9967063fa42e15d9f695220c76641cfa28669f2 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期二, 05 九月 2023 14:23:13 +0800 Subject: [PATCH] 2023-09-05 --- src/tabviews/custom/components/table/edit-table/normalTable/index.jsx | 233 ++++++++++++++++++++++++++++++++++++--------------------- 1 files changed, 146 insertions(+), 87 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 47fb9f2..71db29c 100644 --- a/src/tabviews/custom/components/table/edit-table/normalTable/index.jsx +++ b/src/tabviews/custom/components/table/edit-table/normalTable/index.jsx @@ -2,7 +2,7 @@ import PropTypes from 'prop-types' import { is, fromJS } from 'immutable' import { Table, Typography, Modal, Input, InputNumber, Button, notification, message, Select } from 'antd' -import { EditOutlined } from '@ant-design/icons' +import { EditOutlined, QuestionCircleOutlined } from '@ant-design/icons' import moment from 'moment' import Api from '@/api' @@ -119,7 +119,7 @@ this.setState({editing: false}) setTimeout(() => { - if (col.enter === '$next') { + if (/\$next/.test(col.enter)) { MKEmitter.emit('nextLine', col, record.$$uuid) } else if (col.enter === '$sub') { MKEmitter.emit('subLine', col, record) @@ -208,7 +208,7 @@ this.setState({editing: false}) setTimeout(() => { - if (col.enter === '$next') { + if (/\$next/.test(col.enter)) { MKEmitter.emit('nextLine', col, record.$$uuid) } else if (col.enter === '$sub') { MKEmitter.emit('subLine', col, record) @@ -240,7 +240,7 @@ this.setState({editing: false}) setTimeout(() => { - if (col.enter === '$next') { + if (/\$next/.test(col.enter)) { MKEmitter.emit('nextLine', col, record.$$uuid) } else if (col.enter === '$sub') { MKEmitter.emit('subLine', col, record) @@ -433,21 +433,35 @@ ) } 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) + if (window.GLOB.debugger === true) { 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) { + if (window.GLOB.debugger === true) { + console.info(content) + console.warn(e) + } + content = '' + } } } @@ -462,7 +476,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> @@ -542,7 +558,7 @@ this.onBlur() setTimeout(() => { - if (col.enter === '$next') { + if (/\$next/.test(col.enter)) { MKEmitter.emit('nextLine', col, record.$$uuid) } else if (col.enter === '$sub') { MKEmitter.emit('subLine', col, record) @@ -602,7 +618,7 @@ const { col, record } = this.props setTimeout(() => { - if (col.enter === '$next') { + if (/\$next/.test(col.enter)) { MKEmitter.emit('nextLine', col, record.$$uuid) } else if (col.enter === '$sub') { MKEmitter.emit('subLine', col, record) @@ -638,7 +654,7 @@ } setTimeout(() => { - if (col.enter === '$next') { + if (/\$next/.test(col.enter)) { MKEmitter.emit('nextLine', col, record.$$uuid) } else if (col.enter === '$sub') { MKEmitter.emit('subLine', col, record) @@ -826,21 +842,35 @@ ) } 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) + if (window.GLOB.debugger === true) { 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) { + if (window.GLOB.debugger === true) { + console.info(content) + console.warn(e) + } + content = '' + } } } @@ -855,7 +885,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> @@ -918,7 +950,9 @@ orderfields: {}, // 鎺掑簭id涓巉ield杞崲 loading: false, pageOptions: [], - deForms: null + deForms: null, + visible: false, + midData: null } UNSAFE_componentWillMount () { @@ -1074,23 +1108,18 @@ } transferData = (menuid, data, type) => { - const { MenuID, setting } = this.props + const { MenuID } = this.props + const { edData } = this.state if (menuid !== MenuID) return if (type !== 'line') { - if (setting.editType === 'multi' && data.length > 0) { - this.setState({edData: []}, () => { - this.setState({edData: data}) - }) - } else { - this.setState({edData: data}) - } + let index = edData.findIndex(item => !item.$origin && !item.$forbid) - if (setting.addable && data.length === 0) { - setTimeout(() => { - this.plusLine(true) - }, 10) + if (index > -1) { + this.setState({visible: true, midData: data}) + } else { + this.updateMutil(data) } } else if (type === 'line') { let _edData = this.state.edData.map(item => { @@ -1105,6 +1134,24 @@ } } + updateMutil = (data) => { + const { setting } = this.props + + if (setting.editType === 'multi' && data.length > 0) { + this.setState({edData: []}, () => { + this.setState({edData: data, visible: false, midData: null}) + }) + } else { + this.setState({edData: data, visible: false, midData: null}) + } + + if (setting.addable && data.length === 0) { + setTimeout(() => { + this.plusLine(true) + }, 10) + } + } + improveActionForm = (deForms, BID) => { const { setting } = this.props @@ -1112,7 +1159,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 @@ -1297,7 +1344,12 @@ let next = edData[index + 1] || null if (next) { - let node = document.getElementById(setting.initId + next.$$uuid) + 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') { @@ -1592,6 +1644,8 @@ const { submit, BID, setting } = this.props const { forms } = this.state + this.setState({visible: false, midData: null}) + if (setting.supModule && !BID) { notification.warning({ top: 92, @@ -1620,22 +1674,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 @@ -1649,11 +1693,18 @@ } else { this.execError(res) } - }, () => { + }, (error) => { + if (error && error.ErrCode === 'LoginError') return + this.execError({}) }) } 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) { @@ -1661,50 +1712,44 @@ } else { this.execError(res) } - }, () => { + }, (error) => { + if (error && error.ErrCode === 'LoginError') return + this.execError({}) }) } } - updataLine = (item) => { - if (item.$type === 'del') { - let _data = this.state.edData.filter(m => m.$$uuid !== item.$$uuid) - - this.setState({edData: _data}) - } else { - let _data = this.state.edData.map(m => { - if (m.$$uuid === item.$$uuid) { - item.$origin = true - return item - } - return m - }) - - this.setState({edData: _data}) - } - MKEmitter.emit('reloadData', this.props.MenuID, item.$$uuid) - } - execSuccess = (res) => { const { submit } = this.props + const { edData } = this.state 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') { // 瀹屾垚鍚庝笉鎻愮ず } + let _edData = fromJS(edData).toJS() + + _edData = _edData.map(item => { + if (!item.$forbid) { + item.$origin = true + } + return item + }) + this.setState({ - loading: false + loading: false, + edData: _edData }) if (submit.closetab === 'true') { @@ -1723,23 +1768,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({ @@ -1853,7 +1898,7 @@ render() { const { setting, lineMarks, submit } = this.props - const { tableId, edData, columns, loading, pageOptions, selectedRowKeys } = this.state + const { tableId, edData, columns, loading, pageOptions, selectedRowKeys, visible, midData } = this.state const components = { body: { @@ -1862,7 +1907,6 @@ } } - // 鏁版嵁鏀惰捣鏃讹紝杩囨护宸查�夋暟鎹� let _data = edData.filter(item => !item.$deleted) // 璁剧疆琛ㄦ牸閫夋嫨灞炴�э細鍗曢�夈�佸閫夈�佷笉鍙�� @@ -1894,9 +1938,9 @@ return ( <> - <div className="edit-custom-table-btn-wrap" style={submit.wrapStyle}> + {setting.hasSubmit ? <div className="edit-custom-table-btn-wrap" style={submit.wrapStyle}> <Button style={submit.style} onClick={() => setTimeout(() => {this.submit()}, 10)} loading={loading} className="submit-table" type="link">鎻愪氦</Button> - </div> + </div> : null} <div className={`edit-custom-table ${setting.tableHeader || ''} ${height ? 'fixed-height' : ''} ${setting.mode || ''} table-vertical-${setting.vertical || ''} mk-edit-${setting.editType || 'simple'}`} id={tableId}> <Table rowKey="$$uuid" @@ -1919,8 +1963,23 @@ onChange={this.changeTable} pagination={_pagination} /> - {_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">鎻愪氦</Button> : null} </div> + <Modal + className="mk-user-confirm" + visible={visible} + width={450} + maskClosable={false} + closable={false} + footer={[ + <Button key="cancel" onClick={() => { this.setState({ visible: false, midData: null }) }}>鍙栨秷</Button>, + <Button key="refresh" className="table-refresh" onClick={() => { midData && this.updateMutil(midData) }}>鍒锋柊琛ㄦ牸</Button>, + <Button key="confirm" type="primary" onClick={() => setTimeout(() => {this.submit()}, 10)}>鎻愪氦鏁版嵁</Button> + ]} + destroyOnClose + > + <div><QuestionCircleOutlined />琛ㄦ牸涓湁鏁版嵁灏氭湭鎻愪氦</div> + </Modal> </> ) } -- Gitblit v1.8.0