From 3683e1475e8d74f690172a468518d88d91a69ccc Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 20 八月 2020 20:15:48 +0800
Subject: [PATCH] 2020-08-20

---
 src/components/header/index.jsx |  132 +++++++++++++++++++++++++++++++++-----------
 1 files changed, 99 insertions(+), 33 deletions(-)

diff --git a/src/components/header/index.jsx b/src/components/header/index.jsx
index 7774abf..502960c 100644
--- a/src/components/header/index.jsx
+++ b/src/components/header/index.jsx
@@ -4,7 +4,7 @@
 import {connect} from 'react-redux'
 import { is, fromJS } from 'immutable'
 import moment from 'moment'
-import {Dropdown, Menu, Icon, Modal, Form, notification, Switch, Button, Input } from 'antd'
+import { Dropdown, Menu, Icon, Modal, Form, notification, Switch, Button, Input, Badge } from 'antd'
 
 import asyncComponent from '@/utils/asyncComponent'
 import {
@@ -23,8 +23,8 @@
 } from '@/store/action'
 import Api from '@/api'
 import options from '@/store/options.js'
-import zhCN from '@/locales/zh-CN/header.js'
-import enUS from '@/locales/en-US/header.js'
+import zhCN from '@/locales/zh-CN/main.js'
+import enUS from '@/locales/en-US/main.js'
 import Utils from '@/utils/utils.js'
 import avatar from '@/assets/img/avatar.jpg'
 import Resetpwd from './resetpwd'
