From da64ab0923bf8817fc8599a6e37b953ce38f64c8 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期日, 27 八月 2023 18:37:36 +0800
Subject: [PATCH] 2023-08-27

---
 src/views/design/header/index.jsx |  328 +++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 211 insertions(+), 117 deletions(-)

diff --git a/src/views/design/header/index.jsx b/src/views/design/header/index.jsx
index 7324d56..3fe5ad4 100644
--- a/src/views/design/header/index.jsx
+++ b/src/views/design/header/index.jsx
@@ -1,22 +1,14 @@
 import React, {Component} from 'react'
 import { withRouter } from 'react-router-dom'
-import {connect} from 'react-redux'
-import { is, fromJS } from 'immutable'
 import { Dropdown, Menu, Modal, notification, Switch, Button, Popover } from 'antd'
-import { MenuFoldOutlined, SettingOutlined, AppstoreOutlined, DownOutlined, HomeOutlined, ApiOutlined, PlusOutlined, SwapOutlined } from '@ant-design/icons'
+import { MenuFoldOutlined, SettingOutlined, AppstoreOutlined, DownOutlined, HomeOutlined, ApiOutlined, PlusOutlined, EditOutlined, MenuOutlined, DatabaseOutlined } from '@ant-design/icons'
+import moment from 'moment'
 
-import asyncComponent from '@/utils/asyncComponent'
-import {
-  modifyMenuTree,
-  modifyMainMenu,
-  resetEditLevel,
-  logout
-} from '@/store/action'
 import Api from '@/api'
-import options from '@/store/options.js'
 import Utils from '@/utils/utils.js'
 import avatar from '@/assets/img/avatar.jpg'
 import MainLogo from '@/assets/img/main-logo.png'
+import asyncComponent from '@/utils/asyncComponent'
 import MKEmitter from '@/utils/events.js'
 import './index.scss'
 
@@ -44,7 +36,6 @@
       content: '',
       onOk() {
         sessionStorage.clear()
-        _this.props.logout()
         _this.props.history.replace('/login')
       },
       onCancel() {}
