king
2021-04-07 f3167f8371d19d0ea8fe7d0e7af5517ff0b08cd2
src/tabviews/zshare/actionList/normalbutton/index.jsx
@@ -11,6 +11,7 @@
import zhCN from '@/locales/zh-CN/main.js'
import enUS from '@/locales/en-US/main.js'
import asyncSpinComponent from '@/utils/asyncSpinComponent'
import { updateForm } from '@/utils/utils-update.js'
import MKEmitter from '@/utils/events.js'
import './index.scss'
@@ -53,6 +54,8 @@
    if (position === 'toolbar') {
      MKEmitter.addListener('triggerBtnId', this.actionTrigger)
    } else if (position === 'form') {
      MKEmitter.addListener('triggerFormSubmit', this.actionSubmit)
    }
  }
@@ -61,6 +64,19 @@
      return
    }
    MKEmitter.removeListener('triggerBtnId', this.actionTrigger)
    MKEmitter.removeListener('triggerFormSubmit', this.actionSubmit)
  }
  actionSubmit = (res) => {
    const { btn } = this.props
    if (btn.uuid !== res.menuId) return
    this.setState({
      loading: true
    })
    this.execSubmit(this.state.tabledata, () => {}, res.form)
  }
  /**
@@ -116,7 +132,7 @@
        duration: 5
      })
      return
    } else if (!setting.primaryKey) {
    } else if (btn.OpenType !== 'formSubmit' && !setting.primaryKey) {
      // 需要选择行时,校验是否设置主键
      notification.warning({
        top: 92,
@@ -178,7 +194,13 @@
      return
    }
    if (btn.OpenType === 'prompt') {
    if (btn.OpenType === 'formSubmit') {
      this.setState({
        tabledata: data
      })
      MKEmitter.emit('mkFormSubmit', btn.uuid)
      return
    } else if (btn.OpenType === 'prompt') {
      this.updateStatus('start')
      confirm({
        title: this.state.dict['main.action.confirm.tip'],
@@ -197,9 +219,14 @@
    } else if (btn.OpenType === 'pop') {
      this.updateStatus('start')
      let modal = this.state.btnconfig
      if (!modal && btn.modal) {
        modal = this.handleModelConfig(btn.modal)
      }
      this.setState({
        tabledata: data,
        btnconfig: btn.modal ? btn.modal : this.state.btnconfig
        btnconfig: modal
      }, () => {
        this.improveAction()
      })
@@ -269,7 +296,7 @@
        }
        param.LText = Utils.formatOptions(param.LText)
      } else if (btn.OpenType === 'pop') { // 表单
      } else if (btn.OpenType === 'pop' || btn.OpenType === 'formSubmit') { // 表单
        if (btn.sqlType === 'insert') { // 系统函数添加时,生成uuid
          primaryId = ''
@@ -493,7 +520,7 @@
      param[setting.primaryKey] = primaryId // 设置主键参数
      if (btn.OpenType === 'pop') { // 表单
      if (btn.OpenType === 'pop' || btn.OpenType === 'formSubmit') { // 表单
        formdata.forEach(_data => {
          param[_data.key] = _data.value
        })
@@ -604,7 +631,7 @@
          param.BID = this.props.BID
        }
        if (btn.OpenType === 'pop' && formdata) { // 表单
        if ((btn.OpenType === 'pop' || btn.OpenType === 'formSubmit') && formdata) { // 表单
          formdata.forEach(_data => {
            param[_data.key] = _data.value
          })
@@ -690,10 +717,10 @@
    Api.genericInterface(param).then(res => {
      if (res.status) {
        if (res.mk_ex_invoke === 'false' && params.length === 0) {
        if ((res.mk_ex_invoke === 'false' || res.mk_ex_invoke === false) && params.length === 0) {
          this.execSuccess(res)
          _resolve()
        } else if (res.mk_ex_invoke === 'false' && params.length > 0) {
        } else if ((res.mk_ex_invoke === 'false' || res.mk_ex_invoke === false) && params.length > 0) {
          this.customLoopRequest(params, _resolve)
        } else {
          this.customOuterRequest(params, res, record, _resolve)
@@ -707,10 +734,10 @@
            return new Promise(resolve => {
              Api.genericInterface(_this.state.checkParam).then((result) => {
                if (result.status) {
                  if (result.mk_ex_invoke === 'false' && params.length === 0) {
                  if ((result.mk_ex_invoke === 'false' || result.mk_ex_invoke === false) && params.length === 0) {
                    _this.execSuccess(result)
                    _resolve()
                  } else if (result.mk_ex_invoke === 'false' && params.length > 0) {
                  } else if ((result.mk_ex_invoke === 'false' || result.mk_ex_invoke === false) && params.length > 0) {
                    _this.customLoopRequest(params, _resolve)
                  } else {
                    _this.customOuterRequest(params, result, record, _resolve)
@@ -772,7 +799,7 @@
      param[key] = result[key]
    })
    Api.directRequest(url, btn.method, param).then(res => {
    Api.directRequest(url, btn.method, param, btn.cross).then(res => {
      if (typeof(res) !== 'object' || Array.isArray(res)) {
        let error = '未知的返回结果!'
@@ -1195,7 +1222,7 @@
    }
    if (btn.execSuccess !== 'never') {
      MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execSuccess, btn)
      MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execSuccess || '', btn)
    }
  }
@@ -1397,6 +1424,29 @@
    })
  }
  handleModelConfig = (config) => {
    let roleId = sessionStorage.getItem('role_id') || '' // 角色ID
    config.fields = config.fields.map(cell => {
      // 数据源sql语句,预处理,权限黑名单字段设置为隐藏表单
      if (['select', 'link', 'multiselect', 'radio', 'checkbox', 'checkcard'].includes(cell.type) && cell.resourceType === '1') {
        let _option = Utils.getSelectQueryOptions(cell)
        cell.data_sql = Utils.formatOptions(_option.sql)
        cell.base_sql = window.btoa(window.encodeURIComponent(_option.sql))
        cell.arr_field = _option.field
      }
      // 字段权限黑名单
      if (!cell.blacklist || cell.blacklist.length === 0) return cell
      if (cell.blacklist.filter(v => roleId.indexOf(v) > -1).length > 0) {
        cell.hidden = 'true'
      }
      return cell
    })
    return config
  }
  /**
   * @description 获取按钮配置信息
   */
