From 3cbad93c94c39730e45600efeabdfebcd424c2cc Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 14 一月 2021 19:00:19 +0800
Subject: [PATCH] 2021-01-14

---
 src/views/menudesign/index.jsx |  226 +++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 190 insertions(+), 36 deletions(-)

diff --git a/src/views/menudesign/index.jsx b/src/views/menudesign/index.jsx
index eee1ad2..04167a3 100644
--- a/src/views/menudesign/index.jsx
+++ b/src/views/menudesign/index.jsx
@@ -14,6 +14,7 @@
 import antdEnUS from 'antd/es/locale/en_US'
 import antdZhCN from 'antd/es/locale/zh_CN'
 import MKEmitter from '@/utils/events.js'
+import MenuUtils from '@/menu/utils/menuUtils.js'
 import asyncComponent from '@/utils/asyncComponent'
 import { modifyCustomMenu } from '@/store/action'
 
@@ -54,13 +55,15 @@
     tableFields: [],
     delButtons: [],
     copyButtons: [],
+    thawButtons: [],
     activeKey: 'basedata',
     menuloading: false,
     oriConfig: null,
     openEdition: '',
     config: null,
     popBtn: null,             // 寮圭獥鏍囩椤�
-    visible: false
+    visible: false,
+    customComponents: []
   }
 
   UNSAFE_componentWillMount() {
@@ -91,9 +94,12 @@
 
   componentDidMount () {
     MKEmitter.addListener('delButtons', this.delButtons)
+    MKEmitter.addListener('thawButtons', this.thawButtons)
     MKEmitter.addListener('copyButtons', this.copyButtons)
     MKEmitter.addListener('changePopview', this.initPopview)
     MKEmitter.addListener('submitComponentStyle', this.updateComponentStyle)
+    MKEmitter.addListener('updateCustomComponent', this.updateCustomComponent)
+    this.updateCustomComponent()
   }
 
   /**
@@ -104,9 +110,44 @@
       return
     }
     MKEmitter.removeListener('delButtons', this.delButtons)
+    MKEmitter.removeListener('thawButtons', this.thawButtons)
     MKEmitter.removeListener('copyButtons', this.copyButtons)
     MKEmitter.removeListener('changePopview', this.initPopview)
     MKEmitter.removeListener('submitComponentStyle', this.updateComponentStyle)
+    MKEmitter.removeListener('updateCustomComponent', this.updateCustomComponent)
+  }
+
+  updateCustomComponent = () => {
+    Api.getSystemConfig({
+      func: 's_get_custom_components',
+      typecharone: ''
+    }).then(res => {
+      let coms = []
+      if (res.cus_list && res.cus_list.length > 0) {
+        res.cus_list.forEach(item => {
+          let config = ''
+
+          try {
+            config = JSON.parse(window.decodeURIComponent(window.atob(item.long_param)))
+          } catch (e) {
+            console.warn('Parse Failure')
+            config = ''
+          }
+
+          if (!config || !item.c_name) return
+
+          coms.push({
+            type: 'menu',
+            title: item.c_name,
+            url: item.images,
+            component: config.type,
+            subtype: config.subtype,
+            config
+          })
+        })
+      }
+      this.setState({customComponents: coms})
+    })
   }
 
   updateComponentStyle = (parentId, keys, style) => {
@@ -131,10 +172,20 @@
   }
 
   delButtons = (items) => {
-    this.setState({delButtons: [...this.state.delButtons, ...items]})
+    const { copyButtons } = this.state
+
+    this.setState({
+      delButtons: [...this.state.delButtons, ...items],
+      copyButtons: copyButtons.filter(item => !items.includes(item.uuid))
+    })
   }
+
   copyButtons = (items) => {
     this.setState({copyButtons: [...this.state.copyButtons, ...items]})
+  }
+  
+  thawButtons = (item) => {
+    this.setState({thawButtons: [...this.state.thawButtons, item]})
   }
 
   initPopview = (card, btn) => {
@@ -161,7 +212,7 @@
   }
 
   handleBack = () => {
-    this.setState({popBtn: null, delButtons: []}, () => {
+    this.setState({popBtn: null, delButtons: [], copyButtons: []}, () => {
       sessionStorage.setItem('editMenuType', 'menu')
       this.props.modifyCustomMenu(this.state.config)
       this.setState({visible: false})
@@ -348,7 +399,7 @@
   }
 
   submitConfig = () => {
-    const { openEdition, MenuType, delButtons } = this.state
+    const { openEdition, MenuType, delButtons, copyButtons, thawButtons } = this.state
     let config = fromJS(this.state.config).toJS()
 
     if (MenuType === 'billPrint' && (!config.firstCount || !config.everyPCount)) {
@@ -418,9 +469,13 @@
       LText: []
     }
 
+    let btnIds = '' // 鐢ㄤ簬澶嶅埗鎸夐挳鐨勮繃婊�
     if (MenuType !== 'billPrint') {
       btnParam.LText = this.getMenuMessage()
       btnParam.LText = btnParam.LText.join(' union all ')
+
+      btnIds = btnParam.LText
+
       btnParam.LText = Utils.formatOptions(btnParam.LText)
       btnParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
       btnParam.secretkey = Utils.encrypt(btnParam.LText, btnParam.timestamp)
@@ -432,7 +487,7 @@
       menuloading: true
     }, () => {
       new Promise(resolve => {
-        if (MenuType === 'billPrint') {
+        if (MenuType === 'billPrint') { // 鎵撳嵃鐢熸垚椤甸潰鏁堟灉鍥�
           html2canvas(document.getElementById('menu-shell-inner')).then(canvas => {
             let img = canvas.toDataURL('image/png') // 鑾峰彇鐢熸垚鐨勫浘鐗�
             Api.fileuploadbase64(img, 'cloud').then(result => {
@@ -452,9 +507,6 @@
                       message: response.message,
                       duration: 5
                     })
-                    this.setState({
-                      menuloading: false
-                    })
                     resolve(false)
                   }
                 })
@@ -464,9 +516,6 @@
                   message: result.ErrMesg,
                   duration: 5
                 })
-                this.setState({
-                  menuloading: false
-                })
                 resolve(false)
               }
             })
@@ -474,7 +523,7 @@
         } else {
           resolve(true)
         }
-      }).then(res => {
+      }).then(res => { // 鎸夐挳鍒犻櫎
         if (!res) return
 
         if (delButtons.length === 0) {
@@ -488,18 +537,9 @@
           }
           return Api.getSystemConfig(_param)
         }
-      }).then(res => {
+      }).then(res => { // 鎸夐挳瑙i櫎鍐荤粨
         if (!res) return
-
-        if (res.status) {
-          this.setState({
-            delButtons: []
-          })
-          return Api.getSystemConfig(param)
-        } else {
-          this.setState({
-            menuloading: false
-          })
+        if (!res.status) {
           notification.warning({
             top: 92,
             message: res.message,
@@ -507,7 +547,32 @@
           })
           return false
         }
-      }).then(res => {
+
+        let ids = thawButtons.filter(item => btnIds.indexOf(item) !== -1)
+        if (ids.length === 0) {
+          return {
+            status: true
+          }
+        } else {
+          return Api.getSystemConfig({
+            func: 'sPC_MainMenu_ReDel',
+            MenuID: ids.join(',')
+          })
+        }
+      }).then(res => { // 椤甸潰淇濆瓨
+        if (!res) return
+
+        if (res.status) {
+          return Api.getSystemConfig(param)
+        } else {
+          notification.warning({
+            top: 92,
+            message: res.message,
+            duration: 5
+          })
+          return false
+        }
+      }).then(res => { // 椤甸潰鎸夐挳鍏崇郴淇濆瓨
         if (!res) return
 
         if (res.status) {
@@ -524,9 +589,6 @@
             }
           }
         } else {
-          this.setState({
-            menuloading: false
-          })
           notification.warning({
             top: 92,
             message: res.message,
@@ -534,11 +596,105 @@
           })
           return false
         }
-      }).then(res => {
+      }).then(res => { // 鎸夐挳澶嶅埗
         if (!res) return
-        
-        if (res.status) {
+        if (!res.status) {
+          notification.warning({
+            top: 92,
+            message: res.message,
+            duration: 5
+          })
+          return false
+        }
+
+        if (copyButtons.length === 0) {
+          return {
+            status: true
+          }
+        } else {
+          return new Promise(resolve => {
+            let deffers = copyButtons.map(item => {
+              return new Promise(resolve => {
+                if (btnIds.indexOf(item.uuid) === -1) { // 澶嶅埗鐨勬寜閽凡鍒犻櫎
+                  resolve({
+                    status: true
+                  })
+                  return
+                }
+
+                Api.getSystemConfig({
+                  func: 'sPC_Get_LongParam',
+                  MenuID: item.$originUuid
+                }).then(result => {
+                  if (result.status) {
+                    let _conf = ''
+              
+                    try {
+                      _conf = result.LongParam ? JSON.parse(window.decodeURIComponent(window.atob(result.LongParam))) : ''
+                    } catch (e) {
+                      console.warn('Parse Failure')
+                      _conf = ''
+                    }
+                    
+                    if (_conf) {
+                      _conf.components = MenuUtils.resetConfig(_conf.components)
+                      _conf.uuid = item.uuid
+                      _conf.MenuID = item.uuid
+                      _conf.Template = 'CustomPage'
+                    } else {
+                      resolve({
+                        status: true
+                      })
+                      return
+                    }
+
+                    let _param = {
+                      func: 'sPC_ButtonParam_AddUpt',
+                      ParentID: _config.uuid,
+                      MenuID: item.uuid,
+                      MenuNo: '',
+                      Template: 'CustomPage',
+                      MenuName: item.label,
+                      PageParam: JSON.stringify({Template: 'CustomPage'}),
+                      LongParam: window.btoa(window.encodeURIComponent(JSON.stringify(_conf)))
+                    }
+            
+                    Api.getSystemConfig(_param).then(response => {
+                      resolve(response)
+                    })
+                  }
+                })
+              })
+            })
+            Promise.all(deffers).then(result => {
+              let error = null
+              result.forEach(response => {
+                if (!response.status) {
+                  error = response
+                }
+              })
+    
+              if (error) {
+                notification.warning({
+                  top: 92,
+                  message: error.message,
+                  duration: 5
+                })
+                resolve(false)
+              } else {
+                resolve({
+                  status: true
+                })
+              }
+            })
+          })
+        }
+      }).then(res => {
+        if (res && res.status) {
           this.setState({
+            delButtons: [],
+            copyButtons: [],
+            thawButtons: [],
             menuloading: false,
             config: {...config, components: []}
           }, () => {
@@ -554,11 +710,6 @@
         } else {
           this.setState({
             menuloading: false
-          })
-          notification.warning({
-            top: 92,
-            message: res.message,
-            duration: 5
           })
         }
       })
@@ -678,7 +829,7 @@
   }
 
   render () {
-    const { activeKey, MenuType, popBtn, visible, dict, MenuId, config, ParentId, MenuName, MenuNo, menuloading } = this.state
+    const { activeKey, MenuType, popBtn, visible, dict, MenuId, config, ParentId, MenuName, MenuNo, menuloading, customComponents } = this.state
 
     return (
       <ConfigProvider locale={_locale}>
@@ -717,6 +868,9 @@
                   <Panel header={dict['mob.component']} key="component">
                     <SourceWrap MenuType={MenuType} />
                   </Panel>
+                  {customComponents && customComponents.length ? <Panel header="鑷畾涔夌粍浠�" key="cuscomponent">
+                    <SourceWrap components={customComponents} MenuType={MenuType} />
+                  </Panel> : null}
                   <Panel header={'鑳屾櫙'} key="background">
                     {config ? <BgController config={config} updateConfig={this.updateConfig} /> : null}
                   </Panel>

--
Gitblit v1.8.0