From f3167f8371d19d0ea8fe7d0e7af5517ff0b08cd2 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期三, 07 四月 2021 23:25:29 +0800
Subject: [PATCH] 2021-04-07

---
 src/views/menudesign/index.jsx |  124 ++++++++++++++++-------------------------
 1 files changed, 49 insertions(+), 75 deletions(-)

diff --git a/src/views/menudesign/index.jsx b/src/views/menudesign/index.jsx
index c79828e..84cee4d 100644
--- a/src/views/menudesign/index.jsx
+++ b/src/views/menudesign/index.jsx
@@ -1,5 +1,4 @@
 import React, { Component } from 'react'
-import { connect } from 'react-redux'
 import { DndProvider } from 'react-dnd'
 import { is, fromJS } from 'immutable'
 import moment from 'moment'
@@ -15,15 +14,14 @@
 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 MenuUtils from '@/utils/utils-custom.js'
 import asyncComponent from '@/utils/asyncComponent'
-import { modifyCustomMenu } from '@/store/action'
 
 import './index.scss'
 
 const { Panel } = Collapse
 const { confirm } = Modal
-const _locale = localStorage.getItem('lang') !== 'en-US' ? antdZhCN : antdEnUS
+const _locale = sessionStorage.getItem('lang') !== 'en-US' ? antdZhCN : antdEnUS
 
 const MenuForm = asyncComponent(() => import('./menuform'))
 const HomeForm = asyncComponent(() => import('./homeform'))
@@ -37,6 +35,7 @@
 const PaddingController = asyncComponent(() => import('@/menu/padcontroller'))
 const StyleController = asyncComponent(() => import('@/menu/stylecontroller'))
 const SysInterface = asyncComponent(() => import('@/menu/sysinterface'))
+const UrlFieldComponent = asyncComponent(() => import('@/menu/urlfieldcomponent'))
 const PictureController = asyncComponent(() => import('@/menu/picturecontroller'))
 const ModalController = asyncComponent(() => import('@/menu/modalconfig/controller'))
 const StyleCombController = asyncComponent(() => import('@/menu/stylecombcontroller'))
@@ -47,23 +46,23 @@
 sessionStorage.setItem('editMenuType', 'menu') // 缂栬緫鑿滃崟绫诲瀷
 document.body.className = ''
 window.GLOB.UserComponentMap = new Map() // 缂撳瓨鐢ㄦ埛鑷畾涔夌粍浠�
