From 81c3fd3ac5017591d987d9c9fe42042fae5c7d7d Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 30 十一月 2021 14:30:47 +0800
Subject: [PATCH] 2021-11-30

---
 src/views/mobdesign/index.jsx |  211 +++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 181 insertions(+), 30 deletions(-)

diff --git a/src/views/mobdesign/index.jsx b/src/views/mobdesign/index.jsx
index b981866..d4474f5 100644
--- a/src/views/mobdesign/index.jsx
+++ b/src/views/mobdesign/index.jsx
@@ -5,7 +5,7 @@
 import { is, fromJS } from 'immutable'
 import moment from 'moment'
 import HTML5Backend from 'react-dnd-html5-backend'
-import { ConfigProvider, notification, Modal, Collapse, Switch, Button, message, Spin, Icon } from 'antd'
+import { ConfigProvider, notification, Modal, Collapse, Switch, Button, message, Spin, Icon, Typography } from 'antd'
 
 import Api from '@/api'
 import Utils, { setGLOBFuncs } from '@/utils/utils.js'
@@ -21,12 +21,14 @@
 
 const { Panel } = Collapse
 const { confirm } = Modal
+const { Paragraph } = Typography
 
 const Header = asyncComponent(() => import('@/mob/header'))
 const MenuForm = asyncComponent(() => import('./menuform'))
 const MobShell = asyncComponent(() => import('@/mob/mobshell'))
 const CreateView = asyncComponent(() => import('@/pc/createview'))
 const Transfer = asyncComponent(() => import('@/pc/transfer'))
+const Versions = asyncComponent(() => import('@/menu/versions'))
 const SourceWrap = asyncComponent(() => import('@/mob/modulesource'))
 const BgController = asyncComponent(() => import('@/pc/bgcontroller'))
 const ReplaceField = asyncComponent(() => import('@/menu/replaceField'))
@@ -83,6 +85,7 @@
         sessionStorage.setItem('role_type', param.role_type || 'true')
         sessionStorage.setItem('login_types', param.login_types || 'false')
         sessionStorage.setItem('typename', param.typename || 'mob')
+        sessionStorage.setItem('adapter', param.adapter || 'false')
 
         this.setState({
           localedict: sessionStorage.getItem('lang') !== 'en-US' ? antdZhCN : antdEnUS,
@@ -578,6 +581,7 @@
         }
       } else {
         config.components = MenuUtils.resetConfig(config.components)
+        config.enabled = false
         message.success('澶嶅埗鎴愬姛锛屼繚瀛樺悗鐢熸晥銆�')
       }
       
@@ -692,7 +696,7 @@
           children: []
         }
 
-        if (item.type === 'topbar' || item.type === 'login') {
+        if (item.type === 'topbar' || item.type === 'login' || item.type === 'navbar') {
           return null
         } else if (item.type === 'tabs') {
           let tabs = []
@@ -730,16 +734,8 @@
                 title: cell.label,
               })
             })
-            card.backElements && card.backElements.forEach(cell => {
-              if (cell.eleType !== 'button') return
-              this.checkBtn(cell)
-              m.children.push({
-                key: cell.uuid,
-                title: cell.label,
-              })
-            })
           })
