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/pcdesign/index.jsx |  193 ++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 154 insertions(+), 39 deletions(-)

diff --git a/src/views/pcdesign/index.jsx b/src/views/pcdesign/index.jsx
index c524734..2badd14 100644
--- a/src/views/pcdesign/index.jsx
+++ b/src/views/pcdesign/index.jsx
@@ -76,10 +76,18 @@
   }
 
   UNSAFE_componentWillMount() {
+    if (!sessionStorage.getItem('UserID')) {
+      sessionStorage.removeItem('isEditState')
+      sessionStorage.removeItem('appType')
+      this.props.history.replace('/login')
+      return
+    }
+    
     if (memberLevel < 30) return
 
     sessionStorage.setItem('editMenuType', 'menu') // 缂栬緫鑿滃崟绫诲瀷
 
+    window.GLOB.curDate = moment().format('YYYY-MM-DD')
     window.GLOB.TabsMap = new Map()          // 缂撳瓨鐢ㄦ埛鎿嶄綔鐨勬爣绛鹃〉
     window.GLOB.CacheIndependent = new Map()
     window.GLOB.urlFields = []               // url鍙橀噺
@@ -123,6 +131,7 @@
   }
 
   componentDidMount () {
+    if (!sessionStorage.getItem('UserID')) return
     if (memberLevel < 30) {
       document.getElementById('mk-pc-design-view').innerHTML = '<div style="text-align: center; font-size: 30px; margin-top: 40vh; height: 100vh; background: #fff;">鏈簲鐢ㄦ病鏈塒C绔〉闈㈢殑缂栬緫鏉冮檺锛岃鑱旂郴绠$悊鍛橈紒</div>'
       return
@@ -365,6 +374,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,
@@ -420,15 +431,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
@@ -556,6 +575,8 @@
           this.setState({
             needUpdate: true
           })
+        } else {
+          config.components = this.updateComponents(config.components)
         }
 
         let navItem = null
@@ -581,6 +602,27 @@
     this.getAppMenus()
   }
 
+  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
+    })
+  }
+
   collectTB = (components) => {
     return components.map(item => {
       if (item.type === 'tabs') {
@@ -599,6 +641,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
@@ -913,17 +962,22 @@
               title: btn.label,
             })
           })
-          item.cols.forEach(col => {
-            if (col.type !== 'action') return
-            col.elements.forEach(btn => {
-              if (btn.hidden === 'true') return
-              
-              m.children.push({
-                key: btn.uuid,
-                title: btn.label,
-              })
+          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
+                  m.children.push({
+                    key: cell.uuid,
+                    title: cell.label,
+                  })
+                })
+              }
             })
-          })
+          }
+          loopCol(item.cols)
         }
 
         list.push(m)
@@ -996,8 +1050,14 @@
               })
             }
             card.elements && card.elements.forEach(cell => {
-              if (cell.eleType !== 'button') return
+              if (cell.linkmenu && menuObj[cell.linkmenu]) {
+                menus.push(menuObj[cell.linkmenu])
+              } else if (cell.openmenu && menuObj[cell.openmenu]) {
+                menus.push(menuObj[cell.openmenu])
+              }
+            })
 
+            card.backElements && card.backElements.forEach(cell => {
               if (cell.linkmenu && menuObj[cell.linkmenu]) {
                 menus.push(menuObj[cell.linkmenu])
               } else if (cell.openmenu && menuObj[cell.openmenu]) {
@@ -1007,8 +1067,6 @@
           })
         } else if (item.type === 'balcony') {
           item.elements && item.elements.forEach(cell => {
-            if (cell.eleType !== 'button') return
-
             if (cell.linkmenu && menuObj[cell.linkmenu]) {
                 menus.push(menuObj[cell.linkmenu])
               } else if (cell.openmenu && menuObj[cell.openmenu]) {
@@ -1029,16 +1087,22 @@
               menus.push(menuObj[btn.openmenu])
             }
           })
-          item.cols && item.cols.forEach(col => {
-            if (col.type !== 'action') return
-            col.elements.forEach(btn => {
-              if (btn.linkmenu && menuObj[btn.linkmenu]) {
-                menus.push(menuObj[btn.linkmenu])
-              } else if (btn.openmenu && menuObj[btn.openmenu]) {
-                menus.push(menuObj[btn.openmenu])
+          let loopCol = (cols) => {
+            cols.forEach(col => {
+              if (col.type === 'colspan') {
+                loopCol(col.subcols)
+              } else if (col.type === 'custom') {
+                col.elements.forEach(cell => {
+                  if (cell.linkmenu && menuObj[cell.linkmenu]) {
+                    menus.push(menuObj[cell.linkmenu])
+                  } else if (cell.openmenu && menuObj[cell.openmenu]) {
+                    menus.push(menuObj[cell.openmenu])
+                  }
+                })
               }
             })
-          })
+          }
+          loopCol(item.cols)
         }
       })
     }
@@ -1074,6 +1138,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 = () => {
     let config = fromJS(this.state.config).toJS()
 
@@ -1085,9 +1178,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 = []
@@ -1314,6 +1419,8 @@
           menuloading: false
         })
 
+        window.GLOB.saving = false
+
         if (!res) return
 
         if (res.status) {
@@ -1348,6 +1455,9 @@
     this.setState({
       menuloading: false
     })
+
+    window.GLOB.saving = false
+    
     if (!error) {
       notification.warning({
         top: 92,
@@ -1392,17 +1502,22 @@
   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 } = this.state
+  verifyConfig = (config) => {
     let error = ''
 
     let check = (components) => {
@@ -1429,7 +1544,7 @@
 
     check(config.components)
 
-    if (show && error) {
+    if (config.enabled && error) {
       notification.warning({
         top: 92,
         message: error,
@@ -1437,7 +1552,7 @@
       })
     }
 
-    return error
+    return error === ''
   }
 
   // 鏇存柊閰嶇疆淇℃伅
@@ -1664,7 +1779,7 @@
               </div>
               <div className="wrap">
                 <Button type="primary" className={needUpdate ? 'update-tip' : ''} id="save-config" onClick={this.submitConfig} loading={menuloading}>淇濆瓨</Button>
-                <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}
                 <ArrowLeftOutlined title="鍚庨��" className="back-view" onClick={this.backView}/>
                 <Button className="mk-border-purple" onClick={() => this.setState({eyeopen: !eyeopen})}>{!eyeopen ? <EyeOutlined /> : <EyeInvisibleOutlined />} 缁勪欢鍚�</Button>
                 <CreateView resetmenu={this.getAppMenus} />

--
Gitblit v1.8.0