+window.GLOB.urlFields = []               // url鍙橀噺
+window.GLOB.customMenu = null            // 淇濆瓨鑿滃崟淇℃伅
 
 class MenuDesign extends Component {
   state = {
-    dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
+    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
     MenuType: '',
     MenuId: '',
     ParentId: '',
     MenuName: '',
     MenuNo: '',
-    tableFields: [],
     delButtons: [],
     copyButtons: [],
     thawButtons: [],
     activeKey: 'basedata',
     menuloading: false,
     oriConfig: null,
-    openEdition: '',
     config: null,
     popBtn: null,             // 寮圭獥鏍囩椤�
     visible: false,
@@ -228,10 +227,7 @@
   initPopview = (card, btn) => {
     const { oriConfig, config } = this.state
 
-    let _config = fromJS(config).toJS()
-    delete _config.tableFields
-
-    if (!is(fromJS(oriConfig), fromJS(_config))) {
+    if (!is(fromJS(oriConfig), fromJS(config))) {
       notification.warning({
         top: 92,
         message: '閰嶇疆宸蹭慨鏀癸紝璇蜂繚瀛橈紒',
@@ -240,7 +236,7 @@
       return
     }
 
-    btn.config = _config
+    btn.config = fromJS(config).toJS()
     btn.component = card
 
     sessionStorage.setItem('editMenuType', 'popview') // 缂栬緫寮圭獥鏍囩
@@ -251,7 +247,7 @@
   handleBack = () => {
     this.setState({popBtn: null, delButtons: [], copyButtons: []}, () => {
       sessionStorage.setItem('editMenuType', 'menu')
-      this.props.modifyCustomMenu(this.state.config)
+      window.GLOB.customMenu = this.state.config
       this.setState({visible: false})
     })
   }
@@ -264,10 +260,7 @@
       return
     }
 
-    let _config = fromJS(config).toJS()
-    delete _config.tableFields
-
-    if (!is(fromJS(oriConfig), fromJS(_config))) {
+    if (!is(fromJS(oriConfig), fromJS(config))) {
       confirm({
         title: '閰嶇疆宸蹭慨鏀癸紝鏀惧純淇濆瓨鍚楋紵',
         content: '',
@@ -341,13 +334,14 @@
           config.lastCount = config.lastCount || ''
         }
 
+        config.open_edition = result.open_edition || ''
+        window.GLOB.urlFields = config.urlFields || []
+
         this.setState({
           oriConfig: config,
-          config: fromJS(config).toJS(),
-          openEdition: result.open_edition || '',
+          config: fromJS(config).toJS()
         })
-
-        this.props.modifyCustomMenu(config)
+        window.GLOB.customMenu = config
       } else {
         notification.warning({
           top: 92,
@@ -385,6 +379,15 @@
               _sort++
             })
             card.backElements && card.backElements.forEach(cell => {
+              if (cell.eleType !== 'button') return
+              this.checkBtn(cell)
+              buttons.push(`select '${cell.uuid}' as menuid, '${item.name + '-' + cell.label}' as menuname, '${_sort * 10}' as Sort`)
+              _sort++
+            })
+          })
+        } else if (item.type === 'carousel') {
+          item.subcards.forEach(card => {
+            card.elements && card.elements.forEach(cell => {
               if (cell.eleType !== 'button') return
               this.checkBtn(cell)
               buttons.push(`select '${cell.uuid}' as menuid, '${item.name + '-' + cell.label}' as menuname, '${_sort * 10}' as Sort`)
@@ -458,7 +461,7 @@
   }
 
   submitConfig = () => {
-    const { openEdition, MenuType, delButtons, copyButtons, thawButtons } = this.state
+    const { MenuType, delButtons, copyButtons, thawButtons } = this.state
     let config = fromJS(this.state.config).toJS()
 
     if (MenuType === 'billPrint' && (!config.firstCount || !config.everyPCount)) {
@@ -495,21 +498,19 @@
         config.enabled = false
       }
 
-      let _config = fromJS(config).toJS()
-      delete _config.tableFields
-
       let param = {
         func: 'sPC_TrdMenu_AddUpt',
-        FstID: _config.fstMenuId || '',
-        SndID: _config.parentId,
-        ParentID: _config.parentId,
-        MenuID: _config.uuid,
-        MenuNo: _config.MenuNo || '',
-        EasyCode: _config.easyCode || '',
+        FstID: config.fstMenuId || '',
+        SndID: config.parentId,
+        ParentID: config.parentId,
+        MenuID: config.uuid,
+        MenuNo: config.MenuNo || '',
+        EasyCode: config.easyCode || '',
         Template: 'CustomPage',
-        MenuName: _config.MenuName || '',
-        PageParam: JSON.stringify({Template: 'CustomPage', OpenType: 'newtab'}),
-        LongParam: window.btoa(window.encodeURIComponent(JSON.stringify(_config))),
+        MenuName: config.MenuName || '',
+        PageParam: JSON.stringify({Template: 'CustomPage', OpenType: config.OpenType || 'newtab'}),
+        LongParam: window.btoa(window.encodeURIComponent(JSON.stringify(config))),
+        open_edition: config.open_edition,
         LText: '',
         LTexttb: ''
       }
@@ -518,15 +519,11 @@
       param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
       param.secretkey = Utils.encrypt(param.LText, param.timestamp)
 
-      if (openEdition) { // 鐗堟湰绠$悊
-        param.open_edition = openEdition
-      }
-
       let btnParam = {             // 娣诲姞鑿滃崟鎸夐挳
         func: 'sPC_Button_AddUpt',
         Type: 40,                  // 娣诲姞鑿滃崟涓嬬殑鎸夐挳type涓�40锛屾寜閽笅鐨勬寜閽畉ype涓�60
-        ParentID: _config.uuid,
-        MenuNo: _config.MenuNo,
+        ParentID: config.uuid,
+        MenuNo: config.MenuNo,
         Template: 'CustomPage',
         PageParam: '',
         LongParam: '',
@@ -564,7 +561,7 @@
               if (result.status) {
                 Api.getSystemConfig({
                   func: 's_PrintTemplateMSub',
-                  ID: _config.uuid,
+                  ID: config.uuid,
                   Images: Utils.getcloudurl(result.Images),
                   Remark: '',
                   temp_type: 'billprint',
@@ -646,9 +643,9 @@
         if (!res) return
 
         if (res.status) {
+          config.open_edition = res.open_edition || ''
           this.setState({
-            oriConfig: fromJS(_config).toJS(),
-            openEdition: res.open_edition || ''
+            oriConfig: fromJS(config).toJS()
           })
 
           if (btnParam.LText) {
@@ -720,7 +717,7 @@
 
                     let _param = {
                       func: 'sPC_ButtonParam_AddUpt',
-                      ParentID: _config.uuid,
+                      ParentID: config.uuid,
                       MenuID: item.uuid,
                       MenuNo: '',
                       Template: 'CustomPage',
@@ -869,8 +866,7 @@
     this.setState({
       config: config
     })
-
-    this.props.modifyCustomMenu(config)
+    window.GLOB.customMenu = config
   }
 
   insert = (item) => {
@@ -879,23 +875,7 @@
     config.components.push(item)
 
     this.setState({config})
-    this.props.modifyCustomMenu(config)
-  }
-
-  /**
-   * @description 鏇存柊甯哥敤琛ㄤ俊鎭紝蹇嵎娣诲姞鍚庢洿鏂伴厤缃俊鎭�
-   */
-  updatetable = (config, fields) => {
-    const { tableFields } = this.state
-
-    config.tableFields = fields ? fields : tableFields
-
-    this.setState({
-      tableFields: fields ? fields : tableFields,
-      config
-    })
-
-    this.props.modifyCustomMenu(config)
+    window.GLOB.customMenu = config
   }
 
   render () {
@@ -921,6 +901,10 @@
                       MenuNo={MenuNo}
                       updateConfig={this.updateConfig}
                     /> : null}
+                    {config && MenuType === 'custom' ? <UrlFieldComponent
+                      config={config}
+                      updateConfig={this.updateConfig}
+                    /> : null}
                     {config && MenuType === 'home' ? <HomeForm
                       dict={dict}
                       config={config}
@@ -932,7 +916,7 @@
                       updateConfig={this.updateConfig}
                     /> : null}
                     {/* 琛ㄥ悕娣诲姞 */}
-                    {config ? <TableComponent config={config} updatetable={this.updatetable}/> : null}
+                    {config ? <TableComponent config={config} updatetable={this.updateConfig}/> : null}
                   </Panel>
                   {/* 缁勪欢娣诲姞 */}
                   <Panel header={dict['mob.component']} key="component">
@@ -978,14 +962,4 @@
   }
 }
 
-const mapStateToProps = () => {
-  return {}
-}
-
-const mapDispatchToProps = (dispatch) => {
-  return {
-    modifyCustomMenu: (customMenu) => dispatch(modifyCustomMenu(customMenu))
-  }
-}
-
-export default connect(mapStateToProps, mapDispatchToProps)(MenuDesign)
\ No newline at end of file
+export default MenuDesign
\ No newline at end of file

--
Gitblit v1.8.0