king
2022-02-25 d82fec9e2a4238ff1833e67c01bc9b34e525d904
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'
@@ -33,6 +33,7 @@
    setting: PropTypes.any,           // 页面通用设置
    ContainerId: PropTypes.any,       // tab页面ID,用于弹窗控制
    disabled: PropTypes.any,          // 行按钮禁用
    lineId: PropTypes.any,            // 行索引+主键值,用于行按钮双击
  }
  state = {
@@ -47,7 +48,8 @@
    disabled: false,
    hidden: false,
    checkParam: null,
    autoMatic: false
    autoMatic: false,
    check: false
  }
  moduleParams = null
@@ -78,6 +80,15 @@
    }
    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 || []
      })
    }
  }
@@ -131,6 +142,15 @@
    } 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 || []
      })
    }
  }
  componentWillUnmount () {
@@ -152,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) => {
@@ -187,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({
@@ -282,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)
@@ -311,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])
      })
    }
@@ -381,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 = ''
@@ -629,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
        })
@@ -804,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
          })
@@ -942,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 自定义请求循环执行
@@ -1406,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'],
@@ -1442,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)
@@ -1451,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)
@@ -1683,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})
    }
  }
@@ -1809,7 +1907,7 @@
  }
  modelconfirm = () => {
    const { BData } = this.props
    const { BData, btn } = this.props
    const { btnconfig, selines } = this.state
    let _this = this
@@ -1885,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)
@@ -1908,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
@@ -1956,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 (
@@ -1989,11 +2087,17 @@
  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} onChange={(val,e) => {e.stopPropagation();this.actionTrigger()}} style={style} size={btn.size} checkedChildren={btn.openText || ''} unCheckedChildren={btn.closeText || ''}/>
      } else {
        return <Checkbox disabled={disabled || loading} 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}