king
2024-08-20 58826d6f4eab9f8c9acf9fa8696f60039c645cfe
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 { Dropdown, Menu, Modal, notification, Switch, Button, Popover } from 'antd'
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'
@@ -24,6 +16,8 @@
const VersionsUp = asyncComponent(() => import('./versions'))
const ThawMenu = asyncComponent(() => import('@/components/thawmenu'))
const MenuForm = asyncComponent(() => import('./editfirstmenu/menuform'))
const TransMenu = asyncComponent(() => import('./transmenu'))
const { confirm } = Modal
class Header extends Component {
@@ -31,7 +25,8 @@
    menulist: null, // 一级菜单
    userName: sessionStorage.getItem('CloudUserName'),
    avatar: Utils.getrealurl(sessionStorage.getItem('CloudAvatar')),
    memberLevel: Utils.getMemberLevel(),
    logo: sessionStorage.getItem('CloudLogo') || MainLogo,
    subLang: sessionStorage.getItem('subLangList') !== null,
    visible: false,
    loading: false
  }
@@ -44,8 +39,8 @@
      content: '',
      onOk() {
        sessionStorage.clear()
        _this.props.logout()
        _this.props.history.replace('/login')
        window.location.reload()
      },
      onCancel() {}
    })
@@ -64,12 +59,12 @@
    // 获取主菜单
    let _param = {
      func: 's_get_pc_menus',
      systemType: options.sysType,
      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
@@ -151,6 +146,7 @@
                EasyCode: trd.EasyCode,
                type: 'CommonTable',            // 默认值为常用表
                OpenType: 'newtab',             // 打开方式
                up_action: window.GLOB.upStatus && trd.up_action === 'Y',
                level: 'third'
              }
  
@@ -163,7 +159,7 @@
                trdItem.PageParam = {OpenType: 'newtab'}
              }
              if (trdItem.type === 'CustomPage' && this.state.memberLevel < 20) { // 会员等级大于等于20时,有编辑权限
              if (trdItem.type === 'CustomPage' && window.GLOB.memberLevel < 20) { // 会员等级大于等于20时,有编辑权限
                trdItem.forbidden = true
              }
@@ -189,6 +185,7 @@
  }
  changeEditState = () => {
    sessionStorage.removeItem('isEditState')
    this.props.history.replace('/main')
    window.location.reload()
  }
