king
2022-04-26 5046d0d13dc6a8563b8e54e31913bc44cfa1072f
src/tabviews/zshare/actionList/normalbutton/index.jsx
@@ -3,7 +3,7 @@
import moment from 'moment'
import {connect} from 'react-redux'
import { is, fromJS } from 'immutable'
import { Button, Modal, notification, message, Drawer } from 'antd'
import { Button, Modal, notification, message, Drawer, Switch, Checkbox } from 'antd'
import Api from '@/api'
import Utils, { getSysDefaultSql } from '@/utils/utils.js'
@@ -32,6 +32,8 @@
    columns: PropTypes.any,           // 字段列
    setting: PropTypes.any,           // 页面通用设置
    ContainerId: PropTypes.any,       // tab页面ID,用于弹窗控制
    disabled: PropTypes.any,          // 行按钮禁用
    lineId: PropTypes.any,            // 行索引+主键值,用于行按钮双击
  }
  state = {
@@ -46,23 +48,47 @@
    disabled: false,
    hidden: false,
    checkParam: null,
    autoMatic: false
    autoMatic: false,
    check: false
  }
  moduleParams = null
  UNSAFE_componentWillMount () {
    const { btn, selectedData } = this.props
    const { btn, selectedData, BData } = this.props
    let disabled = false
    if (btn.controlField && selectedData && selectedData.length > 0) { // 表格中按钮隐藏控制
      selectedData.forEach(item => {
        let s = item[btn.controlField] + ''
        let s = item[btn.controlField] !== undefined ? item[btn.controlField] + '' : ''
        if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) {
          disabled = true
        }
      })
      this.setState({disabled, hidden: disabled && btn.control === 'hidden'})
      this.setState({hidden: disabled && btn.control === 'hidden'})
    } else if (btn.control === 'parent') {
      if (!BData || !BData.hasOwnProperty(btn.controlField)) {
        this.setState({hidden: true})
      } else {
        let s = BData[btn.controlField] + ''
        if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) {
          this.setState({hidden: true})
        } else {
          this.setState({hidden: false})
        }
      }
    }
    if (this.props.disabled || disabled) {
      this.setState({disabled: true})
    }
    if (btn.OpenType === 'form') {
      let data = selectedData && selectedData[0] ? selectedData[0] : null
      this.setState({check: data && data[btn.field] === btn.openVal})
    } else if (btn.OpenType === 'formSubmit') {
      this.setState({
        selines: selectedData || []
      })
    }
  }
@@ -85,20 +111,45 @@
  }
  UNSAFE_componentWillReceiveProps (nextProps) {
    const { btn, selectedData } = this.props
    const { btn, selectedData, BData } = this.props
    let disabled = false
    if (btn.controlField && !is(fromJS(nextProps.selectedData || []), fromJS(selectedData || []))) {
      let disabled = false
      if (nextProps.selectedData && nextProps.selectedData.length > 0) { // 表格中按钮隐藏控制
        nextProps.selectedData.forEach(item => {
          let s = item[btn.controlField] + ''
          let s = item[btn.controlField] !== undefined ? item[btn.controlField] + '' : ''
          if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) {
            disabled = true
          }
        })
      }
      this.setState({disabled, hidden: disabled && btn.control === 'hidden'})
      this.setState({hidden: disabled && btn.control === 'hidden'})
    } else if (btn.control === 'parent' && !is(fromJS(nextProps.BData || {}), fromJS(BData || {}))) {
      if (!nextProps.BData || !nextProps.BData.hasOwnProperty(btn.controlField)) {
        this.setState({hidden: true})
      } else {
        let s = nextProps.BData[btn.controlField] + ''
        if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) {
          this.setState({hidden: true})
        } else {
          this.setState({hidden: false})
        }
      }
    }
    if (nextProps.disabled || disabled) {
      this.setState({disabled: true})
    } else {
      this.setState({disabled: false})
    }
    if (btn.OpenType === 'form') {
      let data = nextProps.selectedData && nextProps.selectedData[0] ? nextProps.selectedData[0] : null
      this.setState({check: data && data[btn.field] === btn.openVal})
    } else if (btn.OpenType === 'formSubmit') {
      this.setState({
        selines: nextProps.selectedData || []
      })
    }
  }
