king
2022-10-22 03a22ec6f9ad7303d10b4c65bb5bc6fa5cbd448a
src/tabviews/custom/components/tabs/antv-tabs/index.jsx
@@ -13,26 +13,45 @@
class antvTabs extends Component {
  static propTpyes = {
    BID: PropTypes.any,              // 页面BID
    bids: PropTypes.any,             // 父级Id集
    config: PropTypes.object,        // 组件配置信息
    mainSearch: PropTypes.any,       // 外层搜索条件
    menuType: PropTypes.any,         // 菜单类型
  }
  state = {
    tabs: null,
    parentIds: [],
    bids: {},
    activeIndex: 1
  }
  UNSAFE_componentWillMount () {
    const { config, bids } = this.props
    const { config } = this.props
    let _tabs = fromJS(config).toJS()
    if (_tabs.setting.supModule) {
      _tabs.subtabs = []
      let data = window.GLOB.CacheData.get(_tabs.setting.supModule)
      if (data) {
        let val = ''
        Object.keys(data).forEach(key => {
          if (key.toLowerCase() === _tabs.setting.controlField) {
            val = data[key]
          }
        })
        _tabs.subtabs = config.subtabs.filter(tab => {
          if (tab.controlVal === val) {
            return false
          } else if (/,/ig.test(tab.controlVal)) {
            return !tab.controlVal.split(',').includes(val)
          }
          return true
        })
      }
    }
    this.setState({
      tabs: config,
      parentIds: config.parentIds || [],
      bids: bids ? bids : {}
      tabs: _tabs
    })
  }
@@ -46,8 +65,13 @@
    if (config.setting.autoSwitch === 'true' && config.subtabs.length > 1 && config.setting.interval) {
      this.autoSwitch(config.setting.interval)
    }
    MKEmitter.addListener('resetSelectLine', this.resetParentParam)
    if (config.activeKey) {
      let node = document.getElementById('tab' + config.activeKey)
      node && node.click()
    }
    MKEmitter.addListener('resetSelectLine', this.resetParentParam)
  }
  /**
@@ -61,13 +85,32 @@
  }
  resetParentParam = (MenuID, id, data) => {
    const { parentIds, bids } = this.state
    const { tabs } = this.state
    if (!parentIds.includes(MenuID)) return
    this.setState({
      bids: {...bids, [MenuID]: id, [MenuID + '_data']: data}
    })
    if (tabs.setting.supModule === MenuID) {
      if (!data) {
        this.setState({
          tabs: {...tabs, subtabs: []}
        })
      } else {
        let val = ''
        Object.keys(data).forEach(key => {
          if (key.toLowerCase() === tabs.setting.controlField) {
            val = data[key]
          }
        })
        this.setState({
          tabs: {...tabs, subtabs: this.props.config.subtabs.filter(tab => {
            if (tab.controlVal === val) {
              return false
            } else if (/,/ig.test(tab.controlVal)) {
              return !tab.controlVal.split(',').includes(val)
            }
            return true
          })}
        })
      }
    }
  }
  autoSwitch = (interval) => {
@@ -95,15 +138,17 @@
  }
  render() {
    const { mainSearch, BID } = this.props
    const { tabs, bids } = this.state
    const { mainSearch } = this.props
    const { tabs } = this.state
    if (!tabs.subtabs.length) return null
    return (
      <div className={'menu-antv-tabs-wrap ' + tabs.setting.tabLabel} style={tabs.style}>
        <Tabs defaultActiveKey="1" tabPosition={tabs.setting.position} type={tabs.setting.tabStyle}>
      <div className={'menu-antv-tabs-wrap ' + (tabs.setting.tabLabel || '')} style={tabs.style}>
        <Tabs defaultActiveKey="1" tabBarStyle={{background: tabs.setting.backgroundColor || 'transparent'}} tabPosition={tabs.setting.position} type={tabs.setting.tabStyle}>
          {tabs.subtabs.map(tab => (
            <TabPane tab={<span id={'tab' + tab.uuid}>{tab.icon ? <MkIcon type={tab.icon} /> : null}{tab.label}</span>} key={tab.uuid}>
              <TabTransfer BID={BID} config={tab} bids={bids} mainSearch={mainSearch}/>
            <TabPane tab={<span id={'tab' + tab.uuid}>{tab.icon ? <MkIcon type={tab.icon} /> : null}{tab.label}</span>} style={{backgroundColor: tab.backgroundColor || 'transparent'}} key={tab.uuid}>
              <TabTransfer config={tab} mainSearch={mainSearch}/>
            </TabPane>
          ))}
        </Tabs>