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/views/menudesign/index.jsx |  166 ++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 139 insertions(+), 27 deletions(-)

diff --git a/src/views/menudesign/index.jsx b/src/views/menudesign/index.jsx
index ce3e6e5..eac50e4 100644
--- a/src/views/menudesign/index.jsx
+++ b/src/views/menudesign/index.jsx
@@ -73,8 +73,16 @@
   }
 
   UNSAFE_componentWillMount() {
+    if (!sessionStorage.getItem('UserID')) {
+      sessionStorage.removeItem('isEditState')
+      sessionStorage.removeItem('appType')
+      this.props.history.replace('/login')
+      return
+    }
+
     sessionStorage.setItem('editMenuType', 'menu') // 缂栬緫鑿滃崟绫诲瀷
 
+    window.GLOB.curDate = moment().format('YYYY-MM-DD')
     window.GLOB.UserComponentMap = new Map() // 缂撳瓨鐢ㄦ埛鑷畾涔夌粍浠�
     window.GLOB.TabsMap = new Map()          // 缂撳瓨鐢ㄦ埛鎿嶄綔鐨勬爣绛鹃〉
     window.GLOB.urlFields = []               // url鍙橀噺
@@ -106,6 +114,8 @@
   }
 
   componentDidMount () {
+    if (!sessionStorage.getItem('UserID')) return
+    
     MKEmitter.addListener('changePopview', this.initPopview)
     MKEmitter.addListener('triggerMenuSave', this.triggerMenuSave)
     MKEmitter.addListener('updateCustomComponent', this.updateCustomComponent)
@@ -370,6 +380,8 @@
       _btn.config.MenuID = _btn.uuid
       _btn.config.ParentId = card.uuid
       _btn.config.MenuName = _btn.label
+
+      _btn.config.components = this.updateComponents(_btn.config.components || [])
     } else {
       _btn.config = {
         uuid: _btn.uuid,
@@ -485,6 +497,7 @@
           })
           this.updatePage(config)
         } else {
+          config.components = this.updateComponents(config.components)
           this.setState({
             oriConfig: fromJS(config).toJS(),
             config: config
@@ -498,6 +511,27 @@
           duration: 5
         })
       }
+    })
+  }
+
+  updateComponents = (components) => { // 鍏煎鎬у崌绾� table
+    return components.map(item => {
+      if (item.type === 'tabs') {
+        item.subtabs.forEach(tab => {
+          tab.components = this.updateComponents(tab.components)
+        })
+      } else if (item.type === 'group') {
+        item.components = this.updateComponents(item.components)
+      } else if (item.type === 'table') {
+        item.cols = item.cols.map(col => {
+          if (col.type === 'action') {
+            col.type = 'custom'
+          }
+          return col
+        })
+      }
+
+      return item
     })
   }
 
@@ -519,6 +553,13 @@
 
       if (item.subtype === 'tablecard') { // 鍏煎
         item.type = 'card'
+      } else if (item.type === 'table') {
+        item.cols = item.cols.map(col => {
+          if (col.type === 'action') {
+            col.type = 'custom'
+          }
+          return col
+        })
       }
 
       delete item.tabId
@@ -556,15 +597,23 @@
       })
     })
 
