king
2022-09-06 b8e1395f02c929eaa96b949cf6027ee2a43856a6
src/tabviews/commontable/index.jsx
@@ -2,7 +2,7 @@
import PropTypes from 'prop-types'
import {connect} from 'react-redux'
import { is, fromJS } from 'immutable'
import { notification, Spin, Tabs, Icon, Switch, Row, Col } from 'antd'
import { notification, Spin, Tabs, Switch, Row, Col } from 'antd'
import Api from '@/api'
import zhCN from '@/locales/zh-CN/main.js'
@@ -13,6 +13,7 @@
import { updateCommonTable } from '@/utils/utils-update.js'
import asyncComponent from '@/utils/asyncComponent'
import asyncSpinComponent from '@/utils/asyncSpinComponent'
import MkIcon from '@/components/mk-icon'
import MKEmitter from '@/utils/events.js'
import NotFount from '@/components/404'
import './index.scss'
@@ -50,7 +51,7 @@
    searchlist: null,     // 搜索条件
    actions: null,        // 按钮集
    columns: null,        // 显示列
    arr_field: '',        // 使用 sPC_Get_TableData 时的查询字段集
    arr_field: '',        // 查询字段集
    setting: null,        // 页面全局设置:数据源、按钮及显示列固定、主键等
    data: [],             // 列表数据集
    selectedData: [],     // 已选表格数据
