king
2023-01-16 97e18fa9b628357fa43013cfefc96eec078de25e
src/tabviews/custom/components/card/table-card/index.jsx
@@ -1,8 +1,7 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import { is, fromJS } from 'immutable'
import { Spin, notification, Row, Col, Empty, Pagination } from 'antd'
import { Spin, notification, Row, Col, Empty, Pagination, Modal } from 'antd'
import { DownOutlined } from '@ant-design/icons'
import Api from '@/api'
@@ -34,6 +33,8 @@
    data: null,                // 数据
    BData: ''
  }
  loaded = false
  /**
   * @description 初始化处理
@@ -105,6 +106,8 @@
    _config.wrap.pagestyle = _config.wrap.pagestyle || 'page'
    this.loaded = _data !== null
    this.setState({
      sync: _sync,
      BID: BID || '',
@@ -138,6 +141,21 @@
        }, () => {
          this.loadData('timer')
        })
      })
    }
    if (config.$cache && !this.loaded) {
      Api.getLCacheConfig(config.uuid).then(res => {
        if (!res || this.loaded) return
        let _data = res.map((item, index) => {
          item.key = index
          item.$$uuid = item[config.setting.primaryKey] || ''
          item.$Index = index + 1 + ''
          return item
        })
        this.setState({data: _data})
      })
    }
  }
@@ -179,8 +197,10 @@
        return item
      })
      this.loaded = true
      this.setState({sync: false, data: _data})
    } else if (config.setting.syncRefresh && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
    } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
      this.setState({}, () => {
        this.loadData()
      })
@@ -264,6 +284,8 @@
        data: [],
        total: 0
      })
      this.loaded = true
      return
    }
@@ -296,6 +318,11 @@
      let start = 1
      if (config.setting.laypage) {
        start = config.setting.pageSize * (pageIndex - 1) + 1
      }
      this.loaded = true
      if (config.$cache && pageIndex === 1) {
        Api.writeCacheConfig(config.uuid, result.data || '')
      }
      let data = []
@@ -331,11 +358,18 @@
        loading: false
      })
      this.timer && this.timer.stop()
      notification.error({
        top: 92,
        message: result.message,
        duration: 10
      })
      if (result.ErrCode === 'N') {
        Modal.error({
          title: result.message,
        })
      } else {
        notification.error({
          top: 92,
          message: result.message,
          duration: 10
        })
      }
    }
  }
@@ -348,29 +382,26 @@
  }
  openView = (card, data) => {
    if (card.setting.click === 'menu') {
      let menu = null
    if (card.setting.click === 'menu' && card.setting.menu) {
      let menuId = card.setting.menu.slice(-1)[0]
      let menu = window.GLOB.mkThdMenus.filter(m => m.MenuID === menuId)[0]
      if (card.setting.MenuID) {
        let _menu = this.props.permMenus.filter(m => m.MenuID === card.setting.MenuID)[0] || ''
      if (!menu && card.setting.MenuName && card.setting.MenuID) {
        menu = {
          MenuID: card.setting.MenuID,
          MenuName: _menu ? _menu.MenuName : card.setting.MenuName,
          MenuNo: card.setting.MenuNo,
          type: _menu ? _menu.type : card.setting.tabType
          MenuName: card.setting.MenuName,
          MenuNo: card.setting.MenuNo || '',
          type: card.setting.tabType
        }
      } else if (card.setting.menu && card.setting.menu.length > 0) {
        let menu_id = card.setting.menu.slice(-1)[0]
        menu = this.props.permMenus.filter(m => m.MenuID === menu_id)[0] || ''
      }
        if (!menu) {
          notification.warning({
            top: 92,
            message: '菜单已删除或没有访问权限!',
            duration: 5
          })
          return
        }
      if (!menu) {
        notification.warning({
          top: 92,
          message: '菜单已删除或没有访问权限!',
          duration: 5
        })
        return
      }
      let newtab = {
@@ -380,13 +411,14 @@
      if (card.setting.joint === 'true') {
        newtab.param.$BID = data.$$uuid || ''
        Object.keys(data).forEach(key => {
          if (/^\$/.test(key)) return
          newtab.param[key] = data[key]
        })
      }
      if (['linkage_navigation', 'linkage', 'menu_board'].includes(window.GLOB.navBar)) {
        MKEmitter.emit('modifyTabs', newtab, 'replace')
      } else {
        MKEmitter.emit('modifyTabs', newtab, 'plus', true)
      }
      MKEmitter.emit('modifyTabs', newtab, true)
    } else if (card.setting.click === 'link') {
      let src = card.setting.linkurl
@@ -496,14 +528,4 @@
  }
}
const mapStateToProps = (state) => {
  return {
    permMenus: state.permMenus,
  }
}
const mapDispatchToProps = () => {
  return {}
}
export default connect(mapStateToProps, mapDispatchToProps)(TableCard)
export default TableCard