king
2023-07-17 ba9e189dd33c8d48f7f4ac36bcefeef9afb426f8
src/tabviews/zshare/actionList/normalbutton/index.jsx
@@ -1,8 +1,10 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import moment from 'moment'
import qs from 'qs'
import { is, fromJS } from 'immutable'
import { Button, Modal, notification, message, Drawer, Switch, Checkbox, Progress } from 'antd'
import md5 from 'md5'
import Api from '@/api'
import Utils, { getSysDefaultSql } from '@/utils/utils.js'
@@ -61,7 +63,7 @@
    
    if (btn.OpenType === 'form') {
      let data = selectedData && selectedData[0] ? selectedData[0] : null
      if (btn.formType === 'counter') {
      if (btn.formType === 'counter' || btn.formType === 'count_line') {
        let count = 0
        if (data && data[btn.field]) {
          count = +data[btn.field]
@@ -108,7 +110,7 @@
    if (btn.OpenType === 'form') {
      let data = nextProps.selectedData && nextProps.selectedData[0] ? nextProps.selectedData[0] : null
      if (btn.formType === 'counter') {
      if (btn.formType === 'counter' || btn.formType === 'count_line') {
        let count = 0
        if (data && data[btn.field]) {
          count = +data[btn.field]
@@ -329,6 +331,9 @@
        return
      }
    } else if (!['inner', 'outer', 'system', 'custom'].includes(btn.intertype)) {
      if (btn.OpenType === 'form' && btn.formType === 'count_line') {
        return
      }
      // 接口类型错误
      notification.warning({
        top: 92,
@@ -744,8 +749,10 @@
    let _params = []
    if ( btn.Ot === 'notRequired' || btn.Ot === 'requiredSgl' || btn.Ot === 'requiredOnce' ) {
      let param = {
        func: btn.innerFunc || ''
      let param = {}
      if (btn.innerFunc) {
        param.func = btn.innerFunc
      }
      if (this.props.BID) {
@@ -758,9 +765,7 @@
        let ids = data.map(d => { return d[setting.primaryKey] || ''})
        ids = ids.filter(Boolean)
        primaryId = ids.join(',')
      }
      if (setting.primaryKey) {
        param[setting.primaryKey] = primaryId // 设置主键参数
      }
@@ -1099,7 +1104,8 @@
            this.execError(res)
          }
          _resolve()
        }, () => {
        }, (error) => {
          if (error && error.ErrCode === 'LoginError') return
          this.updateStatus()
          _resolve()
        })
@@ -1112,7 +1118,8 @@
                  this.triggerNote(res) // 消息
                }
                resolve(res)
              }, () => {
              }, (error) => {
                if (error && error.ErrCode === 'LoginError') return
                this.updateStatus()
                _resolve()
              })
@@ -1139,7 +1146,7 @@
          _resolve()
        })
      } else { // 超出20个请求时循环执行
        if (btn.progress === 'progressbar' && btn.$toolbtn && params.length > 1) {
        if (btn.progress === 'progressbar' && params.length > 1) {
          this.setState({
            loadingTotal: params.length
          })
@@ -1160,7 +1167,7 @@
        _params = this.getInnerParam(data, formdata, btn.callbackType === 'script')
      }
      if (_params.length > 1 && btn.progress === 'progressbar' && btn.$toolbtn) {
      if (_params.length > 1 && btn.progress === 'progressbar') {
        this.setState({
          loadingTotal: _params.length
        })
@@ -1181,7 +1188,7 @@
        params = this.getInnerParam(data, formdata, btn.callbackType === 'script')
      }
      if (params.length > 1 && btn.progress === 'progressbar' && btn.$toolbtn) {
      if (params.length > 1 && btn.progress === 'progressbar') {
        this.setState({
          loadingTotal: params.length
        })
@@ -1204,31 +1211,59 @@
    let record = {
      BID: param.BID || '',
      ID: param.ID || '',
      callbacksql: param.$callbacksql || ''
      callbacksql: param.$callbacksql || '',
      mk_api_key: ''
    }
    delete param.$callbacksql
    if (!param.func) {
    if (param.$pice) {
      record = param.$record
      delete param.$record
      this.customOuterRequest(params, param, record, _resolve)
      return
    } else if (!param.func) {
      this.customOuterRequest(params, param, record, _resolve)
      return
    }
    Api.genericInterface(param).then(res => {
      record.mk_api_key = res.mk_api_key || ''
      if (res.status) {
        if ((res.mk_ex_invoke === 'false' || res.mk_ex_invoke === false) && params.length === 0) {
        if (res.mk_ex_invoke + '' === 'false' && params.length === 0) {
          this.execSuccess(res)
          _resolve()
        } else if ((res.mk_ex_invoke === 'false' || res.mk_ex_invoke === false) && params.length > 0) {
        } else if (res.mk_ex_invoke + '' === 'false' && params.length > 0) {
          this.customLoopRequest(params, _resolve)
        } else {
          this.customOuterRequest(params, res, record, _resolve)
          if (res.mk_ex_data) { // 数据分批执行
            if (Array.isArray(res.mk_ex_data) && res.mk_ex_data.length > 0) {
              let pices = res.mk_ex_data.map(item => {
                item.$pice = true
                item.$record = record
                return item
              })
              params = [...pices, ...params]
              this.customLoopRequest(params, _resolve)
            } else if (params.length === 0) {
              this.execSuccess(res)
              _resolve()
            } else {
              this.customLoopRequest(params, _resolve)
            }
          } else {
            this.customOuterRequest(params, res, record, _resolve)
          }
        }
      } else {
        this.execError(res)
        _resolve()
      }
    }, () => {
    }, (error) => {
      if (error && error.ErrCode === 'LoginError') return
      this.updateStatus()
      _resolve()
    })
@@ -1253,23 +1288,73 @@
      url = btn.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]
    })
    if (result.$pice) {
      delete result.$pice
    Api.directRequest(url, btn.method, param, btn.cross).then(res => {
      param = {...result}
    } else {
      delete result.mk_ex_invoke
      delete result.status
      delete result.message
      delete result.ErrCode
      delete result.ErrMesg
      delete result.mk_api_key
      Object.keys(result).forEach(key => {
        key = key.replace(/^mk_/ig, '')
        param[key] = result[key]
      })
    }
    let _params = {
      url: url,
      method: btn.method || 'post'
    }
    if (btn.cross === 'true') {
      if (JSON.stringify(param) !== '{}') {
        if (btn.stringify === 'qs') {
          _params.data = qs.stringify(param)
        } else if (btn.stringify === 'JSON') {
          _params.data = param
        } else {
          _params.data = JSON.stringify(param)
        }
      }
    } else {
      let _url = url
      if (JSON.stringify(param) !== '{}') {
        if (_params.method === 'get') {
          let keys = Object.keys(param).map(key => `${key}=${param[key]}`)
          _url = _url + '?' + keys.join('&')
        } else if (_params.method === 'post') {
          if (btn.stringify === 'qs') {
            _params.data = qs.stringify(param)
          } else if (btn.stringify === 'JSON') {
            _params.data = param
          } else {
            _params.data = JSON.stringify(param)
          }
        }
      }
      _url = _url.replace(/&/ig, '%26')
      _params.url = '/trans/redirect?rd=' + _url + '&method=' + _params.method
      _params.method = 'post'
    }
    if (btn.ContentType) {
      _params.headers = {
        'Content-Type': btn.ContentType
      }
    }
    Api.directRequest(_params).then(res => {
      if (typeof(res) !== 'object') {
        let error = '未知的返回结果!'
@@ -1278,7 +1363,7 @@
        }
        let result = {
          mk_api_key: mkey,
          mk_api_key: record.mk_api_key,
          $ErrCode: 'E',
          $ErrMesg: error
        }
@@ -1288,12 +1373,22 @@
        if (Array.isArray(res)) {
          res = { data: res }
        }
        res.mk_api_key = mkey
        if (btn.outerBlacklist) {
          let list = btn.outerBlacklist.split(',').map(m => m.toLowerCase())
          Object.keys(res).forEach(key => {
            if (list.includes(key.toLowerCase())) {
             delete res[key]
            }
          })
        }
        res.mk_api_key = record.mk_api_key
        this.customCallbackRequest(params, res, record, _resolve)
      }
    }, (e) => {
      let result = {
        mk_api_key: mkey,
        mk_api_key: record.mk_api_key,
        $ErrCode: 'E',
        $ErrMesg: e && e.statusText ? e.statusText : ''
      }
@@ -1381,7 +1476,8 @@
        this.execError(res)
        _resolve()
      }
    }, () => {
    }, (error) => {
      if (error && error.ErrCode === 'LoginError') return
      this.updateStatus()
      _resolve()
    })
@@ -1430,14 +1526,14 @@
          if (typeof(val) === 'string') {
            val = val.replace(/'/ig, '"')
          }
          keys.push(key)
          keys.push('[' + key + ']')
          vals.push(`'${val}'`)
        }
      })
      lines.push({
        table: tb,
        insert: `Insert into ${pre}${tb} (${keys.join(',')},mk_level,mk_id,mk_bid)`,
        insert: `Insert into ${pre}${tb} (${keys.join(',')},[mk_level],[mk_id],[mk_bid])`,
        select: `Select ${vals.join(',')},'${level}','${id}','${bid}'`
      })
@@ -1596,7 +1692,8 @@
        this.execError(res)
        _resolve()
      }
    }, () => {
    }, (error) => {
      if (error && error.ErrCode === 'LoginError') return
      this.updateStatus()
      _resolve()
    })
@@ -1659,7 +1756,8 @@
        this.execError(res)
        _resolve()
      }
    }, () => {
    }, (error) => {
      if (error && error.ErrCode === 'LoginError') return
      this.updateStatus()
      _resolve()
    })