-        } else if (item.type === 'carousel') {
+        } else if (item.type === 'carousel' || item.type === 'timeline') {
           item.subcards.forEach(card => {
             card.elements && card.elements.forEach(cell => {
               if (cell.eleType !== 'button') return
@@ -830,21 +826,85 @@
     }
   }
 
-  filterConfig = (components) => {
-    return components.map(item => {
-      if (item.type === 'tabs') {
-        item.subtabs.forEach(tab => {
-          tab.components = this.filterConfig(tab.components)
-        })
-      } else if (item.type === 'group') {
-        item.components = this.filterConfig(item.components)
-      } else if (item.type === 'table' && item.subtype === 'normaltable') {
-        item.search = item.search.filter(a => !a.origin)
-        item.action = item.action.filter(a => !a.origin)
-        item.cols = item.cols.filter(a => !a.origin)
-      }
-      return item
+  getMiniStyle = (config) => {
+    config.miniStyle = this.transferStyle(config.style)
+
+    let traversal = (components) => {
+      return components.map(item => {
+        if (item.style) {
+          item.miniStyle = this.transferStyle(item.style)
+        }
+        if (item.headerStyle) {
+          item.miniHeaderStyle = this.transferStyle(item.headerStyle)
+        }
+
+        if (item.action && item.action.length > 0) {
+          item.action = item.action.map(btn => {
+            btn.miniStyle = this.transferStyle(btn.style)
+            return btn
+          })
+        }
+
+        if (item.type === 'tabs') {
+          item.subtabs.forEach(tab => {
+            tab.components = traversal(tab.components)
+          })
+        } else if (item.type === 'group') {
+          item.components = traversal(item.components)
+        } else if (['card', 'carousel', 'timeline'].includes(item.type) || (item.type === 'table' && item.subtype === 'tablecard')) {
+          item.subcards.forEach(card => {
+            card.miniStyle = this.transferStyle(card.style)
+            card.elements = card.elements.map(cell => {
+              cell.miniStyle = this.transferStyle(cell.style)
+              return cell
+            })
+          })
+        } else if (item.type === 'balcony') {
+          item.elements && item.elements.forEach(cell => {
+            cell.miniStyle = this.transferStyle(cell.style)
+          })
+        } else if (item.type === 'menubar') {
+          item.subMenus = item.subMenus.map(menu => {
+            menu.miniStyle = this.transferStyle(menu.style)
+            return menu
+          })
+        } else if (item.type === 'table' && item.subtype === 'normaltable') {
+          let getCols = (cols) => {
+            return cols.map(col => {
+              if (col.type === 'colspan') {
+                col.subcols = getCols(col.subcols || [])
+              } else if (col.type === 'custom' || col.type === 'action') {
+                col.elements = col.elements.map(cell => {
+                  cell.miniStyle = this.transferStyle(cell.style)
+                  return cell
+                })
+              }
+  
+              return col
+            })
+          }
+          
+          item.cols = getCols(item.cols)
+        }
+
+        return item
+      })
+    }
+
+    config.components = traversal(config.components)
+
+    return config
+  }
+
+  transferStyle = (style = {}) => {
+    let _style = ''
+    Object.keys(style).forEach(key => {
+      if (['hShadow', 'vShadow', 'shadowBlur', 'shadowColor'].includes(key)) return
+      if (!style[key]) return
+      _style += `${key.replace(/[A-Z]/g, m => '-' + m.toLowerCase())}:${style[key]};`
     })
+
+    return _style
   }
 
   submitConfig = () => {
@@ -868,14 +928,23 @@
     })
 
     setTimeout(() => {
-      config.components = this.filterConfig(config.components)
-
       if (config.enabled && this.verifyConfig()) {
         config.enabled = false
       }
 
       let roleParam = {type: 'view', key: config.uuid, title: config.MenuName, children: []}
       roleParam.children = this.getMenuMessage()
+
+      if (config.components.findIndex(item => item.type === 'login') > -1) {
+        roleParam.login = true
+        config.loginview = true
+      } else {
+        config.loginview = false
+      }
+
+      if (sessionStorage.getItem('adapter') === 'true') {
+        config = this.getMiniStyle(config)
+      }
 
       let param = {
         func: 'sPC_TrdMenu_AddUpt',
@@ -955,7 +1024,7 @@
                 Typename: sessionStorage.getItem('typename'),
                 MenuName: item.name || '',
                 PageParam: JSON.stringify({Template: item.type}),
-                open_edition: item.open_edition || '',
+                open_edition: _item.open_edition || '',
                 menus_rolelist: window.btoa(window.encodeURIComponent(JSON.stringify(roles))),
                 LText: '',
                 LTexttb: ''
@@ -1147,6 +1216,7 @@
 
         if (['propcard', 'brafteditor', 'sandbox', 'tabbar', 'stepform', 'tabform'].includes(item.subtype) && item.wrap.datatype === 'static') return
         if (['balcony'].includes(item.type) && item.wrap.datatype === 'static') return
+        if (['menubar'].includes(item.type) && item.wrap.datatype !== 'dynamic') return
 
         if (item.setting) {
           if (item.setting.interType === 'system' && item.setting.execute !== 'false' && !item.setting.dataresource) {
@@ -1155,6 +1225,8 @@
             error = `缁勪欢銆�${item.name}銆嬫湭璁剧疆鏁版嵁婧愶紒`
           } else if (!item.setting.primaryKey) {
             error = `缁勪欢銆�${item.name}銆嬫湭璁剧疆涓婚敭锛乣
+          } else if (!item.setting.supModule && !['navbar', 'balcony', 'menubar'].includes(item.type)) {
+            error = `缁勪欢銆�${item.name}銆嬫湭璁剧疆涓婄骇缁勪欢锛乣
           }
         }
         if (item.type === 'bar' || item.type === 'line' || item.type === 'pie') {
@@ -1194,10 +1266,25 @@
   insert = (item) => {
     let config = fromJS(this.state.config).toJS()
 
+    if (item.type === 'topbar' && config.components.findIndex(m => m.type === 'topbar') > -1) {
+      notification.warning({
+        top: 92,
+        message: '瀵艰埅鏍忎笉鍙噸澶嶆坊鍔狅紒',
+        duration: 5
+      })
+      return
+    }
+
     config.components.push(item)
 
     this.setState({config})
     window.GLOB.customMenu = config
+
+    notification.success({
+      top: 92,
+      message: '绮樿创鎴愬姛锛�',
+      duration: 2
+    })
   }
 
   refreshView = () => {
@@ -1279,6 +1366,67 @@
     })
   }
 
+  setLoginView = () => {
+    const { oriConfig, config } = this.state
+
+    if (!oriConfig || !is(fromJS(oriConfig), fromJS(config))) {
+      notification.warning({
+        top: 92,
+        message: '閰嶇疆淇℃伅鏈繚瀛橈紒',
+        duration: 5
+      })
+      return
+    }
+
+    let param = {
+      func: 's_kei_link_keyids_addupt',
+      BID: sessionStorage.getItem('appId'),
+      exec_type: 'y',
+      LText: ''
+    }
+
+    let appViewList = sessionStorage.getItem('appViewList')
+    appViewList = appViewList ? JSON.parse(appViewList) : []
+    appViewList = appViewList.filter(item => item.keys_type !== 'login')
+
+    appViewList.unshift({
+      appkey: window.GLOB.appkey || '',
+      bid: sessionStorage.getItem('appId') || '',
+      kei_no: sessionStorage.getItem('kei_no') || '',
+      keys_id: config.MenuID,
+      keys_type: 'login',
+      remark: config.MenuName
+    })
+
+    param.LText = appViewList.map(item => `select '${item.keys_id}','${item.keys_type}','${item.kei_no}','${item.appkey}','${item.bid}','${sessionStorage.getItem('CloudUserID')}','${item.remark}'`)
+    param.LText = param.LText.join(' union all ')
+    param.LText = Utils.formatOptions(param.LText)
+
+    param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
+    param.secretkey = Utils.encrypt('', param.timestamp)
+
+    let hasLogin = config.components.findIndex(item => item.type === 'login') > -1
+
+    confirm({
+      title: '纭畾璁剧疆鏈〉闈负鐧诲綍椤靛悧锛�',
+      content: hasLogin ? '' : '褰撳墠椤甸潰灏氭湭娣诲姞鐧诲綍缁勪欢銆�',
+      onOk() {
+        Api.getSystemConfig(param).then(result => {
+          if (!result.status) {
+            notification.warning({
+              top: 92,
+              message: result.message,
+              duration: 5
+            })
+          } else {
+            sessionStorage.setItem('appViewList', JSON.stringify(appViewList))
+          }
+        })
+      },
+      onCancel() {}
+    })
+  }
+
   changeView = (val) => {
     if (val !== 'vertical') {
       window.GLOB.winWidth = 992
@@ -1342,6 +1490,7 @@
                     {config ? <UrlFieldComponent config={config} updateConfig={this.updateConfig}/> : null}
                     {/* 琛ㄥ悕娣诲姞 */}
                     {config ? <TableComponent config={config} updatetable={this.updateConfig}/> : null}
+                    {config ? <Paragraph style={{padding: '15px 0px 0px 18px'}} copyable={{ text: MenuId }}>鑿滃崟ID</Paragraph> : null}
                   </Panel>
                   {/* 缁勪欢娣诲姞 */}
                   <Panel header={dict['mob.component']} key="component">
@@ -1365,15 +1514,17 @@
                 <Button type="primary" onClick={this.submitConfig} loading={menuloading}>{dict['mob.save']}</Button>
                 <Switch className="big" checkedChildren={dict['mob.enable']} unCheckedChildren={dict['mob.disable']} checked={config && config.enabled} onChange={this.onEnabledChange} />
                 <CreateView resetmenu={this.getAppMenus} />
-                <PasteController type="menu" Tab={null} insert={this.insert} />
+                <PasteController insert={this.insert} />
                 <StyleCombControlButton menu={config} />
                 <SysInterface config={config} updateConfig={this.updateConfig}/>
                 <PictureController/>
                 <Quotecomponent config={config} updateConfig={this.updateConfig}/>
                 <Button className="mk-border-green" icon="home" onClick={this.setHomeView}>璁句负棣栭〉</Button>
-                <Button className="mk-border-danger" icon="redo" onClick={this.refreshView}>寮哄埗鍒锋柊</Button>
+                <Button className="mk-border-purple" icon="login" onClick={this.setLoginView}>璁句负鐧诲綍椤�</Button>
                 <ReplaceField type="custom" config={config} updateConfig={this.resetConfig}/>
                 <Transfer MenuID={MenuId} />
+                <Versions MenuId={MenuId} open_edition={config ? config.open_edition : ''}/>
+                <Button className="mk-border-danger" icon="redo" onClick={this.refreshView}>寮哄埗鍒锋柊</Button>
                 <Button type="default" onClick={this.closeView}>鍏抽棴</Button>
               </div>
             </div>

--
Gitblit v1.8.0