king
2021-01-25 5849fe8dd015b076c303f89233d59561a69571fa
2021-01-25
4个文件已修改
341 ■■■■■ 已修改文件
src/tabviews/commontable/index.jsx 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/tabviews/subtable/index.jsx 321 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/templates/comtableconfig/index.jsx 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/templates/subtableconfig/index.jsx 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/tabviews/commontable/index.jsx
@@ -65,7 +65,8 @@
    statFields: [],       // 合计字段
    statFValue: [],       // 合计值
    absFields: [],        // 绝对值字段
    loadCustomApi: true   // 加载外部资源
    loadCustomApi: true,  // 加载外部资源
    hasReqFields: false
  }
  /**
@@ -341,14 +342,20 @@
      }
      let valid = true // 搜索条件必填验证, 初始搜索条件, 如通过上级透视,写入搜索条件
      let hasReqFields = false
      let initSearch = config.search.map(item => {
        let _item = fromJS(item).toJS()
        if (_item.required === 'true' && !_item.initval) {
          valid = false
        }
        if (_item.required === 'true') {
          hasReqFields = true
        }
        return _item
      })
      initSearch = Utils.initMainSearch(initSearch)
      this.setState({
        loadingview: false,
@@ -363,7 +370,8 @@
        columns: _columns,
        arr_field: _arrField.join(','),
        BID: param && param.BID ? param.BID : '',
        search: Utils.initMainSearch(initSearch) // 搜索条件初始化(含有时间格式,需要转化)
        search: Utils.initMainSearch(initSearch), // 搜索条件初始化(含有时间格式,需要转化)
        hasReqFields
      }, () => {
        if (config.setting.onload !== 'false' && valid) { // 初始化可加载
          this.loadData()
@@ -447,7 +455,7 @@
        duration: 3
      })
      return
    } else if (window.GLOB.systemType === 'production' && !setting.proInterface) {
    } else if (window.GLOB.systemType === 'production' && setting.interType === 'custom' && !setting.proInterface) {
      notification.warning({
        top: 92,
        message: '未设置正式系统地址!',
src/tabviews/subtable/index.jsx
@@ -8,6 +8,7 @@
import zhCN from '@/locales/zh-CN/main.js'
import enUS from '@/locales/en-US/main.js'
import Utils from '@/utils/utils.js'
import options from '@/store/options.js'
import UtilsDM from '@/utils/utils-datamanage.js'
import UtilsUpdate from '@/utils/utils-update.js'
import { modifyTabview } from '@/store/action'
@@ -61,6 +62,8 @@
    statFields: [],       // 合计字段
    statFValue: [],       // 合计值
    absFields: [],        // 绝对值字段
    loadCustomApi: true,  // 加载外部资源
    hasReqFields: false
  }
  /**
@@ -73,7 +76,7 @@
        pageIndex: 1
      }, () => {
        if (this.state.setting) {
          this.loadmaindata(nextProps.BID, 'refresh')
          this.loadmaindata()
        }
      })
    } else if (!this.props.Tab.supMenu && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
@@ -261,9 +264,13 @@
      }
      let valid = true // 搜索条件必填验证
      let hasReqFields = false
      config.search.forEach(field => {
        if (field.required === 'true' && !field.initval) {
          valid = false
        }
        if (field.required === 'true') {
          hasReqFields = true
        }
      })
@@ -316,7 +323,8 @@
        actions: _actions,
        columns: _columns,
        arr_field: _arrField.join(','),
        search: Utils.initMainSearch(config.search) // 搜索条件初始化(含有时间格式,需要转化)
        search: Utils.initMainSearch(config.search), // 搜索条件初始化(含有时间格式,需要转化)
        hasReqFields
      }, () => {
        if (config.setting.onload !== 'false' && (!Tab.supMenu || BID || Tab.isTreeNode) && valid) { // 初始化可加载
          this.loadmaindata()
@@ -336,15 +344,286 @@
      })
    }
  }
  loadData = () => {
    const { mainSearch, BID } = this.props
    const { setting, search, loadCustomApi } = this.state
    let searches = fromJS(search).toJS()
    if (mainSearch && mainSearch.length > 0) { // 主表搜索条件
      searches = [...mainSearch, ...searches]
    }
    let requireFields = searches.filter(item => item.required && (!item.value || item.value.length === 0))
    let prex = this.props.Tab && this.props.Tab.label ? this.props.Tab.label + '-' : ''
    if (requireFields.length > 0) {
      let labels = requireFields.map(item => item.label)
      labels = Array.from(new Set(labels))
      notification.warning({
        top: 92,
        message: prex + this.state.dict['form.required.input'] + labels.join('、') + ' !',
        duration: 3
      })
      return
    } else if (this.props.Tab.supMenu && !BID) { // 主表ID不存在时,不查询子表
      this.setState({
        data: [],
        selectedData: [],
        statFValue: [],
        total: 0
      })
      return
    } else if (window.GLOB.systemType === 'production' && setting.interType === 'custom' && !setting.proInterface) {
      notification.warning({
        top: 92,
        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()
      }
    } else {
      this.loadmaindata()
    }
  }
  loadOutResource = () => {
    const { setting, search, BID } = this.state
    let param = UtilsDM.getPrevQueryParams(setting, search, BID, this.props.menuType)
    if (setting.execType === 'sync') {
      this.setState({
        loading: true
      })
    }
    Api.genericInterface(param).then(res => {
      if (res.status) {
        if (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
    let param = {}
    Object.keys(result).forEach(key => {
      key = key.replace(/^mk_/ig, '')
      param[key] = result[key]
    })
    Api.directRequest(url, setting.method, param).then(res => {
      if (typeof(res) !== 'object' || Array.isArray(res)) {
        let error = '未知的返回结果!'
        if (typeof(res) === 'string') {
          error = res
        }
        let _result = {
          mk_api_key: mkey,
          $ErrCode: 'E',
          $ErrMesg: error
        }
        this.customCallbackRequest(_result)
      } else {
        res.mk_api_key = mkey
        this.customCallbackRequest(res)
      }
    }, () => {
      this.setState({
        loading: false
      })
    })
  }
  customCallbackRequest = (result) => {
    const { setting } = this.state
    let lines = []
    let pre = setting.callbackType === 'script' ? '@' : ''
    let errSql = ''
    if (result.$ErrCode === 'E') {
      errSql = `
        set @ErrorCode='E'
        set @retmsg='${result.$ErrMesg}'
      `
      delete result.$ErrCode
      delete result.$ErrMesg
    }
    let getDefaultSql = (obj, tb, bid, level) => {
      let keys = []
      let vals = []
      let subObjs = []
      let id = Utils.getuuid()
      delete obj.$$key
      Object.keys(obj).forEach(key => {
        let val = obj[key]
        if (typeof(val) === 'object') {
          if (Array.isArray(val)) {
            val.forEach(item => {
              if (typeof(item) !== 'object' || Array.isArray(item)) return
              if (Object.keys(item).length > 0) {
                item.$$key = tb + '_' + key
                subObjs.push(item)
              }
            })
          } else if (Object.keys(val).length > 0) {
            val.$$key = tb + '_' + key
            subObjs.push(val)
          }
        } else if (val !== null && val !== undefined) {
          keys.push(key)
          vals.push(`'${val}'`)
        }
      })
      lines.push({
        table: tb,
        insert: `Insert into ${pre}${tb} (${keys.join(',')},mk_level,mk_id,mk_bid)`,
        select: `Select ${vals.join(',')},'${level}','${id}','${bid}'`
      })
      subObjs.forEach(item => {
        getDefaultSql(item, item.$$key, id, level + 1)
      })
    }
    getDefaultSql(result, setting.cbTable, '', 1)
    let lineMap = new Map()
    lines.forEach(line => {
      if (lineMap.has(line.table)) {
        let _line = lineMap.get(line.table)
        _line.selects.push(line.select)
        lineMap.set(line.table, _line)
      } else {
        lineMap.set(line.table, {
          table: line.table,
          insert: line.insert,
          selects: [line.select]
        })
      }
    })
    let param = {}
    if (setting.callbackType === 'script') { // 使用自定义脚本
      let sql = [...lineMap.values()].map(item => (`
        ${item.insert}
        ${item.selects.join(` union all
        `)}
      `))
      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)
      }
    } else {
      param.func = 's_ex_result_back'
      param.s_ex_result = [...lineMap.values()].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.systemType !== 'production' && options.sysType !== 'cloud') || window.debugger === true) {
        let sql = [...lineMap.values()].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
      })
    })
  }
  /**
   * @description 子表数据加载
   */
  async loadmaindata (bid, type) {
    const { mainSearch } = this.props
  async loadmaindata () {
    const { mainSearch, BID } = this.props
    const { setting, arr_field, search, orderBy, pageIndex, pageSize, absFields } = this.state
    let _BID = this.props.BID
    let searches = fromJS(search).toJS()
    if (mainSearch && mainSearch.length > 0) { // 主表搜索条件
      searches = [...mainSearch, ...searches]
@@ -365,26 +644,22 @@
      return
    }
    if (type === 'refresh') {
      if (!bid) { // 主表ID不存在时,不查询子表
        this.setState({
          data: [],
          statFValue: [],
          total: 0
        })
        return
      } else {
        _BID = bid
      }
    if (this.props.Tab.supMenu && !BID) { // 主表ID不存在时,不查询子表
      this.setState({
        data: [],
        selectedData: [],
        statFValue: [],
        total: 0
      })
      return
    }
    this.setState({
      selectedData: [],
      loading: true
    })
    let _orderBy = orderBy || setting.order
    let param = UtilsDM.getQueryDataParams(setting, arr_field, searches, _orderBy, pageIndex, pageSize, _BID, this.props.menuType)
    let param = UtilsDM.getQueryDataParams(setting, arr_field, searches, _orderBy, pageIndex, pageSize, BID, this.props.menuType)
    this.handleTableId()
@@ -394,7 +669,7 @@
    let result = await Api.genericInterface(param)
    this.getStatFieldsValue(_BID, searches)
    this.getStatFieldsValue(searches)
    if (result.status) {
      this.setState({
@@ -409,7 +684,7 @@
          }
          item.key = index
          item.$$uuid = item[setting.primaryKey] || ''
          item.$$BID = _BID || ''
          item.$$BID = BID || ''
          return item
        }),
@@ -418,6 +693,7 @@
        loading: false
      })
    } else {
      let prex = this.props.Tab && this.props.Tab.label ? this.props.Tab.label + '-' : ''
      this.setState({
        loading: false
      })
@@ -504,13 +780,14 @@
  /**
   * @description 获取合计字段值
   */
  getStatFieldsValue = (bid, searches) => {
  getStatFieldsValue = (searches) => {
    const { BID } = this.props
    const { setting, orderBy, statFields } = this.state
    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, searches, _orderBy, bid, this.props.menuType)
    let param = UtilsDM.getStatQueryDataParams(setting, statFields, searches, _orderBy, BID, this.props.menuType)
    if (param.func === 'sPC_Get_TableData') {
      param.menuname = this.props.Tab.label || ''
src/templates/comtableconfig/index.jsx
@@ -819,7 +819,7 @@
        _view = item.tabTemplate    // 新标签页模板
        _btnTab = item
      } else if (type === 'button' && item.OpenType === 'popview') {
        _view = item.tabType        // 新弹窗标签模板
        _view = item.tabType || 'SubTable' // 新弹窗标签模板 tabType 属性已去除
        uuid = item.linkTab
        isbutton = false
      } else if (type === 'tab') {
src/templates/subtableconfig/index.jsx
@@ -195,7 +195,7 @@
    if (editSubTab) {
      _subconfig = tabConfig
      if (editTab.hasOwnProperty('OpenType')) {
        _tabview = editTab.tabType
        _tabview = editTab.tabType || 'SubTable'
      } else {
        _tabview = editTab.type
      }
@@ -669,7 +669,7 @@
        if (btn.OpenType === 'pop') {
          _view = 'Modal'             // 表单页面
        } else if (btn.OpenType === 'popview') {
          _view = btn.tabType        // 新弹窗标签模板
          _view = btn.tabType || 'SubTable' // 新弹窗标签模板 tabType 属性已去除
          _subtab = btn
          if (editSubTab) {