king
2020-12-16 06404e701a89955958cbf56213e2eec618d8644d
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 MKEmitter from '@/utils/events.js'
import './index.scss'
const MutilForm = asyncSpinComponent(() => import('@/tabviews/zshare/mutilform'))
@@ -19,17 +20,17 @@
class NormalButton extends Component {
  static propTpyes = {
    show: PropTypes.any,              // 按钮显示样式控制
    position: PropTypes.any,          // 按钮位置,工具栏为toolbar
    BID: PropTypes.string,            // 主表ID
    BData: PropTypes.any,             // 主表数据
    style: PropTypes.any,             // 按钮样式
    selectedData: PropTypes.any,      // 子表中选择数据
    Tab: PropTypes.any,               // 如果当前元素为标签时,tab为标签信息
    MenuID: PropTypes.string,         // 菜单ID
    btn: PropTypes.object,            // 按钮
    columns: PropTypes.any,           // 字段列
    setting: PropTypes.any,           // 页面通用设置
    ContainerId: PropTypes.any,       // tab页面ID,用于弹窗控制
    updateStatus: PropTypes.func,     // 按钮状态更新
    triggerBtn: PropTypes.any,
  }
  state = {
@@ -43,17 +44,23 @@
    loadingNumber: ''
  }
  /**
   * @description 外部触发按钮点击
   */
  UNSAFE_componentWillReceiveProps(nextProps) {
    if (nextProps.triggerBtn && !is(fromJS(this.props.triggerBtn), fromJS(nextProps.triggerBtn)) && nextProps.triggerBtn.button.uuid === this.props.btn.uuid) {
      this.actionTrigger(nextProps.triggerBtn.data)
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
  }
  componentDidMount () {
    const { position } = this.props
    if (position === 'toolbar') {
      MKEmitter.addListener('triggerBtnId', this.actionTrigger)
    }
  }
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
  componentWillUnmount () {
    this.setState = () => {
      return
    }
    MKEmitter.removeListener('triggerBtnId', this.actionTrigger)
  }
  /**
@@ -64,21 +71,22 @@
      this.setState({
        loading: true
      })
      this.props.updateStatus('start')
    } else if (type === 'over') {
      this.setState({
        loading: false,
        visible: false
      })
      this.props.updateStatus('over')
    }
  }
  
  /**
   * @description 触发按钮操作
   */
  actionTrigger = (record) => {
  actionTrigger = (triggerId, record) => {
    const { setting, Tab, BID, btn, selectedData } = this.props
    const { loading } = this.state
    if ((triggerId && btn.uuid !== triggerId) || loading) return
    if (Tab && Tab.supMenu && !BID) {
      notification.warning({
@@ -90,13 +98,7 @@
    }
    let _this = this
    let data = []
    if (record) { // 表格中触发按钮
      data = [record]
    } else {
      data = selectedData || []
    }
    let data = record || selectedData || []
    if (btn.Ot !== 'notRequired' && data.length === 0) {
      // 需要选择行时,校验数据
@@ -175,8 +177,10 @@
      this.execSubmit(data, () => { this.setState({loading: false})})
    } else if (btn.OpenType === 'pop') {
      this.updateStatus('start')
      this.setState({
        tabledata: data
        tabledata: data,
        btnconfig: btn.modal ? btn.modal : this.state.btnconfig
      }, () => {
        this.improveAction()
      })
@@ -222,21 +226,17 @@
            param.ID = primaryId
            param.LText = Utils.getSysDefaultSql(btn, setting, '', param, data[0], columns, this.props.Tab) // 数据源
            if (this.props.dataManager) { // 数据权限
            if (sessionStorage.getItem('dataM') === 'true') { // 数据权限
              param.LText = param.LText.replace(/\$@/ig, '/*')
              param.LText = param.LText.replace(/@\$/ig, '*/')
            } else {
              param.LText = param.LText.replace(/@\$|\$@/ig, '')
            }
            let { LText, LText1, LText2 } = Utils.sPCInUpDeFormatOptions(param.LText)
            param.LText2 = LText2
            param.LText1 = LText1
            param.LText = LText
            param.exec_type = 'y' // 后台解码
            param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
            param.secretkey = Utils.encrypt(param.LText, param.timestamp)
            param.secretkey = Utils.encrypt('', param.timestamp)
            param.LText = Utils.formatOptions(param.LText)
          }
        } else if (btn.OpenType === 'pop') { // 表单
          if (btn.innerFunc) {
@@ -263,40 +263,32 @@
            param.ID = primaryId || Utils.getguid()
            param.LText = Utils.getSysDefaultSql(btn, setting, formdata, param, data[0], columns, this.props.Tab) // 数据源
            
            if (this.props.dataManager) { // 数据权限
            if (sessionStorage.getItem('dataM') === 'true') { // 数据权限
              param.LText = param.LText.replace(/\$@/ig, '/*')
              param.LText = param.LText.replace(/@\$/ig, '*/')
            } else {
              param.LText = param.LText.replace(/@\$|\$@/ig, '')
            }
            let { LText, LText1, LText2 } = Utils.sPCInUpDeFormatOptions(param.LText)
            param.LText2 = LText2
            param.LText1 = LText1
            param.LText = LText
            param.exec_type = 'y' // 后台解码
            param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
            param.secretkey = Utils.encrypt(param.LText, param.timestamp)
            param.secretkey = Utils.encrypt('', param.timestamp)
            param.LText = Utils.formatOptions(param.LText)
          } else if (btn.sql) {
            param.ID = primaryId
            param.LText = Utils.getSysDefaultSql(btn, setting, formdata, param, data[0], columns, this.props.Tab) // 数据源
            
            if (this.props.dataManager) { // 数据权限
            if (sessionStorage.getItem('dataM') === 'true') { // 数据权限
              param.LText = param.LText.replace(/\$@/ig, '/*')
              param.LText = param.LText.replace(/@\$/ig, '*/')
            } else {
              param.LText = param.LText.replace(/@\$|\$@/ig, '')
            }
            let { LText, LText1, LText2 } = Utils.sPCInUpDeFormatOptions(param.LText)
            param.LText2 = LText2
            param.LText1 = LText1
            param.LText = LText
            param.exec_type = 'y' // 后台解码
            param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
            param.secretkey = Utils.encrypt(param.LText, param.timestamp)
            param.secretkey = Utils.encrypt('', param.timestamp)
            param.LText = Utils.formatOptions(param.LText)
          }
        }
@@ -306,6 +298,10 @@
          param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
          param.secretkey = Utils.encrypt(param.LTextOut, param.timestamp)
          param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp)
        }
        if (param.func === 'sPC_TableData_InUpDe') {
          param.menuname = btn.logLabel
        }
        Api.genericInterface(param).then((res) => {
@@ -350,20 +346,17 @@
              param.ID = primaryId
              param.LText = Utils.getSysDefaultSql(btn, setting, '', param, cell, columns, this.props.Tab) // 数据源
              
              if (this.props.dataManager) { // 数据权限
              if (sessionStorage.getItem('dataM') === 'true') { // 数据权限
                param.LText = param.LText.replace(/\$@/ig, '/*')
                param.LText = param.LText.replace(/@\$/ig, '*/')
              } else {
                param.LText = param.LText.replace(/@\$|\$@/ig, '')
              }
              let { LText, LText1, LText2 } = Utils.sPCInUpDeFormatOptions(param.LText)
              param.LText2 = LText2
              param.LText1 = LText1
              param.LText = LText
              param.exec_type = 'y' // 后台解码
              param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
              param.secretkey = Utils.encrypt(param.LText, param.timestamp)
              param.secretkey = Utils.encrypt('', param.timestamp)
              param.LText = Utils.formatOptions(param.LText)
            }
          } else if (btn.OpenType === 'pop') { // 表单
            if (index !== 0) {
@@ -389,40 +382,32 @@
              param.ID = _formPrimaryId || Utils.getguid()
              param.LText = Utils.getSysDefaultSql(btn, setting, formdata, param, cell, columns, this.props.Tab) // 数据源
              
              if (this.props.dataManager) { // 数据权限
              if (sessionStorage.getItem('dataM') === 'true') { // 数据权限
                param.LText = param.LText.replace(/\$@/ig, '/*')
                param.LText = param.LText.replace(/@\$/ig, '*/')
              } else {
                param.LText = param.LText.replace(/@\$|\$@/ig, '')
              }
              let { LText, LText1, LText2 } = Utils.sPCInUpDeFormatOptions(param.LText)
              param.LText2 = LText2
              param.LText1 = LText1
              param.LText = LText
              param.exec_type = 'y' // 后台解码
              param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
              param.secretkey = Utils.encrypt(param.LText, param.timestamp)
              param.secretkey = Utils.encrypt('', param.timestamp)
              param.LText = Utils.formatOptions(param.LText)
            } else if (btn.sql) {
              param.ID = primaryId
              param.LText = Utils.getSysDefaultSql(btn, setting, formdata, param, cell, columns, this.props.Tab) // 数据源
              
              if (this.props.dataManager) { // 数据权限
              if (sessionStorage.getItem('dataM') === 'true') { // 数据权限
                param.LText = param.LText.replace(/\$@/ig, '/*')
                param.LText = param.LText.replace(/@\$/ig, '*/')
              } else {
                param.LText = param.LText.replace(/@\$|\$@/ig, '')
              }
              let { LText, LText1, LText2 } = Utils.sPCInUpDeFormatOptions(param.LText)
              param.LText2 = LText2
              param.LText1 = LText1
              param.LText = LText
              param.exec_type = 'y' // 后台解码
              param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
              param.secretkey = Utils.encrypt(param.LText, param.timestamp)
              param.secretkey = Utils.encrypt('', param.timestamp)
              param.LText = Utils.formatOptions(param.LText)
            }
          }
@@ -432,6 +417,10 @@
            param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
            param.secretkey = Utils.encrypt(param.LTextOut, param.timestamp)
            param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp)
          }
          if (param.func === 'sPC_TableData_InUpDe') {
            param.menuname = btn.logLabel
          }
          return param
@@ -725,17 +714,123 @@
    }
    
    let _unclose = false
    if (btn.OpenType !== 'pop' || !btnconfig || btnconfig.setting.finish !== 'unclose') {
      this.setState({
        loading: false,
        visible: false
      })
    } else {
      _unclose = true
    }
    this.props.updateStatus('refresh', btn.execSuccess, _unclose)
    if (btn.verify && btn.verify.noteEnable === 'true') {
      this.sendMessage()
    }
    this.props.updateStatus('refresh', btn.execSuccess, btn)
  }
  sendMessage = () => {
    const { btn : { verify } } = this.props
    let param = {
      func: 's_get_sms_local',
      TypeCharOne: verify.noteTemp, // N不同内容,Y相同内容
      TypeCharTwo: verify.noteType  // N定时,Y实时
    }
    param.LText = Utils.formatOptions(Utils.getuuid())
    param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
    param.secretkey = Utils.encrypt(param.LText, param.timestamp)
    Api.genericInterface(param).then(res => {
      if (!res.status) {
        notification.warning({
          top: 92,
          message: res.message,
          duration: 5
        })
        return
      }
      let _param = {
        templatecode: verify.noteCode, // 模板编码
        TypeCharOne: verify.noteTemp,  // N不同内容,Y相同内容
      }
      _param.submitdate = res.submitdate
      let limit = 5 // 实时最大为5条,定时最大为100条
      let mobMap = new Map()
      if (verify.noteType === 'N') {
        _param.func = 's_get_sms_sso_timer'
        limit = 100
      } else if (verify.noteType === 'Y') {
        _param.func = 's_get_sms_sso_realtime'
      }
      let Ltext = []
      let error = false
      if (verify.noteTemp === 'Y') {
        _param.p1 = res.p1 || ''
        _param.p2 = res.p2 || ''
        _param.p3 = res.p3 || ''
        _param.p4 = res.p4 || ''
        _param.p5 = res.p5 || ''
        let _p = _param.p1 + _param.p2 + _param.p3 + _param.p4 + _param.p5
        if (/\/|\.|.*共.*产|.*习.*近|面试|邀请|下载|红包|招聘|好评|评价|政务通知|缴费|保险|股票|金融|房地产|教育|游戏|微信|Q/.test(_p)) {
          error = true
        }
      }
      res.send_data && res.send_data.forEach(item => {
        if (item.mob && !mobMap.has(item.mob) && Ltext.length < limit) {
          if (verify.noteTemp === 'Y') {
            Ltext.push(`'${item.mob}'`)
          } else {
            let _p = `'${item.p1 || ''}','${item.p2 || ''}','${item.p3 || ''}','${item.p4 || ''}','${item.p5 || ''}','${item.mob}'`
            if (/\/|\.|.*共.*产|.*习.*近|面试|邀请|下载|红包|招聘|好评|评价|政务通知|缴费|保险|股票|金融|房地产|教育|游戏|微信|Q/.test(_p)) {
              error = true
            }
            Ltext.push(_p)
          }
          mobMap.set(item.mob, true)
        }
      })
      if (error) {
        notification.warning({
          top: 92,
          message: '消息中含有非法字符',
          duration: 5
        })
        return
      }
      if (Ltext.length === 0) return
      Ltext = Ltext.join(';')
      _param.LText = window.btoa(window.encodeURIComponent(Ltext))
      _param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
      _param.secretkey = Utils.encrypt(_param.LText, _param.timestamp)
      _param.rduri = 'http://sso.mk9h.cn/webapi/dostar'
      _param.appkey = window.GLOB.appkey || ''
      Api.dostarInterface(_param).then(result => {
        if (!result.status) {
          notification.warning({
            top: 92,
            message: result.message,
            duration: 5
          })
        }
      })
    })
  }
  /**
@@ -746,7 +841,6 @@
   */
  execError = (res) => {
    const { btn } = this.props
    const { btnconfig } = this.state
    if (res.ErrCode === 'E') {
      Modal.error({
@@ -769,16 +863,11 @@
      message.error(res.message || res.ErrMesg)
    }
    let _unclose = false
    if (btn.OpenType === 'pop' && btnconfig && btnconfig.setting.display !== 'prompt') {
      _unclose = true
    } else {
      this.setState({
        loading: false
      })
    }
    this.setState({
      loading: false
    })
    this.props.updateStatus('refresh', btn.execError, _unclose)
    this.props.updateStatus('refresh', btn.execError, btn)
  }
  /**
@@ -838,18 +927,23 @@
          })
          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'].includes(cell.type) && cell.resourceType === '1') {
                if (['select', 'link', 'multiselect', 'radio', 'checkbox', 'checkcard'].includes(cell.type) && cell.resourceType === '1') {
                  let _option = Utils.getSelectQueryOptions(cell)
                  if (this.props.dataManager) { // 数据权限
                  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)
@@ -859,12 +953,7 @@
                // 字段权限黑名单
                if (!cell.blacklist || cell.blacklist.length === 0) return cell
                let _black = cell.blacklist.filter(v => {
                  return this.props.permRoles.indexOf(v) !== -1
                })
                if (_black.length > 0) {
                if (cell.blacklist.filter(v => roleId.indexOf(v) > -1).length > 0) {
                  cell.hidden = 'true'
                }
@@ -874,10 +963,10 @@
          } else {
            _LongParam.fields = _LongParam.fields.map(cell => {
              // 数据源sql语句,预处理,权限黑名单字段设置为隐藏表单
              if (['select', 'link', 'multiselect'].includes(cell.type) && cell.resourceType === '1') {
              if (['select', 'link', 'multiselect', 'radio', 'checkbox', 'checkcard'].includes(cell.type) && cell.resourceType === '1') {
                let _option = Utils.getSelectQueryOptions(cell)
                if (this.props.dataManager) { // 数据权限
                if (sessionStorage.getItem('dataM') === 'true') { // 数据权限
                  _option.sql = _option.sql.replace(/\$@/ig, '/*')
                  _option.sql = _option.sql.replace(/@\$/ig, '*/')
                } else {
@@ -891,12 +980,7 @@
              // 字段权限黑名单
              if (!cell.blacklist || cell.blacklist.length === 0) return cell
              let _black = cell.blacklist.filter(v => {
                return this.props.permRoles.indexOf(v) !== -1
              })
              if (_black.length > 0) {
              if (cell.blacklist.filter(v => roleId.indexOf(v) > -1).length > 0) {
                cell.hidden = 'true'
              }
@@ -1063,33 +1147,50 @@
  }
  render() {
    const { btn, show } = this.props
    const { btn, show, style } = this.props
    const { loadingNumber, loading } = this.state
    return (
      <div className="mk-btn-wrap">
        {!show ? <Button
          className={'mk-btn mk-' + btn.class}
    if (show === 'actionList') {
      return <div style={{display: 'inline-block'}} onClick={(e) => e.stopPropagation()}>
        <Button
          style={style}
          icon={btn.icon}
          onClick={() => {this.actionTrigger()}}
          loading={loading}
        >{loadingNumber ? `(${loadingNumber})` : '' + btn.label}</Button> : null}
        {show === 'icon' ? <Button className="action-cell" icon={btn.icon || 'dash'} loading={loading} onClick={() => {this.actionTrigger()}}></Button> : null}
        {show === 'text' ? <Button className="action-cell" loading={loading} onClick={() => {this.actionTrigger()}}>{btn.label}</Button> : null}
        {show === 'all' ? <Button className="action-cell" icon={btn.icon || ''} loading={loading} onClick={() => {this.actionTrigger()}}>{btn.label}</Button> : null}
        {show && show.indexOf('plus') > -1 ? <Button className="action-cell" style={{fontSize: show.substring(4) + 'px'}} icon={btn.icon || 'plus'} loading={loading} onClick={() => {this.actionTrigger()}}></Button> : null}
          className={'mk-btn mk-' + btn.class}
          onClick={() => {this.actionTrigger()}}
        >{loadingNumber ? `(${loadingNumber})` : '' + btn.label}</Button>
        {this.getModels()}
      </div>
    )
    } else if (show && show.indexOf('plus') > -1) {
      return <div className="mk-btn-wrap">
        <Button
          type="link"
          loading={loading}
          icon={btn.icon || 'plus'}
          style={{fontSize: show.substring(4) + 'px'}}
          onClick={() => {this.actionTrigger()}}
        ></Button>
        {this.getModels()}
      </div>
    } else { // icon、text、 all 卡片
      return <div style={{display: 'inline-block'}} onClick={(e) => e.stopPropagation()}>
        <Button
          type="link"
          loading={loading}
          style={btn.btnstyle || style}
          icon={show === 'text' ? '' : (btn.icon || '')}
          onClick={() => {this.actionTrigger()}}
        >{show === 'icon' && btn.icon ? '' : btn.label}</Button>
        {this.getModels()}
      </div>
    }
  }
}
const mapStateToProps = (state) => {
  return {
    tabviews: state.tabviews,
    menuType: state.editLevel,
    permRoles: state.permRoles,
    dataManager: state.dataManager
    menuType: state.editLevel
  }
}