From 08cce3334a2dc81d690b518136b0aaea64e48b0b Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期三, 14 六月 2023 09:55:50 +0800
Subject: [PATCH] 2023-06-14

---
 src/templates/zshare/editTable/index.jsx |  210 ++++++++++++++++++++++++++++-----------------------
 1 files changed, 115 insertions(+), 95 deletions(-)

diff --git a/src/templates/zshare/editTable/index.jsx b/src/templates/zshare/editTable/index.jsx
index ff2c97f..ad29e43 100644
--- a/src/templates/zshare/editTable/index.jsx
+++ b/src/templates/zshare/editTable/index.jsx
@@ -3,17 +3,17 @@
 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, SnippetsOutlined, SwapOutlined } from '@ant-design/icons'
+import { CopyOutlined, EditOutlined, DeleteOutlined, SwapOutlined } from '@ant-design/icons'
 
 import Utils from '@/utils/utils.js'
 import ColorSketch from '@/mob/colorsketch'
-import PasteForm from '@/templates/zshare/pasteform'
 import asyncComponent from '@/utils/asyncComponent'
 import CusSwitch from './cusSwitch'
 import MKEmitter from '@/utils/events.js'
 import './index.scss'
 
 const MkEditIcon = asyncComponent(() => import('@/components/mkIcon'))
+const PasteBoard = asyncComponent(() => import('@/components/pasteboard'))
 const EditableContext = React.createContext()
 const { confirm } = Modal
 let dragingIndex = -1
@@ -163,6 +163,7 @@
 class EditTable extends Component {
   static propTpyes = {
     actions: PropTypes.any,         // 鎿嶄綔椤�
+    searchKey: PropTypes.any,       // 鎼滅储鏉′欢
     data: PropTypes.any,            // 鏁版嵁鍒楄〃
     columns: PropTypes.array,       // 鏄剧ず鍒�
     onChange: PropTypes.func        // 鏁版嵁鍙樺寲
@@ -171,7 +172,6 @@
   state = {
     data: [],
     editingKey: '',
-    visible: false,
     editLineId: '',
     columns: []
   }
@@ -195,7 +195,7 @@
           鎿嶄綔
           <span className="copy-control">
             {actions.includes('copy') ? <CopyOutlined title="澶嶅埗" onClick={() => this.copy()} /> : null}
-            {actions.includes('copy') ? <SnippetsOutlined title="绮樿创" onClick={this.paste} /> : null}
+            {actions.includes('copy') ? <PasteBoard getPasteValue={this.pasteSubmit}/> : null}
             {actions.includes('clear') ? <DeleteOutlined title="娓呯┖" onClick={this.clear} /> : null}
           </span>
         </div>),
@@ -351,66 +351,74 @@
     }
   }
   
