king
2023-07-21 71e3da644eca32a5aa40503e903efb0640748093
src/tabviews/commontable/index.jsx
@@ -5,7 +5,6 @@
import Api from '@/api'
import Utils from '@/utils/utils.js'
import options from '@/store/options.js'
import UtilsDM from '@/utils/utils-datamanage.js'
import { updateCommonTable } from '@/utils/utils-update.js'
import asyncComponent from '@/utils/asyncComponent'
@@ -23,8 +22,8 @@
const SubTable = asyncSpinComponent(() => import('@/tabviews/subtable'))
const CardComponent = asyncSpinComponent(() => import('@/tabviews/zshare/cardcomponent'))
const ChartComponent = asyncSpinComponent(() => import('@/tabviews/zshare/chartcomponent'))
const PagemsgComponent = asyncComponent(() => import('@/tabviews/zshare/pageMessage'))
const AutoMatic = asyncComponent(() => import('@/tabviews/zshare/automatic'))
// const PagemsgComponent = asyncComponent(() => import('@/tabviews/zshare/pageMessage'))
// const AutoMatic = asyncComponent(() => import('@/tabviews/zshare/automatic'))
const DebugTable = asyncComponent(() => import('@/tabviews/debugtable'))
const { TabPane } = Tabs
@@ -46,7 +45,6 @@
    lostmsg: '',          // 页面丢失时的提示信息
    config: {},           // 页面配置信息,包括按钮、搜索、显示列、标签等
    shortcuts: null,      // 快捷键
    searchlist: null,     // 搜索条件
    actions: null,        // 按钮集
    columns: null,        // 显示列
    arr_field: '',        // 查询字段集
@@ -65,8 +63,6 @@
    statFields: [],       // 合计字段
    statFValue: [],       // 合计值
    absFields: [],        // 绝对值字段
    loadCustomApi: true,  // 加载外部资源
    hasReqFields: false,
    autoMatic: null,
    visible: false
  }
@@ -212,19 +208,13 @@
        chartId = config.charts[0] ? config.charts[0].uuid : ''
      }
      config.search = Utils.initSearchVal(config.search)
      Utils.initSearchVal(config)
      // 字段透视及必填标志
      let hasReqFields = false
      config.search = config.search.map(item => {
        if (['text', 'select', 'link'].includes(item.type) && param && param.$searchkey === item.field) {
          item.initval = param.$searchval
        }
        if (item.required) {
          hasReqFields = true
        }
        return item
      })
