From 8d66ff34fae5b048a6b7923cc75d34f13a08be9d Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 02 八月 2022 11:42:43 +0800
Subject: [PATCH] Merge branch 'develop'

---
 src/views/design/sidemenu/index.jsx |  426 +++++++++++++++++++++++++++++++---------------------
 1 files changed, 253 insertions(+), 173 deletions(-)

diff --git a/src/views/design/sidemenu/index.jsx b/src/views/design/sidemenu/index.jsx
index 06454bb..f46de51 100644
--- a/src/views/design/sidemenu/index.jsx
+++ b/src/views/design/sidemenu/index.jsx
@@ -1,35 +1,41 @@
 import React, {Component} from 'react'
 import { connect } from 'react-redux'
 import { is, fromJS } from 'immutable'
-import { Menu, notification } from 'antd'
-import { EditOutlined } 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 { SySMenuList } from './config'
-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'
 import './index.scss'
 
-const EditSecMenu = asyncComponent(() => import('@/templates/menuconfig/editsecmenu'))
-const EditThdMenu = asyncComponent(() => import('@/templates/menuconfig/editthdmenu'))
+const EditSecMenu = asyncComponent(() => import('./editsecmenu'))
+const EditThdMenu = asyncComponent(() => import('./editthdmenu'))
+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,57 +51,20 @@
     }
 
     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
     })
   }
 
-  enterManageView = () => {
-    let menulist = SySMenuList
-
-    if (window.GLOB.systemType === 'production') {
-      menulist.forEach(menu => {
-        menu.children = menu.children.filter(item => item.systems && item.systems.includes(window.GLOB.systemType))
-      })
-
-      menulist = menulist.filter(menu => menu.children.length > 0)
-    } else {
-      menulist.forEach(menu => {
-        menu.children = menu.children.filter(item => !item.systems || item.systems.includes(options.sysType))
-      })
-
-      menulist = menulist.filter(menu => menu.children.length > 0)
-    }
-
-    this.setState({
-      subMenulist: menulist,
-      rootSubmenuKeys: menulist.map(item => item.MenuID),
-      openKeys: [menulist[0].MenuID]
-    })
-  }
-
-  changemenu(e, menu) {
-    e.preventDefault()
-    if (this.props.editLevel !== 'HS') {
-      return
-    }
-
-    MKEmitter.emit('modifyTabs', menu, 'plus')
+  shouldComponentUpdate (nextProps, nextState) {
+    return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
   }
 
   UNSAFE_componentWillReceiveProps (nextProps) {
-    if (!is(fromJS(this.props.mainMenu), fromJS(nextProps.mainMenu)) && nextProps.mainMenu && nextProps.mainMenu.MenuID === 'systemManageView') {
-      this.enterManageView()
-    } else if (!is(fromJS(this.props.mainMenu), fromJS(nextProps.mainMenu))) {
-      // 涓昏彍鍗曞垏鎹紝璇锋眰2銆�3绾ц彍鍗曟暟鎹�
+    if (!is(fromJS(this.props.mainMenu), fromJS(nextProps.mainMenu))) {
       this.loadsubmenu(nextProps.mainMenu)
     }
-  }
-
-  shouldComponentUpdate(nextProps, nextState) {
-    return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
   }
 
   onOpenChange = openKeys => {
@@ -112,6 +81,9 @@
   enterSubEdit = (e) => {
     // 缂栬緫浜岀骇鑿滃崟
     e.stopPropagation()
+
+    if (this.props.mainMenu.children.length === 0) return
+
     this.props.resetEditLevel('level2')
   }
 
@@ -122,110 +94,6 @@
     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 = () => {
     if (this.props.editLevel === 'level3') {
       this.setState({editMenu: null})
@@ -233,57 +101,272 @@
     this.props.resetEditLevel(false)
   }
 
+  editmenu = (cell) => {
+    if (cell.type === 'CustomPage') {
+      let _param = {
+        MenuType: 'custom',
+        MenuId: cell.MenuID,
+        ParentId: cell.ParentId,
+        MenuName: cell.MenuName,
+        MenuNo: cell.MenuNo
+      }
+      _param = window.btoa(window.encodeURIComponent(JSON.stringify(_param)))
+      window.open(`#/menudesign/${_param}`)
+    } else if (['CommonTable', 'TreePage', 'CalendarPage'].includes(cell.type)) {
+      sessionStorage.setItem('menuTree', JSON.stringify(this.props.menuTree))
+      let _param = window.btoa(window.encodeURIComponent(JSON.stringify(cell)))
+
+      window.open(`#/basedesign/${_param}`)
+    } else if (['RolePermission', 'NewPage'].includes(cell.type)) {
+      let _cell = fromJS(cell).toJS()
+      _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
+      })
+    } else {
+      notification.warning({
+        top: 92,
+        message: '褰撳墠鑿滃崟涓嶅彲缂栬緫',
+        duration: 5
+      })
+    }
+  }
+
+  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 } = this.props
+    const { mainMenu, editLevel } = this.props
+    const { visible, loading, thdVisible } = this.state
 
     return (
       <aside className="mk-sys-side-menu ant-menu-dark mk-edit">
-        {!(this.props.editLevel === 'level2' || this.props.editLevel === 'level3') &&
+        {editLevel !== 'level2' && editLevel !== 'level3' && mainMenu ?
           <Menu openKeys={this.state.openKeys} onOpenChange={this.onOpenChange} mode="inline" theme="dark">
-          {!this.props.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}
                 title={
-                  <span className={!this.props.editLevel && index === 0 ? 'edit-control' : ''}>
+                  <span className={!editLevel && index === 0 ? 'edit-control' : ''}>
                     <MkIcon type={item.PageParam.Icon} />
                     <span>{item.MenuName}</span>
                   </span>
                 }
               >
-                {!this.props.editLevel ? <li className={'ant-menu-item ' + (item.children.length > 0 ? 'sub-menu' : '')}>
-                  <EditOutlined onClick={(e) => {this.enterThrEdit(e, item)}} className="edit-check"/>
-                </li> : null}
+                <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">
+                      <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>
                 {item.children.map(cell => {
                   return (
                     <Menu.Item key={cell.MenuID}>
-                      <a href={cell.src} id={cell.MenuID} onClick={(e) => this.changemenu(e, cell)}>{cell.MenuName}</a>
+                      <span className="editable-menu-item" onDoubleClick={() => this.editmenu(cell)}>{cell.MenuName}</span>
                     </Menu.Item>
                   )
                 })}
               </SubMenu>
             )
           })}
-        </Menu>}
-        {this.props.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
         }
-        {this.props.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="娣诲姞鑿滃崟"
+          visible={visible}
+          onOk={this.secSubmit}
+          // confirmLoading={loading}
+          onCancel={() => this.setState({visible: false})}
+          destroyOnClose
+        >
+          <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>
     )
   }
@@ -293,15 +376,12 @@
   return {
     mainMenu: state.mainMenu,
     menuTree: state.menuTree,
-    memberLevel: state.memberLevel,
     editLevel: state.editLevel
   }
 }
 
 const mapDispatchToProps = (dispatch) => {
   return {
-    modifyMenuTree: (menuTree) => dispatch(modifyMenuTree(menuTree)),
-    modifyMainMenu: (mainMenu) => dispatch(modifyMainMenu(mainMenu)),
     resetEditLevel: (level) => dispatch(resetEditLevel(level))
   }
 }

--
Gitblit v1.8.0