@@ -46,7 +46,7 @@
   state = {
     menulist: null, // 涓�绾ц彍鍗�
     visible: false, // 淇敼瀵嗙爜妯℃�佹
-    dict: (!localStorage.getItem('lang') || localStorage.getItem('lang') === 'zh-CN') ? zhCN : enUS,
+    dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
     confirmLoading: false,
     userName: sessionStorage.getItem('User_Name'),
     logourl: window.GLOB.mainlogo,
@@ -55,7 +55,9 @@
     avatar: avatar,
     systems: [],
     searchkey: '',
-    thdMenuList: []
+    thdMenuList: [],
+    oriVersion: '',
+    newVersion: ''
   }
 
   handleCollapse = () => {
@@ -101,7 +103,7 @@
       })
       notification.success({
         top: 92,
-        message: this.state.dict['header.password.resetsuccess'],
+        message: this.state.dict['main.password.resetsuccess'],
         duration: 2
       })
     } else {
@@ -127,10 +129,10 @@
     // 閫�鍑虹櫥褰�
     let _this = this
     confirm({
-      title: this.state.dict['header.logout.hint'],
+      title: this.state.dict['main.logout.hint'],
       content: '',
-      okText: this.state.dict['header.confirm'],
-      cancelText: this.state.dict['header.cancel'],
+      okText: this.state.dict['main.confirm'],
+      cancelText: this.state.dict['main.cancel'],
       onOk() {
         sessionStorage.clear()
         _this.props.logout()
@@ -155,11 +157,11 @@
 
   async loadmenu () {
     // 鑾峰彇涓昏彍鍗�
-    let _param = {func: 'sPC_Get_MainMenu', systemType: options.systemType}
+    let _param = {func: 'sPC_Get_MainMenu', systemType: options.sysType}
     if (sessionStorage.getItem('isEditState') === 'true') { // 缂栬緫鐘舵�佹椂锛岃幏鍙栦竴绾ц彍鍗曪紝澧炲姞鍙傛暟debug
       _param.debug = 'Y'
     }
-    if (options.systemType !== 'cloud' && window.GLOB.systemType !== 'official') {
+    if (options.sysType !== 'cloud' && window.GLOB.systemType !== 'production') {
       _param.linkurl = window.GLOB.linkurl
     }
 
@@ -244,8 +246,8 @@
     
     // 鑾峰彇涓昏彍鍗曞弬鏁�
     let promiseMenu = new Promise(resolve => {
-      let _param = {func: 'sPC_Get_MainMenu', systemType: options.systemType}
-      if (options.systemType !== 'cloud' && window.GLOB.systemType !== 'official') {
+      let _param = {func: 'sPC_Get_MainMenu', systemType: options.sysType}
+      if (options.sysType !== 'cloud' && window.GLOB.systemType !== 'production') {
         _param.linkurl = window.GLOB.linkurl
       }
 
@@ -347,7 +349,7 @@
         _userName = sessionStorage.getItem('CloudUserName')
       }
 
-      if (window.GLOB.systemType === 'official' && state) {
+      if (window.GLOB.systemType === 'production' && state) {
         this.props.resetEditLevel('HS')
         this.props.modifyMainMenu({
           MenuID: 'systemManageView'
@@ -360,7 +362,7 @@
         this.props.resetEditState(state)
 
         return
-      } else if (window.GLOB.systemType === 'official' && !state) {
+      } else if (window.GLOB.systemType === 'production' && !state) {
         this.props.resetEditLevel(false)
         this.props.modifyMainMenu(menulist[0] || '')
 
@@ -383,7 +385,7 @@
       this.props.resetEditState(state)
     }
 
-    if (state && this.props.sysRoles.length === 0 && this.props.permFuncField.length === 0 && window.GLOB.systemType !== 'official') {
+    if (state && this.props.sysRoles.length === 0 && this.props.permFuncField.length === 0 && window.GLOB.systemType !== 'production') {
       Api.getSystemConfig({func: 'sPC_Get_Roles_sModular'}).then(res => {
         if (res.status) {
           let _permFuncField = []
@@ -422,7 +424,6 @@
       Api.getusermsg(param.username, param.password, true).then(res => {
         if (res.status) {
           sessionStorage.setItem('CloudUserID', res.UserID)
-          sessionStorage.setItem('CloudSessionUid', Utils.getuuid())
           sessionStorage.setItem('CloudLoginUID', res.LoginUID)
           sessionStorage.setItem('CloudUserName', res.UserName)
           sessionStorage.setItem('CloudFullName', res.FullName)
@@ -434,7 +435,7 @@
             _avatar = Utils.getrealurl(res.icon) // 澶村儚
           }
 
-          if (window.GLOB.systemType === 'official') {
+          if (window.GLOB.systemType === 'production') {
             this.props.resetEditLevel('HS')
             this.props.modifyMainMenu({
               MenuID: 'systemManageView'
@@ -495,7 +496,7 @@
    * @description 閫�鍑虹鐞嗙晫闈㈣彍鍗�
    */
   exitManage = () => {
-    if (window.GLOB.systemType === 'official') { // 姝e紡绯荤粺鐗堟湰鍗囩骇鍚庯紝椤甸潰鍒锋柊
+    if (window.GLOB.systemType === 'production') { // 姝e紡绯荤粺鐗堟湰鍗囩骇鍚庯紝椤甸潰鍒锋柊
       window.location.reload()
       return
     }
@@ -511,7 +512,7 @@
   }
 
   changeSystem = (system) => {
-    let _param = window.btoa('ud=' + sessionStorage.getItem('UserID') + '&sd=' + sessionStorage.getItem('SessionUid') + '&ld=' + sessionStorage.getItem('LoginUID') + '&un=' + sessionStorage.getItem('User_Name'))
+    let _param = window.btoa('ud=' + sessionStorage.getItem('UserID') + '&ld=' + sessionStorage.getItem('LoginUID') + '&un=' + sessionStorage.getItem('User_Name'))
     window.location.href = system.LinkUrl1 + '#/ssologin/' + _param
   }
 
@@ -575,10 +576,15 @@
 
         if (result.UserRoles) {
           let iframes = ['Main/Index', 'bda/rdt', 'Home/rdt']
+          let menukeys = []
 
           result.UserRoles.forEach(role => {
             role.RoleMenu.forEach(menu => {
               if (!menu.MenuID) return
+              if (menukeys.includes(menu.MenuID)) {
+                console.warn('s_Get_TrdMenu_Role閲嶅鐨勮彍鍗旾D锛�' + menu.MenuID)
+                return
+              }
               _permMenus[menu.MenuID] = true
 
               let _type = ''
@@ -601,6 +607,8 @@
                 }
                 _type = pageParam.Template || _type
               }
+
+              menukeys.push(menu.MenuID)
 
               menulist.push({
                 MenuID: menu.MenuID,
@@ -627,28 +635,86 @@
         })
       }
     })
+
+    // 鑾峰彇绯荤粺鐨勭増鏈俊鎭�
+    new Promise((resolve, reject) => {
+      Api.getAppVersion(resolve, reject)
+    }).then(res => {
+      this.setState({
+        oriVersion: res.oldVersion,
+        newVersion: res.newVersion
+      })
+    })
   }
 
   shouldComponentUpdate (nextProps, nextState) {
     return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
   }
 
+  verup = () => {
+    const { oriVersion, newVersion } = this.state
+    const _this = this
+
+    confirm({
+      title: this.state.dict['main.verup'],
+      content: `鏈�鏂扮増鏈�${newVersion}锛屽綋鍓嶇増鏈�${oriVersion}`,
+      okText: this.state.dict['main.confirm'],
+      cancelText: this.state.dict['main.cancel'],
+      onOk() {
+        return new Promise(resolve => {
+          Api.updateAppVersion(newVersion).then(res => {
+            if (res.status) {
+              notification.success({
+                top: 92,
+                message: '鍗囩骇鎴愬姛锛�',
+                duration: 2
+              })
+              _this.setState({oriVersion: newVersion})
+            } else {
+              notification.warning({
+                top: 92,
+                message: '鍗囩骇澶辫触锛岃鍒锋柊椤甸潰閲嶈瘯锛�',
+                duration: 2
+              })
+            }
+            resolve()
+          })
+        })
+      },
+      onCancel() {}
+    })
+  }
+
+  gotoDoc = () => {
+    if (options.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') {
+      window.open(`${window.location.href.replace(/\/index.html(.*)|\/#(.*)/ig, '')}/doc/index.html#?appkey=${window.GLOB.appkey}&LoginUID=${sessionStorage.getItem('LoginUID')}`)
+    }
+  }
+
   render () {
-    const { thdMenuList, searchkey } = this.state
+    const { thdMenuList, searchkey, oriVersion, newVersion } = this.state
 
     const menu = (
-      <Menu overlayclassname="header-dropdown">
-        {this.props.debug && <Menu.Item key="0">
-          {this.state.dict['header.edit']}
+      <Menu className="header-dropdown">
+        {this.props.debug && <Menu.Item key="switch">
+          {this.state.dict['main.edit']}
           <Switch size="small" className="edit-switch" disabled={!!this.props.editLevel} checked={this.props.editState} onChange={this.changeEditState} />
         </Menu.Item>}
-        {!this.props.editState ? <Menu.Item key="1" onClick={this.changePassword}>{this.state.dict['header.password']}</Menu.Item> : null}
+        {!this.props.editState ? <Menu.Item key="password" onClick={this.changePassword}>{this.state.dict['main.password']}</Menu.Item> : null}
         {/* {this.state.systems.length > 0 ? <Menu.SubMenu title="鍒囨崲绯荤粺">
           {this.state.systems.map((system, index) => (
             <Menu.Item className="header-subSystem" key={'sub' + index} onClick={() => {this.changeSystem(system)}}> {system.AppName} </Menu.Item>
           ))}
         </Menu.SubMenu> : null} */}
-        <Menu.Item key="2" onClick={this.logout}>{this.state.dict['header.logout']}</Menu.Item>
+        <Menu.Item key="doc" onClick={this.gotoDoc}>{this.state.dict['main.doc']}</Menu.Item>
+        {oriVersion ? <Menu.Item key="verup" onClick={this.verup}>
+          <Badge dot={oriVersion !== newVersion}>{this.state.dict['main.verup']}</Badge>
+        </Menu.Item> : null}
+        <Menu.Item key="logout" onClick={this.logout}>{this.state.dict['main.logout']}</Menu.Item>
       </Menu>
     )
 
@@ -678,7 +744,7 @@
         {this.props.editLevel === 'HS' ? <Button className="level4-close" type="primary" onClick={this.exitManage}>閫�鍑�</Button> : null}
         {/* 杩涘叆缂栬緫鎸夐挳 */}
         {this.props.editState && !this.props.editLevel ? <Icon onClick={this.enterEdit} className="edit-check" type="edit" /> : null}
-        {this.props.editState && !this.props.editLevel && options.systemType === 'local' && window.GLOB.systemType !== 'official' ?
+        {this.props.editState && !this.props.editLevel && options.sysType === 'local' && window.GLOB.systemType !== 'production' ?
           <a href="#/mobmanage" target="_blank" className="mobile" type="edit"> 搴旂敤绠$悊 <Icon type="arrow-right" /></a> : null
         }
         {/* 缂栬緫鑿滃崟 */}
@@ -730,9 +796,9 @@
         }
         {/* 淇敼瀵嗙爜 */}
         <Modal
-          title={this.state.dict['header.password']}
-          okText={this.state.dict['header.confirm']}
-          cancelText={this.state.dict['header.cancel']}
+          title={this.state.dict['main.password']}
+          okText={this.state.dict['main.confirm']}
+          cancelText={this.state.dict['main.cancel']}
           visible={this.state.visible}
           onOk={this.resetPwdSubmit}
           confirmLoading={this.state.confirmLoading}
@@ -743,9 +809,9 @@
         </Modal>
         {/* 缂栬緫鐘舵�佺櫥褰� */}
         <Modal
-          title={this.state.dict['header.login.develop']}
-          okText={this.state.dict['header.confirm']}
-          cancelText={this.state.dict['header.cancel']}
+          title={this.state.dict['main.login.develop']}
+          okText={this.state.dict['main.confirm']}
+          cancelText={this.state.dict['main.cancel']}
           visible={this.state.loginVisible}
           onOk={this.loginSubmit}
           width={'430px'}

--
Gitblit v1.8.0