king
2019-12-13 a70940450c021a47e69abdf8fa8f7f98594601cc
src/tabviews/commontable/index.jsx
@@ -16,14 +16,15 @@
export default class NormalTable extends Component {
  static propTpyes = {
    MenuNo: PropTypes.string, // 菜单参数
    MenuID: PropTypes.string // 菜单Id
    MenuNo: PropTypes.string,  // 菜单参数
    MenuID: PropTypes.string   // 菜单Id
  }
  state = {
    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    loadingview: true,
    viewlost: false,
    loadingview: true,    // 页面加载中
    viewlost: false,      // 页面丢失:1、未获取到配置-页面丢失;2、页面未启用
    lostmsg: '',          // 页面丢失时的提示信息
    config: {},
    searchlist: null,
    actions: null,
@@ -41,39 +42,51 @@
    configMap: {}
  }
  /**
   * @description 获取页面配置信息
   */
  async loadconfig () {
    // 获取主菜单
    let param = {
      func: 'sPC_Get_LongParam',
      MenuID: this.props.MenuID
    }
    let result = await Api.getSystemCacheConfig(param)
    if (result.status && result.LongParam) {
      let config = window.decodeURIComponent(window.atob(result.LongParam))
      let config = ''
      try {
      try { // 配置信息解析
        config = window.decodeURIComponent(window.atob(result.LongParam))
        config = JSON.parse(config)
        this.setState({
          loadingview: false
        })
      } catch (e) {
        this.setState({
          loadingview: false,
          viewlost: true
        })
        config = ''
      }
      // 页面配置解析错误时提示
      if (!config) {
        notification.warning({
          top: 92,
          message: this.state.dict['main.page.settingerror'],
          duration: 10
        })
        return
      }
      let _search = Utils.mainjointsearchkey(config.search)
      let _arrField = []
      let _columns = []
      let _hideCol = []
      // 页面未启用时,显示未启用页面
      if (!config.enabled) {
        this.setState({
          loadingview: false,
          viewlost: true,
          lostmsg: this.state.dict['main.view.unenabled']
        })
        return
      }
      let _arrField = []     // 字段集
      let _columns = []      // 显示列
      let _hideCol = []      // 隐藏及合并列中字段的uuid集
      let colMap = new Map()
      // 1、筛选字段集,2、过滤隐藏列及合并列中的字段uuid
      config.columns.forEach(col => {
        if (col.field) {
          _arrField.push(col.field)
@@ -86,8 +99,10 @@
        colMap.set(col.uuid, col)
      })
      // 生成显示列,处理合并列中的字段
      config.columns.forEach(col => {
        if (_hideCol.includes(col.uuid)) return
        if (col.type === 'colspan' && col.sublist) {
          let _col = JSON.parse(JSON.stringify(col))
          let subColumn = []
@@ -103,31 +118,26 @@
        }
      })
      let _actions = config.action.filter(item => item.position === 'toolbar')
      // let _operation = config.action.filter(item => item.position === 'grid')
      // 添加操作列(存在时)(未经过权限过滤)
      if (config.gridBtn && config.gridBtn.display) {
        _columns.push({
          ...config.gridBtn,
          operations: config.action.filter(item => item.position === 'grid')
        })
      }
      // if (_operation.length > 0) {
      //   _columns.push({
      //     Align: 'center',
      //     uuid: Utils.getuuid(),
      //     IsSort: 'false',
      //     Width: 120,
      //     type: 'action',
      //     style: 'button',
      //     label: this.state.dict['main.column.operation'],
      //     operations: _operation
      //   })
      // }
      // 过滤工具栏按钮(未经过权限过滤)
      let _actions = config.action.filter(item => item.position === 'toolbar')
      this.setState({
        loadingview: false,
        config: config,
        setting: config.setting,
        searchlist: config.search,
        actions: _actions,
        columns: _columns,
        arr_field: _arrField.join(','),
        search: _search ? 'where (' + _search + ')' : '',
        // orderColumn: config.setting.orderColumn,
        search: Utils.initMainSearch(config.search), // 搜索条件初始化(含有时间格式,需要转化)
        loading: true
      }, () => {
        this.improveSearch()
@@ -255,7 +265,9 @@
  async loadmaindata () {
    const { arr_field, pageIndex, pageSize, orderColumn, orderType, search, setting } = this.state
    console.log(setting)
    let _search = Utils.joinMainSearchkey(search)
    _search = _search ? 'where (' + _search + ')' : ''
    // 获取列表数据
    let param = {
      func: setting.innerFunc || 'sPC_Get_TableData',
@@ -265,8 +277,8 @@
    let orderBy = orderColumn ? (orderColumn + ' ' + orderType) : setting.order
    let LText = `select top ${pageSize} ${arr_field} from (select ${arr_field} ,ROW_NUMBER() over(order by ${orderBy}) as rows from ${setting.dataresource} ${search}) tmptable where rows > ${pageSize * (pageIndex - 1)} order by tmptable.rows`
    let DateCount = `select count(1) as total from ${setting.dataresource} ${search}`
    let LText = `select top ${pageSize} ${arr_field} from (select ${arr_field} ,ROW_NUMBER() over(order by ${orderBy}) as rows from ${setting.dataresource} ${_search}) tmptable where rows > ${pageSize * (pageIndex - 1)} order by tmptable.rows`
    let DateCount = `select count(1) as total from ${setting.dataresource} ${_search}`
    console.log(LText)
    param.LText = Utils.formatOptions(LText)
    param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
@@ -284,17 +296,20 @@
        loading: false
      })
    } else {
      // this.setState({
      //   data: [1,2,3,4,5,6,7,8,9,10].map((item, index) => {
      //     let cell = {}
      //     this.state.config.columns.forEach(column => {
      //       if (!column.field) return
      //       cell[column.field] = 'test' + item
      //     })
      //     cell.key = index
      //     return cell
      //   }),
      //   total: 329,
      //   loading: false
      // })
      this.setState({
        data: [1,2,3,4,5,6,7,8,9,10].map((item, index) => {
          let cell = {}
          this.state.config.columns.forEach(column => {
            if (!column.field) return
            cell[column.field] = 'test' + item
          })
          cell.key = index
          return cell
        }),
        total: 329,
        loading: false
      })
      notification.error({
@@ -307,12 +322,11 @@
  refreshbysearch = (searches) => {
    // 搜索条件变化
    let search = Utils.mainjointsearchkey(searches)
    this.refs.mainTable.resetTable()
    this.setState({
      loading: true,
      search: search ? 'where (' + search + ')' : ''
      search: searches
    }, () => {
      this.loadmaindata()
    })
@@ -412,7 +426,7 @@
            </div>
          </div>
        </BackTop>
        {viewlost ? <NotFount /> : null}
        {viewlost ? <NotFount msg={this.state.lostmsg} /> : null}
      </div>
    )
  }