From 81d0d7721bb14a34b1eef99fd9506c3eda4bda99 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期三, 18 十月 2023 17:17:47 +0800 Subject: [PATCH] 2023-10-18 --- src/templates/zshare/editTable/index.jsx | 75 +++++++++++++++++++++++++++++++++++++ 1 files changed, 74 insertions(+), 1 deletions(-) diff --git a/src/templates/zshare/editTable/index.jsx b/src/templates/zshare/editTable/index.jsx index 60dd750..24902d3 100644 --- a/src/templates/zshare/editTable/index.jsx +++ b/src/templates/zshare/editTable/index.jsx @@ -3,7 +3,7 @@ import { is, fromJS } from 'immutable' import { DndProvider, DragSource, DropTarget } from 'react-dnd' import { Table, Input, InputNumber, Popconfirm, Form, Select, Radio, Cascader, notification, message, Modal, Typography } from 'antd' -import { CopyOutlined, EditOutlined, DeleteOutlined, SwapOutlined } from '@ant-design/icons' +import { CopyOutlined, EditOutlined, DeleteOutlined, SwapOutlined, PlusOutlined } from '@ant-design/icons' import Utils from '@/utils/utils.js' import ColorSketch from '@/mob/colorsketch' @@ -258,6 +258,7 @@ } UNSAFE_componentWillReceiveProps (nextProps) { + if (!is(fromJS(this.state.data), fromJS(nextProps.data))) { this.setState({data: nextProps.data, editingKey: ''}) } else if (!is(fromJS(this.props.columns), fromJS(nextProps.columns))) { @@ -518,6 +519,26 @@ return } + let forbid = false + + columns.forEach(col => { + if (!col.forbids || forbid) return + + let key = record[col.dataIndex].toLowerCase() + if (col.forbids.includes(key)) { + forbid = col.title + '涓嶅彲浣跨敤' + record[col.dataIndex] + } + }) + + if (forbid) { + notification.warning({ + top: 92, + message: forbid, + duration: 5 + }) + return + } + let unique = true columns.forEach(col => { if (col.unique !== true || !unique) return @@ -582,6 +603,26 @@ row = {...newData[index], ...row} } else { row.uuid = uuid + } + + let forbid = false + + columns.forEach(col => { + if (!col.forbids || forbid) return + + let key = row[col.dataIndex].toLowerCase() + if (col.forbids.includes(key)) { + forbid = col.title + '涓嶅彲浣跨敤' + row[col.dataIndex] + } + }) + + if (forbid) { + notification.warning({ + top: 92, + message: forbid, + duration: 5 + }) + return } let unique = true @@ -652,6 +693,37 @@ }) } + handleAdd = () => { + const { columns } = this.props + const { data } = this.state + + let _index = data.length + 1 + let item = { + uuid: Utils.getuuid() + } + + columns.forEach(col => { + if (!col.dataIndex) return + + item[col.dataIndex] = col.initval || '' + + if (col.unique) { + while (data.filter(cell => cell[col.dataIndex] === item[col.dataIndex]).length > 0) { + _index++ + item[col.dataIndex] = col.initval + _index + } + } + }) + + let _data = [...data, item] + + this.setState({ + data: _data + }, () => { + this.props.onChange(_data) + }) + } + render() { const { actions, indexShow, searchKey } = this.props const { editLineId } = this.state @@ -714,6 +786,7 @@ return ( <EditableContext.Provider value={this.props.form}> <div className="modal-edit-table"> + {actions.includes('add') ? <PlusOutlined className="add-row" onClick={this.handleAdd} /> : null} <DndProvider> <Table bordered -- Gitblit v1.8.0