From ddddb07002201150da9551875c25e75499563249 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期五, 15 一月 2021 15:22:55 +0800
Subject: [PATCH] 2021-01-15

---
 src/menu/components/share/usercomponent/index.jsx |  184 +++++++++++++++++++++++++++++++++++----------
 1 files changed, 141 insertions(+), 43 deletions(-)

diff --git a/src/menu/components/share/usercomponent/index.jsx b/src/menu/components/share/usercomponent/index.jsx
index 8936f77..fd071da 100644
--- a/src/menu/components/share/usercomponent/index.jsx
+++ b/src/menu/components/share/usercomponent/index.jsx
@@ -22,7 +22,7 @@
     dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
     visible: false,
     loading: false,
-    name: ''
+    name: '',
   }
 
   shouldComponentUpdate (nextProps, nextState) {
@@ -31,7 +31,7 @@
 
   trigger = () => {
     const { config } = this.props
-    
+
     this.setState({
       visible: true,
       loading: false,
@@ -39,53 +39,151 @@
     })
   }
 
+  getUserComponent = () => {
+    let config = fromJS(this.props.config).toJS()
+    let _config = {}
+
+    _config.wrap = config.wrap || {}
+    _config.type = config.type || ''
+    _config.subtype = config.subtype || ''
+    _config.style = config.style || {}
+    _config.subcards = config.subcards || []
+    _config.headerStyle = config.headerStyle || {}
+    _config.action = config.action || []
+    _config.search = config.search || []
+    _config.cols = config.cols || []
+    _config.plot = config.plot || {}
+
+    _config.width = _config.wrap.width || _config.plot.width || config.width || 24
+
+    _config.subcards = _config.subcards.map(card => {
+      if (card.elements) {
+        card.elements = card.elements.map(item => this.resetElement(item))
+      }
+      if (card.backElements) {
+        card.backElements = card.backElements.map(item => this.resetElement(item))
+      }
+      return card
+    })
+    _config.action = _config.action.map(item => {
+      item.verify = null
+      return item
+    })
+    _config.search = _config.search.map(item => {
+      if (item.resourceType === '1') {
+        item.resourceType = '0'
+        item.dataSource = ''
+        item.valueText = ''
+        item.valueText = ''
+        item.options = ''
+      }
+      item.blacklist = []
+      return item
+    })
+
+    _config.cols = _config.cols.map(col => {
+      if (col.type === 'colspan' && col.subcols) {
+        col = this.loopCol(col)
+      } else if (col.type === 'custom' && col.elements) {
+        col.elements = col.elements.map(cell => this.resetElement(cell))
+      } else if (col.type === 'action' && col.elements) {
+        col.elements = col.elements.map(cell => {
+          cell.verify = null
+          return cell
+        })
+      }
+      col.marks = null
+      return col
+    })
+
+    return _config
+  }
+
+  loopCol = (col) => {
+    col.subcols = col.subcols.map(c => {
+      if (c.type === 'colspan' && c.subcols) {
+        c = this.loopCol(c)
+      } else if (c.type === 'custom' && c.elements) {
+        c.elements = c.elements.map(cell => this.resetElement(cell))
+      }
+      c.marks = null
+      return c
+    })
+
+    return col
+  }
+
+  resetElement = (item) => {
+    item.marks = null
+    item.verify = null
+
+    if (item.datatype === 'dynamic') {
+      if (item.eleType ===  'icon') {
+        item.tooltip = item.field
+      } else if (item.eleType === 'slider') {
+        item.value = 50
+      } else {
+        item.value = item.field
+      }
+      
+      item.datatype = 'static'
+      item.field = ''
+    }
+    if (item.link === 'dynamic') {
+      item.link = 'static'
+    }
+    return item
+  }
+
   submit = () => {
     const { config } = this.props
 
     this.verifyRef.handleConfirm().then(res => {
-      this.setState({loading: true})
       document.getElementsByClassName('menu-view')[0].classList.add('saving')
-
-      html2canvas(document.getElementById(config.uuid)).then(canvas => {
-        let img = canvas.toDataURL('image/png') // 鑾峰彇鐢熸垚鐨勫浘鐗�
-        Api.fileuploadbase64(img, 'cloud').then(result => {
-          if (result.status) {
-            Api.getSystemConfig({
-              func: 's_custom_components_adduptdel',
-              c_id: config.uuid,
-              images: Utils.getcloudurl(result.Images),
-              c_name: res.name,
-              long_param: window.btoa(window.encodeURIComponent(JSON.stringify(config))),
-              del_type: ''
-            }).then(response => {
-              if (response.status) {
-                this.setState({loading: false, visible: false})
-                notification.success({
-                  top: 92,
-                  message: '淇濆瓨鎴愬姛',
-                  duration: 2
-                })
-                document.getElementsByClassName('menu-view')[0].classList.remove('saving')
-                MKEmitter.emit('updateCustomComponent')
-              } else {
-                this.setState({loading: false})
-                notification.warning({
-                  top: 92,
-                  message: response.message,
-                  duration: 5
-                })
-              }
-            })
-          } else {
-            this.setState({loading: false})
-            notification.warning({
-              top: 92,
-              message: result.ErrMesg,
-              duration: 5
-            })
-          }
+      this.setState({loading: true})
+      setTimeout(() => {
+        let template = this.getUserComponent()
+        html2canvas(document.getElementById(config.uuid)).then(canvas => {
+          let img = canvas.toDataURL('image/png') // 鑾峰彇鐢熸垚鐨勫浘鐗�
+          Api.fileuploadbase64(img, 'cloud').then(result => {
+            if (result.status) {
+              Api.getSystemConfig({
+                func: 's_custom_components_adduptdel',
+                c_id: config.uuid,
+                images: Utils.getcloudurl(result.Images),
+                c_name: res.name,
+                long_param: window.btoa(window.encodeURIComponent(JSON.stringify(template))),
+                del_type: ''
+              }).then(response => {
+                if (response.status) {
+                  this.setState({loading: false, visible: false})
+                  notification.success({
+                    top: 92,
+                    message: '淇濆瓨鎴愬姛',
+                    duration: 2
+                  })
+                  document.getElementsByClassName('menu-view')[0].classList.remove('saving')
+                  MKEmitter.emit('updateCustomComponent')
+                } else {
+                  this.setState({loading: false})
+                  notification.warning({
+                    top: 92,
+                    message: response.message,
+                    duration: 5
+                  })
+                }
+              })
+            } else {
+              this.setState({loading: false})
+              notification.warning({
+                top: 92,
+                message: result.ErrMesg,
+                duration: 5
+              })
+            }
+          })
         })
-      })
+      }, 300)
     })
   }
 

--
Gitblit v1.8.0