@@ -1721,7 +1819,8 @@
        this.execError(res)
        _resolve()
      }
    }, () => {
    }, (error) => {
      if (error && error.ErrCode === 'LoginError') return
      this.updateStatus()
      _resolve()
    })
@@ -1791,7 +1890,8 @@
        return
      }
      this.outerCallbackRequest(params, res, record, outParam, _resolve)
    }, () => {
    }, (error) => {
      if (error && error.ErrCode === 'LoginError') return
      this.outerCallbackRequest(params, {status: false, message: 500, ErrCode: 'E', ErrMesg: 500}, record, outParam, _resolve)
    })
  }
@@ -2096,6 +2196,10 @@
      MKEmitter.emit('modifyTabs', newtab, true)
    }
    if (btn.execSuccess === 'popclose' && btn.$tabId) { // 标签关闭刷新
      MKEmitter.emit('refreshPopButton', btn.$tabId)
    }
  }
  triggerNote = (res) => {
@@ -2222,7 +2326,7 @@
        if (!res.oa_access_token) return
  
        params.forEach(n => {
          Api.wxNginxRequest(`${domain2}cgi-bin/message/template/send?access_token=${res.oa_access_token}`, 'post', n).then(re => {
          Api.wxNginxRequest(`${domain2}cgi-bin/message/template/send?access_token=${res.oa_access_token}`, 'post', JSON.stringify(n)).then(re => {
            if (verify.wxNoteCallback === 'true') {
              let msg = re.errmsg || ''
@@ -2383,6 +2487,29 @@
            duration: 5
          })
        }
      }, (error) => {
        if (error && error.ErrCode === 'LoginError') {
          let param = {
            func: 's_visitor_login',
            timestamp: moment().format('YYYY-MM-DD HH:mm:ss'),
            SessionUid: 'bh0bapabtd45epsgra79segbch6c1ibk',
            TypeCharOne: 'pc',
            appkey: '202004041613277377A6A2456D34A4948AE84'
          }
          param.LText = md5(window.btoa('bh0bapabtd45epsgra79segbch6c1ibk' + param.timestamp))
          param.secretkey = md5(param.LText + 'mingke' + param.timestamp)
          let params = {
            url: 'https://sso.mk9h.cn/webapi/dologon',
            method: 'post',
            data: JSON.stringify(param)
          }
          Api.directRequest(params)
          return
        }
      })
    })
  }
