From 04dc8530bf6241573fe788e0e74a5cf4d9a8e0b3 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 25 八月 2022 18:29:56 +0800
Subject: [PATCH] 2022-08-25

---
 src/views/tabledesign/index.jsx |  982 ++++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 827 insertions(+), 155 deletions(-)

diff --git a/src/views/tabledesign/index.jsx b/src/views/tabledesign/index.jsx
index 27dffe6..22235cd 100644
--- a/src/views/tabledesign/index.jsx
+++ b/src/views/tabledesign/index.jsx
@@ -1,46 +1,78 @@
-import React, {Component} from 'react'
-import { notification, Spin, ConfigProvider } from 'antd'
-import enUS from 'antd/es/locale/en_US'
-import zhCN from 'antd/es/locale/zh_CN'
+import React, { Component } from 'react'
+import { DndProvider } from 'react-dnd'
+import { withRouter } from 'react-router'
+import { is, fromJS } from 'immutable'
+import moment from 'moment'
+import HTML5Backend from 'react-dnd-html5-backend'
+import { ConfigProvider, notification, Modal, Collapse, Card, Switch, Button, Typography } from 'antd'
+import { DoubleLeftOutlined, DoubleRightOutlined } from '@ant-design/icons'
 
 import Api from '@/api'
+import Utils, { setGLOBFuncs } from '@/utils/utils.js'
+import antdZhCN from 'antd/es/locale/zh_CN'
+import MKEmitter from '@/utils/events.js'
 import asyncComponent from '@/utils/asyncComponent'
-import asyncLoadComponent from '@/utils/asyncLoadComponent'
+
 import './index.scss'
 
-const _locale = sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS
-const Header = asyncComponent(() => import('@/menu/header'))
-const ComTableConfig = asyncLoadComponent(() => import('@/templates/comtableconfig'))
-const ModalConfig = asyncLoadComponent(() => import('@/templates/modalconfig'))
+const { Panel } = Collapse
+const { confirm } = Modal
+const { Paragraph } = Typography
+const _locale = antdZhCN
 
-document.body.className = ''
+const MenuForm = asyncComponent(() => import('./menuform'))
+const Header = asyncComponent(() => import('@/menu/header'))
+const MenuShell = asyncComponent(() => import('@/menu/menushell'))
+const BgController = asyncComponent(() => import('@/pc/bgcontroller'))
+const StyleController = asyncComponent(() => import('@/menu/stylecontroller'))
+const ReplaceField = asyncComponent(() => import('@/menu/replaceField'))
+const Versions = asyncComponent(() => import('@/menu/versions'))
+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 TableComponent = asyncComponent(() => import('@/templates/sharecomponent/tablecomponent'))
+
 sessionStorage.setItem('isEditState', 'true')
