king
2021-05-08 6afdec0062dacbded57e166230eb22cc55ced0c1
src/components/header/index.jsx
@@ -16,6 +16,7 @@
  logout
} from '@/store/action'
import Api from '@/api'
import MKEmitter from '@/utils/events.js'
import options from '@/store/options.js'
import zhCN from '@/locales/zh-CN/main.js'
import enUS from '@/locales/en-US/main.js'
@@ -35,7 +36,7 @@
  state = {
    menulist: null, // 一级菜单
    visible: false, // 修改密码模态框
    dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    confirmLoading: false,
    userName: sessionStorage.getItem('User_Name'),
    logourl: window.GLOB.mainlogo,
@@ -47,7 +48,8 @@
    thdMenuList: [],
    oriVersion: '',
    newVersion: '',
    debug: sessionStorage.getItem('debug') === 'true'
    debug: sessionStorage.getItem('debug') === 'true',
    navBar: ['linkage_navigation', 'linkage'].includes(window.GLOB.navBar) ? 'topmenu' : ''
  }
  handleCollapse = () => {
@@ -125,10 +127,10 @@
  changeMenu (value) {
    // 主菜单切换
    if (value.PageParam.OpenType === 'menu') {
    if (value.OpenType === 'outpage' && value.linkUrl) {
      window.open(value.linkUrl)
    } else if (value.OpenType === 'menu') {
      this.props.modifyMainMenu(value)
    } else if (value.PageParam.OpenType === 'outpage') {
      window.open(value.PageParam.linkUrl)
    }
  }
@@ -141,7 +143,7 @@
        edition_type: 'A',
        pro_sys: window.GLOB.systemType === 'production' ? 'Y' : ''
      }).then(result => {
        let _permAction = {} // 按钮权限
        let _permAction = {loaded: true} // 按钮权限
        if (result && result.status) {
          if (result.UserRoles_Menu) {
@@ -166,9 +168,6 @@
    // 获取主菜单参数
    let menudefer = new Promise(resolve => {
      let _param = {func: 's_get_pc_menus', systemType: options.sysType}
      if (options.sysType !== 'cloud' && window.GLOB.systemType !== 'production') {
        _param.linkurl = window.GLOB.linkurl
      }
      _param.pro_sys = window.GLOB.systemType === 'production' ? 'Y' : ''
      
      Api.getSystemConfig(_param).then(result => {
@@ -215,7 +214,7 @@
        this.props.modifyMenuTree(menulist)
        this.props.modifyMainMenu(mainMenu)
        this.props.initMenuPermission(thdMenuList)
        this.props.initMenuPermission([...thdMenuList, {MenuID: 'home_page_id', EasyCode: '', MenuName: 'home', type: 'CustomPage'}])
        resolve(_menu)
      })
@@ -226,14 +225,19 @@
        let tabs = fromJS(this.props.tabviews).toJS()
        let menu = fromJS(response[1]).toJS()
        tabs = tabs.map(tab => {
          tab.selected = false
          return tab
        })
        if (this.state.navBar === 'topmenu') {
          menu.selected = true
          this.props.modifyTabview([menu])
        } else {
          tabs = tabs.map(tab => {
            tab.selected = false
            return tab
          })
        menu.selected = true
        tabs.push(menu)
        this.props.modifyTabview(tabs)
          menu.selected = true
          tabs.push(menu)
          this.props.modifyTabview(tabs)
        }
      }
    })
  }
@@ -246,14 +250,18 @@
      let fstItem = {
        MenuID: fst.MenuID,
        MenuName: fst.MenuName,
        PageParam: {OpenType: 'menu', linkUrl: ''},
        OpenType: 'menu',
        children: []
      }
      if (fst.PageParam) {
        try {
          fstItem.PageParam = JSON.parse(fst.PageParam)
        } catch (e) {
          fstItem.PageParam = {OpenType: 'menu', linkUrl: ''}
          fstItem.PageParam = null
        }
        if (fstItem.PageParam && fstItem.PageParam.OpenType === 'outpage' && fstItem.PageParam.linkUrl) {
          fstItem.OpenType = 'outpage'
          fstItem.linkUrl = fstItem.PageParam.linkUrl
        }
      }
@@ -286,6 +294,7 @@
            debug: sessionStorage.getItem('debug'),
            role_id: sessionStorage.getItem('role_id'),
            mainlogo: window.GLOB.mainlogo,
            navBar: window.GLOB.navBar || '',
            mstyle: window.GLOB.style
          }
@@ -296,6 +305,7 @@
                ParentId: snd.MenuID,
                MenuID: trd.MenuID,
                MenuName: trd.MenuName,
                ParentNames: [fst.MenuName, snd.MenuName],
                MenuNo: trd.MenuNo,
                EasyCode: trd.EasyCode,
                type: 'CommonTable',            // 默认值为常用表
@@ -304,7 +314,7 @@
  
              if (trd.LinkUrl && iframes.includes(trd.LinkUrl.split('?')[0])) {
                trdItem.type = 'iframe'
                trdItem.LinkUrl = trd.LinkUrl
                trdItem.LinkUrl = trd.LinkUrl.replace('&', '&')
              } else {
                try {
                  trdItem.PageParam = trd.PageParam ? JSON.parse(trd.PageParam) : {OpenType: 'newtab'}
@@ -404,6 +414,10 @@
          this.props.history.replace('/design')
        } else {
          if (res.message.indexOf('密码错误') > -1) {
            const input = document.getElementById('password')
            input && input.select()
          }
          this.setState({
            loginLoading: false
          })
@@ -457,26 +471,6 @@
      }
    })
  }
  selectMenu = (item) => {
    let tabs = fromJS(this.props.tabviews).toJS()
    let menu = fromJS(item).toJS()
    menu.selected = true
    tabs = tabs.filter(tab => {
      tab.selected = false
      return tab.MenuID !== menu.MenuID
    })
    if (this.props.tabviews.length !== tabs.length) {
      this.props.modifyTabview(fromJS(tabs).toJS())
    }
    this.setState({}, () => {
      tabs.push(menu)
      this.props.modifyTabview(tabs)
    })
  }
  
  UNSAFE_componentWillMount () {
    // 组件加载时,获取菜单数据
@@ -494,16 +488,12 @@
  componentDidMount () {
    // 获取系统的版本信息,延时查询
    setTimeout(() => {
      new Promise((resolve, reject) => {
        Api.getAppVersion(resolve, reject)
      }).then(res => {
      Api.getAppVersion().then(res => {
        this.setState({
          oriVersion: res.oldVersion,
          newVersion: res.newVersion
        })
      }, () => {
        console.warn('websql 初始化错误!')
      })
      }, () => {})
    }, 1000)
  }
@@ -529,23 +519,23 @@
      content: `最新版本${newVersion},当前版本${oriVersion}`,
      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
              })
            }
          if (!window.GLOB.WebSql) {
            notification.warning({
              top: 92,
              message: '升级失败,请刷新页面重试!',
              duration: 2
            })
            resolve()
          })
          } else {
            Api.updateAppVersion(newVersion)
            notification.success({
              top: 92,
              message: '升级成功!',
              duration: 2
            })
            _this.setState({oriVersion: newVersion})
            resolve()
          }
        })
      },
      onCancel() {}
