From dddb2c96f42d9c852dba26ff9a27daa12bd85008 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期四, 14 十月 2021 00:07:20 +0800 Subject: [PATCH] 2021-10-14 --- src/tabviews/custom/components/table/edit-table/normalTable/index.jsx | 112 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 91 insertions(+), 21 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 0881563..a391160 100644 --- a/src/tabviews/custom/components/table/edit-table/normalTable/index.jsx +++ b/src/tabviews/custom/components/table/edit-table/normalTable/index.jsx @@ -192,6 +192,7 @@ tdFocus = (id) => { const { col, record } = this.props + if (id !== col.uuid + record.$Index) return this.focus() } @@ -201,11 +202,13 @@ const { value } = this.state this.setState({editing: false}) - if (col.enter === '$next') { - MKEmitter.emit('nextLine', col, record.$Index) - } else { - MKEmitter.emit('tdFocus', col.enter + record.$Index) - } + setTimeout(() => { + if (col.enter === '$next') { + MKEmitter.emit('nextLine', col, record.$Index) + } else { + MKEmitter.emit('tdFocus', col.enter + record.$Index) + } + }, 50) if (value !== record[col.field]) { MKEmitter.emit('changeRecord', col.tableId, {...record, [col.field]: value}) @@ -367,6 +370,39 @@ {content ? <Paragraph copyable ellipsis={{ rows: 3, expandable: true }}>{content}</Paragraph> : null } </div> ) + } 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') { + try { + // eslint-disable-next-line + content = eval(content) + } catch (e) { + content = '' + } + } + + content = content === undefined ? '' : content + + if (content !== '') { + content = `${col.prefix || ''}${content}${col.postfix || ''}` + + if (col.eval === 'false') { + content = content.replace(/\n/ig, '<br/>').replace(/\s/ig, ' ') + content = <span dangerouslySetInnerHTML={{__html: content}}></span> + } + } + + if (col.marks) { + style = style || {} + content = this.getMark(record, col.marks, style, content) + } + + children = content } else if (col.type === 'custom') { style.padding = '0px' if (col.style) { @@ -419,7 +455,8 @@ fields: [], pickup: false, // 鏀惰捣鏈�夋嫨椤� orderfields: {}, // 鎺掑簭id涓巉ield杞崲 - loading: false + loading: false, + editable: 'false' } UNSAFE_componentWillMount () { @@ -474,22 +511,28 @@ if (item.type !== 'action') { let _copy = fromJS(_item).toJS() _copy.sorter = false + + if (item.editable === 'true') { + _copy.title = <span>{item.label}<Icon className="system-color" style={{position: 'absolute', bottom: 0, right: 0}} type="edit" /></span> + } edColumns.push(_copy) } _columns.push(_item) }) - edColumns.push({ - align: 'center', - dataIndex: 'mkoperation', - title: '鎿嶄綔', - sorter: false, - width: 100, - onCell: record => ({ - record, - col: {type: 'operation', tableId: tableId}, + if (setting.delable !== 'false') { + edColumns.push({ + align: 'center', + dataIndex: 'mkoperation', + title: '鎿嶄綔', + sorter: false, + width: 100, + onCell: record => ({ + record, + col: {type: 'operation', tableId: tableId}, + }) }) - }) + } if (setting.borderColor) { // 杈规棰滆壊 let style = `#${tableId} table, #${tableId} tr, #${tableId} th, #${tableId} td {border-color: ${setting.borderColor}}` @@ -504,7 +547,8 @@ edColumns, tableId, orderfields, - initEditLine + initEditLine, + editable: setting.editable }) } @@ -514,6 +558,7 @@ componentDidMount () { const { fields, columns } = this.props + const { data, editable } = this.state let _fields = [] @@ -531,6 +576,12 @@ this.setState({ fields: _fields, }) + + if (editable === 'true' && data && data.length > 0) { + setTimeout(() => { + this.pickupChange() + }, 200) + } MKEmitter.addListener('nextLine', this.nextLine) MKEmitter.addListener('delRecord', this.delRecord) @@ -554,6 +605,11 @@ UNSAFE_componentWillReceiveProps(nextProps) { if (!is(fromJS(this.props.data), fromJS(nextProps.data))) { this.setState({data: nextProps.data || []}) + if (this.state.editable === 'true') { + setTimeout(() => { + this.pickupChange() + }, 200) + } } } @@ -844,6 +900,9 @@ loading: false }) + if (submit.closetab === 'true') { + MKEmitter.emit('popclose') + } if (submit.execSuccess !== 'never') { this.repick() MKEmitter.emit('refreshByButtonResult', submit.$menuId, submit.execSuccess, submit) @@ -924,9 +983,19 @@ } pickupChange = () => { + const { submit } = this.props const { data } = this.state let pickup = !this.state.pickup + + if (!submit.sheet) { + notification.warning({ + top: 92, + message: '鎻愪氦鎸夐挳灏氭湭璁剧疆锛屼笉鍙紪杈戯紒', + duration: 5 + }) + return + } if (!pickup && !is(fromJS(data), fromJS(this.state.edData))) { const _this = this @@ -951,7 +1020,8 @@ data: [], edData: [], pickup, - loading: false + loading: false, + editable: 'false' }, () => { this.setState({ data: data, @@ -962,7 +1032,7 @@ } render() { - const { setting, statFValue, lineMarks } = this.props + const { setting, statFValue, lineMarks, submit } = this.props const { pickup, tableId, data, edData, columns, edColumns, loading } = this.state const components = { @@ -1005,7 +1075,7 @@ 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} /> - {pickup ? <Button onClick={() => setTimeout(() => {this.checkData()}, 10)} loading={loading} className="submit-table" type="link">鎻愪氦</Button> : null} + {pickup ? <Button style={submit.style} onClick={() => setTimeout(() => {this.checkData()}, 10)} loading={loading} className="submit-table" type="link">鎻愪氦</Button> : null} <Table components={components} style={setting.style} @@ -1025,7 +1095,7 @@ 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'}} icon="plus" type="link"></Button> : null} + {pickup && setting.addable === 'true' ? <Button onClick={this.addLine} style={{display: 'block', width: '100%', color: '#26C281', border: '1px solid #dddddd', borderRadius: 0}} icon="plus" type="link"></Button> : null} </div> ) } -- Gitblit v1.8.0