@@ -99,7 +100,7 @@
      }
      
      // HS不使用自定义设置
      if (result.LongParamUser && this.props.menuType !== 'HS') {
      if (result.LongParamUser && !window.GLOB.mkHS) {
        try { // 配置信息解析
          let userConfig = JSON.parse(window.decodeURIComponent(window.atob(result.LongParamUser)))
          if (userConfig && !userConfig.version) {
@@ -157,8 +158,8 @@
      config = updateCommonTable(config)
      // 权限过滤
      if (this.props.menuType !== 'HS') {
        config.action = config.action.filter(item => permAction[item.uuid])
      if (!window.GLOB.mkHS) {
        config.action = config.action.filter(item => item.hidden !== 'true' && permAction[item.uuid])
        config.tabgroups.forEach(group => {
          group.sublist = group.sublist.filter(tab => {
            if (tab.supMenu === 'mainTable') {
@@ -168,6 +169,7 @@
          })
        })
      } else {
        config.action = config.action.filter(item => item.hidden !== 'true')
        config.tabgroups.forEach(group => {
          group.sublist = group.sublist.map(tab => {
            if (tab.supMenu === 'mainTable') {
@@ -181,17 +183,22 @@
      config.tabgroups = config.tabgroups.filter(group => group.sublist.length > 0)
      let roleId = sessionStorage.getItem('role_id') || '' // 角色ID
      // 视图权限
      config.charts = config.charts.filter(item => {
        if (item.Hide === 'true') return false
        if (!item.blacklist || item.blacklist.length === 0) return true
        return item.blacklist.filter(v => roleId.indexOf(v) > -1).length === 0
      })
      if (config.charts.length <= 1) {
        config.expand = true
      let chartId = ''
      if (config.charts) {
        // 视图权限
        config.charts = config.charts.filter(item => {
          if (item.Hide === 'true') return false
          if (!item.blacklist || item.blacklist.length === 0) return true
          return item.blacklist.filter(v => roleId.indexOf(v) > -1).length === 0
        })
        if (config.charts.length <= 1) {
          config.expand = true
        }
        chartId = config.charts[0] ? config.charts[0].uuid : ''
      }
      let chartId = config.charts[0] ? config.charts[0].uuid : ''
      config.search = Utils.initSearchVal(config.search)
@@ -257,7 +264,6 @@
        let userName = sessionStorage.getItem('User_Name') || ''
        let fullName = sessionStorage.getItem('Full_Name') || ''
        let city = sessionStorage.getItem('city') || ''
        if (sessionStorage.getItem('isEditState') === 'true') {
          userName = sessionStorage.getItem('CloudUserName') || ''
@@ -266,8 +272,7 @@
        let regs = [
          { reg: /@userName@/ig, value: `'${userName}'` },
          { reg: /@fullName@/ig, value: `'${fullName}'` },
          { reg: /@login_city@/ig, value: `'${city}'` }
          { reg: /@fullName@/ig, value: `'${fullName}'` }
        ]
        regs.forEach(cell => {
@@ -317,6 +322,7 @@
        }
        
        if (item.position === 'toolbar') {
          item.$toolbtn = true
          _actions.push(item)
        } else if (item.position === 'grid') {
          _operations.push(item)
@@ -333,6 +339,15 @@
            col.linkThdMenu = permMenus.filter(m => m.MenuID === menu_id)[0] || ''
          } else {
            col.linkThdMenu = ''
          }
          if (col.type === 'number') {
            col.decimal = col.decimal || 0
            col.round = Math.pow(10, col.decimal)
            if (col.format === 'percent') {
              col.decimal = col.decimal > 2 ? col.decimal - 2 : 0
            }
          }
          col.nameField && _arrField.push(col.nameField) // 链接名字段
@@ -385,6 +400,8 @@
        config.setting.selected = 'false'
      } else if (config.setting.selected === 'init' && config.setting.onload === 'false') {
        config.setting.selected = 'false'
      } else {
        config.setting.orisel = true
      }
      let autoMatic = null
@@ -392,12 +409,23 @@
        _actions.forEach(item => {
          if (item.uuid === config.autoMatic.action && (['pop', 'prompt', 'exec'].includes(item.OpenType) || (item.OpenType === 'funcbutton' && item.funcType === 'print'))) {
            autoMatic = config.autoMatic
            autoMatic.OpenType = item.execMode || item.OpenType
            config.setting.selected = 'false'
            item.autoMatic = true
          }
        })
      }
      if (config.setting.controlField) {
        if (config.setting.controlVal) {
          config.setting.controlVal = config.setting.controlVal.split(',')
        } else {
          config.setting.controlVal = ['']
        }
      }
      this.setState({
        pageSize: config.setting.pageSize || 10,
        loadingview: false,
        absFields,
        autoMatic,
@@ -473,17 +501,14 @@
    }
  }
  loadData = () => {
    const { setting, search, BIDs, loadCustomApi, hasReqFields } = this.state
  loadData = (id) => {
    const { MenuID } = this.props
    const { setting, search, loadCustomApi, hasReqFields, ContainerId } = this.state
    this.setState({
      selectedData: [],
      BIDs: {
        ...BIDs,
        mainTable: '',
        mainTabledata: ''
      }
      selectedData: []
    })
    MKEmitter.emit('changeTableLine', ContainerId, MenuID, '', '')
    if (hasReqFields) {
      let requireFields = search.filter(item => item.required && item.value === '')
@@ -512,17 +537,17 @@
      this.loadOutResource()
      if (setting.execType === 'async') {
        this.loadmaindata()
        this.loadmaindata(id)
      }
    } else {
      this.loadmaindata()
      this.loadmaindata(id)
    }
  }
  loadOutResource = () => {
    const { setting, search, BID } = this.state
    let param = UtilsDM.getPrevQueryParams(setting, search, BID, this.props.menuType)
    let param = UtilsDM.getPrevQueryParams(setting, search, BID)
    if (setting.execType === 'sync') {
      this.setState({
@@ -614,7 +639,7 @@
  }
  customCallbackRequest = (result) => {
    const { setting } = this.state
    const { setting, BID } = this.state
    let errSql = ''
    if (result.$ErrCode === 'E') {
      errSql = `
@@ -636,15 +661,7 @@
      `))
      sql = sql.join('')
      
      param = UtilsDM.getCallBackQueryParams(setting, sql, errSql)
      if (this.state.BID) {
        param.BID = this.state.BID
      }
      if (this.props.menuType === 'HS') { // 函数 sPC_TableData_InUpDe 云端验证
        param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp)
      }
      param = UtilsDM.getCallBackQueryParams(setting, sql, errSql, BID)
    } else {
      param.func = 's_ex_result_back'
      param.s_ex_result = lines.map((item, index) => ({
@@ -655,7 +672,7 @@
        Sort: index + 1
      }))
      if ((window.GLOB.systemType !== 'production' && options.sysType !== 'cloud') || window.debugger === true) {
      if (window.GLOB.debugger === true || (window.debugger === true && options.sysType !== 'cloud')) {
        let sql = lines.map(item => (`
          ${item.insert}
          ${item.selects.join(` union all
@@ -689,15 +706,15 @@
  /**
   * @description 主表数据加载
   */ 
  async loadmaindata () {
    const { setting, arr_field, search, orderBy, BID, pageIndex, pageSize, absFields } = this.state
  async loadmaindata (id) {
    const { setting, arr_field, search, orderBy, BID, pageIndex, pageSize, absFields, autoMatic } = this.state
    this.setState({
      loading: true
    })
    let _orderBy = orderBy || setting.order
    let param = UtilsDM.getQueryDataParams(setting, arr_field, search, _orderBy, pageIndex, pageSize, BID, this.props.menuType)
    let param = UtilsDM.getQueryDataParams(setting, arr_field, search, _orderBy, pageIndex, pageSize, BID)
    let result = await Api.genericInterface(param)
@@ -709,9 +726,9 @@
        start = pageSize * (pageIndex - 1) + 1
      }
      if (setting.selected !== 'false') {
      if (setting.selected !== 'false' || (setting.orisel && id)) {
        setTimeout(() => {
          MKEmitter.emit('mkTableCheckTopLine', this.props.MenuID)
          MKEmitter.emit('mkTableCheckTopLine', this.props.MenuID, id)
        }, 200)
        if (setting.selected === 'init') {
          this.setState({setting: {...setting, selected: 'false'}})
@@ -731,8 +748,15 @@
          item.key = index
          item.$$uuid = item[setting.primaryKey] || ''
          item.$$key = '' + item.key + item.$$uuid
          item.$$BID = BID || ''
          item.$Index = start + index + ''
          if (setting.controlField) {
            if (setting.controlVal.includes(item[setting.controlField])) {
              item.$disabled = true
            }
          }
          return item
        }),
@@ -740,10 +764,21 @@
        loading: false,
        pickup: false
      })
      if (autoMatic) {
        if (result.data && result.data.length > 0) {
          MKEmitter.emit('autoGetData', this.props.MenuID)
        } else {
          MKEmitter.emit('autoMaticOver', this.props.MenuID)
        }
      }
    } else {
      this.setState({
        loading: false
      })
      if (autoMatic) {
        MKEmitter.emit('autoMaticError', this.props.MenuID)
      }
      notification.error({
        top: 92,
        message: result.message,
@@ -763,7 +798,7 @@
    })
    let _orderBy = orderBy || setting.order
    let param = UtilsDM.getQueryDataParams(setting, arr_field, search, _orderBy, pageIndex, pageSize, BID, this.props.menuType, id)
    let param = UtilsDM.getQueryDataParams(setting, arr_field, search, _orderBy, pageIndex, pageSize, BID, id)
    let result = await Api.genericInterface(param)
    if (result.status) {
@@ -787,6 +822,7 @@
          data = data.map(item => {
            if (item.$$uuid === _data.$$uuid) {
              _data.key = item.key
              _data.$$key = '' + item.key + item.$$uuid
              _data.$Index = item.$Index
              return _data
            } else {
@@ -830,7 +866,7 @@
    if (statFields.length === 0 || !(setting.interType === 'system' || (setting.interType === 'custom' && setting.requestMode === 'system')) || !setting.dataresource) return
    let _orderBy = orderBy || setting.order
    let param = UtilsDM.getStatQueryDataParams(setting, statFields, search, _orderBy, BID, this.props.menuType)
    let param = UtilsDM.getStatQueryDataParams(setting, statFields, search, _orderBy, BID)
    Api.genericInterface(param).then(res => {
      if (res.status) {
@@ -881,7 +917,7 @@
        this.loadData()
      })
    } else {
      MKEmitter.emit('resetTable', this.props.MenuID + 'mainTable') // 列表重置
      MKEmitter.emit('resetTable', this.props.MenuID) // 列表重置
      this.setState({
        pageIndex: 1,
        search: searches
@@ -895,6 +931,15 @@
   * @description 表格条件改变时重置数据(分页或排序)
   */
  refreshbytable = (pagination, filters, sorter) => {
    if (!sorter) {
      this.setState({
        pageIndex: pagination.pageIndex
      }, () => {
        this.loadData()
      })
      return
    }
    if (sorter.order) {
      let _chg = {
        ascend: 'asc',
@@ -915,17 +960,17 @@
  /**
   * @description 表格刷新
   */
  reloadtable = (btn) => {
  reloadtable = (btn, id = '') => {
    if (!btn || btn.resetPageIndex !== 'false') {
      MKEmitter.emit('resetTable', this.props.MenuID + 'mainTable') // 列表重置
      MKEmitter.emit('resetTable', this.props.MenuID) // 列表重置
      this.setState({
        pageIndex: 1
      }, () => {
        this.loadData()
        this.loadData(id)
      })
    } else {
      MKEmitter.emit('resetTable', this.props.MenuID + 'mainTable', 'false') // 列表重置
      this.loadData()
      MKEmitter.emit('resetTable', this.props.MenuID, 'false') // 列表重置
      this.loadData(id)
    }
  }
@@ -935,7 +980,7 @@
  reloadview = () => {
    this.setState({ loadingview: true, viewlost: false, config: {}, setting: null,
      data: null, total: 0, loading: false, pageIndex: 1, shortcuts: null,
      pageSize: 10, orderBy: '', search: '', BIDs: {}, pickup: false
      pageSize: 10, orderBy: '', search: '', BIDs: {}, pickup: false, searchlist: null
    }, () => {
      this.loadconfig()
    })
@@ -944,13 +989,13 @@
  /**
   * @description 导出Excel时,获取页面搜索排序等参数
   */
  queryModuleParam = (menuId, btnId) => {
  queryModuleParam = (menuId, callback) => {
    const { MenuName, MenuID } = this.props
    const { arr_field, orderBy, search, setting} = this.state
    if (MenuID !== menuId) return
    MKEmitter.emit('returnModuleParam', MenuID, btnId, {
    callback({
      arr_field: arr_field,
      orderBy: orderBy || setting.order,
      search: search,
@@ -963,21 +1008,6 @@
   */
  changeSelectedData = (selectedData) => {
    this.setState({selectedData})
  }
  /**
   * @description 表格Id变化
   */
  handleTableId = (type, id, data) => {
    const { BIDs } = this.state
    this.setState({
      BIDs: {
        ...BIDs,
        [type]: id,
        [type + 'data']: data
      }
    })
  }
  
  /**
@@ -1001,7 +1031,6 @@
    const { MenuID } = this.props
    if (MenuID !== menuId) return
    if (id === 'empty') return
    if (id === 'formtab') { // 表单标签页刷新
      this.reloadtable(btn)
@@ -1035,18 +1064,30 @@
    this.setShortcut()
  }
  changeTableLine = (ContainerId, tableId, id, data) => {
    if (this.state.ContainerId !== ContainerId) return
    this.setState({
      BIDs: {...this.state.BIDs, [tableId]: id, [tableId + 'data']: data}
    })
  }
  /**
   * @description 按钮执行完成后页面刷新
   * @param {*} menuId     // 菜单Id
   * @param {*} position   // 刷新位置
   * @param {*} btn        // 执行的按钮
   */
  refreshByButtonResult = (menuId, position, btn) => {
  refreshByButtonResult = (menuId, position, btn, id, lines) => {
    const { MenuID } = this.props
    if (MenuID !== menuId) return
    this.reloadtable(btn)
    if (position === 'line' && lines && lines.length === 1) {
      this.loadmainLinedata(lines[0].$$uuid)
    } else {
      this.reloadtable(btn, id)
    }
  }
  UNSAFE_componentWillMount () {
@@ -1061,6 +1102,7 @@
  componentDidMount () {
    MKEmitter.addListener('reloadData', this.reloadData)
    MKEmitter.addListener('reloadMenuView', this.reloadMenuView)
    MKEmitter.addListener('changeTableLine', this.changeTableLine)
    MKEmitter.addListener('resetActiveMenu', this.resetActiveMenu)
    MKEmitter.addListener('queryModuleParam', this.queryModuleParam)
    MKEmitter.addListener('refreshByButtonResult', this.refreshByButtonResult)
@@ -1076,26 +1118,27 @@
    document.onkeydown = () => {}
    MKEmitter.removeListener('reloadData', this.reloadData)
    MKEmitter.removeListener('reloadMenuView', this.reloadMenuView)
    MKEmitter.removeListener('changeTableLine', this.changeTableLine)
    MKEmitter.removeListener('resetActiveMenu', this.resetActiveMenu)
    MKEmitter.removeListener('queryModuleParam', this.queryModuleParam)
    MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult)
  }
  render() {
    const { menuType, MenuID } = this.props
    const { MenuID } = this.props
    const { BID, setting, searchlist, pageSize, actions, columns, loadingview, viewlost, pickup, config, chartId, search, selectedData, shortcuts, autoMatic } = this.state
    return (
      <div className="commontable" id={this.state.ContainerId}>
        {loadingview ? <Spin size="large" /> : null}
        {searchlist && searchlist.length ?
          <MainSearch BID={BID} searchlist={searchlist} setting={setting} menuType={this.props.menuType} refreshdata={this.refreshbysearch}/> : null
          <MainSearch BID={BID} searchlist={searchlist} setting={setting} refreshdata={this.refreshbysearch}/> : null
        }
        {setting ? <Row className="chart-view" gutter={16}>
        {setting && config.charts ? <Row className="chart-view" gutter={16}>
          {/* 视图组 */}
          {!config.expand ? <Tabs activeKey={chartId} onChange={this.changeChart}>
            {config.charts.map(item => (
              <TabPane tab={<Icon type={item.icon} />} key={item.uuid}></TabPane>
              <TabPane tab={<MkIcon type={item.icon} />} key={item.uuid}></TabPane>
            ))}
          </Tabs> : null}
          {config.charts.map(item => {
@@ -1135,7 +1178,6 @@
                      statFValue={this.state.statFValue}
                      ContainerId={this.state.ContainerId}
                      refreshdata={this.refreshbytable}
                      handleTableId={this.handleTableId}
                      chgSelectData={this.changeSelectedData}
                    />
                  </div>
@@ -1154,7 +1196,6 @@
                    data={this.state.data}
                    loading={this.state.loading}
                    ContainerId={this.state.ContainerId}
                    handleTableId={this.handleTableId}
                  />
                </Col>
              )
@@ -1173,13 +1214,48 @@
            }
          })}
        </Row> : null }
        {setting && !config.charts ? <div className="chart-view">
          <div className="commontable-main-action">
            <MainAction
              BID={BID}
              setting={setting}
              actions={actions}
              columns={columns}
              dict={this.state.dict}
              MenuID={MenuID}
              selectedData={selectedData}
              ContainerId={this.state.ContainerId}
            />
          </div>
          <div className="main-table-box">
            {(setting.tableType === 'radio' || setting.tableType === 'checkbox') && this.state.data && this.state.data.length > 0 ?
              <Switch title="收起" className="main-pickup" checkedChildren="开" unCheckedChildren="关" checked={pickup} onChange={this.pickupChange} /> : null
            }
            <MainTable
              MenuID={MenuID}
              tableId={MenuID}
              pickup={pickup}
              setting={setting}
              columns={columns}
              pageSize={pageSize}
              dict={this.state.dict}
              data={this.state.data}
              total={this.state.total}
              loading={this.state.loading}
              statFValue={this.state.statFValue}
              ContainerId={this.state.ContainerId}
              refreshdata={this.refreshbytable}
              chgSelectData={this.changeSelectedData}
            />
          </div>
        </div> : null }
        {setting && config.tabgroups.map(group => (
          <Tabs key={group.uuid}>
            {group.sublist.map(_tab => {
              return (
                <TabPane tab={
                  <span id={_tab.uuid}>
                    {_tab.icon ? <Icon type={_tab.icon} /> : null}
                    {_tab.icon ? <MkIcon type={_tab.icon} /> : null}
                    {_tab.label}
                  </span>
                } key={_tab.uuid}>
@@ -1191,16 +1267,15 @@
                    ContainerId={this.state.ContainerId}
                    BID={this.state.BIDs[_tab.supMenu] || ''}
                    BData={this.state.BIDs[_tab.supMenu + 'data'] || ''}
                    handleTableId={this.handleTableId}
                  />
                </TabPane>
              )
            })}
          </Tabs>))
        }
        {menuType !== 'HS' && autoMatic ? <AutoMatic autoMatic={autoMatic} config={config} /> : null}
        {menuType !== 'HS' && window.GLOB.systemType !== 'production' ? <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}
        {!window.GLOB.mkHS && autoMatic ? <AutoMatic autoMatic={autoMatic} config={config} /> : null}
        {!window.GLOB.mkHS && window.GLOB.systemType !== 'production' ? <PagemsgComponent menu={{MenuName: this.props.MenuName, MenuNo: this.props.MenuNo}} config={config} dict={this.state.dict} /> : null}
        {!window.GLOB.mkHS && shortcuts ? <SettingComponent config={config} dict={this.state.dict} shortcuts={shortcuts} permAction={this.props.permAction}/> : null}
        {viewlost ? <NotFount msg={this.state.lostmsg} /> : null}
      </div>
    )
@@ -1209,7 +1284,6 @@
const mapStateToProps = (state) => {
  return {
    menuType: state.editLevel,
    permAction: state.permAction,
    permMenus: state.permMenus
  }