From b488c2f9630583a72e2bcae3df68f4227622ec78 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期六, 15 六月 2024 13:42:21 +0800
Subject: [PATCH] 2024-06-15

---
 src/views/design/header/transmenu/index.jsx |  350 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 343 insertions(+), 7 deletions(-)

diff --git a/src/views/design/header/transmenu/index.jsx b/src/views/design/header/transmenu/index.jsx
index c31228e..67cba4f 100644
--- a/src/views/design/header/transmenu/index.jsx
+++ b/src/views/design/header/transmenu/index.jsx
@@ -3,15 +3,20 @@
 import { Modal, notification, Button, Spin, Cascader } from 'antd'
 // import { ClockCircleOutlined, SyncOutlined, WarningOutlined, CheckCircleOutlined } from '@ant-design/icons'
 import moment from 'moment'
+import md5 from 'md5'
 
 import Api from '@/api'
 import Utils from '@/utils/utils.js'
+import MenuUtils, { setLangTrans } from '@/utils/utils-custom.js'
 import './index.scss'
+
+const { confirm } = Modal
 
 class TransMenu extends Component {
   state = {
     visible: false,
     loading: false,
+    saveing: false,
     lang: '',
     dicts: [],
     menus: [],
@@ -30,6 +35,7 @@
       lang: langs[0],
       loading: true,
       visible: true,
+      saveing: false,
       values: []
     })
     
@@ -135,25 +141,354 @@
         menus.push(fstItem)
       })
 
