From fbf25a99e0bc643be89b0f9dd0efed7867f1490e Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期三, 27 七月 2022 18:08:02 +0800
Subject: [PATCH] 2022-07-27

---
 src/views/design/sidemenu/index.jsx |  377 ++++++++++++++++++++++++++++++-----------------------
 1 files changed, 211 insertions(+), 166 deletions(-)

diff --git a/src/views/design/sidemenu/index.jsx b/src/views/design/sidemenu/index.jsx
index 9e0e8bb..e41d70d 100644
--- a/src/views/design/sidemenu/index.jsx
+++ b/src/views/design/sidemenu/index.jsx
@@ -1,12 +1,13 @@
 import React, {Component} from 'react'
 import { connect } from 'react-redux'
 import { is, fromJS } from 'immutable'
-import { Menu, notification, Popover, Modal, Spin } from 'antd'
-import { EditOutlined, SwapOutlined, PlusOutlined, UnlockOutlined, SettingOutlined } from '@ant-design/icons'
+import { Menu, Popover, Modal, notification } from 'antd'
+import { SwapOutlined, PlusOutlined, SettingOutlined } from '@ant-design/icons'
+import moment from 'moment'
 
 import asyncComponent from '@/utils/asyncComponent'
-import { resetEditLevel, modifyMenuTree, modifyMainMenu } from '@/store/action'
-import options from '@/store/options.js'
+import { resetEditLevel } from '@/store/action'
+import Utils from '@/utils/utils.js'
 import Api from '@/api'
 import MKEmitter from '@/utils/events.js'
 import MkIcon from '@/components/mk-icon'
@@ -14,22 +15,27 @@
 
 const EditSecMenu = asyncComponent(() => import('./editsecmenu'))
 const EditThdMenu = asyncComponent(() => import('./editthdmenu'))