-  paste = () => {
-    this.setState({visible: true})
-  }
-  
-  pasteSubmit = () => {
+  pasteSubmit = (res, callback) => {
     const { type } = this.props
     const { columns } = this.state
     let data = fromJS(this.state.data).toJS()
 
-    this.pasteFormRef.handleConfirm().then(res => {
-      if (res.copyType === 'columns' && type === 'datasourcefield') {
-        res.type = 'array'
-        res.data = []
-        res.columns.forEach(col => {
-          if (!col.field) return
-          if (col.type === 'number') {
-            let datatype = 'Int'
-            if (col.decimal) {
-              datatype = `Decimal(18,${col.decimal})`
-            }
-
-            res.data.push({
-              $index: res.data.length + 1,
-              datatype: datatype,
-              field: col.field,
-              decimal: col.decimal,
-              label: col.label,
-              type: 'number',
-              uuid: Utils.getuuid()
-            })
-          } else {
-            let datatype = 'Nvarchar(50)'
-            let fieldlength = 50
-            if (col.fieldlength && [10, 20, 50, 100, 256, 512, 1024, 2048].includes(col.fieldlength)) {
-              fieldlength = col.fieldlength
-              datatype = `Nvarchar(${fieldlength})`
-            }
-
-            res.data.push({
-              $index: res.data.length + 1,
-              datatype: datatype,
-              field: col.field,
-              fieldlength: fieldlength,
-              label: col.label,
-              type: 'text',
-              uuid: Utils.getuuid()
-            })
+    if (res.copyType === 'columns' && type === 'datasourcefield') {
+      res.type = 'array'
+      res.data = []
+      res.columns.forEach(col => {
+        if (!col.field) return
+        if (col.type === 'number') {
+          let datatype = 'Int'
+          if (col.decimal) {
+            datatype = `Decimal(18,${col.decimal})`
           }
-        })
-      } else if (res.key !== type) {
-        message.warning('閰嶇疆淇℃伅鏍煎紡閿欒锛�')
-        return
-      }
 
-      if (res.type === 'line') {
-        let unique = true
-        res.data.uuid = Utils.getuuid()
-        columns.forEach(col => {
-          if (col.unique !== true || !unique) return
+          res.data.push({
+            $index: res.data.length + 1,
+            datatype: datatype,
+            field: col.field,
+            decimal: col.decimal,
+            label: col.label,
+            type: 'number',
+            uuid: Utils.getuuid()
+          })
+        } else {
+          let datatype = 'Nvarchar(50)'
+          let fieldlength = 50
+          if (col.fieldlength && [10, 20, 50, 100, 256, 512, 1024, 2048].includes(col.fieldlength)) {
+            fieldlength = col.fieldlength
+            datatype = `Nvarchar(${fieldlength})`
+          }
 
+          res.data.push({
+            $index: res.data.length + 1,
+            datatype: datatype,
+            field: col.field,
+            fieldlength: fieldlength,
+            label: col.label,
+            type: 'text',
+            uuid: Utils.getuuid()
+          })
+        }
+      })
+    } else if (res.key !== type) {
+      message.warning('閰嶇疆淇℃伅鏍煎紡閿欒锛�')
+      return
+    }
+
+    if (res.type === 'line') {
+      let unique = true
+      res.data.uuid = Utils.getuuid()
+      columns.forEach(col => {
+        if (col.unique !== true || !unique) return
+
+        if (col.strict) {
+          let key = res.data[col.dataIndex].toLowerCase()
+          let _index = data.findIndex(item => key === item[col.dataIndex].toLowerCase())
+
+          if (_index > -1) {
+            notification.warning({
+              top: 92,
+              message: col.title + '涓嶅彲閲嶅锛�',
+              duration: 5
+            })
+            unique = false
+          }
+        } else {
           let _index = data.findIndex(item => res.data[col.dataIndex] === item[col.dataIndex])
 
           if (_index > -1) {
@@ -421,38 +429,49 @@
             })
             unique = false
           }
-        })
+        }
+      })
 
-        if (!unique) return
+      if (!unique) return
 
-        data.unshift(res.data)
-        this.setState({ data, editingKey: '', visible: false }, () => {
-          this.props.onChange(data)
-        })
-      } else if (res.type === 'array') {
-        res.data.forEach(cell => {
-          let unique = true
-          cell.uuid = Utils.getuuid()
-          columns.forEach(col => {
-            if (col.unique !== true || !unique) return
+      data.unshift(res.data)
+      this.setState({ data, editingKey: '', editLineId: res.data.uuid || '' }, () => {
+        this.props.onChange(data)
+      })
+    } else if (res.type === 'array') {
+      res.data.forEach(cell => {
+        let unique = true
+        cell.uuid = Utils.getuuid()
+        columns.forEach(col => {
+          if (col.unique !== true || !unique) return
+
+          if (col.strict) {
+            let _index = data.findIndex(item => cell[col.dataIndex].toLowerCase() === item[col.dataIndex].toLowerCase())
+  
+            if (_index > -1) {
+              unique = false
+            }
+          } else {
             let _index = data.findIndex(item => cell[col.dataIndex] === item[col.dataIndex])
   
             if (_index > -1) {
               unique = false
             }
-          })
-  
-          if (!unique) return
-  
-          data.push(cell)
+          }
         })
 
-        this.setState({ data, editingKey: '', visible: false }, () => {
-          this.props.onChange(data)
-        })
-      }
-      message.success('绮樿创鎴愬姛銆�')
-    })
+        if (!unique) return
+
+        data.push(cell)
+      })
+
+      this.setState({ data, editingKey: '' }, () => {
+        this.props.onChange(data)
+      })
+    }
+
+    callback()
+    message.success('绮樿创鎴愬姛銆�')
   }
 
   handleStatus = (record) => {
@@ -585,7 +604,7 @@
   }
 
   render() {
-    const { actions, indexShow } = this.props
+    const { actions, indexShow, searchKey } = this.props
     const { editLineId } = this.state
 
     let components = {
@@ -595,7 +614,7 @@
     }
 
     let moveprops = {}
-    if (actions.includes('move')) {
+    if (actions.includes('move') && !searchKey) {
       components.body.row = DragableBodyRow
       moveprops.moveAble = !this.state.editingKey
       moveprops.moveRow = this.moveRow
@@ -641,6 +660,8 @@
       return item
     })
 
+    let reg = searchKey ? new RegExp(searchKey, 'ig') : null
+
     return (
       <EditableContext.Provider value={this.props.form}>
         <div className="modal-edit-table">
@@ -651,7 +672,18 @@
               components={components}
               dataSource={data}
               columns={columns}
-              rowClassName={record => !editLineId || editLineId !== record.uuid ? 'editable-row' : 'editable-row active'}
+              rowClassName={record => {
+                let className = 'editable-row'
+                if (editLineId && editLineId === record.uuid) {
+                  className += ' active'
+                }
+                if (searchKey) {
+                  if (!reg.test(record.field) && !reg.test(record.label)) {
+                    className += ' hidden'
+                  }
+                }
+                return className
+              }}
               pagination={false}
               onRow={(record, index) => ({
                 index,
@@ -659,18 +691,6 @@
               })}
             />
           </DndProvider>
-          {/* 淇℃伅绮樿创 */}
-          <Modal
-            title="绮樿创"
-            visible={this.state.visible}
-            width={600}
-            maskClosable={false}
-            onOk={this.pasteSubmit}
-            onCancel={() => {this.setState({visible: false})}}
-            destroyOnClose
-          >
-            <PasteForm wrappedComponentRef={(inst) => this.pasteFormRef = inst} inputSubmit={this.pasteSubmit}/>
-          </Modal>
         </div>
       </EditableContext.Provider>
     )

--
Gitblit v1.8.0