From 1da6506bf58270bacc2a4345002c6b082835580e Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 21 十月 2021 23:17:08 +0800
Subject: [PATCH] 2021-10-21

---
 src/templates/zshare/editcomponent/index.jsx |  112 ++++++++++++++++++--------------------------------------
 1 files changed, 36 insertions(+), 76 deletions(-)

diff --git a/src/templates/zshare/editcomponent/index.jsx b/src/templates/zshare/editcomponent/index.jsx
index 6fd72b8..cbc5832 100644
--- a/src/templates/zshare/editcomponent/index.jsx
+++ b/src/templates/zshare/editcomponent/index.jsx
@@ -9,6 +9,7 @@
 import TransferForm from '@/templates/zshare/basetransferform'
 import zhCN from '@/locales/zh-CN/model.js'
 import enUS from '@/locales/en-US/model.js'
+import MKEmitter from '@/utils/events.js'
 import './index.scss'
 
 class editComponent extends Component {
@@ -116,30 +117,35 @@
   }
 
   pasteSubmit = () => {
-    const { options } = this.props
+    const { options, config, type } = this.props
     let _config = fromJS(this.props.config).toJS()
 
     this.pasteFormRef.handleConfirm().then(res => {
-      if (res.copyType === 'action' && options.includes('action')) {
-        res.uuid = Utils.getuuid()
-
-        _config.action = _config.action.filter(item => !item.origin)
-        _config.action.push(res)
-
-        this.setState({
-          pasteVisible: false
-        }, () => {
-          this.props.refresh({
-            type: 'paste',
-            config: _config
-          })
+      if (!options.includes(res.copyType)) {
+        notification.warning({
+          top: 92,
+          message: '閰嶇疆淇℃伅鏍煎紡閿欒锛�',
+          duration: 5
         })
-      } else if (options.includes('search') && res.copyType === 'search') {
+        return
+      } else if (res.copyType === 'action') {
         res.uuid = Utils.getuuid()
-        _config.search = _config.search.filter(item => !item.origin)
-        let keys = _config.search.map(item => item.field.toLowerCase())
+        MKEmitter.emit('pasteButton', config.uuid, res)
+      } else if (res.copyType === 'search' || (type === 'table' && res.copyType === 'form')) {
+        res.uuid = Utils.getuuid()
+        let keys = _config.search.map(item => item.field ? item.field.toLowerCase() : '')
 
-        _config.search.push(res)
+        if (type === 'table') {
+          if (['number', 'switch', 'textarea', 'fileupload', 'hint', 'color', 'funcvar'].includes(res.type)) {
+            res.type = 'text'
+          } else if (res.type === 'radio') {
+            res.type = 'select'
+          } else if (res.type === 'checkbox') {
+            res.type = 'multiselect'
+          } else if (res.type === 'datetime') {
+            res.type = 'date'
+          }
+        }
 
         if (res.field && keys.includes(res.field.toLowerCase())) {
           notification.warning({
@@ -149,83 +155,37 @@
           })
           return
         }
-
-        this.setState({
-          pasteVisible: false
-        }, () => {
-          this.props.refresh({
-            type: 'paste',
-            config: _config
-          })
-        })
-      } else if (options.includes('columns') && res.copyType === 'columns') {
-        _config.columns = _config.columns.filter(col => !col.origin)
+        MKEmitter.emit('plusSearch', config.uuid, res, 'simple')
+      } else if (res.copyType === 'columns') {
         let keys = _config.columns.map(item => item.field ? item.field.toLowerCase() : '')
-
-        if (_config.columns.length === 0) {
-          _config.columns = res.columns
-        } else {
-          res.columns.forEach(col => {
-            if (!col.field) return
-            let _key = col.field.toLowerCase()
-            if (!keys.includes(_key)) {
-              keys.push(_key)
-              _config.columns.push(col)
-            }
-          })
-        }
+        let items = res.columns.filter(col => col.field && !keys.includes(col.field.toLowerCase()))
         
-        this.setState({
-          pasteVisible: false
-        }, () => {
-          this.props.refresh({
-            type: 'paste',
-            config: _config
-          })
-        })
-      } else if (options.includes('form') && res.copyType === 'form') {
-        let fields = []
-        let labels = []
+        MKEmitter.emit('plusColumns', config.uuid, items)
+      } else if (res.copyType === 'form') {
+        let keys = _config.fields.map(item => item.field ? item.field.toLowerCase() : '')
         res.uuid = Utils.getuuid()
 
-        _config.fields.forEach(item => {
-          item.field && fields.push(item.field.toLowerCase())
-          labels.push(item.label)
-        })
-        _config.fields.push(res)
-
-        if (res.field && fields.includes(res.field.toLowerCase())) {
+        if (res.field && keys.includes(res.field.toLowerCase())) {
           notification.warning({
             top: 92,
             message: '瀛楁宸插瓨鍦紒',
             duration: 10
           })
           return
-        } else if (labels.includes(res.label)) {
-          notification.warning({
-            top: 92,
-            message: '鍚嶇О宸插瓨鍦紒',
-            duration: 10
-          })
-          return
         }
         
-        this.setState({
-          pasteVisible: false
-        }, () => {
-          this.props.refresh({
-            type: 'paste',
-            config: _config,
-            newform: res
-          })
-        })
+        this.props.plusFields([res])
       } else {
         notification.warning({
           top: 92,
           message: '閰嶇疆淇℃伅鏍煎紡閿欒锛�',
           duration: 5
         })
+        return
       }
+      this.setState({
+        pasteVisible: false
+      })
     })
   }
 

--
Gitblit v1.8.0