king
2021-11-17 c51f5e007a3e03c9d6731ab7f28f0080de009990
src/tabviews/zshare/actionList/changeuserbutton/index.jsx
@@ -1,29 +1,47 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Button, notification, Modal } from 'antd'
import { Button, notification, Modal, Icon } from 'antd'
import Api from '@/api'
import zhCN from '@/locales/zh-CN/main.js'
import enUS from '@/locales/en-US/main.js'
import MKEmitter from '@/utils/events.js'
import './index.scss'
// import './index.scss'
const { confirm } = Modal
class NewPageButton extends Component {
  static propTpyes = {
    show: PropTypes.any,              // 按钮显示样式控制
    position: PropTypes.any,          // 按钮位置,工具栏为toolbar
    MenuID: PropTypes.any,            // 菜单ID
    BID: PropTypes.string,            // 主表ID
    btn: PropTypes.object,            // 按钮
    selectedData: PropTypes.any,      // 子表中选择数据
    setting: PropTypes.any,           // 页面通用设置
    updateStatus: PropTypes.func,     // 按钮状态更新
  }
  state = {
    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    disabled: false,
    hidden: false,
    loading: false
  }
  UNSAFE_componentWillMount () {
    const { btn, selectedData } = this.props
    let disabled = false
    if (btn.controlField && selectedData && selectedData.length > 0) { // 表格中按钮隐藏控制
      selectedData.forEach(item => {
        let s = item[btn.controlField] + ''
        if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) {
          disabled = true
        }
      })
      this.setState({disabled, hidden: disabled && btn.control === 'hidden'})
    }
  }
  shouldComponentUpdate (nextProps, nextState) {
@@ -31,10 +49,24 @@
  }
  componentDidMount () {
    const { show } = this.props
    MKEmitter.addListener('triggerBtnId', this.actionTrigger)
  }
    if (show === 'actionList') {
      MKEmitter.addListener('triggerBtnId', this.actionTrigger)
  UNSAFE_componentWillReceiveProps (nextProps) {
    const { btn, selectedData } = this.props
    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] + ''
          if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) {
            disabled = true
          }
        })
      }
      this.setState({disabled, hidden: disabled && btn.control === 'hidden'})
    }
  }
@@ -48,13 +80,26 @@
  /**
   * @description 触发按钮操作
   */
  actionTrigger = (triggerId) => {
    const { setting, selectedData, btn } = this.props
    const { loading } = this.state
  actionTrigger = (triggerId, record, type) => {
    const { setting, selectedData, btn, MenuID } = this.props
    const { loading, disabled } = this.state
    
    if ((triggerId && btn.uuid !== triggerId) || loading) return
    if ((triggerId && btn.uuid !== triggerId) || loading || disabled) return
    if (btn.funcType === 'closetab') {
      MKEmitter.emit('closeTabView', MenuID || btn.$MenuID)
      if (btn.refreshTab && btn.refreshTab.length > 0) {
        MKEmitter.emit('reloadMenuView', btn.refreshTab[btn.refreshTab.length - 1], 'table')
      }
      return
    } else if (type === 'linkbtn' && selectedData && selectedData.length === 1) {
      if (record[0].$Index !== selectedData[0].$Index) {
        return
      }
    }
    
    let data = selectedData || []
    let data = record || selectedData || []
    if (data.length !== 1) {
      // 需要选择单行时,校验数据
@@ -114,8 +159,12 @@
              sessionStorage.setItem('Full_Name', res.FullName)
              sessionStorage.setItem('avatar', res.icon || '')
              sessionStorage.setItem('dataM', res.dataM ? 'true' : '')
              sessionStorage.setItem('localDataM', res.dataM ? 'true' : '')
              sessionStorage.setItem('debug', res.debug || '')
              sessionStorage.setItem('role_id', res.role_id || '')
              sessionStorage.setItem('departmentcode', res.departmentcode || '')
              sessionStorage.setItem('organization', res.organization || '')
              sessionStorage.setItem('localRole_id', res.role_id || '')
              
              sessionStorage.removeItem('CloudAvatar')
              sessionStorage.removeItem('cloudDataM')
@@ -147,25 +196,47 @@
  render() {
    const { btn, show } = this.props
    const { loading } = this.state
    const { loading, disabled, hidden } = this.state
    if (hidden) return null
    if (show === 'actionList') {
      return (
        <Button
          icon={btn.icon}
          loading={loading}
          disabled={disabled}
          className={'mk-btn mk-' + btn.class}
          onClick={(e) => {e.stopPropagation(); this.actionTrigger()}}
        >{btn.label}</Button>
      )
    } else { // icon、text、 all 卡片
      let label = ''
      let icon = ''
      if (show === 'button') {
        label = btn.label
        icon = btn.icon || ''
      } else if (show === 'link') {
        label = <span>{btn.label}{btn.icon ? <Icon style={{marginLeft: '8px'}} type={btn.icon}/> : ''}</span>
        icon = ''
      } else if (show === 'icon') {
        icon = btn.icon || ''
      // } else if (show === 'text') {
      } else {
        label = btn.label
      }
      return (
        <Button
          type="link"
          title={show === 'icon' ? btn.label : ''}
          loading={loading}
          icon={show === 'text' ? '' : (btn.icon || '')}
          disabled={disabled}
          style={btn.style}
          icon={icon}
          onClick={(e) => {e.stopPropagation(); this.actionTrigger()}}
        >{show === 'icon' && btn.icon ? '' : btn.label}</Button>
        >{label}</Button>
      )
    }
  }