@@ -53,10 +44,6 @@
 
   changeMenu (value) {
     // 涓昏彍鍗曞垏鎹�
-    if (this.props.editLevel) {
-      // 缂栬緫鐘舵�佷笅锛屼笉鍙垏鎹㈣彍鍗�
-      return
-    }
     if (value.PageParam.OpenType === 'menu') {
       this.props.modifyMainMenu(value)
     } else if (value.PageParam.OpenType === 'outpage') {
@@ -66,10 +53,14 @@
 
   async loadmenu () {
     // 鑾峰彇涓昏彍鍗�
-    let _param = {func: 's_get_pc_menus', systemType: options.sysType, debug: 'Y'}
-    _param.pro_sys = window.GLOB.systemType === 'production' ? 'Y' : ''
+    let _param = {
+      func: 's_get_pc_menus',
+      systemType: window.GLOB.sysType,
+      pro_sys: window.GLOB.systemType === 'production' ? 'Y' : '',
+      debug: 'Y'
+    }
 
-    let result = await Api.getSystemConfig(_param)
+    let result = await Api.getCloudConfig(_param)
 
     // 鐧诲綍瓒呮椂
     if (!result) return
@@ -79,12 +70,21 @@
 
       this.setState({ menulist })
 
-      this.props.modifyMenuTree(menulist)
-      if (window.GLOB.systemType !== 'production') { // 闈炴寮忕郴缁熼�夋嫨绗竴椤�
-        this.props.modifyMainMenu(menulist[0] || null)
-      } else {
+      let mainMenu = menulist[0] || null
 
+      if (this.props.editLevel === 'level1') {
+        mainMenu = null
+      } else if (this.props.mainMenu && this.props.mainMenu.MenuID) {
+        let _menu = menulist.filter(item => item.MenuID === this.props.mainMenu.MenuID)[0]
+        mainMenu = _menu || mainMenu
+
+        if (!_menu && (this.props.editLevel === 'level2' || this.props.editLevel === 'level3')) {
+          this.props.resetEditLevel(false)
+        }
       }
+
+      this.props.modifyMenuTree(menulist)
+      this.props.modifyMainMenu(mainMenu)
     } else {
       notification.error({
         top: 92,
@@ -95,7 +95,6 @@
   }
 
   getMenulist = (result) => {
-    let iframes = ['Main/Index', 'bda/rdt', 'Home/rdt']
     let menulist = []
     let thdMenuList = []
     result.fst_menu && result.fst_menu.forEach(fst => {
@@ -120,7 +119,8 @@
             MenuID: snd.MenuID,
             MenuName: snd.MenuName,
             PageParam: {Icon: 'folder'},
-            children: []
+            children: [],
+            level: 'second'
           }
 
           if (snd.PageParam) {
@@ -141,26 +141,21 @@
                 MenuNo: trd.MenuNo,
                 EasyCode: trd.EasyCode,
                 type: 'CommonTable',            // 榛樿鍊间负甯哥敤琛�
-                OpenType: 'newtab'              // 鎵撳紑鏂瑰紡
+                OpenType: 'newtab',             // 鎵撳紑鏂瑰紡
+                level: 'third'
               }
   
-              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'}
-                }
+              try {
+                trdItem.PageParam = trd.PageParam ? JSON.parse(trd.PageParam) : {OpenType: 'newtab'}
 
                 trdItem.type = trdItem.PageParam.Template || trdItem.type
-                trdItem.OpenType = trdItem.PageParam.OpenType || trdItem.OpenType
+                trdItem.OpenType = trdItem.PageParam.OpenType
+              } catch (e) {
+                trdItem.PageParam = {OpenType: 'newtab'}
+              }
 
-                if (trdItem.type === 'CustomPage' && this.state.memberLevel < 20) { // 浼氬憳绛夌骇澶т簬绛変簬20鏃讹紝鏈夌紪杈戞潈闄�
-                  trdItem.forbidden = true
-                }
+              if (trdItem.type === 'CustomPage' && this.state.memberLevel < 20) { // 浼氬憳绛夌骇澶т簬绛変簬20鏃讹紝鏈夌紪杈戞潈闄�
+                trdItem.forbidden = true
               }
 
               thdMenuList.push(trdItem)
@@ -185,6 +180,7 @@
   }
 
   changeEditState = () => {
+    sessionStorage.removeItem('isEditState')
     this.props.history.replace('/main')
     window.location.reload()
   }
@@ -192,14 +188,15 @@
   enterEdit = () => {
     // 杩涘叆缂栬緫鐘舵��
     this.props.resetEditLevel('level1')
+    this.props.modifyMainMenu(null)
   }
   
   exitEdit = () => {
     // 閫�鍑虹紪杈戠姸鎬�
     this.props.resetEditLevel(false)
+    this.props.modifyMainMenu(this.state.menulist[0] || null)
   }
 
-  
   addMemuSubmit = () => {
     // 鏂板缓鑿滃崟锛氭彁浜�
     this.addMenuFormRef.handleConfirm().then(param => {
@@ -209,7 +206,7 @@
       this.setState({
         loading: true
       })
-      Api.getSystemConfig(param).then(res => {
+      Api.getCloudConfig(param).then(res => {
         if (res.status) {
           this.setState({
             loading: false,
@@ -230,27 +227,128 @@
       })
     }, () => {})
   }
+
+  setSystemFuncs = () => {
+    if (!window.GLOB.IndexDB) {
+      return
+    }
+    this.getfuncTime().then(res => {
+      Api.getSystemFuncs(res.createDate).then(result => {
+        if (!result.status) {
+          notification.error({
+            top: 92,
+            message: result.message,
+            duration: 10
+          })
+        } else if (result.func_detail && result.func_detail.length > 0) {
+          this.writeFuncs(result.func_detail)
+        }
+      })
+    })
+  }
+
+  writeFuncs = (funcs) => {
+    let shim = +sessionStorage.getItem('sys_time_shim')
+    let timestamp = moment().add(shim, 'seconds').format('YYYY-MM-DD HH:mm:ss')
+
+    let objectStore = window.GLOB.IndexDB.transaction(['funcs'], 'readwrite').objectStore('funcs')
+
+    objectStore.clear()
+
+    funcs.forEach(item => {
+      if (!item.key_sql) return
+      item.id = item.func_code
+      objectStore.add(item)
+    })
+
+    let funcStore = window.GLOB.IndexDB.transaction(['version'], 'readwrite').objectStore('version')
+    funcStore.put({id: 'funcs', version: '1.0', createDate: timestamp})
+  }
+
+  getfuncTime = () => {
+    return new Promise((resolve, reject) => {
+      let objectStore = window.GLOB.IndexDB.transaction(['version'], 'readwrite').objectStore('version')
+      let request = objectStore.get('funcs')
+
+      request.onerror = (event) => {
+        console.warn(event)
+        reject()
+      }
+
+      request.onsuccess = () => {
+        if (request.result) {
+          resolve(request.result)
+        } else {
+          let add = objectStore.add({id: 'funcs', version: '1.0', createDate: '1970-01-01 14:59:09.000'})
+  
+          add.onerror = () => {
+            reject()
+          }
+          add.onsuccess = () => {
+            resolve({id: 'funcs', version: '1.0', createDate: '1970-01-01 14:59:09.000'})
+          }
+        }
+      }
+    })
+  }
+
+  getSmStemp = () => {
+    if (!sessionStorage.getItem('msgTemplate')) {
+      let _sql = `select聽ID,TemplateCode,SignName+'_'+describe as SignName from (select * from bd_msn_sms_temp where deleted=0 and status=20 ) a 
+        inner join (select openid from sapp where id='${window.GLOB.appkey}') b 
+        on a.openid=b.openid`
+  
+      _sql = Utils.formatOptions(_sql)
+  
+      let param = {
+        func: 'sPC_Get_SelectedList',
+        LText: _sql,
+        obj_name: 'data',
+        arr_field: 'ID,TemplateCode,SignName'
+      }
+      
+      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.getCloudConfig(param).then(res => {
+        let msgs = []
+        if (!res.status) {
+          notification.warning({
+            top: 92,
+            message: res.message,
+            duration: 5
+          })
+        } else if (res.data) {
+          msgs = res.data
+        }
+        sessionStorage.setItem('msgTemplate', JSON.stringify(msgs))
+      })
+    }
+  }
   
   UNSAFE_componentWillMount () {
-    sessionStorage.setItem('isEditState', 'true')
     document.body.className = ''
     
     // 缁勪欢鍔犺浇鏃讹紝鑾峰彇鑿滃崟鏁版嵁
     this.loadmenu()
   }
 
-  UNSAFE_componentWillReceiveProps (nextProps) {
-    if (!is(fromJS(this.props.menuTree), fromJS(nextProps.menuTree)) && !is(fromJS(this.state.menulist), fromJS(nextProps.menuTree))) {
-      this.setState({
-        menulist: nextProps.menuTree
-      })
-    }
-  }
-
   componentDidMount () {
+    window.addEventListener('storage', (e) => {
+      if (e.key === 'menuUpdate') {
+        this.reload()
+      } else if (e.key === 'wxTemplates') {
+        if (e.newValue) {
+          sessionStorage.setItem('wxTemplates', e.newValue)
+        }
+      }
+    })
+    MKEmitter.addListener('mkUpdateMenuList', this.reload)
+
     if (window.GLOB.systemType !== 'production') {
       setTimeout(() => {
-        Api.getSystemConfig({func: 'sPC_Get_Roles_sModular'}).then(res => {
+        Api.getCloudConfig({func: 'sPC_Get_Roles_sModular'}).then(res => {
           if (res.status) {
             let _permFuncField = []
             let _sysRoles = []
@@ -278,19 +376,14 @@
             sessionStorage.setItem('permFuncField', JSON.stringify(_permFuncField))
           }
         })
-      }, 50)
+      }, 100)
+
+      setTimeout(() => {
+        // positecgroup
+        // this.setSystemFuncs()
+        this.getSmStemp()
+      }, 500)
     }
-
-    window.addEventListener('storage', (e) => {
-      if (e.key !== 'menuUpdate') return
-
-      this.reload()
-    })
-    MKEmitter.addListener('mkUpdateMenuList', this.reload)
-  }
-
-  shouldComponentUpdate (nextProps, nextState) {
-    return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
   }
 
   /**
@@ -304,11 +397,11 @@
   }
 
   gotoDoc = () => {
-    if (options.sysType === 'local' && window.GLOB.mainSystemApi) {
+    if (window.GLOB.sysType === 'local' && window.GLOB.mainSystemApi) {
       let ssodomain = window.GLOB.mainSystemApi.replace('/webapi/dostars', '')
       let url = `${ssodomain}/doc/index.html#?appkey=${window.GLOB.appkey}&LoginUID=${sessionStorage.getItem('LoginUID')}`
       window.open(url)
-    } else if (options.sysType === 'SSO' || options.sysType === 'cloud') {
+    } else if (window.GLOB.sysType === 'SSO' || window.GLOB.sysType === 'cloud') {
       window.open(`${window.location.href.replace(/\/index.html(.*)|\/#(.*)/ig, '')}/doc/index.html#?appkey=${window.GLOB.appkey}&LoginUID=${sessionStorage.getItem('LoginUID')}`)
     }
   }
@@ -343,45 +436,63 @@
         {/* 杩涘叆缂栬緫鎸夐挳 */}
         {!editLevel && window.GLOB.systemType !== 'production' && menulist ? <Popover overlayClassName="mk-popover-control-wrap mk-menu-control" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={
           <div className="mk-popover-control">
-            <PlusOutlined onClick={() => this.setState({visible: true, loading: false})} className="mk-edit-menu"/>
-            <SwapOutlined onClick={this.enterEdit} className="mk-edit-menu"/>
-            <div style={{display: 'inline-block', minWidth: '32px'}}><ThawMenu ParentId="0" Type="10" className="mk-edit-menu"/></div>
+            <PlusOutlined onClick={() => this.setState({visible: true, loading: false})}/>
+            <EditOutlined onClick={this.enterEdit}/>
+            <div style={{display: 'inline-block', minWidth: '32px'}}><ThawMenu ParentId="0" Type="10"/></div>
           </div>
         } trigger="hover">
           <SettingOutlined className="edit-check"/>
         </Popover> : null}
-        <div className="app-entrance entrance">
-          <div className="icon"><AppstoreOutlined /></div>
-          <div className="title">搴旂敤绠$悊</div>
-          <div className="detail">鍙垱寤哄強绠$悊PC銆乸ad鍙婄Щ鍔ㄧ绛変笉鍚岃澶囩殑搴旂敤锛屽疄鐜版槑绉戜簯APP銆佸井淇″叕浼楀彿銆佸皬绋嬪簭绛夊骞冲彴鐨勫簲鐢ㄥ叡浜��</div>
-          {window.GLOB.systemType !== 'production' ? 
-            <Button type="primary" disabled={!(memberLevel >= 20)} title={memberLevel >= 20 ? '' : '浼氬憳绛夌骇涓嶅锛屾棤寮�鍙戞潈闄愩��'} onClick={() => {window.open('#/appmanage')}}>
-              缂栬緫
-            </Button> :
-            <Button type="primary" disabled={!(memberLevel >= 20)} title={memberLevel >= 20 ? '' : '浼氬憳绛夌骇涓嶅锛屾棤寮�鍙戞潈闄愩��'} onClick={() => {window.open('#/appcheck')}}>
-              鏌ョ湅
-            </Button>
-          }
-        </div>
-        <div className="api-entrance entrance">
-          <div className="icon"><ApiOutlined /></div>
-          <div className="title">鎺ュ彛璋冭瘯</div>
-          <div className="detail">鍙嚜鍔ㄥ鐞嗙櫥褰曟帴鍙g殑鍙傛暟鍔犲瘑锛屼互鍙婁笟鍔℃帴鍙g殑绛惧悕璁$畻锛屾柟渚垮紑鍙戜汉鍛樼殑鎺ュ彛娴嬭瘯宸ヤ綔銆�</div>
-          <Button type="primary" disabled={!(memberLevel >= 20)} title={memberLevel >= 20 ? '' : '浼氬憳绛夌骇涓嶅锛屾棤寮�鍙戞潈闄愩��'} onClick={() => {window.open('#/interface')}}>
-            缂栬緫
-          </Button>
-        </div>
         {/* window.btoa(window.encodeURIComponent(JSON.stringify({ MenuType: 'home', MenuId: 'home_page_id', MenuName: '棣栭〉' }))) */}
-        {window.GLOB.systemType !== 'production' ?
-          <div className="home-entrance entrance">
-            <div className="icon"><HomeOutlined /></div>
-            <div className="title">棣栭〉</div>
-            <div className="detail">鍩轰簬鑷畾涔夐〉闈㈢殑棣栭〉璁捐锛屽彲瀹炵幇鐏垫椿鐨勫厓绱犻厤缃強鏍峰紡璋冩暣锛屽睍鐜板綋鍓嶇郴缁熺殑椋庢牸銆�</div>
-            <Button type="primary" disabled={!(memberLevel >= 20)} title={memberLevel >= 20 ? '' : '浼氬憳绛夌骇涓嶅锛屾棤寮�鍙戞潈闄愩��'} onClick={() => {window.open('#/menudesign/JTdCJTIyTWVudVR5cGUlMjIlM0ElMjJob21lJTIyJTJDJTIyTWVudUlkJTIyJTNBJTIyaG9tZV9wYWdlX2lkJTIyJTJDJTIyTWVudU5hbWUlMjIlM0ElMjIlRTklQTYlOTYlRTklQTElQjUlMjIlN0Q=')}}>
+        <div className="entrance-wrap">
+          {window.GLOB.systemType !== 'production' ?
+            <div className="entrance">
+              <div className="icon"><HomeOutlined /></div>
+              <div className="title">棣栭〉</div>
+              <div className="detail">鍩轰簬鑷畾涔夐〉闈㈢殑棣栭〉璁捐锛屽彲瀹炵幇鐏垫椿鐨勫厓绱犻厤缃強鏍峰紡璋冩暣锛屽睍鐜板綋鍓嶇郴缁熺殑椋庢牸銆�</div>
+              <Button type="primary" disabled={!(memberLevel >= 20)} title={memberLevel >= 20 ? '' : '浼氬憳绛夌骇涓嶅锛屾棤寮�鍙戞潈闄愩��'} onClick={() => {window.open('#/menudesign/JTdCJTIyTWVudVR5cGUlMjIlM0ElMjJob21lJTIyJTJDJTIyTWVudUlkJTIyJTNBJTIyaG9tZV9wYWdlX2lkJTIyJTJDJTIyTWVudU5hbWUlMjIlM0ElMjIlRTklQTYlOTYlRTklQTElQjUlMjIlN0Q=')}}>
+                缂栬緫
+              </Button>
+            </div> : null
+          }
+          <div className="entrance">
+            <div className="icon"><ApiOutlined /></div>
+            <div className="title">鎺ュ彛璋冭瘯</div>
+            <div className="detail">鍙嚜鍔ㄥ鐞嗙櫥褰曟帴鍙g殑鍙傛暟鍔犲瘑锛屼互鍙婁笟鍔℃帴鍙g殑绛惧悕璁$畻锛屾柟渚垮紑鍙戜汉鍛樼殑鎺ュ彛娴嬭瘯宸ヤ綔銆�</div>
+            <Button type="primary" disabled={!(memberLevel >= 20)} title={memberLevel >= 20 ? '' : '浼氬憳绛夌骇涓嶅锛屾棤寮�鍙戞潈闄愩��'} onClick={() => {window.open('#/interface')}}>
               缂栬緫
             </Button>
-          </div> : null
-        }
+          </div>
+          <div className="entrance">
+            <div className="icon"><AppstoreOutlined /></div>
+            <div className="title">搴旂敤绠$悊</div>
+            <div className="detail">鍙垱寤哄強绠$悊PC銆乸ad鍙婄Щ鍔ㄧ绛変笉鍚岃澶囩殑搴旂敤锛屽疄鐜版槑绉戜簯APP銆佸井淇″叕浼楀彿銆佸皬绋嬪簭绛夊骞冲彴鐨勫簲鐢ㄥ叡浜��</div>
+            {window.GLOB.systemType !== 'production' ? 
+              <Button type="primary" disabled={!(memberLevel >= 20)} title={memberLevel >= 20 ? '' : '浼氬憳绛夌骇涓嶅锛屾棤寮�鍙戞潈闄愩��'} onClick={() => {window.open('#/appmanage')}}>
+                缂栬緫
+              </Button> :
+              <Button type="primary" disabled={!(memberLevel >= 20)} title={memberLevel >= 20 ? '' : '浼氬憳绛夌骇涓嶅锛屾棤寮�鍙戞潈闄愩��'} onClick={() => {window.open('#/appcheck')}}>
+                鏌ョ湅
+              </Button>
+            }
+          </div>
+          {window.GLOB.systemType !== 'production' ? <div className="entrance">
+            <div className="icon"><MenuOutlined /></div>
+            <div className="title">鑿滃崟鎿嶄綔璇存槑</div>
+            <div className="detail">榧犳爣鎮仠 <SettingOutlined style={{color: '#1890ff'}}/> 鍙樉绀鸿彍鍗曠殑娣诲姞銆佹帓搴忥紙鍖呮嫭缂栬緫銆佸垹闄わ級涓庤В鍐诲姛鑳斤紝鍙屽嚮涓夌骇鑿滃崟鍙繘鍏ョ紪杈戠獥鍙c��</div>
+            <Button type="primary" onClick={() => {window.open('#/main')}}>
+              鏂扮獥鍙�
+            </Button>
+          </div> : null}
+          {window.GLOB.systemType !== 'production' ? <div className="entrance">
+            <div className="icon"><DatabaseOutlined /></div>
+            <div className="title">瀛樺偍杩囩▼</div>
+            <div className="detail">鍙湪椤甸潰涓煡鐪嬫垨缂栬緫鏈湴瀛樺偍杩囩▼銆�</div>
+            <Button type="primary" onClick={() => {window.open('#/proc')}}>
+              缂栬緫
+            </Button>
+          </div> : null}
+        </div>
         {/* 缂栬緫鑿滃崟 */}
         {editLevel === 'level1' ? <EditMenu menulist={this.state.menulist} reload={this.reload} exitEdit={this.exitEdit}/> : null}
         {/* 澶村儚銆佺敤鎴峰悕 */}
@@ -392,7 +503,7 @@
               <Switch size="small" style={{marginLeft: '7px'}} disabled={!!editLevel} checked={true} onChange={this.changeEditState} />
             </Menu.Item>
             <Menu.Item key="doc" onClick={this.gotoDoc}>鏂囨。涓績</Menu.Item>
-            {options.sysType !== 'cloud' ? <Menu.Item style={{padding: 0}} key="verup">
+            {window.GLOB.sysType !== 'cloud' ? <Menu.Item style={{padding: 0}} key="verup">
               <VersionsUp />
             </Menu.Item> : null}
             <Menu.Item key="logout" onClick={this.logout}>閫�鍑�</Menu.Item>
@@ -424,21 +535,4 @@
   }
 }
 
-const mapStateToProps = (state) => {
-  return {
-    menuTree: state.menuTree,
-    mainMenu: state.mainMenu,
-    editLevel: state.editLevel
-  }
-}
-
-const mapDispatchToProps = (dispatch) => {
-  return {
-    modifyMenuTree: (menuTree) => dispatch(modifyMenuTree(menuTree)),
-    modifyMainMenu: (mainMenu) => dispatch(modifyMainMenu(mainMenu)),
-    resetEditLevel: (level) => dispatch(resetEditLevel(level)),
-    logout: () => dispatch(logout())
-  }
-}
-
-export default withRouter(connect(mapStateToProps, mapDispatchToProps)(Header))
\ No newline at end of file
+export default withRouter(Header)
\ No newline at end of file

--
Gitblit v1.8.0