@@ -2490,6 +2617,10 @@
    if (window.GLOB.breakpoint) {
      MKEmitter.emit('refreshDebugTable')
    }
    if (btn.execError === 'popclose' && btn.$tabId) { // 标签关闭刷新
      MKEmitter.emit('refreshPopButton', btn.$tabId)
    }
  }
@@ -2879,6 +3010,37 @@
    })
  }
  changeLineCount = (count) => {
    const { btn, selectedData } = this.props
    const { disabled } = this.state
    if (disabled) return
    let data = selectedData || []
    if (data.length === 0) {
      // 需要选择行时,校验数据
      notification.warning({
        top: 92,
        message: this.state.dict['main.action.confirm.selectline'],
        duration: 5
      })
      return
    } else if (data.length !== 1) {
      // 需要选择单行时,校验数据
      notification.warning({
        top: 92,
        message: this.state.dict['main.action.confirm.selectSingleLine'],
        duration: 5
      })
      return
    }
    this.setState({count}, () => {
      MKEmitter.emit('refreshLineData', btn.$menuId, btn, data[0].$$uuid, count)
    })
  }
  render() {
    const { btn } = this.props
    const { loadingNumber, loadingTotal, loading, disabled, hidden, check, count } = this.state
@@ -2889,6 +3051,8 @@
        return <Switch loading={loading} checked={check} disabled={disabled || loading} title={disabled ? (btn.reason || '') : ''} onChange={(val,e) => {e.stopPropagation();this.actionTrigger()}} style={btn.style} className={btn.size === 'large' ? 'ant-switch-large' : ''} size={btn.size} checkedChildren={btn.openText || ''} unCheckedChildren={btn.closeText || ''}/>
      } else if (btn.formType === 'counter') {
        return <MkCounter count={count} disabled={disabled} btn={btn} onChange={this.changeCount}/>
      } else if (btn.formType === 'count_line') {
        return <MkCounter count={count} disabled={disabled} btn={btn} onChange={this.changeLineCount}/>
      } else if (btn.formType === 'radio') {
        return <Checkbox className={btn.checkType || ''} disabled={disabled || loading} title={disabled ? (btn.reason || '') : ''} checked={check} onChange={(e) => {e.stopPropagation();this.actionTrigger()}} style={btn.style}></Checkbox>
      } else {
@@ -2920,8 +3084,8 @@
      className = 'mk-btn mk-' + (btn.class || 'unset')
    }
    if (loadingNumber && !loadingTotal && btn.$toolbtn && (!btn.show || btn.show === 'button')) {
      label = (loadingNumber && !loadingTotal ? `(${loadingNumber})` : '') + btn.label
    if (loadingNumber && btn.progress !== 'progressbar' && btn.$toolbtn && (!btn.show || btn.show === 'button')) {
      label = (loadingNumber ? `(${loadingNumber})` : '') + btn.label
    }
    return <>