+sessionStorage.setItem('appType', '')          // 搴旂敤绫诲瀷
+document.body.className = ''
 
 class TableDesign extends Component {
   state = {
-    loading: false,         // 缂栬緫鑿滃崟鎴栦娇鐢ㄥ凡浣跨敤妯℃澘鏃讹紝鑾峰彇閰嶇疆淇℃伅
-    btnParam: null,         // 缂栬緫鎸夐挳鐨勯厤缃俊鎭�
-    menulist: null,         // 缂栬緫涓殑鑿滃崟
-    tabview: '',            // 閫夋嫨妯℃澘绐楀彛锛坱emplate锛夈�佸熀纭�琛ㄦ牸閰嶇疆锛圕ommonTable锛夈�佽〃鍗曪紙Modal锛夈�佸瓙琛紙SubTable锛�
-    editMenu: null,         // 缂栬緫鑿滃崟
-    editAction: null,       // 缂栬緫鎸夐挳
-    editTab: null,          // 缂栬緫鏍囩
-    tabConfig: null,        // 鏍囩閰嶇疆淇℃伅
-    editSubTab: null,       // 缂栬緫瀛愭爣绛撅紙鏍囩涓殑鏍囩锛�
-    subTabConfig: null,     // 瀛愭爣绛鹃厤缃俊鎭�
-    subConfig: null,        // 瀛愰厤缃俊鎭�
-    btnTab: null,           // 鎵撳紑鏂版爣绛炬垨褰撳墠椤甸潰鍒锋柊鐨勬寜閽�
-    btnTabConfig: null,     // 鎵撳紑鏂版爣绛炬寜閽厤缃�
-    handleMVisible: false,  // 娣诲姞鎴栦慨鏀硅彍鍗曟ā鎬佹锛堣鑹叉潈闄愬垎閰嶇瓑锛�
-    sysMenu: null,          // 娣诲姞鎴栫紪杈戣彍鍗曪紙瑙掕壊鏉冮檺鍒嗛厤绛夛級
-    change: false
+    MenuId: '',
+    ParentId: '',
+    MenuName: '',
+    MenuNo: '',
+    delButtons: [],
+    activeKey: 'basedata',
+    menuloading: false,
+    oriConfig: null,
+    config: null,
+    customComponents: [],
+    comloading: false,
+    settingshow: true,
+    modalStatus: false       // 寮圭獥鏄惁寮�鍚紝鍒ゆ柇ctrl+s鏄惁鍙敤
   }
 
   UNSAFE_componentWillMount() {
+    sessionStorage.setItem('editMenuType', 'menu') // 缂栬緫鑿滃崟绫诲瀷
+
+    window.GLOB.UserComponentMap = new Map() // 缂撳瓨鐢ㄦ埛鑷畾涔夌粍浠�
+    window.GLOB.TabsMap = new Map()          // 缂撳瓨鐢ㄦ埛鎿嶄綔鐨勬爣绛鹃〉
+    window.GLOB.urlFields = []               // url鍙橀噺
+    window.GLOB.customMenu = null            // 淇濆瓨鑿滃崟淇℃伅
+
     try {
       let param = JSON.parse(window.decodeURIComponent(window.atob(this.props.match.params.param)))
 
-      this.getMenuParam(param)
+      this.setState({
+        MenuId: param.MenuID,
+        ParentId: param.ParentId || '',
+        MenuName: param.MenuName || '',
+        MenuNo: param.MenuNo || '',
+      }, () => {
+        this.getMenuParam()
+      })
     } catch (e) {
       notification.warning({
         top: 92,
@@ -50,101 +82,71 @@
     }
   }
 
-  getMenuParam = (editMenu) => {
-    editMenu.fstMenuId = editMenu.FstId
-    editMenu.supMenuList = []
-    editMenu.fstMenuList = []
+  shouldComponentUpdate (nextProps, nextState) {
+    return !is(fromJS(this.state), fromJS(nextState))
+  }
 
-    let tree = sessionStorage.getItem('menuTree')
-    if (tree) {
-      tree = JSON.parse(tree)
-      editMenu.fstMenuList = tree
+  componentDidMount () {
+    MKEmitter.addListener('delButtons', this.delButtons)
+    MKEmitter.addListener('modalStatus', this.modalStatus)
+    MKEmitter.addListener('changePopview', this.initPopview)
+    MKEmitter.addListener('triggerMenuSave', this.triggerMenuSave)
+    MKEmitter.addListener('submitComponentStyle', this.updateComponentStyle)
+    MKEmitter.addListener('updateCustomComponent', this.updateCustomComponent)
+    setTimeout(() => {
+      if (sessionStorage.getItem('app_custom_components')) {
+        let list = sessionStorage.getItem('app_custom_components')
+        list = JSON.parse(list)
 
-      tree.forEach(item => {
-        if (item.MenuID === editMenu.FstId) {
-          editMenu.supMenuList = item.children
-        }
-      })
-    }
-
-    let param = {
-      func: 'sPC_Get_LongParam',
-      MenuID: editMenu.MenuID
-    }
-
-    this.setState({
-      loading: true
-    })
-
-    Api.getSystemConfig(param).then(res => {
-      if (res.status) {
-        editMenu.open_edition = res.open_edition || ''
-        editMenu.LongParam = ''
-
-        if (res.LongParam) {
-          let _LongParam = ''
-          try {
-            _LongParam = JSON.parse(window.decodeURIComponent(window.atob(res.LongParam)))
-          } catch (e) {
-            console.warn('Parse Failure')
-            _LongParam = ''
-          }
-          editMenu.LongParam = _LongParam
-        } else if (editMenu.PageParam.copyMenuId) {
-          let _param = {
-            func: 'sPC_Get_LongParam',
-            MenuID: editMenu.PageParam.copyMenuId
-          }
-      
-          Api.getSystemConfig(_param).then(res => {
-            if (res.status) {
-              if (res.LongParam) {
-                let _LongParam = ''
-                try {
-                  _LongParam = JSON.parse(window.decodeURIComponent(window.atob(res.LongParam)))
-                  _LongParam.type = 'user'
-                } catch (e) {
-                  console.warn('Parse Failure')
-                  _LongParam = ''
-                }
-                editMenu.LongParam = _LongParam
-              }
-              
-              this.setState({
-                editMenu: editMenu,
-                loading: false,
-                tabview: editMenu.type
-              })
-            } else {
-              this.setState({
-                loading: false
-              })
-              notification.warning({
-                top: 92,
-                message: res.message,
-                duration: 5
-              })
-            }
-          })
-          return
-        }
-        
-        this.setState({
-          editMenu: editMenu,
-          loading: false,
-          tabview: editMenu.type
-        })
+        this.setCustomComponent(list)
       } else {
-        this.setState({
-          loading: false
-        })
-        notification.warning({
-          top: 92,
-          message: res.message,
-          duration: 5
-        })
+        this.updateCustomComponent()
       }
-    })
+      this.getAppPictures()
+      this.getPrintTemp()
+      this.getRoleFields()
+      setGLOBFuncs()
+    }, 1000)
+
+    document.onkeydown = (event) => {
+      let e = event || window.event
+      let keyCode = e.keyCode || e.which || e.charCode
+      let preKey = ''
+
+      if (e.ctrlKey) {
+        preKey = 'ctrl'
+      }
+      if (e.shiftKey) {
+        preKey = 'shift'
+      } else if (e.altKey) {
+        preKey = 'alt'
+      }
+      
+      if (!preKey || !keyCode) return
+      
+      let _shortcut = `${preKey}+${keyCode}`
+
+      if (_shortcut === 'ctrl+83') {
+        if (this.state.modalStatus) {
+          notification.warning({
+            top: 92,
+            message: '璇蜂繚瀛�' + this.state.modalStatus,
+            duration: 5
+          })
+          return false
+        }
+
+        let node = document.getElementById('save-modal-config')
+        if (!node) {
+          node = document.getElementById('save-config')
+        }
+
+        if (node) {
+          node.click()
+        }
+        return false
+      }
+    }
   }
 
   /**
@@ -154,53 +156,723 @@
     this.setState = () => {
       return
     }
+    MKEmitter.removeListener('delButtons', this.delButtons)
+    MKEmitter.removeListener('modalStatus', this.modalStatus)
+    MKEmitter.removeListener('changePopview', this.initPopview)
+    MKEmitter.removeListener('triggerMenuSave', this.triggerMenuSave)
+    MKEmitter.removeListener('submitComponentStyle', this.updateComponentStyle)
+    MKEmitter.removeListener('updateCustomComponent', this.updateCustomComponent)
   }
 
-  handleView = (param) => {
-    this.setState({
-      tabview: ''
-    }, () => {
-      if (param) {
-        this.setState(param)
-      } else {
-        window.close()
+  modalStatus = (val) => {
+    this.setState({modalStatus: val})
+  }
+
+  triggerMenuSave = () => {
+    this.submitConfig()
+  }
+
+  getPrintTemp = () => {
+    if (!sessionStorage.getItem('printTemps')) {
+      let _sql = `select ID,Images,PrintTempNO+PrintTempName as PN from sPrintTemplate 
+      where appkey= @appkey@ and Deleted=0 and typechartwo='web_print'
+      union select ID,Images,a.PrintTempNO+PrintTempName as PN 
+      from (select * from sPrintTemplate where appkey= '' and Deleted=0 and typechartwo='web_print') a 
+      left join (select PrintTempNO from sPrintTemplate where appkey= @appkey@ and Deleted=0 ) b 
+      on a.PrintTempNO=b.PrintTempNO 
+      left join (select Srcid from sPrintTemplate_Log where appkey='' and apicode= @appkey@ and Deleted=0 ) c 
+      on a.ID=c.Srcid where b.PrintTempNO is null and c.Srcid is null`
+  
+      let param = {
+        func: 'sPC_Get_SelectedList',
+        LText: Utils.formatOptions(_sql),
+        obj_name: 'data',
+        arr_field: 'PN,ID,Images'
+      }
+  
+      param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
+      param.secretkey = Utils.encrypt(param.LText, param.timestamp)
+  
+      param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp) // 浜戠鏁版嵁楠岃瘉
+  
+      Api.getSystemConfig(param).then(res => {
+        if (res.status) {
+          let temps = res.data.map(temp => {
+            return {
+              value: temp.ID,
+              text: temp.PN
+            }
+          })
+  
+          sessionStorage.setItem('printTemps', JSON.stringify(temps))
+        } else {
+          notification.warning({
+            top: 92,
+            message: res.message,
+            duration: 5
+          })
+        }
+      })
+    }
+  }
+
+  getAppPictures = () => {
+    if (sessionStorage.getItem('app_videos') || sessionStorage.getItem('app_pictures')) return
+    
+    Api.getSystemConfig({
+      func: 's_url_db_adduptdel',
+      PageIndex: 0,  // 0 浠h〃鍏ㄩ儴
+      PageSize: 0,   // 0 浠h〃鍏ㄩ儴
+      typecharone: 'image',
+      type: 'search'
+    }).then(res => {
+      if (res.status) {
+        sessionStorage.setItem('app_pictures', JSON.stringify(res.data || []))
+      }
+
+      Api.getSystemConfig({
+        func: 's_url_db_adduptdel',
+        PageIndex: 0,  // 0 浠h〃鍏ㄩ儴
+        PageSize: 0,   // 0 浠h〃鍏ㄩ儴
+        typecharone: 'video',
+        type: 'search'
+      }).then(res => {
+        if (res.status) {
+          sessionStorage.setItem('app_videos', JSON.stringify(res.data || []))
+        }
+      })
+      Api.getSystemConfig({
+        func: 's_url_db_adduptdel',
+        PageIndex: 0,  // 0 浠h〃鍏ㄩ儴
+        PageSize: 0,   // 0 浠h〃鍏ㄩ儴
+        typecharone: 'color',
+        type: 'search'
+      }).then(res => {
+        if (res.status) {
+          sessionStorage.setItem('app_colors', JSON.stringify(res.data || []))
+        }
+      })
+    })
+  }
+
+  updateCustomComponent = () => {
+    Api.getSystemConfig({
+      func: 's_get_custom_components',
+      typename: '',
+      typecharone: ''
+    }).then(res => {
+      if (!res.status) {
+        notification.warning({
+          top: 92,
+          message: res.message,
+          duration: 5
+        })
+      } else if (res.cus_list) {
+        sessionStorage.setItem('app_custom_components', JSON.stringify(res.cus_list))
+        this.setCustomComponent(res.cus_list)
       }
     })
   }
 
+  setCustomComponent = (cus_list) => {
+    let coms = []
+
+    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
+
+      window.GLOB.UserComponentMap.set(item.c_id, item.c_name)
+      coms.push({
+        uuid: item.c_id,
+        type: 'menu',
+        title: item.c_name,
+        url: item.images,
+        component: config.type,
+        subtype: config.subtype,
+        config
+      })
+    })
+    this.setState({customComponents: coms})
+  }
+
+  updateComponentStyle = (parentId, keys, style) => {
+    const { config } = this.state
+
+    if (config.uuid !== parentId) return
+
+    let components = config.components.map(item => {
+      if (keys.includes(item.uuid)) {
+        item.style = {...item.style, ...style}
+      }
+      return item
+    })
+
+    this.setState({
+      config: {...config, components},
+      comloading: true
+    }, () => {
+      this.setState({
+        comloading: false
+      })
+    })
+  }
+
+  delButtons = (items) => {
+    this.setState({ delButtons: [...this.state.delButtons, ...items] })
+  }
+
+  initPopview = (card, btn) => {
+    const { oriConfig, config } = this.state
+
+    if (!is(fromJS(oriConfig), fromJS(config))) {
+      notification.warning({
+        top: 92,
+        message: '閰嶇疆宸蹭慨鏀癸紝璇蜂繚瀛橈紒',
+        duration: 5
+      })
+      return
+    }
+
+    let _btn = fromJS(btn).toJS()
+    _btn.MenuName = config.MenuName + '-' + card.name + '-' + btn.label
+    _btn.ParentMenuID = config.uuid
+
+    this.props.history.push('/popdesign/' + window.btoa(window.encodeURIComponent((JSON.stringify(_btn)))))
+  }
+
+  closeView = () => {
+    const { oriConfig, config } = this.state
+
+    if (!config) {
+      window.close()
+      return
+    }
+
+    if (!is(fromJS(oriConfig), fromJS(config))) {
+      confirm({
+        title: '閰嶇疆宸蹭慨鏀癸紝鏀惧純淇濆瓨鍚楋紵',
+        content: '',
+        onOk() {
+          window.close()
+        },
+        onCancel() {}
+      })
+    } else {
+      window.close()
+    }
+  }
+
+  getMenuParam = () => {
+    const { MenuId, ParentId, MenuName, MenuNo } = this.state
+
+    let param = {
+      func: 'sPC_Get_LongParam',
+      MenuID: MenuId
+    }
+
+    Api.getSystemConfig(param).then(result => {
+      if (result.status) {
+        let config = null
+
+        try {
+          config = result.LongParam ? JSON.parse(window.decodeURIComponent(window.atob(result.LongParam))) : null
+        } catch (e) {
+          console.warn('Parse Failure')
+          config = null
+        }
+
+        if (!config) {
+          config = {
+            version: 1.0,
+            uuid: MenuId,
+            MenuID: MenuId,
+            parentId: ParentId,
+            Template: 'BaseTable',
+            easyCode: '',
+            enabled: false,
+            MenuName: MenuName,
+            MenuNo: MenuNo,
+            tables: [],
+            components: [],
+            viewType: 'menu',
+            style: {
+              backgroundColor: '#ffffff', backgroundImage: '',
+              paddingTop: '16px', paddingBottom: '80px', paddingLeft: '16px', paddingRight: '16px'
+            },
+          }
+        } else {
+          config.uuid = MenuId
+          config.MenuID = MenuId
+          config.Template = 'BaseTable'
+        }
+
+        config.open_edition = result.open_edition || ''
+        window.GLOB.urlFields = config.urlFields || []
+
+        this.setState({
+          oriConfig: config,
+          config: fromJS(config).toJS()
+        })
+        window.GLOB.customMenu = config
+      } else {
+        notification.warning({
+          top: 92,
+          message: result.message,
+          duration: 5
+        })
+      }
+    })
+  }
+
+  getMenuMessage = (delButtons) => {
+    const { config } = this.state
+    let buttons = []
+    let _sort = 1
+
+    let traversal = (components) => {
+      components.forEach(item => {
+        if (item.type === 'tabs') {
+          item.subtabs.forEach(tab => {
+            traversal(tab.components)
+          })
+        } else if (item.type === 'group') {
+          traversal(item.components)
+        } else if (item.type === 'card' || (item.type === 'table' && item.subtype === 'tablecard')) {
+          item.action && item.action.forEach(btn => {
+            if (btn.hidden === 'true') {
+              delButtons.push(btn.uuid)
+              return
+            }
+            buttons.push(`select '${btn.uuid}' as menuid, '${item.name + '-' + btn.label}' as menuname, '${_sort * 10}' as Sort`)
+            _sort++
+          })
+          item.subcards.forEach(card => {
+            card.elements && card.elements.forEach(cell => {
+              if (cell.eleType !== 'button') return
+              if (cell.hidden === 'true') {
+                delButtons.push(cell.uuid)
+                return
+              }
+              buttons.push(`select '${cell.uuid}' as menuid, '${item.name + '-' + cell.label}' as menuname, '${_sort * 10}' as Sort`)
+              _sort++
+            })
+            card.backElements && card.backElements.forEach(cell => {
+              if (cell.eleType !== 'button') return
+              if (cell.hidden === 'true') {
+                delButtons.push(cell.uuid)
+                return
+              }
+              buttons.push(`select '${cell.uuid}' as menuid, '${item.name + '-' + cell.label}' as menuname, '${_sort * 10}' as Sort`)
+              _sort++
+            })
+          })
+        } else if (item.type === 'carousel' || item.type === 'timeline') {
+          item.subcards.forEach(card => {
+            card.elements && card.elements.forEach(cell => {
+              if (cell.eleType !== 'button') return
+              if (cell.hidden === 'true') {
+                delButtons.push(cell.uuid)
+                return
+              }
+              buttons.push(`select '${cell.uuid}' as menuid, '${item.name + '-' + cell.label}' as menuname, '${_sort * 10}' as Sort`)
+              _sort++
+            })
+          })
+        } else if (item.type === 'balcony') {
+          item.elements && item.elements.forEach(cell => {
+            if (cell.eleType !== 'button') return
+            if (cell.hidden === 'true') {
+              delButtons.push(cell.uuid)
+              return
+            }
+            buttons.push(`select '${cell.uuid}' as menuid, '${item.name + '-' + cell.label}' as menuname, '${_sort * 10}' as Sort`)
+            _sort++
+          })
+        } else if (item.type === 'line' || item.type === 'bar' || item.type === 'chart') {
+          item.action && item.action.forEach(btn => {
+            if (btn.hidden === 'true') {
+              delButtons.push(btn.uuid)
+              return
+            }
+            buttons.push(`select '${btn.uuid}' as menuid, '${item.name + '-' + btn.label}' as menuname, '${_sort * 10}' as Sort`)
+            _sort++
+          })
+        } else if (item.type === 'table' && (item.subtype === 'normaltable' || item.subtype === 'editable')) {
+          item.action && item.action.forEach(btn => {
+            if (btn.hidden === 'true') {
+              delButtons.push(btn.uuid)
+              return
+            }
+            buttons.push(`select '${btn.uuid}' as menuid, '${item.name + '-' + btn.label}' as menuname, '${_sort * 10}' as Sort`)
+            _sort++
+          })
+          item.cols && item.cols.forEach(col => {
+            if (col.type !== 'action') return
+            col.elements.forEach(btn => {
+              if (btn.hidden === 'true') {
+                delButtons.push(btn.uuid)
+                return
+              }
+              buttons.push(`select '${btn.uuid}' as menuid, '${item.name + '-' + btn.label}' as menuname, '${_sort * 10}' as Sort`)
+              _sort++
+            })
+          })
+        }
+      })
+    }
+
+    traversal(config.components)
+
+    return buttons
+  }
+
+  submitConfig = () => {
+    let config = fromJS(this.state.config).toJS()
+
+    if (!config.MenuName || !config.MenuNo || !config.fstMenuId || !config.parentId) {
+      notification.warning({
+        top: 92,
+        message: '璇峰畬鍠勮彍鍗曞熀鏈俊鎭紒',
+        duration: 5
+      })
+      return
+    }
+
+    this.setState({
+      menuloading: true
+    })
+
+    setTimeout(() => {
+      if (config.enabled && this.verifyConfig()) {
+        config.enabled = false
+      }
+
+      let param = {
+        func: 'sPC_TrdMenu_AddUpt',
+        FstID: config.fstMenuId || '',
+        SndID: config.parentId,
+        ParentID: config.parentId,
+        MenuID: config.uuid,
+        MenuNo: config.MenuNo || '',
+        EasyCode: config.easyCode || '',
+        Template: 'BaseTable',
+        MenuName: config.MenuName || '',
+        PageParam: JSON.stringify({Template: 'BaseTable', OpenType: config.OpenType || 'newtab', hidden: config.hidden || 'false'}),
+        LongParam: window.btoa(window.encodeURIComponent(JSON.stringify(config))),
+        open_edition: config.open_edition,
+        LText: '',
+        LTexttb: ''
+      }
+
+      param.LText = Utils.formatOptions(param.LText)
+      param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
+      param.secretkey = Utils.encrypt(param.LText, param.timestamp)
+
+      let btnParam = {             // 娣诲姞鑿滃崟鎸夐挳
+        func: 'sPC_Button_AddUpt',
+        Type: 40,                  // 娣诲姞鑿滃崟涓嬬殑鎸夐挳type涓�40锛屾寜閽笅鐨勬寜閽畉ype涓�60
+        ParentID: config.uuid,
+        MenuNo: config.MenuNo,
+        Template: 'BaseTable',
+        PageParam: '',
+        LongParam: '',
+        LText: []
+      }
+
+      let delButtons = fromJS(this.state.delButtons).toJS()
+
+      btnParam.LText = this.getMenuMessage(delButtons)
+      btnParam.LText = btnParam.LText.join(' union all ')
+
+      btnParam.LText = Utils.formatOptions(btnParam.LText)
+      btnParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
+      btnParam.secretkey = Utils.encrypt(btnParam.LText, btnParam.timestamp)
+
+      new Promise(resolve => {
+        resolve(true)
+      }).then(res => { // 鎸夐挳鍒犻櫎
+        if (delButtons.length === 0) {
+          return {
+            status: true
+          }
+        } else {
+          let _param = {
+            func: 'sPC_MainMenu_Del',
+            MenuID: delButtons.join(',')
+          }
+          return Api.getSystemConfig(_param)
+        }
+      }).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) {
+          let ori = this.state.oriConfig
+          if (config.MenuName !== ori.MenuName || config.MenuNo !== ori.MenuNo || config.parentId !== ori.parentId) {
+            localStorage.setItem('menuUpdate', new Date().getTime())
+          }
+          config.open_edition = res.open_edition || ''
+          this.setState({
+            config,
+            oriConfig: fromJS(config).toJS(),
+          })
+
+          if (btnParam.LText) {
+            return Api.getSystemConfig(btnParam)
+          } else {
+            return {
+              status: true
+            }
+          }
+        } else {
+          notification.warning({
+            top: 92,
+            message: res.message,
+            duration: 5
+          })
+          return false
+        }
+      }).then(res => { // 鎸夐挳澶嶅埗
+        if (!res) return
+        if (!res.status) {
+          notification.warning({
+            top: 92,
+            message: res.message,
+            duration: 5
+          })
+          return false
+        }
+      }).then(res => {
+        if (res && res.status) {
+          this.setState({
+            delButtons: [],
+            menuloading: false
+          })
+          notification.success({
+            top: 92,
+            message: '淇濆瓨鎴愬姛',
+            duration: 2
+          })
+        } else {
+          this.setState({
+            menuloading: false
+          })
+        }
+        MKEmitter.emit('completeSave')
+      })
+    }, 300 + (+sessionStorage.getItem('mkDelay')))
+  }
+
+  getRoleFields = () => {
+    if (sessionStorage.getItem('sysRoles')) return
+    Api.getSystemConfig({func: 'sPC_Get_Roles_sModular'}).then(res => {
+      if (res.status) {
+        let _permFuncField = []
+        let _sysRoles = []
+
+        if (res.Roles && res.Roles.length > 0) {
+          _sysRoles = res.Roles.map(role => {
+            return {
+              uuid: Utils.getuuid(),
+              value: role.RoleID,
+              text: role.RoleName
+            }
+          })
+        }
+
+        if (res.sModular && res.sModular.length > 0) {
+          res.sModular.forEach(field => {
+            if (field.ModularNo) {
+              _permFuncField.push(field.ModularNo)
+            }
+          })
+          _permFuncField = _permFuncField.sort()
+        }
+
+        sessionStorage.setItem('sysRoles', JSON.stringify(_sysRoles))
+        sessionStorage.setItem('permFuncField', JSON.stringify(_permFuncField))
+      }
+    })
+  }
+
+  onEnabledChange = () => {
+    const { config } = this.state
+
+    if (!config || (!config.enabled && this.verifyConfig(true))) {
+      return
+    }
+
+    this.setState({
+      config: {...config, enabled: !config.enabled}
+    })
+  }
+
+  verifyConfig = (show) => {
+    const { config } = this.state
+    let error = ''
+
+    let check = (components) => {
+      components.forEach(item => {
+        if (error) return
+        
+        if (item.type === 'tabs') {
+          item.subtabs.forEach(tab => {
+            check(tab.components)
+          })
+          return
+        } else if (item.type === 'group') {
+          check(item.components)
+          return
+        } else if (!item.errors || item.errors.length === 0) {
+          return
+        }
+
+        item.errors.forEach(err => {
+          if (err.level !== 0 || error) return
+          error = `缁勪欢銆�${item.name}銆�${err.detail}`
+        })
+      })
+    }
+
+    check(config.components)
+
+    if (show && error) {
+      notification.warning({
+        top: 92,
+        message: error,
+        duration: 5
+      })
+    }
+
+    return error
+  }
+
+  // 鏇存柊閰嶇疆淇℃伅
+  updateConfig = (config) => {
+    this.setState({
+      config: config
+    })
+    window.GLOB.customMenu = config
+  }
+
+  resetConfig = (config) => {
+    this.setState({
+      config,
+      comloading: true
+    }, () => {
+      this.setState({
+        comloading: false
+      })
+    })
+    window.GLOB.customMenu = config
+  }
+
+  insert = (item) => {
+    let config = fromJS(this.state.config).toJS()
+
+    config.components.push(item)
+
+    this.setState({config})
+    window.GLOB.customMenu = config
+
+    notification.success({
+      top: 92,
+      message: '绮樿创鎴愬姛锛�',
+      duration: 2
+    })
+  }
+
+  changeSetting = () => {
+    this.setState({settingshow: !this.state.settingshow})
+
+    setTimeout(() => {
+      MKEmitter.emit('tabsChange', 'all')
+    }, 400)
+  }
+
   render () {
-    const { loading } = this.state
+    const { activeKey, comloading, MenuId, config, settingshow, ParentId, menuloading } = this.state
 
     return (
-      <div className="mk-base-design-wrap">
-        <ConfigProvider locale={_locale}>
-          <Header/>
-          {this.state.tabview === 'CommonTable' ?
-            <ComTableConfig
-              menu={this.state.editMenu}
-              reloadmenu={() => {localStorage.setItem('menuUpdate', new Date().getTime())}}
-              handleView={this.handleView}
-            /> : null
-          }
-          {this.state.tabview === 'Modal' ?
-            <ModalConfig
-              menu={this.state.editMenu}
-              editTab={this.state.editTab}
-              tabConfig={this.state.tabConfig}
-              editSubTab={this.state.editSubTab}
-              subTabConfig={this.state.subTabConfig}
-              btnTab={this.state.btnTab}
-              btnTabConfig={this.state.btnTabConfig}
-              editAction={this.state.editAction}
-              subConfig={this.state.subConfig}
-              handleView={this.handleView}
-            /> : null
-          }
-          {loading ? <Spin className="loading-view" size="large"/> : null}
-        </ConfigProvider>
-      </div>
+      <ConfigProvider locale={_locale}>
+        <div className="pc-table-view">
+          <Header />
+          <DndProvider backend={HTML5Backend}>
+            <div className="menu-body">
+              <div className={'menu-setting ' + (!settingshow ? 'hidden' : '')}>
+                <div className="draw">
+                  {settingshow ? <DoubleLeftOutlined onClick={this.changeSetting}/> : <DoubleRightOutlined onClick={this.changeSetting}/>}
+                </div>
+                <Collapse accordion activeKey={activeKey} bordered={false} onChange={(key) => this.setState({activeKey: key})}>
+                  {/* 鍩烘湰淇℃伅 */}
+                  <Panel header="鍩烘湰淇℃伅" key="basedata">
+                    {/* 鑿滃崟淇℃伅 */}
+                    {config ? <MenuForm
+                      config={config}
+                      MenuId={MenuId}
+                      parentId={ParentId}
+                      MenuName={config.MenuName}
+                      MenuNo={config.MenuNo}
+                      updateConfig={this.updateConfig}
+                    /> : null}
+                    {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="椤甸潰鏍峰紡" key="background">
+                    {config ? <BgController config={config} updateConfig={this.updateConfig} /> : null}
+                  </Panel>
+                </Collapse>
+              </div>
+              <div className={'menu-view' + (menuloading ? ' saving' : '')}>
+                <Card title={
+                  <div style={{paddingLeft: '15px'}}> {config && config.MenuName} </div>
+                } bordered={false} extra={
+                  <div>
+                    <Versions MenuId={MenuId} open_edition={config ? config.open_edition : ''}/>
+                    <ReplaceField type="custom" config={config} updateConfig={this.resetConfig}/>
+                    <SysInterface config={config} updateConfig={this.updateConfig}/>
+                    <PictureController/>
+                    <Switch className="big" checkedChildren="鍚�" unCheckedChildren="鍋�" checked={config && config.enabled} onChange={this.onEnabledChange} />
+                    <Button type="primary" id="save-config" onClick={this.submitConfig} loading={menuloading}>淇濆瓨</Button>
+                    <Button type="default" onClick={this.closeView}>鍏抽棴</Button>
+                  </div>
+                } style={{ width: '100%' }}>
+                  {config && !comloading ? <MenuShell menu={config} handleList={this.updateConfig} /> : null}
+                </Card>
+              </div>
+            </div>
+          </DndProvider>
+          <StyleController />
+          <ModalController />
+        </div>
+      </ConfigProvider>
     )
   }
 }
 
-export default TableDesign
\ No newline at end of file
+export default withRouter(TableDesign)
\ No newline at end of file

--
Gitblit v1.8.0