@@ -247,7 +237,7 @@
      config.setting.customScript = ''                                // 自定义脚本
      config.setting.dataresource = config.setting.dataresource || ''
      if (config.setting.interType === 'system' || (config.setting.interType === 'custom' && config.setting.requestMode === 'system')) {
      if (config.setting.interType === 'system') {
        if (config.setting.scripts && config.setting.scripts.length > 0) {
          let _customScript = ''
          config.setting.scripts.forEach(item => {
@@ -266,10 +256,8 @@
        }
  
        if (sessionStorage.getItem('dataM') === 'true') { // 数据权限
          config.setting.dataresource = config.setting.dataresource.replace(/\$@/ig, '/*')
          config.setting.dataresource = config.setting.dataresource.replace(/@\$/ig, '*/')
          config.setting.customScript = config.setting.customScript.replace(/\$@/ig, '/*')
          config.setting.customScript = config.setting.customScript.replace(/@\$/ig, '*/')
          config.setting.dataresource = config.setting.dataresource.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/')
          config.setting.customScript = config.setting.customScript.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/')
        } else {
          config.setting.dataresource = config.setting.dataresource.replace(/@\$|\$@/ig, '')
          config.setting.customScript = config.setting.customScript.replace(/@\$|\$@/ig, '')
@@ -447,6 +435,19 @@
        }
      }
      config.type = 'table'
      config.wrap = {
        show: config.setting.show || '',
        float: config.setting.float || '',
        advanceType: config.setting.advanceType || '',
        advanceWidth: config.setting.advanceWidth || '',
        drawerPlacement: config.setting.drawerPlacement || '',
        searchRatio: config.setting.searchRatio || '',
        searchLwidth: config.setting.searchLwidth,
        borderRadius: config.setting.borderRadius,
        resetContrl: config.setting.resetContrl,
      }
      this.setState({
        pageSize: config.setting.pageSize || 10,
        loadingview: false,
@@ -457,13 +458,11 @@
        statFields,
        shortcuts: shortcuts.length > 0 ? shortcuts : null,
        setting: config.setting,
        searchlist: config.search,
        actions: _actions,
        columns: _columns,
        arr_field: _arrField.join(','),
        BID: param && param.$BID ? param.$BID : '',
        search: Utils.initMainSearch(config.search),
        hasReqFields
        search: Utils.initMainSearch(config.search)
      }, () => {
        if (config.setting.onload !== 'false') { // 初始化可加载
          this.loadData()
@@ -531,14 +530,14 @@
  loadData = (id) => {
    const { MenuID } = this.props
    const { setting, search, loadCustomApi, hasReqFields, ContainerId } = this.state
    const { setting, search, config, ContainerId } = this.state
    this.setState({
      selectedData: []
    })
    MKEmitter.emit('changeTableLine', ContainerId, MenuID, '', '')
    if (hasReqFields) {
    if (config.$s_req) {
      let requireFields = search.filter(item => item.required && item.value === '')
      if (requireFields.length > 0) {
@@ -549,186 +548,16 @@
      }
    }
    if (window.GLOB.systemType === 'production' && setting.interType === 'custom' && !setting.proInterface) {
    if (setting.interType === 'custom') {
      notification.warning({
        top: 92,
        message: '未设置正式系统地址!',
        message: '系统不在支持自定义接口!',
        duration: 3
      })
      return
    }
    if (setting.interType === 'custom' && loadCustomApi) {
      if (setting.execTime === 'once') {
        this.setState({loadCustomApi: false})
      }
      this.loadOutResource()
      if (setting.execType === 'async') {
        this.loadmaindata(id)
      }
    } else {
      this.loadmaindata(id)
    }
  }
  loadOutResource = () => {
    const { setting, search, BID } = this.state
    let param = UtilsDM.getPrevQueryParams(setting, search, BID)
    if (setting.execType === 'sync') {
      this.setState({
        loading: true
      })
    }
    Api.genericInterface(param).then(res => {
      if (res.status) {
        if (res.mk_ex_invoke === 'false' || res.mk_ex_invoke === false) {
          this.loadmaindata()
        } else {
          this.customOuterRequest(res)
        }
      } else {
        this.setState({
          loading: false
        })
        notification.error({
          top: 92,
          message: res.message,
          duration: 10
        })
      }
    }, () => {
      this.setState({
        loading: false
      })
    })
  }
  customOuterRequest = (result) => {
    const { setting } = this.state
    let url = ''
    if (window.GLOB.systemType === 'production') {
      url = setting.proInterface
    } else {
      url = setting.interface
    }
    let mkey = result.mk_api_key || ''
    delete result.mk_ex_invoke // 是否继续执行
    delete result.status
    delete result.message
    delete result.ErrCode
    delete result.ErrMesg
    delete result.mk_api_key   // 当前请求的key值,用于回调
    let param = {}
    Object.keys(result).forEach(key => {
      key = key.replace(/^mk_/ig, '')
      param[key] = result[key]
    })
    Api.directRequest(url, setting.method, param, setting.cross).then(res => {
      if (typeof(res) !== 'object') {
        let error = '未知的返回结果!'
        if (typeof(res) === 'string') {
          error = res.replace(/'/ig, '"')
        }
        let _result = {
          mk_api_key: mkey,
          $ErrCode: 'E',
          $ErrMesg: error
        }
        this.customCallbackRequest(_result)
      } else {
        if (Array.isArray(res)) {
          res = { data: res }
        }
        res.mk_api_key = mkey
        this.customCallbackRequest(res)
      }
    }, (e) => {
      let _result = {
        mk_api_key: mkey,
        $ErrCode: 'E',
        $ErrMesg: e && e.statusText ? e.statusText : ''
      }
      this.customCallbackRequest(_result)
    })
  }
  customCallbackRequest = (result) => {
    const { setting, BID } = this.state
    let errSql = ''
    if (result.$ErrCode === 'E') {
      errSql = `
        set @ErrorCode='E'
        set @retmsg='${result.$ErrMesg}'
      `
      delete result.$ErrCode
      delete result.$ErrMesg
    }
    let lines = UtilsDM.getCallBackSql(setting, result)
    let param = {}
    if (setting.callbackType === 'script') { // 使用自定义脚本
      let sql = lines.map(item => (`
        ${item.insert}
        ${item.selects.join(` union all
        `)}
      `))
      sql = sql.join('')
      param = UtilsDM.getCallBackQueryParams(setting, sql, errSql, BID)
    } else {
      param.func = 's_ex_result_back'
      param.s_ex_result = lines.map((item, index) => ({
        MenuID: this.state.config.MenuID,
        MenuName: this.state.config.MenuName,
        TableName: item.table,
        LongText: window.btoa(window.encodeURIComponent(`${item.insert}  ${item.selects.join(` union all `)}`)),
        Sort: index + 1
      }))
      if (window.GLOB.debugger === true || (window.debugger === true && options.sysType !== 'cloud')) {
        let sql = lines.map(item => (`
          ${item.insert}
          ${item.selects.join(` union all
          `)}
        `))
        sql = sql.join('')
        console.info(sql.replace(/\n\s{10}/ig, '\n'))
      }
    }
    Api.genericInterface(param).then(res => {
      if (res.status) {
        this.loadmaindata()
      } else {
        this.setState({
          loading: false
        })
        notification.error({
          top: 92,
          message: res.message,
          duration: 10
        })
      }
    }, () => {
      this.setState({
        loading: false
      })
    })
    this.loadmaindata(id)
  }
  /**
@@ -898,7 +727,7 @@
  getStatFieldsValue = () => {
    const { setting, search, BID, orderBy, statFields } = this.state
    if (statFields.length === 0 || !(setting.interType === 'system' || (setting.interType === 'custom' && setting.requestMode === 'system')) || !setting.dataresource) return
    if (statFields.length === 0 || setting.interType !== 'system' || !setting.dataresource) return
    let _orderBy = orderBy || setting.order
    let param = UtilsDM.getStatQueryDataParams(setting, statFields, search, _orderBy, BID)
@@ -1015,7 +844,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, searchlist: null
      pageSize: 10, orderBy: '', search: '', BIDs: {}, pickup: false
    }, () => {
      this.loadconfig()
    })
@@ -1167,13 +996,13 @@
  render() {
    const { MenuID } = this.props
    const { BID, setting, searchlist, pageSize, actions, columns, loadingview, viewlost, pickup, config, chartId, search, selectedData, shortcuts, autoMatic } = this.state
    const { BID, setting, pageSize, actions, columns, loadingview, viewlost, pickup, config, chartId, search, selectedData, shortcuts } = 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} refreshdata={this.refreshbysearch}/> : null
        {config && config.search && config.search.length ?
          <MainSearch BID={BID} config={config} refreshdata={this.refreshbysearch}/> : null
        }
        {setting && config.charts ? <Row className="chart-view" gutter={16}>
          {/* 视图组 */}
@@ -1305,8 +1134,8 @@
          </Tabs>))
        }
        {setting && window.GLOB.breakpoint ? <DebugTable /> : 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}/> : 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}/> : null} */}
        {!window.GLOB.mkHS && setting ? <SettingComponent config={config} shortcuts={shortcuts || []}/> : null}
        {viewlost ? <NotFount msg={this.state.lostmsg} /> : null}
      </div>