-const TransferForm = asyncComponent(() => import('@/templates/zshare/basetransferform'))
+const ThawMenu = asyncComponent(() => import('@/components/thawmenu'))
+const AddThdMenu = asyncComponent(() => import('./thdmenuplus'))
+const ThdMenuForm = asyncComponent(() => import('./thdmenuform'))
+const MenuForm = asyncComponent(() => import('./menuform'))
 const { SubMenu } = Menu
 
 class Sidemenu extends Component {
   state = {
-    subMenulist: [],         // 浜岀骇鑿滃崟
     editMenu: null,          // 缂栬緫涓夌骇鑿滃崟鏃惰缃�
     rootSubmenuKeys: null,
     openKeys: null,
-    preview: null
+    preview: null,
+    loading: false,
+    thdVisible: false,
+    sysMenu: null,
+    formlist: []
   }
 
   async loadsubmenu (menu) {
     if (!menu || !menu.MenuID) { // 娌℃湁涓昏彍鍗曟椂锛屾竻绌轰笅绾ц彍鍗�
       this.setState({
-        subMenulist: [],
         rootSubmenuKeys: [],
         openKeys: [],
         editMenu: null
@@ -45,28 +51,14 @@
     }
 
     this.setState({
-      subMenulist: menu.children,
       rootSubmenuKeys: menu.children.map(item => item.MenuID),
       openKeys: openKey ? [openKey] : [],
       editMenu: this.props.editLevel === 'level3' ? menu.children.filter(_menu => _menu.MenuID === this.state.editMenu.MenuID)[0] : null
     })
   }
 
-  changemenu(e, menu) {
-    e.preventDefault()
-    if (this.props.editLevel !== 'HS') {
-      return
-    }
-
-    MKEmitter.emit('modifyTabs', menu, 'plus')
-  }
-
-  componentDidMount () {
-    window.addEventListener('storage', (e) => {
-      if (e.key !== 'menuUpdate') return
-
-      this.reload()
-    })
+  shouldComponentUpdate (nextProps, nextState) {
+    return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
   }
 
   UNSAFE_componentWillReceiveProps (nextProps) {
@@ -74,10 +66,6 @@
       // 涓昏彍鍗曞垏鎹紝璇锋眰2銆�3绾ц彍鍗曟暟鎹�
       this.loadsubmenu(nextProps.mainMenu)
     }
-  }
-
-  shouldComponentUpdate(nextProps, nextState) {
-    return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
   }
 
   onOpenChange = openKeys => {
@@ -94,6 +82,9 @@
   enterSubEdit = (e) => {
     // 缂栬緫浜岀骇鑿滃崟
     e.stopPropagation()
+
+    if (this.props.mainMenu.children.length === 0) return
+
     this.props.resetEditLevel('level2')
   }
 
@@ -102,110 +93,6 @@
     e.stopPropagation()
     this.props.resetEditLevel('level3')
     this.setState({editMenu: menu})
-  }
-
-  reload = () => {
-    const { mainMenu } = this.props
-    let _param = {func: 's_get_pc_menus', systemType: options.sysType, debug: 'Y'}
-    _param.pro_sys = window.GLOB.systemType === 'production' ? 'Y' : ''
-
-    Api.getSystemConfig(_param).then(result => {
-      // 鐧诲綍瓒呮椂
-      if (!result) return
-  
-      if (result.status) {
-        let res = this.getMenulist(result)
-        let _mainMenu = res.menulist.filter(item => item.MenuID === mainMenu.MenuID)[0]
-  
-        this.props.modifyMenuTree(res.menulist)
-        this.props.modifyMainMenu(_mainMenu || null)
-      } else {
-        notification.error({
-          top: 92,
-          message: result.message,
-          duration: 10
-        })
-      }
-      this.loadsubmenu(this.props.mainMenu)
-    })
-  }
-
-  getMenulist = (result) => {
-    let iframes = ['Main/Index', 'bda/rdt', 'Home/rdt']
-    let menulist = result.fst_menu.map(fst => {
-      let fstItem = {
-        MenuID: fst.MenuID,
-        MenuName: fst.MenuName,
-        PageParam: {OpenType: 'menu', linkUrl: ''},
-        children: []
-      }
-      if (fst.PageParam) {
-        try {
-          fstItem.PageParam = JSON.parse(fst.PageParam)
-        } catch (e) {
-          fstItem.PageParam = {OpenType: 'menu', linkUrl: ''}
-        }
-      }
-
-      if (fst.snd_menu) {
-        fstItem.children = fst.snd_menu.map(snd => {
-          let sndItem = {
-            ParentId: fst.MenuID,
-            MenuID: snd.MenuID,
-            MenuName: snd.MenuName,
-            PageParam: {Icon: 'folder'},
-            children: []
-          }
-
-          if (snd.PageParam) {
-            try {
-              sndItem.PageParam = JSON.parse(snd.PageParam)
-            } catch (e) {
-              sndItem.PageParam = {Icon: 'folder'}
-            }
-          }
-
-          if (snd.trd_menu) {
-            sndItem.children = snd.trd_menu.map(trd => {
-              let trdItem = {
-                FstId: fst.MenuID,
-                ParentId: snd.MenuID,
-                MenuID: trd.MenuID,
-                MenuName: trd.MenuName,
-                MenuNo: trd.MenuNo,
-                EasyCode: trd.EasyCode,
-                type: 'CommonTable',            // 榛樿鍊间负甯哥敤琛�
-                OpenType: 'newtab'              // 鎵撳紑鏂瑰紡
-              }
-  
-              if (trd.LinkUrl && iframes.includes(trd.LinkUrl.split('?')[0])) {
-                trdItem.type = 'iframe'
-                trdItem.LinkUrl = trd.LinkUrl.replace('&amp;', '&')
-                trdItem.forbidden = true
-              } else {
-                try {
-                  trdItem.PageParam = trd.PageParam ? JSON.parse(trd.PageParam) : {OpenType: 'newtab'}
-                } catch (e) {
-                  trdItem.PageParam = {OpenType: 'newtab'}
-                }
-
-                trdItem.type = trdItem.PageParam.Template || trdItem.type
-                trdItem.OpenType = trdItem.PageParam.OpenType || trdItem.OpenType
-
-                if (trdItem.type === 'CustomPage' && this.props.memberLevel < 20) { // 浼氬憳绛夌骇澶т簬绛変簬20鏃讹紝鏈夌紪杈戞潈闄�
-                  trdItem.forbidden = true
-                }
-              }
-              return trdItem
-            })
-          }
-          return sndItem
-        })
-      }
-      return fstItem
-    })
-
-    return { menulist }
   }
 
   exitEdit = () => {
@@ -226,23 +113,172 @@
       }
       _param = window.btoa(window.encodeURIComponent(JSON.stringify(_param)))
       window.open(`#/menudesign/${_param}`)
-    } else {
+    } else if (['RolePermission', 'NewPage'].includes(cell.type)) {
+      cell.Template = cell.PageParam.Template
+      cell.url = cell.PageParam.url || ''
 
+      cell.fstMenuId = cell.FstId
+      cell.supMenuList = this.props.mainMenu.children
+      cell.fstMenuList = this.props.menuTree
+
+      this.setState({
+        thdVisible: true,
+        loading: false,
+        sysMenu: cell
+      })
     }
+  }
+
+  addSecMenu = () => {
+    this.setState({
+      visible: true,
+      loading: false,
+      formlist: [
+        { // 鐖剁骇鑿滃崟
+          type: 'select',
+          key: 'parentId',
+          label: '涓婄骇鑿滃崟',
+          initVal: this.props.mainMenu.MenuID,
+          required: true,
+          options: this.props.menuTree
+        },
+        { // 鑿滃崟鍚嶇О
+          type: 'text',
+          key: 'menuName',
+          label: '鑿滃崟鍚嶇О',
+          initVal: '',
+          required: true,
+          readonly: false
+        },
+        { // 鑿滃崟鍥炬爣
+          type: 'icon',
+          key: 'icon',
+          label: '鍥炬爣',
+          initVal: 'folder',
+          required: true
+        }
+      ]
+    })
+  }
+
+  secSubmit = () => {
+    this.menuFormRef.handleConfirm().then(values => {
+      let param = {
+        ParentID: values.parentId,
+        MenuID: Utils.getuuid(),
+        MenuName: values.menuName,
+        PageParam: JSON.stringify({
+          Icon: values.icon
+        })
+      }
+      param.func = 'sPC_SndMenu_Add'
+      param.Sort = (this.props.mainMenu.children.length + 1) * 10
+
+      this.setState({
+        loading: true
+      })
+      Api.getSystemConfig(param).then(res => {
+        if (res.status) {
+          this.setState({
+            loading: false,
+            visible: false
+          })
+          MKEmitter.emit('mkUpdateMenuList')
+        } else {
+          this.setState({
+            loading: false
+          })
+          notification.warning({
+            top: 92,
+            message: res.message,
+            duration: 5
+          })
+        }
+      })
+    })
+  }
+
+  /**
+   * @description 涓夌骇鑿滃崟淇敼
+   */
+  thdSubmit = () => {
+    const { sysMenu } = this.state
+
+    this.menuThdFormRef.handleConfirm().then(res => {
+      let PageParam = {
+        Template: sysMenu.Template,
+        OpenType: 'newtab'
+      }
+
+      if (sysMenu.Template === 'NewPage') {
+        PageParam.OpenType = 'NewPage'
+        PageParam.url = res.url
+      }
+
+      let param = {
+        func: 'sPC_TrdMenu_AddUpt',
+        FstID: res.fstMenuId,
+        SndID: res.ParentID,
+        ParentID: res.ParentID,
+        MenuID: sysMenu.MenuID,
+        MenuNo: res.MenuNo,
+        Template: sysMenu.Template,
+        MenuName: res.MenuName,
+        PageParam: JSON.stringify(PageParam),
+        LongParam: '',
+        LText: '',
+        LTexttb: ''
+      }
+
+      param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
+      param.secretkey = Utils.encrypt(param.LText, param.timestamp)
+
+      this.setState({
+        loading: true
+      })
+
+      Api.getSystemConfig(param).then(response => {
+        if (response.status) {
+          this.setState({
+            loading: false,
+            thdVisible: false,
+            sysMenu: null
+          })
+          MKEmitter.emit('mkUpdateMenuList')
+        } else {
+          this.setState({
+            loading: false
+          })
+          notification.warning({
+            top: 92,
+            message: response.message,
+            duration: 5
+          })
+        }
+      })
+    })
   }
 
   render () {
     const { mainMenu, editLevel } = this.props
-    const { visible } = this.state
-
-    let isnew = true
+    const { visible, loading, thdVisible } = this.state
 
     return (
       <aside className="mk-sys-side-menu ant-menu-dark mk-edit">
-        {!(editLevel === 'level2' || editLevel === 'level3') &&
+        {editLevel !== 'level2' && editLevel !== 'level3' && mainMenu ?
           <Menu openKeys={this.state.openKeys} onOpenChange={this.onOpenChange} mode="inline" theme="dark">
-          {!editLevel && mainMenu ? <li className="sup-menu"><EditOutlined onClick={this.enterSubEdit} className="edit-check"/></li> : null}
-          {this.state.subMenulist && this.state.subMenulist.map((item, index) => {
+          <li className="sup-menu">
+            <Popover overlayClassName="mk-popover-control-wrap mk-menu-control" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={
+              <div className="mk-popover-control">
+                <PlusOutlined onClick={this.addSecMenu}/>
+                <SwapOutlined onClick={this.enterSubEdit} className={'mk-swap' + (mainMenu.children.length === 0 ? ' disabled' : '')}/>
+                <div style={{display: 'inline-block', minWidth: '32px'}}><ThawMenu ParentId={mainMenu.MenuID} Type="20"/></div>
+              </div>
+            } trigger="hover" placement="top">
+              <SettingOutlined className="edit-check"/>
+            </Popover>
+          </li>
+          {mainMenu.children.map((item, index) => {
             return (
               <SubMenu
                 key={item.MenuID}
@@ -253,61 +289,72 @@
                   </span>
                 }
               >
-                {!editLevel ? <li className={'ant-menu-item ' + (item.children.length > 0 ? 'sub-menu' : '')}>
-                  {!isnew ? <EditOutlined onClick={(e) => {this.enterThrEdit(e, item)}} className="edit-check"/> :
+                <li className={'ant-menu-item ' + (item.children.length > 0 ? 'sub-menu' : '')}>
                   <Popover overlayClassName="mk-popover-control-wrap mk-menu-control" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={
                     <div className="mk-popover-control">
-                      <PlusOutlined onClick={(e) => {this.enterThrEdit(e, item)}} className="mk-edit-menu"/>
-                      <SwapOutlined onClick={(e) => {this.enterThrEdit(e, item)}} className="mk-edit-menu mk-swap"/>
-                      <UnlockOutlined onClick={(e) => {this.enterThrEdit(e, item)}} className="mk-edit-menu"/>
+                      <div style={{display: 'inline-block', minWidth: '32px'}}><AddThdMenu mainMenu={mainMenu} supMenu={item} menuTree={this.props.menuTree}/></div>
+                      <SwapOutlined onClick={(e) => {this.enterThrEdit(e, item)}} className="mk-swap"/>
+                      <div style={{display: 'inline-block', minWidth: '32px'}}><ThawMenu ParentId={item.MenuID} Type="30"/></div>
                     </div>
                   } trigger="hover" placement="top">
                     <SettingOutlined className="edit-check"/>
-                  </Popover>}
-                </li> : null}
+                  </Popover>
+                </li>
                 {item.children.map(cell => {
                   return (
                     <Menu.Item key={cell.MenuID}>
-                      {editLevel !== 'HS' ?
-                        <span className="editable-menu-item" onDoubleClick={() => this.editmenu(cell)}>{cell.MenuName}</span> :
-                        <a href={cell.src} id={cell.MenuID} onClick={(e) => this.changemenu(e, cell)}>{cell.MenuName}</a>
-                      }
+                      <span className="editable-menu-item" onDoubleClick={(e) => {e.stopPropagation();this.editmenu(cell)}}>{cell.MenuName}</span>
                     </Menu.Item>
                   )
                 })}
               </SubMenu>
             )
           })}
-        </Menu>}
-        {editLevel === 'level2' ?
+        </Menu> : null}
+        {editLevel === 'level2' && mainMenu ?
           <EditSecMenu
-            menulist={this.state.subMenulist}
+            menulist={mainMenu.children}
             menuTree={this.props.menuTree}
             supMenu={this.props.mainMenu}
-            reload={this.reload}
             exitEdit={this.exitEdit}
           /> : null
         }
-        {editLevel === 'level3' && this.state.editMenu ?
+        {editLevel === 'level3' && mainMenu && this.state.editMenu ?
           <EditThdMenu
             menulist={this.state.editMenu.children}
-            supMenuList={this.state.subMenulist}
+            supMenuList={mainMenu.children}
             supMenu={this.state.editMenu}
-            reload={this.reload}
             exitEdit={this.exitEdit}
           /> : null
         }
         <Modal
-          title="瑙e喕鑿滃崟"
-          width={600}
+          title="娣诲姞鑿滃崟"
           visible={visible}
-          onOk={this.thawMemuSubmit}
-          confirmLoading={this.state.confirmLoading}
-          onCancel={this.thawMemuCancel}
+          onOk={this.secSubmit}
+          // confirmLoading={loading}
+          onCancel={() => this.setState({visible: false})}
           destroyOnClose
         >
-          {!this.state.thawmenulist ? <Spin style={{marginLeft: 'calc(50% - 22px)', marginTop: '70px', marginBottom: '70px'}} size="large" /> :
-          <TransferForm onChange={(vals) => this.setState({targetKeys: vals})} menulist={this.state.thawmenulist}/>}
+          <MenuForm
+            inputSubmit={this.secSubmit}
+            formlist={this.state.formlist}
+            wrappedComponentRef={(inst) => this.menuFormRef = inst}
+          />
+        </Modal>
+        <Modal
+          title="淇敼鑿滃崟"
+          visible={thdVisible}
+          width={600}
+          onOk={this.thdSubmit}
+          confirmLoading={loading}
+          onCancel={() => {this.setState({thdVisible: false})}}
+          destroyOnClose
+        >
+          <ThdMenuForm
+            menu={this.state.sysMenu}
+            inputSubmit={this.thdSubmit}
+            wrappedComponentRef={(inst) => this.menuThdFormRef = inst}
+          />
         </Modal>
       </aside>
     )
@@ -324,8 +371,6 @@
 
 const mapDispatchToProps = (dispatch) => {
   return {
-    modifyMenuTree: (menuTree) => dispatch(modifyMenuTree(menuTree)),
-    modifyMainMenu: (mainMenu) => dispatch(modifyMainMenu(mainMenu)),
     resetEditLevel: (level) => dispatch(resetEditLevel(level))
   }
 }

--
Gitblit v1.8.0