@@ -1443,67 +1493,9 @@
          })
          this.updateStatus('over')
        } else {
          let roleId = sessionStorage.getItem('role_id') || '' // 角色ID
          if (_LongParam.groups.length > 0) {
            _LongParam.groups.forEach(group => {
              group.sublist = group.sublist.map(cell => {
                // 数据源sql语句,预处理, 权限黑名单字段设置为隐藏表单
                if (['select', 'link', 'multiselect', 'radio', 'checkbox', 'checkcard'].includes(cell.type) && cell.resourceType === '1') {
                  let _option = Utils.getSelectQueryOptions(cell)
                  if (sessionStorage.getItem('dataM') === 'true') { // 数据权限
                    _option.sql = _option.sql.replace(/\$@/ig, '/*')
                    _option.sql = _option.sql.replace(/@\$/ig, '*/')
                  } else {
                    _option.sql = _option.sql.replace(/@\$|\$@/ig, '')
                  }
                  // 外联数据库替换
                  if (window.GLOB.externalDatabase !== null) {
                    _option.sql = _option.sql.replace(/@db@/ig, window.GLOB.externalDatabase)
                  }
                  cell.data_sql = Utils.formatOptions(_option.sql)
                  cell.base_sql = window.btoa(window.encodeURIComponent(_option.sql))
                  cell.arr_field = _option.field
                }
                // 字段权限黑名单
                if (!cell.blacklist || cell.blacklist.length === 0) return cell
                if (cell.blacklist.filter(v => roleId.indexOf(v) > -1).length > 0) {
                  cell.hidden = 'true'
                }
                return cell
              })
            })
          } else {
            _LongParam.fields = _LongParam.fields.map(cell => {
              // 数据源sql语句,预处理,权限黑名单字段设置为隐藏表单
              if (['select', 'link', 'multiselect', 'radio', 'checkbox', 'checkcard'].includes(cell.type) && cell.resourceType === '1') {
                let _option = Utils.getSelectQueryOptions(cell)
                if (sessionStorage.getItem('dataM') === 'true') { // 数据权限
                  _option.sql = _option.sql.replace(/\$@/ig, '/*')
                  _option.sql = _option.sql.replace(/@\$/ig, '*/')
                } else {
                  _option.sql = _option.sql.replace(/@\$|\$@/ig, '')
                }
                cell.data_sql = Utils.formatOptions(_option.sql)
                cell.base_sql = window.btoa(window.encodeURIComponent(_option.sql))
                cell.arr_field = _option.field
              }
              // 字段权限黑名单
              if (!cell.blacklist || cell.blacklist.length === 0) return cell
              if (cell.blacklist.filter(v => roleId.indexOf(v) > -1).length > 0) {
                cell.hidden = 'true'
              }
              return cell
            })
          }
          _LongParam = updateForm(_LongParam)
          _LongParam = this.handleModelConfig(_LongParam)
          this.setState({
            btnconfig: _LongParam
          }, () => {
@@ -1552,17 +1544,10 @@
    const { BData } = this.props
    const { btnconfig, tabledata } = this.state
    let _this = this
    let _fields = []
    if (btnconfig.groups.length > 0) {
      btnconfig.groups.forEach(group => {
        _fields = [..._fields, ...group.sublist]
      })
    } else {
      _fields = btnconfig.fields
    }
    let result = _fields.map(item => {
    let result = []
    btnconfig.fields.forEach(item => {
      if (!item.field) return
      let _readin = item.readin !== 'false'
      let _initval = item.initval
@@ -1589,14 +1574,19 @@
        _fieldlen = item.decimal ? item.decimal : 0
      }
      return {
      if (_initval === undefined) {
        _initval = ''
      }
      result.push({
        key: item.field,
        readonly: item.readonly === 'true',
        readin: _readin,
        fieldlen: _fieldlen,
        writein: item.writein !== 'false',
        type: item.type,
        value: _initval
      }
      })
    })
    confirm({