+      menus.push({
+        value: 'home_page_id',
+        label: '棣栭〉',
+      })
+
       this.setState({menus: menus, loading: false})
     })
   }
 
   submit = () => {
-    const { menulist } = this.props
     const { values } = this.state
 
-    if (!values || values.length !== 3) {
+    if (!values || (values.length !== 3 && values[0] !== 'home_page_id')) {
       notification.warning({
         top: 92,
-        message: '璇烽�夋嫨涓夌骇鑿滃崟锛�',
+        message: '璇烽�夋嫨鑿滃崟锛�',
         duration: 5
       })
       return
     }
-    
-    console.log(values)
-    console.log(menulist)
+
+    this.setState({saveing: true})
+
+    if (values[0] === 'home_page_id') {
+      this.transThdMenu({
+        value: 'home_page_id',
+        MenuID: 'home_page_id',
+        label: '棣栭〉'
+      })
+    } else {
+      this.transFirstMenu(values[0], values[1], values[2])
+    }
+  }
+
+  transFirstMenu = (firstId, secId, thdId) => {
+    const { menulist } = this.props
+    const { menus, dicts } = this.state
+    let tail = md5(window.GLOB.appkey + sessionStorage.getItem('lang')).toLowerCase()
+
+    tail = tail.slice(-8)
+
+    let oriFirstMenu = menus.filter(item => item.value === firstId)[0]
+    let oriSecMenu = oriFirstMenu.children.filter(item => item.value === secId)[0]
+    let oriThdMenu = oriSecMenu.children.filter(item => item.value === thdId)[0]
+
+    oriThdMenu = fromJS(oriThdMenu).toJS()
+
+    let curFirstId = firstId
+    if (curFirstId.length <= 24) {
+      curFirstId = md5(window.GLOB.appkey + curFirstId + sessionStorage.getItem('lang')).toLowerCase()
+    } else {
+      curFirstId = curFirstId.slice(0, 24) + tail
+    }
+
+    let curSectId = secId
+    if (curSectId.length <= 24) {
+      curSectId = md5(window.GLOB.appkey + curSectId + sessionStorage.getItem('lang')).toLowerCase()
+    } else {
+      curSectId = curSectId.slice(0, 24) + tail
+    }
+
+    let curThdId = thdId
+    if (curThdId.length <= 24) {
+      curThdId = md5(window.GLOB.appkey + curThdId + sessionStorage.getItem('lang')).toLowerCase()
+    } else {
+      curThdId = curThdId.slice(0, 24) + tail
+    }
+
+    let firstName = oriFirstMenu.label
+    let secName = oriSecMenu.label
+
+    dicts.forEach(item => {
+      if (item.type !== 'menu') return
+      if (item.reg === firstName) {
+        firstName = item.value
+      }
+      if (item.reg === secName) {
+        secName = item.value
+      }
+      if (item.reg === oriThdMenu.label) {
+        oriThdMenu.label = item.value
+      }
+    })
+
+    let firstParam = {
+      func: 'sPC_MainMenu_Add',
+      MenuID: curFirstId,
+      MenuName: firstName,
+      PageParam: JSON.stringify({
+        OpenType: 'menu',
+        linkUrl: ''
+      })
+    }
+
+    let secParam = {
+      func: 'sPC_SndMenu_Add',
+      ParentID: curFirstId,
+      MenuID: curSectId,
+      MenuName: secName,
+      PageParam: JSON.stringify({
+        Icon: ''
+      })
+    }
+
+    oriThdMenu.fstMenuId = curFirstId
+    oriThdMenu.parentId = curSectId
+    oriThdMenu.MenuID = curThdId
+
+    if (menulist.findIndex(item => item.MenuID === firstParam.MenuID) === -1) {
+      Api.getCloudConfig(firstParam).then(res => {
+        if (!res.status) {
+          notification.warning({
+            top: 92,
+            message: res.message,
+            duration: 5
+          })
+          this.setState({saveing: false})
+          return
+        }
+
+        this.transSecondMenu(secParam, oriThdMenu, true)
+      })
+    } else {
+      this.transSecondMenu(secParam, oriThdMenu)
+    }
+  }
+
+  transSecondMenu = (secParam, oriThdMenu, reload) => {
+    const { menulist } = this.props
+
+    let creat = true
+
+    menulist.forEach(item => {
+      if (item.children.findIndex(cell => cell.MenuID === secParam.MenuID) > -1) {
+        creat = false
+      }
+    })
+
+    if (creat) {
+      Api.getCloudConfig(secParam).then(res => {
+        if (!res.status) {
+          notification.warning({
+            top: 92,
+            message: res.message,
+            duration: 5
+          })
+          this.setState({saveing: false})
+          return
+        }
+
+        this.transThdMenu(oriThdMenu, true)
+      })
+    } else {
+      this.transThdMenu(oriThdMenu, reload)
+    }
+  }
+
+  transThdMenu = (menu, reload) => {
+    const { menulist } = this.props
+    const { lang, dicts } = this.state
+
+    let _param = {
+      func: 'sPC_Get_LongParam',
+      MenuID: menu.value,
+      lang: lang
+    }
+
+    let creat = true
+
+    if (menu.MenuID === 'home_page_id') {
+      creat = false
+    } else {
+      menulist.forEach(item => {
+        item.children.forEach(cell => {
+          if (cell.children.findIndex(n => n.MenuID === menu.MenuID) > -1) {
+            creat = false
+          }
+        })
+      })
+    }
+
+    Api.getCloudConfig(_param).then(res => {
+      if (!res.status) {
+        notification.warning({
+          top: 92,
+          message: res.message,
+          duration: 5
+        })
+        this.setState({saveing: false})
+        return
+      }
+
+      let config = null
+      if (res.LongParam) {
+        try {
+          config = JSON.parse(window.decodeURIComponent(window.atob(res.LongParam)))
+        } catch (e) {
+          console.warn('Parse Failure')
+          config = ''
+        }
+      }
+
+      if (!config) {
+        notification.warning({
+          top: 92,
+          message: '鏈幏鍙栧埌鑿滃崟閰嶇疆淇℃伅',
+          duration: 5
+        })
+        this.setState({saveing: false})
+
+        if (reload) {
+          this.props.reload()
+        }
+        return
+      }
+
+      let btnDict = {}
+      let titDict = {}
+      let lisDict = {}
+      let regs = []
+
+      dicts.forEach(item => {
+        if (item.type === 'button') {
+          btnDict[item.reg] = item.value
+        } else if (item.type === 'title') {
+          titDict[item.reg] = item.value
+        } else if (item.type === 'list') {
+          lisDict[item.reg] = item.value
+        } else if (item.type === 'text') {
+          regs.push({reg: new RegExp(item.reg, 'g'), value: item.value, sort: item.reg.length})
+        }
+      })
+
+      regs.sort((a, b) => b.sort - a.sort)
+
+      let tail = md5(window.GLOB.appkey + sessionStorage.getItem('lang')).toLowerCase()
+
+      tail = tail.slice(-8)
+
+      setLangTrans(config, btnDict, titDict, lisDict, regs, tail)
+
+      if (config.components) {
+        let commonId = Utils.getuuid()
+        if (config.interfaces && config.interfaces.length > 0) {
+          config.interfaces = config.interfaces.map(inter => {
+            inter.uuid = md5(commonId + inter.uuid)
+            return inter
+          })
+        }
+        config.components = MenuUtils.resetConfig(config.components, commonId, false)
+        config.tables = config.tables || []
+        config.style = config.style || {}
+      }
+
+      config.MenuName = menu.label
+      config.fstMenuId = menu.fstMenuId || ''
+      config.parentId = menu.parentId || ''
+      config.uuid = menu.MenuID || ''
+      config.open_edition = ''
+      if (config.MenuNo) {
+        config.MenuNo = config.MenuNo + '_' + sessionStorage.getItem('lang')
+      }
+
+      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: config.Template,
+        MenuName: config.MenuName || '',
+        PageParam: JSON.stringify({Template: config.Template, OpenType: config.OpenType || 'newtab'})
+      }
+
+      if (creat) {
+        param.open_edition = config.open_edition
+        param.LongParam = window.btoa(window.encodeURIComponent(JSON.stringify(config)))
+
+        this.setMenu(param, true)
+      } else {
+        Api.getCloudConfig({
+          func: 'sPC_Get_LongParam',
+          MenuID: menu.MenuID
+        }).then(res => {
+          if (!res.status) {
+            notification.warning({
+              top: 92,
+              message: res.message,
+              duration: 5
+            })
+            this.setState({saveing: false})
+            return
+          }
+
+          config.open_edition = res.open_edition || ''
+          param.open_edition = config.open_edition
+          param.LongParam = window.btoa(window.encodeURIComponent(JSON.stringify(config)))
+  
+          if (res.LongParam) {
+            const that = this
+            confirm({
+              title: '鑿滃崟宸插瓨鍦紝纭畾閲嶆柊鐢熸垚鍚�?',
+              content: '',
+              onOk() {
+                that.setMenu(param, true)
+              },
+              onCancel() {}
+            })
+          } else {
+            this.setMenu(param, true)
+          }
+        })
+      }
+    })
+  }
+
+  setMenu = (param, reload) => {
+    param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
+    param.secretkey = Utils.encrypt('', param.timestamp)
+
+    Api.getCloudConfig(param).then(res => {
+      if (!res.status) {
+        notification.warning({
+          top: 92,
+          message: res.message,
+          duration: 5
+        })
+        this.setState({saveing: false})
+        return
+      }
+
+      notification.success({
+        top: 92,
+        message: '娣诲姞鎴愬姛銆�',
+        duration: 5
+      })
+      
+      this.setState({
+        loading: false,
+        visible: false
+      })
+
+      if (reload) {
+        this.props.reload()
+      }
+    })
   }
 
   cancel = () => {
@@ -164,7 +499,7 @@
   }
 
   render () {
-    const { visible, loading, menus } = this.state
+    const { visible, loading, saveing, menus } = this.state
 
     return (
       <>
@@ -180,6 +515,7 @@
           maskClosable={false}
           onOk={this.submit}
           onCancel={this.cancel}
+          confirmLoading={saveing}
           destroyOnClose
         >
           {loading ? <Spin /> : <div>

--
Gitblit v1.8.0