@@ -121,13 +172,39 @@
  }
  actionSubmit = (res) => {
    const { btn } = this.props
    const { btn, setting, BID } = this.props
    const { selines } = this.state
    if (btn.uuid !== res.menuId) return
    let data = selines || []
    if (setting.supModule && !BID) {
      notification.warning({
        top: 92,
        message: '需要上级主键值!',
        duration: 3
      })
      return
    } else if (btn.Ot !== 'notRequired' && data.length === 0) {
      notification.warning({
        top: 92,
        message: '请选择行!',
        duration: 5
      })
      return
    } else if (btn.Ot === 'requiredSgl' && data.length !== 1) {
      notification.warning({
        top: 92,
        message: '请选择单行数据!',
        duration: 5
      })
      return
    }
    this.setState({ loading: true })
    this.execSubmit(this.state.selines, () => {}, res.form)
    this.execSubmit(data, () => {}, res.form)
  }
  resetModuleParam = (menuId, btnId, param) => {
@@ -156,7 +233,13 @@
    const { Tab, BID, btn, selectedData, setting } = this.props
    const { loading, disabled } = this.state
    if ((triggerId && btn.uuid !== triggerId) || loading || disabled) return
    if (loading || disabled) return
    if (triggerId) {
      if (btn.uuid !== triggerId) return
      if (this.props.lineId && record && record[0] && this.props.lineId !== record[0].$$key) {
        return
      }
    }
    if (((Tab && Tab.supMenu) || setting.supModule) && !BID) {
      notification.warning({
@@ -251,12 +334,14 @@
    })
    
    if (btn.OpenType === 'formSubmit') {
      MKEmitter.emit('mkFormSubmit', btn.uuid)
      this.setState({}, () => {
        MKEmitter.emit('mkFormSubmit', btn.uuid)
      })
      return
    } else if (btn.OpenType === 'prompt') {
      this.setState({loading: true})
      confirm({
        title: this.state.dict['main.action.confirm.tip'],
        title: btn.tipTitle || this.state.dict['main.action.confirm.tip'],
        onOk() {
          return new Promise(resolve => {
            _this.execSubmit(data, resolve)
@@ -280,6 +365,31 @@
        btnconfig: modal
      }, () => {
        this.improveAction()
      })
    } else if (btn.OpenType === 'form') {
      this.setState({
        loading: true,
        check: !this.state.check
      }, () => {
        let type = 'text'
        let fieldlen = 50
        let value = this.state.check ? btn.openVal : btn.closeVal
        if (typeof(value) === 'number') {
          type = 'number'
          fieldlen = 0
        }
        let item = {
          type: type,
          readonly: false,
          readin: true,
          writein: true,
          fieldlen: fieldlen,
          key: btn.field,
          value: value
        }
        this.execSubmit(data, () => { this.setState({loading: false})}, [item])
      })
    }
@@ -350,7 +460,7 @@
        }
        param.LText = Utils.formatOptions(param.LText)
      } else if (btn.OpenType === 'pop' || btn.OpenType === 'formSubmit') { // 表单
      } else if (btn.OpenType === 'pop' || btn.OpenType === 'formSubmit' || btn.OpenType === 'form') { // 表单
        if (btn.sqlType === 'insert') { // 系统函数添加时,生成uuid
          primaryId = ''
@@ -598,7 +708,7 @@
        param[setting.primaryKey] = primaryId // 设置主键参数
      }
      if (btn.OpenType === 'pop' || btn.OpenType === 'formSubmit') { // 表单
      if (btn.OpenType === 'pop' || btn.OpenType === 'formSubmit' || btn.OpenType === 'form') { // 表单
        formdata.forEach(_data => {
          param[_data.key] = _data.value
        })
@@ -773,7 +883,7 @@
          param.BID = this.props.BID
        }
        if ((btn.OpenType === 'pop' || btn.OpenType === 'formSubmit') && formdata) { // 表单
        if ((btn.OpenType === 'pop' || btn.OpenType === 'formSubmit' || btn.OpenType === 'form') && formdata) { // 表单
          formdata.forEach(_data => {
            param[_data.key] = _data.value
          })
@@ -911,6 +1021,12 @@
      _resolve()
    })
  }
  // xml调用方式
  // Api.directRequest('http://localhost:3001/test.xml', 'get', null, 'true').then(res => {
  //   let $x2js = new x2js()
  //   let jsonObj = $x2js.xml2js(res);
  //   console.info(jsonObj)
  // })
  /**
   * @description 自定义请求循环执行
@@ -1098,7 +1214,7 @@
      sql = _prevCustomScript + sql
      sql = sql + _backCustomScript
      if ((window.GLOB.systemType !== 'production' && options.sysType !== 'cloud') || window.debugger === true) {
      if (window.GLOB.debugger === true || (window.debugger === true && options.sysType !== 'cloud')) {
        console.info(sql.replace(/\n\s{8}/ig, '\n'))
      }
@@ -1135,7 +1251,7 @@
        Sort: index + 1
      }))
      if ((window.GLOB.systemType !== 'production' && options.sysType !== 'cloud') || window.debugger === true) {
      if (window.GLOB.debugger === true || (window.debugger === true && options.sysType !== 'cloud')) {
        let sql = [...lineMap.values()].map(item => (`
          ${item.insert}
          ${item.selects.join(` union all
@@ -1375,7 +1491,7 @@
    const { btn } = this.props
    const { btnconfig, autoMatic } = this.state
    if ((res && res.ErrCode === 'S') || autoMatic) { // 执行成功
    if ((res && (res.ErrCode === 'S' || !res.ErrCode)) || autoMatic) { // 执行成功
      notification.success({
        top: 92,
        message: res.ErrMesg || this.state.dict['main.action.confirm.success'],
@@ -1411,6 +1527,15 @@
    if (btn.output) {
      id = res.mk_b_id || res[btn.output] || ''
    }
    let tabId = ''
    if (btn.refreshTab && btn.refreshTab.length > 0) {
      tabId = btn.refreshTab[btn.refreshTab.length - 1]
    }
    if (tabId && btn.$MenuID === tabId) { // 刷新当前菜单时,停止其他操作
      MKEmitter.emit('reloadMenuView', tabId, 'table')
      return
    }
    if (btn.execSuccess === 'closetab') {
      MKEmitter.emit('closeTabView', btn.$MenuID)
@@ -1420,9 +1545,10 @@
      MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execSuccess, btn, id, this.state.selines)
    }
    if (btn.refreshTab && btn.refreshTab.length > 0) {
      MKEmitter.emit('reloadMenuView', btn.refreshTab[btn.refreshTab.length - 1], 'table')
    if (tabId) {
      MKEmitter.emit('reloadMenuView', tabId, 'table')
    }
    if (btn.switchTab && btn.switchTab.length > 0) {
      let id = btn.switchTab[btn.switchTab.length - 1]
      let node = document.getElementById('tab' + id)
@@ -1652,6 +1778,9 @@
      MKEmitter.emit('popclose')
    } else if (btn.execError !== 'never') {
      MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execError, btn, '', this.state.selines)
    } else if (btn.OpenType === 'form') {
      let data = this.props.selectedData && this.props.selectedData[0] ? this.props.selectedData[0] : null
      this.setState({check: data && data[btn.field] === btn.openVal})
    }
  }
@@ -1778,7 +1907,7 @@
  }
  modelconfirm = () => {
    const { BData } = this.props
    const { BData, btn } = this.props
    const { btnconfig, selines } = this.state
    let _this = this
@@ -1854,7 +1983,7 @@
      this.execSubmit(selines, () => {}, result)
    } else {
      confirm({
        title: this.state.dict['main.action.confirm.tip'],
        title: btn.tipTitle || this.state.dict['main.action.confirm.tip'],
        onOk() {
          return new Promise(resolve => {
            _this.execSubmit(selines, resolve, result)
@@ -1877,14 +2006,14 @@
    if (!btnconfig || !btnconfig.setting) return null
    let title = btnconfig.setting.title
    let width = btnconfig.setting.width + 'vw'
    let width = btnconfig.setting.width > 100 ? btnconfig.setting.width : btnconfig.setting.width + 'vw'
    let clickouter = btnconfig.setting.clickouter === 'close'
    if (btnconfig.setting.display === 'drawer') {
      let height = '100vh'
      if (btnconfig.setting.placement === 'top' || btnconfig.setting.placement === 'bottom') {
        width = '100vw'
        height = btnconfig.setting.width + 'vh'
        height = btnconfig.setting.width > 100 ? btnconfig.setting.width : btnconfig.setting.width + 'vh'
      }
      return (
        <Drawer
@@ -1925,7 +2054,7 @@
        (setting.tabType === 'main' && btnconfig.setting.container === 'tab' && this.props.ContainerId) ||
        (btnconfig.setting.container === 'tab' && btn.ContainerId)
      ) {
        width = btnconfig.setting.width + '%'
        width = btnconfig.setting.width > 100 ? btnconfig.setting.width : btnconfig.setting.width + '%'
        container = () => document.getElementById(this.props.ContainerId || btn.ContainerId)
      }
      return (
@@ -1958,17 +2087,24 @@
  render() {
    const { btn, show, style } = this.props
    const { loadingNumber, loading, disabled, hidden } = this.state
    const { loadingNumber, loading, disabled, hidden, check } = this.state
    if (hidden) return null
    if (show === 'actionList') {
    if (btn.OpenType === 'form') {
      if (btn.formType === 'switch') {
        return <Switch loading={loading} checked={check} disabled={disabled || loading} title={disabled ? (btn.reason || '') : ''} onChange={(val,e) => {e.stopPropagation();this.actionTrigger()}} style={style} className={btn.size === 'large' ? 'ant-switch-large' : ''} size={btn.size} checkedChildren={btn.openText || ''} unCheckedChildren={btn.closeText || ''}/>
      } else {
        return <Checkbox disabled={disabled || loading} title={disabled ? (btn.reason || '') : ''} checked={check} onChange={(e) => {e.stopPropagation();this.actionTrigger()}} style={style}></Checkbox>
      }
    } else if (show === 'actionList') {
      return <div style={{display: 'inline-block'}} onClick={(e) => e.stopPropagation()}>
        <Button
          style={style}
          icon={btn.icon}
          loading={loading}
          disabled={disabled}
          title={disabled ? (btn.reason || '') : ''}
          className={'mk-btn mk-' + btn.class}
          onClick={() => {this.actionTrigger()}}
        >{(loadingNumber ? `(${loadingNumber})` : '') + btn.label}</Button>
@@ -2004,7 +2140,7 @@
      return <div style={{display: 'inline-block'}} onClick={(e) => e.stopPropagation()}>
        <Button
          type="link"
          title={show === 'icon' ? btn.label : ''}
          title={disabled ? (btn.reason || '') : (show === 'icon' ? btn.label : '')}
          loading={loading}
          disabled={disabled}
          style={btn.style || style}