From d59f518f466274b2caeb2e01c10c92deafe7c93b Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期三, 09 二月 2022 11:48:29 +0800 Subject: [PATCH] 2022-02-09 --- src/menu/components/table/edit-table/columns/index.jsx | 261 +++++++++++++++++++++++++++------------------------ 1 files changed, 137 insertions(+), 124 deletions(-) diff --git a/src/menu/components/table/edit-table/columns/index.jsx b/src/menu/components/table/edit-table/columns/index.jsx index c347313..4ed5e10 100644 --- a/src/menu/components/table/edit-table/columns/index.jsx +++ b/src/menu/components/table/edit-table/columns/index.jsx @@ -2,7 +2,8 @@ import PropTypes from 'prop-types' import { is, fromJS } from 'immutable' import { DndProvider, DragSource, DropTarget } from 'react-dnd' -import { Table, Popover, Icon, Modal, message } from 'antd' +import { Table, Popover, Modal, message, Button } from 'antd' +import { PlusOutlined, FileSyncOutlined, EditOutlined, CopyOutlined, DeleteOutlined, FontColorsOutlined, CloseCircleOutlined, AntDesignOutlined } from '@ant-design/icons' import asyncComponent from '@/utils/asyncComponent' import asyncIconComponent from '@/utils/asyncIconComponent' @@ -13,7 +14,8 @@ import './index.scss' const { confirm } = Modal -const EditColumn = asyncIconComponent(() => import('./editColumn')) +const EditColumn = asyncComponent(() => import('./editColumn')) +const TableVerify = asyncComponent(() => import('./tableIn')) const MarkColumn = asyncIconComponent(() => import('@/menu/components/share/markcomponent')) const CardCellComponent = asyncComponent(() => import('@/menu/components/card/cardcellcomponent')) @@ -51,44 +53,23 @@ render() { const { connectDragSource, connectDropTarget, moveCol, addElement, updateCol, editColumn, changeStyle, deleteCol, index, column, align, fields, children, ...restProps } = this.props - if (index !== undefined) { - return connectDragSource( - connectDropTarget(<th {...restProps} index={index} style={{ cursor: 'move', textAlign: align }} onDoubleClick={() => column && this.props.editColumn(column)}> - <Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={ - <div className="mk-popover-control"> - {column && ['custom', 'colspan', 'action'].includes(column.type) ? - <Icon className="plus" title="娣诲姞" type="plus" onClick={() => this.props.addElement(column)} /> : null - } - <Icon className="edit" title="缂栬緫" type="edit" onClick={() => this.props.editColumn(column)} /> - {column && column.type === 'custom' ? <Icon className="style" title="璋冩暣鏍峰紡" onClick={() => this.props.changeStyle(column)} type="font-colors" /> : null} - <Icon className="close" title="鍒犻櫎" type="delete" onClick={this.deleteCol} /> - {column && ['text', 'number'].includes(column.type) ? <MarkColumn columns={fields} marks={column.marks} onSubmit={this.updateMarks} /> : null } - </div> - } trigger="hover"> - {children} - </Popover> - </th>), - ) - } else if (column) { - return ( - <th {...restProps} key={column.uuid} onDoubleClick={() => this.props.editColumn(column)}> - <Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={ - <div className="mk-popover-control"> - {column && ['custom', 'colspan'].includes(column.type) ? - <Icon className="plus" title="娣诲姞" type="plus" onClick={() => this.props.addElement(column)} /> : null - } - <Icon className="edit" title="缂栬緫" type="edit" onClick={() => this.props.editColumn(column)} /> - <Icon className="close" title="鍒犻櫎" type="delete" onClick={this.deleteCol} /> - {column && ['text', 'number'].includes(column.type) ? <MarkColumn columns={fields} marks={column.marks} onSubmit={this.updateMarks} /> : null } - </div> - } trigger="hover"> - {children} - </Popover> - </th> - ) - } else { - return (<th {...restProps}>{children}</th>) - } + return connectDragSource( + connectDropTarget(<th {...restProps} index={index} style={{ cursor: 'move', textAlign: align }} onDoubleClick={() => column && this.props.editColumn(column)}> + <Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={ + <div className="mk-popover-control" onDoubleClick={(e) => e.stopPropagation()}> + {column && ['custom', 'action'].includes(column.type) ? + <PlusOutlined className="plus" title="娣诲姞" onClick={() => this.props.addElement(column)} /> : null + } + <EditOutlined className="edit" title="缂栬緫" onClick={() => this.props.editColumn(column)} /> + {column && column.type === 'custom' ? <FontColorsOutlined className="style" title="璋冩暣鏍峰紡" onClick={() => this.props.changeStyle(column)}/> : null} + <DeleteOutlined className="close" title="鍒犻櫎" onClick={this.deleteCol} /> + {column && ['text', 'number', 'formula'].includes(column.type) ? <MarkColumn columns={fields} marks={column.marks} onSubmit={this.updateMarks} /> : null } + </div> + } trigger="hover"> + {children} + </Popover> + </th>), + ) } } @@ -155,11 +136,21 @@ </td> ) } else if (column) { + let val = column.field || '' + if (column.type === 'index') { + val = '$Index' + } else if (column.type === 'formula') { + val = column.formula + if (column.eval === 'false') { + val = val.replace(/\n/ig, '<br/>').replace(/\s/ig, ' ') + val = <span dangerouslySetInnerHTML={{__html: val}}></span> + } + } return ( <td style={{...style, minWidth: column.Width || 100}} className={className}> - {column.field || (column.type === 'index' ? '$Index' : '')} - {column.Hide === 'true' ? <Icon style={{marginLeft: '5px', color: 'orange', fontSize: '12px'}} type="close-circle" /> : null} - {column.marks && column.marks.length ? <Icon className="profile" type="ant-design"/> : null} + {val} + {column.Hide === 'true' ? <CloseCircleOutlined style={{marginLeft: '5px', color: 'orange', fontSize: '12px'}}/> : null} + {column.marks && column.marks.length ? <AntDesignOutlined className="profile"/> : null} </td> ) } else { @@ -240,6 +231,7 @@ return !is(fromJS(this.state), fromJS(nextState)) || !is(fromJS(config.wrap), fromJS(nextProps.config.wrap)) || + !is(fromJS(config.submit), fromJS(nextProps.config.submit)) || !is(fromJS(config.search), fromJS(nextProps.config.search)) || !is(fromJS(config.action), fromJS(nextProps.config.action)) || config.setting.laypage !== nextProps.config.setting.laypage @@ -257,21 +249,14 @@ }) } - loopCol = (columns, col) => { - return columns.map(column => { - if (column.type === 'colspan') { - column.subcols = this.loopCol(column.subcols, col) - } + updateCol = (col, btn) => { + let _columns = fromJS(this.state.columns).toJS() + _columns = _columns.map(column => { if (column.uuid === col.uuid) { return col } return column }) - } - - updateCol = (col, btn) => { - let _columns = fromJS(this.state.columns).toJS() - _columns = this.loopCol(_columns, col) this.setState({ columns: _columns, @@ -295,17 +280,8 @@ const { config } = this.props let column = fromJS(col).toJS() - if (column.type === 'colspan') { - column.subcols = column.subcols || [] - let subcol = { isSub: true, focus: true, uuid: Utils.getuuid(), label: 'label', field: '', type: 'text' } - column.subcols.push(subcol) - - this.setState({ - card: subcol - }) - this.updateCol(column) - } else if (column.type === 'custom') { - let newcard = {uuid: Utils.getuuid(), focus: true, eleType: 'text', datatype: 'dynamic', style: {paddingLeft: '4px'}} + if (column.type === 'custom') { + let newcard = {uuid: Utils.getuuid(), focus: true, width: 24, eleType: 'text', datatype: 'dynamic', style: {paddingLeft: '4px'}} // 娉ㄥ唽浜嬩欢-娣诲姞鍏冪礌 MKEmitter.emit('cardAddElement', [config.uuid, column.uuid], newcard) @@ -320,8 +296,7 @@ intertype: 'system', execSuccess: 'grid', execError: 'never', - show: 'link', - $type: 'tableButton' + show: 'link' } // 娉ㄥ唽浜嬩欢-娣诲姞鍏冪礌 @@ -331,14 +306,8 @@ submitCol = (col) => { const { card } = this.state - - col.uuid = card.uuid - col.isSub = card.isSub === true - col.marks = card.marks || [] - if (col.type === 'colspan') { - col.subcols = card.subcols || [] - } else if (col.type === 'custom') { + if (col.type === 'custom') { col.elements = card.type === 'custom' ? (card.elements || []) : [] } else if (col.type === 'action') { col.elements = card.type === 'action' ? (card.elements || []) : [] @@ -356,10 +325,24 @@ MKEmitter.emit('changeStyle', [col.uuid], ['font', 'padding'], col.style || {}) } + changeSubmitStyle = () => { + const { config } = this.props + + MKEmitter.emit('changeStyle', [config.uuid, 'submit'], ['font', 'background', 'border', 'margin', 'padding'], config.submit.style || {}) + } + getStyle = (comIds, style) => { + const { config } = this.props const { editStyleCard } = this.state - if (!editStyleCard || comIds[0] !== editStyleCard.uuid || comIds.length !== 1) return + if (comIds.length === 2 && comIds[0] === config.uuid && comIds[1] === 'submit') { + let submit = {...config.submit, style} + + this.props.updatecolumn({...config, submit: submit}) + + return + } + if (comIds.length !== 1 || !editStyleCard || comIds[0] !== editStyleCard.uuid) return let _card = {...editStyleCard, style} @@ -376,20 +359,11 @@ this.setState({card: null}) } - loopDelCol = (columns, col) => { - return columns.filter(column => { - if (column.type === 'colspan') { - column.subcols = this.loopDelCol(column.subcols, col) - } - return column.uuid !== col.uuid - }) - } - deleteCol = (col) => { const { appType } = this.state let _columns = fromJS(this.state.columns).toJS() - _columns = this.loopDelCol(_columns, col) + _columns = _columns.filter(column => column.uuid !== col.uuid) this.setState({ columns: _columns @@ -443,36 +417,6 @@ document.body.removeChild(oInput) } - handlecolumns = (columns, fields, config, isSub) => { - return columns.map((col, index) => { - return { - title: col.label, - dataIndex: col.uuid, - align: col.Align, - sorter: !isSub && col.IsSort === 'true', - onCell: () => ({ - column: col, - width: col.Width, - config: config, - upComponent: this.updateCol - }), - onHeaderCell: () => ({ - index: isSub ? undefined : index, - column: col, - fields: fields, - align: col.Align, - moveCol: this.moveCol, - updateCol: this.updateCol, - addElement: this.addElement, - editColumn: this.editColumn, - changeStyle: this.changeStyle, - deleteCol: this.deleteCol, - }), - children: col.subcols && col.subcols.length ? this.handlecolumns(col.subcols, fields, config, true) : null, - } - }) - } - syncfield = () => { const { fields } = this.state let columns = fromJS(this.state.columns).toJS() @@ -484,9 +428,9 @@ fields.forEach(item => { if (keys.includes(item.field)) return - let cell = { uuid: Utils.getuuid(), label: item.label, field: item.field, Align: 'left', Hide: 'false', IsSort: 'true', Width: 120, blacklist: [], postfix: '', prefix: '', linkmenu: [], marks: [], perspective: 'linkmenu' } + let cell = { uuid: Utils.getuuid(), label: item.label, field: item.field, Align: 'left', Hide: 'false', IsSort: 'false', Width: 120, blacklist: [], postfix: '', prefix: '', linkmenu: [], marks: [], perspective: 'linkmenu' } - if (/Nvarchar/ig.test(item.datatype)) { + if (/Nvarchar|date/ig.test(item.datatype)) { cell.type = 'text' cell.rowspan = 'false' cell.textFormat = 'none' @@ -495,6 +439,7 @@ cell.format = 'none' cell.sum = 'false' cell.decimal = item.decimal || 0 + cell.Width = 80 } columns.push(cell) @@ -527,6 +472,19 @@ }) } + verifySubmit = () => { + const { config } = this.props + + this.verifyRef.handleConfirm().then(res => { + res.style = config.submit.style || {} + this.setState({ + visible: false + }, () => { + this.props.updatecolumn({...config, submit: res}) + }) + }) + } + componentDidMount () { MKEmitter.addListener('submitStyle', this.getStyle) } @@ -543,7 +501,7 @@ render() { const { config } = this.props - const { fields, card, lineMarks, dict, tableId } = this.state + const { fields, card, lineMarks, dict, tableId, visible } = this.state const components = { header: { cell: DragableHeaderCol @@ -553,7 +511,36 @@ } } - const columns = this.handlecolumns(this.state.columns, fields, config) + const columns = this.state.columns.map((col, index) => { + let title = col.label + if (col.editable === 'true') { + title = <span>{col.label}<EditOutlined style={{position: 'absolute', bottom: 0, right: 0, color: '#1890ff'}}/></span> + } + return { + title: title, + dataIndex: col.uuid, + align: col.Align, + sorter: col.IsSort === 'true', + onCell: () => ({ + column: col, + width: col.Width, + config: config, + upComponent: this.updateCol + }), + onHeaderCell: () => ({ + index, + column: col, + fields: fields, + align: col.Align, + moveCol: this.moveCol, + updateCol: this.updateCol, + addElement: this.addElement, + editColumn: this.editColumn, + changeStyle: this.changeStyle, + deleteCol: this.deleteCol, + }), + } + }) let style = {} if (config.wrap.color) { @@ -564,12 +551,20 @@ } return ( - <div className={`normal-table-columns ${config.setting.laypage} ${config.wrap.tableType} ${config.wrap.mode || ''}`} id={tableId}> + <div className={`edit-table-columns ${config.setting.laypage} ${config.wrap.mode || ''}`} id={tableId}> <div className="col-control"> - <Icon title="澶嶅埗鏄剧ず鍒�" type="copy" onClick={this.copycolumn} /> + <Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={ + <div className="mk-popover-control"> + <EditOutlined className="edit" title="缂栬緫" onClick={() => this.setState({visible: true})} /> + <FontColorsOutlined className="style" title="璋冩暣鏍峰紡" onClick={this.changeSubmitStyle}/> + </div> + } trigger="hover"> + <Button className="submit-btn" style={config.submit.style} onDoubleClick={() => this.setState({visible: true})} type="primary">鎻愪氦</Button> + </Popover> + <CopyOutlined title="澶嶅埗鏄剧ず鍒�" onClick={this.copycolumn} /> <MarkColumn columns={fields} type="line" marks={lineMarks} onSubmit={this.updateLineMarks} /> - <Icon title="鍚屾瀛楁闆�" type="file-sync" onClick={this.syncfield} /> - <Icon title="娓呯┖鏄剧ず鍒�" type="delete" onClick={this.clear}/> + <FileSyncOutlined title="鍚屾瀛楁闆�" onClick={this.syncfield} /> + <DeleteOutlined title="娓呯┖鏄剧ず鍒�" onClick={this.clear}/> </div> <DndProvider> <Table @@ -580,7 +575,6 @@ bordered={config.wrap.bordered !== 'false'} components={components} dataSource={this.state.data} - rowSelection={config.wrap.tableType ? { type: 'radio' } : null} columns={columns} pagination={{ current: 1, @@ -592,7 +586,26 @@ }} /> </DndProvider> - <EditColumn column={card} dict={dict} fields={fields} submitCol={this.submitCol} cancelCol={this.cancelCol}/> + <EditColumn column={card} dict={dict} columns={this.state.columns} fields={fields} submitCol={this.submitCol} cancelCol={this.cancelCol}/> + <Modal + wrapClassName="model-table-action-verify-modal" + title={'缂栬緫'} + visible={visible} + width={'75vw'} + maskClosable={false} + onOk={this.verifySubmit} + onCancel={() => { this.setState({ visible: false }) }} + destroyOnClose + > + <TableVerify + card={config.submit} + setting={config.setting} + dict={dict} + cols={config.cols} + columns={config.columns} + wrappedComponentRef={(inst) => this.verifyRef = inst} + /> + </Modal> </div> ) } -- Gitblit v1.8.0