king
2021-01-13 23cb54bbb041413ba327d046a4b396267ef2ecfe
src/tabviews/custom/index.jsx
@@ -26,6 +26,7 @@
const MainSearch = asyncComponent(() => import('@/tabviews/zshare/topSearch'))
const NormalTable = asyncComponent(() => import('./components/table/normal-table'))
const NormalGroup = asyncComponent(() => import('./components/group/normal-group'))
const SettingComponent = asyncComponent(() => import('@/tabviews/zshare/settingcomponent'))
const PagemsgComponent = asyncComponent(() => import('@/tabviews/zshare/pageMessage'))
class CustomPage extends Component {
@@ -51,6 +52,7 @@
    loading: false,       // 列表数据加载中
    visible: false,       // 标签页控制
    treevisible: false,   // 菜单结构树弹框显示隐藏控制
    shortcuts: null       // 快捷键
  }
  /**
@@ -67,7 +69,7 @@
    if (result.status) {
      let config = ''
      let userConfig = null
      let shortcuts = []
      try { // 配置信息解析
        config = JSON.parse(window.decodeURIComponent(window.atob(result.LongParam)))
@@ -79,10 +81,15 @@
      // 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)))
          if (userConfig) {
            shortcuts = userConfig.action
            userConfig.printers.forEach(item => {
              window.GLOB.UserCacheMap.set(item.parentId + item.uuid, item)
            })
          }
        } catch (e) {
          console.warn('Parse Failure')
          userConfig = null
        }
      }
@@ -154,7 +161,7 @@
      this.setState({
        BID: BID,
        userConfig: userConfig,
        shortcuts,
        config,
        mainSearch
      }, () => {
@@ -167,6 +174,10 @@
        } else {
          this.loadmaindata(params)
        }
        if (!this.props.Tab) {
          this.setShortcut()
        }
      })
    } else {
      this.setState({
@@ -177,6 +188,41 @@
        top: 92,
        message: result.message,
        duration: 5
      })
    }
  }
  setShortcut = () => {
    const { shortcuts } = this.state
    if (!shortcuts || shortcuts.length === 0) {
      document.onkeydown = () => {}
      return
    }
    document.onkeydown = (event) => {
      let e = event || window.event
      let keyCode = e.keyCode || e.which || e.charCode
      let preKey = ''
      if (e.ctrlKey) {
        preKey = 'ctrl'
      } else if (e.shiftKey) {
        preKey = 'shift'
      } else if (e.altKey) {
        preKey = 'alt'
      }
      if (!preKey || !keyCode) return
      let _shortcut = `${preKey}+${keyCode}`
      shortcuts.some(item => {
        if (item.$shortcut === _shortcut) {
          MKEmitter.emit('triggerBtnId', item.uuid)
          return true
        }
        return false
      })
    }
  }
@@ -260,6 +306,10 @@
          cell.$tabId = tabId
          cell.$type = 'CustomPage'
          if (cell.OpenType === 'funcbutton' && cell.funcType === 'print' && cell.verify) { // 打印机设置
            cell = this.getPrinter(cell, item.uuid)
          }
          return isHS || permAction[cell.uuid]
        })
      }
@@ -281,6 +331,10 @@
              cell.$menuId = item.uuid
              cell.$tabId = tabId
              cell.$type = 'CustomPage'
              if (cell.OpenType === 'funcbutton' && cell.funcType === 'print' && cell.verify) { // 打印机设置
                cell = this.getPrinter(cell, item.uuid)
              }
            } else if (['text', 'number', 'link'].includes(cell.eleType) && !cell.height && _hasheight) {
              cell.innerHeight = 'auto'
            }
@@ -296,6 +350,10 @@
              cell.$menuId = item.uuid
              cell.$tabId = tabId
              cell.$type = 'CustomPage'
              if (cell.OpenType === 'funcbutton' && cell.funcType === 'print' && cell.verify) { // 打印机设置
                cell = this.getPrinter(cell, item.uuid)
              }
            } else if (['text', 'number', 'link'].includes(cell.eleType) && !cell.height && _hasheight) {
              cell.innerHeight = 'auto'
            }
@@ -314,6 +372,10 @@
              cell.$menuId = item.uuid
              cell.$tabId = tabId
              cell.$type = 'CustomPage'
              if (cell.OpenType === 'funcbutton' && cell.funcType === 'print' && cell.verify) { // 打印机设置
                cell = this.getPrinter(cell, item.uuid)
              }
            } else if (['text', 'number', 'link'].includes(cell.eleType) && !cell.height && _hasheight) {
              cell.innerHeight = 'auto'
            }
@@ -331,6 +393,10 @@
            cell.$menuId = item.uuid
            cell.$tabId = tabId
            cell.$type = 'CustomPage'
            if (cell.OpenType === 'funcbutton' && cell.funcType === 'print' && cell.verify) { // 打印机设置
              cell = this.getPrinter(cell, item.uuid)
            }
            return isHS || permAction[cell.uuid]
          })
@@ -355,6 +421,24 @@
      
      return true
    })
  }
  getPrinter = (item, parentId) => {
    let _item = window.GLOB.UserCacheMap.get(parentId + item.uuid)
    if (_item) {
      item.printer = _item.printer || ''
      item.verify.defaultPrinter = _item.printer || ''
      if (item.verify.printerTypeList && _item.printerList) {
        item.verify.printerTypeList = item.verify.printerTypeList.map(cell => {
          cell.printer = _item.printerList[cell.Value] || ''
          return cell
        })
      }
    }
    return item
  }
  getCols = (cols, roleId, permMenus) => {
@@ -620,6 +704,14 @@
    this.reloadview()
  }
  resetActiveMenu = (menuId) => {
    const { MenuID, Tab } = this.props
    if (MenuID !== menuId || Tab) return
    this.setShortcut()
  }
  UNSAFE_componentWillMount () {
    // 组件加载时,获取菜单数据
    this.loadconfig()
@@ -631,6 +723,7 @@
  componentDidMount () {
    MKEmitter.addListener('reloadMenuView', this.reloadMenuView)
    MKEmitter.addListener('resetActiveMenu', this.resetActiveMenu)
  }
  /**
@@ -641,6 +734,7 @@
      return
    }
    MKEmitter.removeListener('reloadMenuView', this.reloadMenuView)
    MKEmitter.removeListener('resetActiveMenu', this.resetActiveMenu)
  }
  reloadview = () => {
@@ -649,7 +743,8 @@
      loadingview: true,    // 页面加载中
      viewlost: false,      // 页面丢失:1、未获取到配置-页面丢失;2、页面未启用
      config: null,         // 页面配置信息,包括组件等
      loading: false        // 列表数据加载中
      loading: false,       // 列表数据加载中
      shortcuts: null
    }, () => {
      this.loadconfig()
    })
@@ -735,13 +830,14 @@
  render() {
    const { menuType } = this.props
    const { loadingview, viewlost, config, loading } = this.state
    const { loadingview, viewlost, config, loading, shortcuts } = this.state
    return (
      <div className={'custom-page-wrap ' + (loadingview || loading ? 'loading' : '')} id={this.state.ContainerId} style={config ? config.style : null}>
        {(loadingview || loading) ? <Spin className="view-spin" size="large" /> : null}
        <Row>{this.getComponents()}</Row>
        {menuType !== 'HS' ? <PagemsgComponent menu={{MenuName: this.props.MenuName, MenuNo: this.props.MenuNo}} config={config} dict={this.state.dict} /> : null}
        {menuType !== 'HS' && shortcuts ? <SettingComponent config={config} dict={this.state.dict} shortcuts={shortcuts} permAction={this.props.permAction}/> : null}
        {viewlost ? <NotFount msg={this.state.lostmsg} /> : null}
      </div>
    )