@@ -214,7 +211,7 @@
      this.setState({
        loading: true
      })
      Api.getSystemConfig(param).then(res => {
      Api.getCloudConfig(param).then(res => {
        if (res.status) {
          this.setState({
            loading: false,
@@ -236,74 +233,69 @@
    }, () => {})
  }
  setSystemFuncs = () => {
    if (!window.GLOB.IndexDB) {
      return
    }
    this.getfuncTime().then(res => {
      let param = {
        func: 's_get_func_base_sso',
        update_date: res.createDate
      }
      // Api.getSystemFuncs(res.createDate).then(result => {
      Api.getSystemConfig(param).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)
        }
      })
    })
  }
  // 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')
  // 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')
  //   let objectStore = window.GLOB.IndexDB.transaction(['funcs'], 'readwrite').objectStore('funcs')
    objectStore.clear()
  //   objectStore.clear()
    funcs.forEach(item => {
      if (!item.key_sql) return
      item.id = item.func_code
      objectStore.add(item)
    })
  //   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})
  }
  //   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')
  // 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.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'})
  //     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'})
          }
        }
      }
    })
  }
  //         add.onerror = () => {
  //           reject()
  //         }
  //         add.onsuccess = () => {
  //           resolve({id: 'funcs', version: '1.0', createDate: '1970-01-01 14:59:09.000'})
  //         }
  //       }
  //     }
  //   })
  // }
  getSmStemp = () => {
    if (!sessionStorage.getItem('msgTemplate')) {
@@ -311,20 +303,21 @@
        inner join (select openid from sapp where id='${window.GLOB.appkey}') b 
        on a.openid=b.openid`
  
      _sql = Utils.formatOptions(_sql)
      _sql = Utils.formatOptions(_sql, 'x')
  
      let param = {
        func: 'sPC_Get_SelectedList',
        LText: _sql,
        obj_name: 'data',
        arr_field: 'ID,TemplateCode,SignName'
        arr_field: 'ID,TemplateCode,SignName',
        exec_type: 'x'
      }
      
      param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
      param.secretkey = Utils.encrypt(param.LText, param.timestamp)
      param.secretkey = Utils.encrypt('', param.timestamp)
      param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp) // 云端数据验证
      
      Api.getSystemConfig(param).then(res => {
      Api.getCloudConfig(param).then(res => {
        let msgs = []
        if (!res.status) {
          notification.warning({
@@ -341,7 +334,6 @@
  }
  
  UNSAFE_componentWillMount () {
    sessionStorage.setItem('isEditState', 'true')
    document.body.className = ''
    
    // 组件加载时,获取菜单数据
@@ -352,17 +344,13 @@
    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 = []
@@ -393,7 +381,7 @@
      }, 100)
      setTimeout(() => {
        this.setSystemFuncs()
        // this.setSystemFuncs()
        this.getSmStemp()
      }, 500)
    }
@@ -410,22 +398,22 @@
  }
  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')}`)
    }
  }
  render () {
    const { mainMenu, editLevel } = this.props
    const { menulist, memberLevel, visible, loading } = this.state
    const { menulist, visible, loading, logo, subLang } = this.state
    return (
      <header className={'sys-header-container ant-menu-dark ' + (['level2', 'level3'].includes(editLevel) ? 'mask' : '')} id="main-header-container">
        <div className="header-logo"><img src={MainLogo} alt=""/></div>
        <div className="header-logo"><img src={logo} alt=""/></div>
        <div className="header-collapse">
          <MenuFoldOutlined/>
        </div>
@@ -463,7 +451,7 @@
              <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 type="primary" disabled={window.GLOB.memberLevel < 20} title={window.GLOB.memberLevel < 20 ? '会员等级不够,无开发权限。' : ''} onClick={() => {window.open('#/menudesign/JTdCJTIyTWVudVR5cGUlMjIlM0ElMjJob21lJTIyJTJDJTIyTWVudUlkJTIyJTNBJTIyaG9tZV9wYWdlX2lkJTIyJTJDJTIyTWVudU5hbWUlMjIlM0ElMjIlRTklQTYlOTYlRTklQTElQjUlMjIlN0Q=')}}>
                编辑
              </Button>
            </div> : null
@@ -472,7 +460,7 @@
            <div className="icon"><ApiOutlined /></div>
            <div className="title">接口调试</div>
            <div className="detail">可自动处理登录接口的参数加密,以及业务接口的签名计算,方便开发人员的接口测试工作。</div>
            <Button type="primary" disabled={!(memberLevel >= 20)} title={memberLevel >= 20 ? '' : '会员等级不够,无开发权限。'} onClick={() => {window.open('#/interface')}}>
            <Button type="primary" disabled={window.GLOB.memberLevel < 20} title={window.GLOB.memberLevel < 20 ? '会员等级不够,无开发权限。' : ''} onClick={() => {window.open('#/interface')}}>
              编辑
            </Button>
          </div>
@@ -481,10 +469,10 @@
            <div className="title">应用管理</div>
            <div className="detail">可创建及管理PC、pad及移动端等不同设备的应用,实现明科云APP、微信公众号、小程序等多平台的应用共享。</div>
            {window.GLOB.systemType !== 'production' ? 
              <Button type="primary" disabled={!(memberLevel >= 20)} title={memberLevel >= 20 ? '' : '会员等级不够,无开发权限。'} onClick={() => {window.open('#/appmanage')}}>
              <Button type="primary" disabled={window.GLOB.memberLevel < 20} title={window.GLOB.memberLevel < 20 ? '会员等级不够,无开发权限。' : ''} onClick={() => {window.open('#/appmanage')}}>
                编辑
              </Button> :
              <Button type="primary" disabled={!(memberLevel >= 20)} title={memberLevel >= 20 ? '' : '会员等级不够,无开发权限。'} onClick={() => {window.open('#/appcheck')}}>
              <Button type="primary" disabled={window.GLOB.memberLevel < 20} title={window.GLOB.memberLevel < 20 ? '会员等级不够,无开发权限。' : ''} onClick={() => {window.open('#/appcheck')}}>
                查看
              </Button>
            }
@@ -505,6 +493,12 @@
              编辑
            </Button>
          </div> : null}
          {window.GLOB.systemType !== 'production' && subLang ? <div className="entrance">
            <div className="icon"><PlusOutlined /></div>
            <div className="title">菜单转换</div>
            <div className="detail">可选择母语系统的菜单,快速转换到当前语言。打印模板请在HS下复制后,在此处选择指定模板进行语言转换。</div>
            <TransMenu reload={this.reload} menulist={menulist}/>
          </div> : null}
        </div>
        {/* 编辑菜单 */}
        {editLevel === 'level1' ? <EditMenu menulist={this.state.menulist} reload={this.reload} exitEdit={this.exitEdit}/> : null}
@@ -516,7 +510,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>
@@ -548,21 +542,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))
export default withRouter(Header)