king
2021-01-12 c27d57333ed38c92f595219d2190ea63cef4d182
src/tabviews/commontable/index.jsx
@@ -44,7 +44,7 @@
    viewlost: false,      // 页面丢失:1、未获取到配置-页面丢失;2、页面未启用
    lostmsg: '',          // 页面丢失时的提示信息
    config: {},           // 页面配置信息,包括按钮、搜索、显示列、标签等
    userConfig: null,     // 用户自定义设置
    shortcuts: null,      // 快捷键
    searchlist: null,     // 搜索条件
    actions: null,        // 按钮集
    columns: null,        // 显示列
@@ -60,7 +60,6 @@
    search: '',           // 搜索条件数组,使用时需分场景处理
    BIDs: {},             // 上级表id
    pickup: false,        // 主表数据隐藏显示切换
    tabActive: null,      // 标签页展开控制
    chartId: '',          // 展开图表ID
    statFields: [],       // 合计字段
    statFValue: [],       // 合计值
@@ -81,7 +80,7 @@
    if (result.status) {
      let config = ''
      let userConfig = null
      let shortcuts = []
      let _curUserConfig = ''
      try { // 配置信息解析
@@ -94,13 +93,32 @@
      // HS不使用自定义设置
      if (result.LongParamUser && this.props.menuType !== 'HS') {
        try { // 配置信息解析
          userConfig = JSON.parse(window.decodeURIComponent(window.atob(result.LongParamUser)))
          let userConfig = JSON.parse(window.decodeURIComponent(window.atob(result.LongParamUser)))
          userConfig = []
          // if (window.GLOB.UserCacheMap.has(_param)) {
          //   return Promise.resolve(window.GLOB.UserCacheMap.get(_param))
          // } else {
          //   param = this.encryptParam(param)
          //   return new Promise(resolve => {
          //     axios({
          //       url: `/webapi/dostars${param.func ? '/' + param.func : ''}`,
          //       data: param
          //     }).then(res => {
          //       if (res.status) {
          //         window.GLOB.UserCacheMap.set(_param, res)
          //       }
          //       resolve(res)
          //     })
          //   })
          // }
          _curUserConfig = userConfig[this.props.MenuID]
        } catch (e) {
          console.warn('Parse Failure')
          userConfig = null
        }
      }
      console.log(config)
      console.log(shortcuts)
      // 页面配置解析错误时提示
      if (!config) {
@@ -218,8 +236,6 @@
      }
      if (_curUserConfig) {
        config.easyCode = _curUserConfig.easyCode || config.easyCode || ''
        config.action = config.action.map(item => {
          if (_curUserConfig.action[item.uuid]) {
            delete _curUserConfig.action[item.uuid].label
@@ -240,12 +256,6 @@
          return item
        })
      }
      let _tabActive = {} // 筛选展开的tab页
      config.tabgroups.forEach(group => {
        _tabActive[group.uuid] = group.sublist[0].uuid
      })
      let _arrField = []     // 字段集
      let _columns = []      // 显示列
@@ -336,29 +346,13 @@
        return _item
      })
      if (_curUserConfig) {
        _columns = _columns.map(item => {
          if (_curUserConfig.columns[item.uuid]) {
            delete _curUserConfig.columns[item.uuid].label
            item = {...item, ..._curUserConfig.columns[item.uuid]}
          }
          return item
        })
        _columns.sort((pre, next) => {
          return pre.sort - next.sort
        })
      }
      this.setState({
        loadingview: false,
        absFields,
        chartId,
        config,
        statFields,
        userConfig,
        tabActive: _tabActive,
        shortcuts,
        setting: config.setting,
        searchlist: config.search,
        actions: _actions,
@@ -387,8 +381,12 @@
  }
  setShortcut = () => {
    const { actions, userConfig, config } = this.state
    if (!userConfig) return
    const { shortcuts } = this.state
    if (!shortcuts || shortcuts.length === 0) {
      document.onkeydown = () => {}
      return
    }
    document.onkeydown = (event) => {
      let e = event || window.event
@@ -403,56 +401,21 @@
        preKey = 'alt'
      }
      if (!preKey) return
      if (!preKey || !keyCode) return
      let triggerId = ''
      let _shortcut = preKey + keyCode
      actions.some(item => {
        if (Array.isArray(item.shortcut) && preKey === item.shortcut[0] && keyCode === item.shortcut[1]) {
          e.preventDefault()
          triggerId = item.uuid
      shortcuts.some(item => {
        if (item.shortcut === _shortcut) {
          MKEmitter.emit('triggerBtnId', item.uuid)
          let element = item.parentId ? document.getElementById(item.parentId) : '' // 标签切换
          if (element && element.click) {
            element.click()
          }
          return true
        }
        return false
      })
      if (triggerId) {
        MKEmitter.emit('triggerBtnId', triggerId)
        return
      }
      Object.keys(userConfig).some(key => {
        if (key === this.props.MenuID || !userConfig[key].action) return false
        let _actions = userConfig[key].action
        Object.keys(_actions).some(btnkey => {
          let item = _actions[btnkey]
          if (Array.isArray(item.shortcut) && preKey === item.shortcut[0] && keyCode === item.shortcut[1]) {
            e.preventDefault()
            triggerId = btnkey
            let _groupId = ''
            let _ActiveTabId = ''
            config.tabgroups.forEach(group => {
              let _tab = group.sublist.filter(tab => tab.uuid === key)[0]
              if (!_tab) return
              _groupId = group.uuid
              _ActiveTabId = _tab.uuid
            })
            if (_ActiveTabId && this.state.tabActive[_groupId] === _ActiveTabId) {
              MKEmitter.emit('triggerBtnId', triggerId)
              return true
            }
          }
          return false
        })
        if (triggerId) return true
        return false
      })
    }
@@ -884,8 +847,8 @@
  }
  render() {
    const { menuType, MenuName } = this.props
    const { BID, setting, searchlist, pageSize, actions, columns, loadingview, viewlost, pickup, config, userConfig, tabActive, chartId, search, selectedData } = this.state
    const { menuType } = this.props
    const { BID, setting, searchlist, pageSize, actions, columns, loadingview, viewlost, pickup, config, chartId, search, selectedData } = this.state
    return (
      <div className="commontable" id={this.state.ContainerId}>
@@ -920,16 +883,6 @@
                    />
                  </div>
                  <div className="main-table-box">
                    {this.props.menuType !== 'HS' ? <SettingComponent
                      config={config}
                      columns={columns}
                      MenuName={MenuName}
                      dict={this.state.dict}
                      MenuID={this.props.MenuID}
                      permAction={this.props.permAction}
                      userConfig={this.state.userConfig}
                      reloadview={this.reloadview}
                    /> : null}
                    {(setting.tableType === 'radio' || setting.tableType === 'checkbox') && this.state.data && this.state.data.length > 0 ?
                      <Switch title="收起" className="main-pickup" checkedChildren="开" unCheckedChildren="关" defaultChecked={pickup} onChange={this.pickupChange} /> : null
                    }
@@ -986,11 +939,11 @@
          })}
        </Row> : null }
        {setting && config.tabgroups.map(group => (
          <Tabs key={group.uuid} onChange={(key) => this.setState({tabActive: {...tabActive, [group.uuid]: key}})}>
          <Tabs key={group.uuid}>
            {group.sublist.map(_tab => {
              return (
                <TabPane tab={
                  <span>
                  <span id={_tab.uuid}>
                    {_tab.icon ? <Icon type={_tab.icon} /> : null}
                    {_tab.label}
                  </span>
@@ -999,7 +952,6 @@
                    Tab={_tab}
                    MenuID={_tab.linkTab}
                    mainSearch={_tab.searchPass === 'true' ? search : null}
                    userConfig={userConfig ? userConfig[_tab.uuid] : null}
                    SupMenuID={this.props.MenuID}
                    ContainerId={this.state.ContainerId}
                    BID={this.state.BIDs[_tab.supMenu] || ''}
@@ -1012,6 +964,7 @@
          </Tabs>))
        }
        {menuType !== 'HS' ? <PagemsgComponent menu={{MenuName: this.props.MenuName, MenuNo: this.props.MenuNo}} config={config} dict={this.state.dict} /> : null}
        {menuType !== 'HS' ? <SettingComponent config={config} dict={this.state.dict} MenuID={this.props.MenuID} permAction={this.props.permAction}/> : null}
        {viewlost ? <NotFount msg={this.state.lostmsg} /> : null}
      </div>
    )