From d1cd5af5adb53e91efdd278328e1b6f8ad834fb5 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 06 二月 2025 21:11:56 +0800
Subject: [PATCH] Merge branch 'positec' into dms

---
 src/templates/zshare/editTable/index.jsx |  288 +++++++++++++++++++++++++++++++++++----------------------
 1 files changed, 176 insertions(+), 112 deletions(-)

diff --git a/src/templates/zshare/editTable/index.jsx b/src/templates/zshare/editTable/index.jsx
index 6a19cdb..932f55b 100644
--- a/src/templates/zshare/editTable/index.jsx
+++ b/src/templates/zshare/editTable/index.jsx
@@ -485,83 +485,151 @@
       return
     }
 
-    if (res.type === 'line') {
-      let unique = true
+    let ucol = columns.filter(col => col.unique === true)[0]
+    const that = this
+
+    if (data.length === 0) {
+      if (res.type === 'line') {
+        res.data.uuid = Utils.getuuid()
+        data.push(res.data)
+      } else if (res.type === 'array') {
+        res.data.forEach(cell => {
+          cell.uuid = Utils.getuuid()
+          data.push(cell)
+        })
+      }
+      this.setState({ data, editingKey: '', editLineId: res.type === 'line' ? res.data.uuid : '' }, () => {
+        this.props.onChange(data)
+      })
+    } else if (res.type === 'line') {
+      let index = -1
       res.data.uuid = Utils.getuuid()
-      columns.forEach(col => {
-        if (col.unique !== true || !unique) return
 
-        if (col.uniqueFunc) {
-          unique = col.uniqueFunc(data, res.data)
-        } else if (col.strict) {
-          let key = res.data[col.dataIndex].toLowerCase()
-          let _index = data.findIndex(item => key === item[col.dataIndex].toLowerCase())
+      if (ucol) {
+        if (ucol.uniqueFunc) {
+          let msg = ucol.uniqueFunc(data, res.data)
 
-          if (_index > -1) {
+          if (msg) {
             notification.warning({
               top: 92,
-              message: col.title + '涓嶅彲閲嶅锛�',
+              message: msg,
               duration: 5
             })
-            unique = false
+            callback()
+            return
+          }
+        } else if (ucol.strict) {
+          let key = res.data[ucol.dataIndex].toLowerCase()
+          index = data.findIndex(item => key === item[ucol.dataIndex].toLowerCase())
+        } else {
+          index = data.findIndex(item => res.data[ucol.dataIndex] === item[ucol.dataIndex])
+        }
+      }
+
+      if (index > -1) {
+        callback()
+        data.splice(index, 1, res.data)
+
+        confirm({
+          title: `${ucol.title}锛�${res.data[ucol.dataIndex]}锛夊凡瀛樺湪锛乣,
+          okText: '鐭ラ亾浜�',
+          cancelText: '鏇挎崲',
+          onOk() {},
+          onCancel() {
+            that.setState({ data, editingKey: '', editLineId: res.data.uuid || '' }, () => {
+              that.props.onChange(data)
+            })
+          }
+        })
+        return
+      } else {
+        if (type === 'excelcolumn') {
+          data.push(res.data)
+        } else {
+          data.unshift(res.data)
+        }
+  
+        this.setState({ data, editingKey: '', editLineId: res.data.uuid || '' }, () => {
+          this.props.onChange(data)
+        })
+      }
+    } else if (res.type === 'array') {
+      let repeats = []
+      let vals = []
+
+      if (ucol) {
+        if (ucol.uniqueFunc) {
+
+        } else if (ucol.strict) {
+          vals = data.map(item => item[ucol.dataIndex].toLowerCase())
+        } else {
+          vals = data.map(item => item[ucol.dataIndex])
+        }
+      }
+
+      res.data.forEach(cell => {
+        cell.uuid = Utils.getuuid()
+        
+        if (ucol) {
+          let unique = true
+          if (ucol.uniqueFunc) {
+            let msg = ucol.uniqueFunc(data, cell)
+  
+            if (msg) return
+          } else if (ucol.strict) {
+            unique = !vals.includes(cell[ucol.dataIndex].toLowerCase())
+          } else {
+            unique = !vals.includes(cell[ucol.dataIndex])
+          }
+
+          if (unique) {
+            data.push(cell)
+          } else {
+            repeats.push(cell)
           }
         } else {
-          let _index = data.findIndex(item => res.data[col.dataIndex] === item[col.dataIndex])
-
-          if (_index > -1) {
-            notification.warning({
-              top: 92,
-              message: col.title + '涓嶅彲閲嶅锛�',
-              duration: 5
-            })
-            unique = false
-          }
+          data.push(cell)
         }
       })
 
-      if (!unique) return
-
-      if (type === 'excelcolumn') {
-        data.push(res.data)
-      } else {
-        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.uniqueFunc) {
-            unique = col.uniqueFunc(data, cell)
-          } else if (col.strict) {
-            let _index = data.findIndex(item => cell[col.dataIndex].toLowerCase() === item[col.dataIndex].toLowerCase())
-  
-            if (_index > -1) {
-              unique = false
+      if (repeats.length) {
+        callback()
+        let _data = fromJS(data).toJS().map(cell => {
+          let _cell = cell
+          repeats.forEach(item => {
+            if (ucol.strict) {
+              if (cell[ucol.dataIndex].toLowerCase() === item[ucol.dataIndex].toLowerCase()) {
+                _cell = item
+              }
+            } else if (cell[ucol.dataIndex] === item[ucol.dataIndex]) {
+              _cell = item
             }
-          } else {
-            let _index = data.findIndex(item => cell[col.dataIndex] === item[col.dataIndex])
-  
-            if (_index > -1) {
-              unique = false
-            }
-          }
+          })
+
+          return _cell
         })
 
-        if (!unique) return
-
-        data.push(cell)
-      })
-
-      this.setState({ data, editingKey: '' }, () => {
-        this.props.onChange(data)
-      })
+        confirm({
+          content: `瀛樺湪閲嶅鐨�${ucol.title}锛岃閫夋嫨澶勭悊鏂瑰紡銆俙,
+          okText: '璺宠繃',
+          cancelText: '鏇挎崲',
+          onOk() {
+            that.setState({ data, editingKey: '', editLineId: '' }, () => {
+              that.props.onChange(data)
+            })
+          },
+          onCancel() {
+            that.setState({ data: _data, editingKey: '', editLineId: '' }, () => {
+              that.props.onChange(data)
+            })
+          }
+        })
+        return
+      } else {
+        this.setState({ data, editingKey: '' }, () => {
+          this.props.onChange(data)
+        })
+      }
     }
 
     callback()
@@ -618,40 +686,36 @@
       return
     }
 
-    let unique = true
-    columns.forEach(col => {
-      if (col.unique !== true || !unique) return
+    let ucol = columns.filter(col => col.unique === true)[0]
+    if (ucol) {
+      let index = -1
+      if (ucol.uniqueFunc) {
+        let msg = ucol.uniqueFunc(newData, record)
 
-      if (col.uniqueFunc) {
-        unique = col.uniqueFunc(newData, record)
-        return
-      } else if (col.strict) {
-        let key = record[col.dataIndex].toLowerCase()
-        let _index = newData.findIndex(item => record.uuid !== item.uuid && key === item[col.dataIndex].toLowerCase())
-
-        if (_index > -1) {
+        if (msg) {
           notification.warning({
             top: 92,
-            message: col.title + '涓嶅彲閲嶅锛�',
+            message: msg,
             duration: 5
           })
-          unique = false
+          return
         }
+      } else if (ucol.strict) {
+        let key = record[ucol.dataIndex].toLowerCase()
+        index = newData.findIndex(item => record.uuid !== item.uuid && key === item[ucol.dataIndex].toLowerCase())
       } else {
-        let _index = newData.findIndex(item => record.uuid !== item.uuid && record[col.dataIndex] === item[col.dataIndex])
-  
-        if (_index > -1) {
-          notification.warning({
-            top: 92,
-            message: col.title + '涓嶅彲閲嶅锛�',
-            duration: 5
-          })
-          unique = false
-        }
+        index = newData.findIndex(item => record.uuid !== item.uuid && record[ucol.dataIndex] === item[ucol.dataIndex])
       }
-    })
 
-    if (!unique) return
+      if (index > -1) {
+        notification.warning({
+          top: 92,
+          message: ucol.title + '涓嶅彲閲嶅锛�',
+          duration: 5
+        })
+        return
+      }
+    }
 
     newData.splice(index, 1, record)
     this.setState({ data: newData, editingKey: '' }, () => {
@@ -704,40 +768,36 @@
         return
       }
 
-      let unique = true
-      columns.forEach(col => {
-        if (col.unique !== true || !unique) return
+      let ucol = columns.filter(col => col.unique === true)[0]
+      if (ucol) {
+        let _index = -1
+        if (ucol.uniqueFunc) {
+          let msg = ucol.uniqueFunc(newData, row)
 
-        if (col.uniqueFunc) {
-          unique = col.uniqueFunc(newData, row)
-          return
-        } else if (col.strict) {
-          let key = row[col.dataIndex].toLowerCase()
-          let _index = newData.findIndex(item => row.uuid !== item.uuid && key === item[col.dataIndex].toLowerCase())
-  
-          if (_index > -1) {
+          if (msg) {
             notification.warning({
               top: 92,
-              message: col.title + '涓嶅彲閲嶅锛�',
+              message: msg,
               duration: 5
             })
-            unique = false
+            return
           }
+        } else if (ucol.strict) {
+          let key = row[ucol.dataIndex].toLowerCase()
+          _index = newData.findIndex(item => row.uuid !== item.uuid && key === item[ucol.dataIndex].toLowerCase())
         } else {
-          let _index = newData.findIndex(item => row.uuid !== item.uuid && row[col.dataIndex] === item[col.dataIndex])
-  
-          if (_index > -1) {
-            notification.warning({
-              top: 92,
-              message: col.title + '涓嶅彲閲嶅锛�',
-              duration: 5
-            })
-            unique = false
-          }
+          _index = newData.findIndex(item => row.uuid !== item.uuid && row[ucol.dataIndex] === item[ucol.dataIndex])
         }
-      })
 
-      if (!unique) return
+        if (_index > -1) {
+          notification.warning({
+            top: 92,
+            message: ucol.title + '涓嶅彲閲嶅锛�',
+            duration: 5
+          })
+          return
+        }
+      }
 
       if (index > -1) {
         newData.splice(index, 1, row)
@@ -912,6 +972,10 @@
                 ...moveprops
               })}
             />
+            {actions.includes('copy') && data.length > 10 ? <span className="footer-copy-control">
+              <CopyOutlined title="澶嶅埗" onClick={() => this.copy()} />
+              <PasteBoard getPasteValue={this.pasteSubmit}/>
+            </span> : null}
           </DndProvider>
         </div>
       </EditableContext.Provider>

--
Gitblit v1.8.0