-    config.cols && config.cols.forEach(col => {
-      if (col.type === 'action') {
-        col.elements.forEach(cell => {
-          if (cell.OpenType === 'popview' && popbtns[cell.uuid]) {
-            cell.config = popbtns[cell.uuid]
+    if (config.cols) {
+      let loopCol = (cols) => {
+        cols.forEach(col => {
+          if (col.type === 'colspan') {
+            loopCol(col.subcols)
+          } else if (col.type === 'custom') {
+            col.elements.forEach(cell => {
+              if (cell.eleType !== 'button') return
+              if (cell.OpenType === 'popview' && popbtns[cell.uuid]) {
+                cell.config = popbtns[cell.uuid]
+              }
+            })
           }
         })
       }
-    })
+      loopCol(config.cols)
+    }
 
     config.elements && config.elements.forEach(cell => {
       if (cell.eleType !== 'button') return
@@ -684,6 +733,11 @@
         if (item.$tables) {
           tbs.push(...item.$tables)
         }
+
+        if (item.wrap && item.wrap.permission === 'false') {
+          return
+        }
+        
         if (item.action && item.action.length > 0) {
           item.action.forEach(btn => {
             if (btn.hidden === 'true') return
@@ -720,14 +774,20 @@
             _sort++
           })
         } else if (item.type === 'table') {
-          item.cols && item.cols.forEach(col => {
-            if (col.type !== 'action') return
-            col.elements.forEach(btn => {
-              if (btn.hidden === 'true') return
-              buttons.push(`select '${btn.uuid}' as menuid, '${item.name + '-' + btn.label}' as menuname, '${_sort * 10}' as Sort, '${config.uuid}' as parentid, 40 as Type`)
-              _sort++
+          let loopCol = (cols) => {
+            cols.forEach(col => {
+              if (col.type === 'colspan') {
+                loopCol(col.subcols)
+              } else if (col.type === 'custom') {
+                col.elements.forEach(cell => {
+                  if (cell.eleType !== 'button' || cell.hidden === 'true') return
+                  buttons.push(`select '${cell.uuid}' as menuid, '${item.name + '-' + cell.label}' as menuname, '${_sort * 10}' as Sort, '${config.uuid}' as parentid, 40 as Type`)
+                  _sort++
+                })
+              }
             })
-          })
+          }
+          loopCol(item.cols)
         }
       })
     }
@@ -758,6 +818,35 @@
     return true
   }
 
+  resetSyncQuery = (components) => {
+    return components.map(item => {
+      if (item.type === 'tabs') {
+        item.subtabs.forEach(tab => {
+          tab.components = this.resetSyncQuery(tab.components)
+        })
+      } else if (item.type === 'group') {
+        item.components = this.resetSyncQuery(item.components)
+      } else if (item.setting && item.setting.interType === 'system' && item.setting.sync === 'true') {
+        let sql = ''
+        if (item.setting.execute !== 'false' && item.setting.dataresource) {
+          sql = item.setting.dataresource
+        }
+
+        item.scripts && item.scripts.forEach(script => {
+          if (script.status === 'false') return
+
+          sql += script.sql
+        })
+
+        if (sql.length > 8000) {
+          item.setting.sync = 'false'
+        }
+      }
+
+      return item
+    })
+  }
+
   submitConfig = () => {
     const { MenuType } = this.state
     let config = fromJS(this.state.config).toJS()
@@ -775,9 +864,21 @@
       menuloading: true
     })
 
+    window.GLOB.saving = true
+
     setTimeout(() => {
-      if (config.enabled && this.verifyConfig()) {
+      let _pass = this.verifyConfig(config)
+
+      if (config.enabled && !_pass) {
         config.enabled = false
+        config.force = true
+      } else if (!config.enabled && config.force && _pass) {
+        config.enabled = true
+        delete config.force
+      }
+
+      if (config.cacheUseful !== 'true') {
+        config.components = this.resetSyncQuery(config.components)
       }
 
       let tbs = []
@@ -928,6 +1029,8 @@
           menuloading: false
         })
 
+        window.GLOB.saving = false
+
         if (!res) return
 
         if (res.status) {
@@ -952,6 +1055,9 @@
     this.setState({
       menuloading: false
     })
+
+    window.GLOB.saving = false
+
     if (!error) {
       notification.warning({
         top: 92,
@@ -997,17 +1103,23 @@
   onEnabledChange = () => {
     const { config } = this.state
 
-    if (!config || (!config.enabled && this.verifyConfig(true))) {
-      return
-    }
+    let _config = {...config, enabled: !config.enabled}
 
-    this.setState({
-      config: {...config, enabled: !config.enabled}
-    })
+    delete _config.force
+
+    if (!_config.enabled) {
+      this.setState({
+        config: _config
+      })
+    } else if (this.verifyConfig(_config)) {
+      this.setState({
+        config: _config
+      })
+    }
   }
 
-  verifyConfig = (show) => {
-    const { config, MenuType } = this.state
+  verifyConfig = (config) => {
+    const { MenuType } = this.state
     let error = ''
 
     let check = (components) => {
@@ -1035,7 +1147,7 @@
 
     check(config.components)
 
-    if (show && error) {
+    if (config.enabled && error) {
       notification.warning({
         top: 92,
         message: error,
@@ -1051,7 +1163,7 @@
         carousel: '杞挱',
         tree: '鏍戝舰鍒楄〃',
         chart: '鑷畾涔夊浘琛�',
-        editor: '瀵屾枃鏈�',
+        // editor: '瀵屾枃鏈�',
         group: '鍒嗙粍',
         iframe: 'iframe'
       }
@@ -1069,7 +1181,7 @@
         }
       })
 
-      if (show && error) {
+      if (config.enabled && error) {
         notification.warning({
           top: 92,
           message: error,
@@ -1078,7 +1190,7 @@
       }
     }
 
-    return error
+    return error === ''
   }
 
   // 鏇存柊閰嶇疆淇℃伅
@@ -1193,7 +1305,7 @@
                     <PictureController/>
                     <StyleCombControlButton menu={config} />
                     <PasteController insert={this.insert} />
-                    <Switch className="big" checkedChildren="鍚�" unCheckedChildren="鍋�" checked={config && config.enabled} onChange={this.onEnabledChange} />
+                    {config ? <Switch className="big" checkedChildren="鍚�" unCheckedChildren="鍋�" checked={config.enabled} onChange={this.onEnabledChange} /> : null}
                     <Button type="primary" id="save-config" className={needUpdate ? 'update-tip' : ''} onClick={this.submitConfig} loading={menuloading}>淇濆瓨</Button>
                     <Button type="default" onClick={this.closeView}>鍏抽棴</Button>
                   </div>

--
Gitblit v1.8.0