@@ -562,9 +552,49 @@
    }
  }
  changeVerMenu(menu, type) {
    if (type === 'first') {
      if (menu.OpenType === 'outpage' && menu.linkUrl) {
        window.open(menu.linkUrl)
      } else if (menu.OpenType === 'menu') {
      }
    } else {
      if (menu.OpenType === 'newpage' || menu.OpenType === 'NewPage') { // NewPage为打开外部页面地址,newpage为打开系统菜单
        window.open(menu.src)
      } else if (menu.OpenType === 'blank') {
        menu.selected = true
        this.props.modifyTabview([menu])
      } else if (this.state.navBar === 'topmenu') {
        menu.selected = true
        this.props.modifyTabview([menu])
      } else {
        let tabs = fromJS(this.props.tabviews).toJS()
        tabs = tabs.filter(tab => {
          tab.selected = false
          return tab.MenuID !== menu.MenuID
        })
        if (this.props.tabviews.length > tabs.length) {
          this.props.modifyTabview(fromJS(tabs).toJS())
        }
        this.setState({}, () => {
          menu.selected = true
          tabs.push(menu)
          this.props.modifyTabview(tabs)
        })
      }
      if (window.GLOB.systemType === 'production') {
        MKEmitter.emit('queryTrigger', {menuId: menu.MenuID, name: '菜单'})
      }
    }
  }
  render () {
    const { mainMenu, collapse } = this.props
    const { thdMenuList, searchkey, oriVersion, newVersion, debug, menulist } = this.state
    const { thdMenuList, searchkey, oriVersion, newVersion, debug, menulist, navBar } = this.state
    const menu = (
      <Menu className="header-dropdown">
@@ -588,12 +618,12 @@
    return (
      <header className="header-container ant-menu-dark" id="main-header-container">
        <div className={'header-logo ' + (collapse ? 'collapse' : '')}><img src={this.state.logourl} alt=""/></div>
        <div className={'header-collapse ' + (collapse ? 'collapse' : '')}>
          {menulist && menulist.length ? <Icon type={collapse ? 'menu-unfold' : 'menu-fold'} onClick={this.handleCollapse}/> : null}
        <div className={'header-logo ' + (collapse && navBar !== 'topmenu' ? 'collapse' : '')}><img src={this.state.logourl} alt=""/></div>
        <div className={'header-collapse ' + (collapse && navBar !== 'topmenu' ? 'collapse' : '')}>
          {navBar !== 'topmenu' ? <Icon type={collapse ? 'menu-unfold' : 'menu-fold'} onClick={this.handleCollapse}/> : null}
        </div>
        {/* 正常菜单 */}
        {menulist ?
        {navBar !== 'topmenu' && menulist ?
          <ul className="header-menu">{
            menulist.map(item => {
              return (
@@ -604,18 +634,13 @@
            })}
          </ul> : null
        }
        {/* {menulist ?
          <Menu className="header-vertical-menu" mode="horizontal">
            {menulist.map(item => {
              if (!item.children || item.children.length === 0) {
        {/* 正常菜单 */}
        {navBar === 'topmenu' && menulist ?
          <ul className="header-menu vertical-menu">{
            menulist.map(item => {
              if (item.children && item.children.length > 0) {
                return (
                  <Menu.Item key={item.MenuID}>
                    {item.MenuName}
                  </Menu.Item>
                )
              } else {
                return (
                  <Menu.SubMenu key={item.MenuID} title={item.MenuName}>
                  <Dropdown key={item.MenuID} overlayClassName="vertical-dropdown-menu" overlay={
                    <Menu mode="vertical">
                      {item.children.map(cell => {
                        if (!cell.children || cell.children.length === 0) {
@@ -626,26 +651,33 @@
                          )
                        } else {
                          return (
                            <Menu.SubMenu key={cell.MenuID} title={cell.MenuName}>
                              <Menu mode="vertical">
                                {cell.children.map(m => (
                                  <Menu.Item key={m.MenuID}>
                                    {m.MenuName}
                                  </Menu.Item>
                                ))}
                              </Menu>
                            <Menu.SubMenu popupClassName="vertical-dropdown-submenu" key={cell.MenuID} title={cell.MenuName}>
                              {cell.children.map(m => (
                                <Menu.Item key={m.MenuID} onClick={() => {this.changeVerMenu(m)}}>
                                  {m.MenuName}
                                </Menu.Item>
                              ))}
                            </Menu.SubMenu>
                          )
                        }
                      })}
                    </Menu>
                  </Menu.SubMenu>
                  }>
                    <li>
                      <span>{item.MenuName}</span>
                    </li>
                  </Dropdown>
                )
              } else {
                return (
                  <li key={item.MenuID} onClick={() => {this.changeVerMenu(item, 'first')}}>
                    <span>{item.MenuName}</span>
                  </li>
                )
              }
            })}
          </Menu> : null
          </ul> : null
        }
         */}
        {/* 头像、用户名 */}
        <Dropdown className="header-setting" overlay={menu}>
          <div>
@@ -677,12 +709,12 @@
                        option.MenuNo.toLowerCase().indexOf(searchkey.toLowerCase()) >= 0 ||
                        option.EasyCode.toLowerCase().indexOf(searchkey.toLowerCase()) >= 0
                      ) {
                        return <Menu.Item key={option.MenuID} onClick={() => this.selectMenu(option)}>{option.MenuName}</Menu.Item>
                        return <Menu.Item key={option.MenuID} onClick={() => this.changeVerMenu(option)}>{option.MenuName}</Menu.Item>
                      } else {
                        return null
                      }
                    }
                    return <Menu.Item key={option.MenuID} onClick={() => this.selectMenu(option)}>{option.MenuName}</Menu.Item>
                    return <Menu.Item key={option.MenuID} onClick={() => this.changeVerMenu(option)}>{option.MenuName}</Menu.Item>
                  })}
                </Menu>
              </div>