king
2020-11-18 d3272e82652361e5e9bd045925222ef042b6731f
src/tabviews/zshare/actionList/changeuserbutton/index.jsx
@@ -4,9 +4,9 @@
import { Button, notification, Modal } from 'antd'
import Api from '@/api'
import Utils from '@/utils/utils.js'
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'
const { confirm } = Modal
@@ -19,38 +19,42 @@
    selectedData: PropTypes.any,      // 子表中选择数据
    setting: PropTypes.any,           // 页面通用设置
    updateStatus: PropTypes.func,     // 按钮状态更新
    triggerBtn: PropTypes.any
  }
  state = {
    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS
  }
  /**
   * @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)
    }
    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    loading: false
  }
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
  }
  componentDidMount () {
    const { show } = this.props
    if (show === 'actionList') {
      MKEmitter.addListener('triggerBtnId', this.actionTrigger)
    }
  }
  componentWillUnmount () {
    this.setState = () => {
      return
    }
    MKEmitter.removeListener('triggerBtnId', this.actionTrigger)
  }
  
  /**
   * @description 触发按钮操作
   */
  actionTrigger = (record) => {
    const { setting, selectedData } = this.props
    let data = []
    if (record) { // 表格中触发按钮
      data = [record]
    } else {
      data = selectedData || []
    }
  actionTrigger = (triggerId) => {
    const { setting, selectedData, btn } = this.props
    const { loading } = this.state
    if ((triggerId && btn.uuid !== triggerId) || loading) return
    let data = selectedData || []
    if (data.length !== 1) {
      // 需要选择单行时,校验数据
@@ -72,7 +76,7 @@
    let primaryId = data[0][setting.primaryKey] || ''
    this.props.updateStatus('start')
    this.setState({loading: true})
    this.changeUser(primaryId)
  }
@@ -104,12 +108,21 @@
          Api.genericInterface(param).then(res => {
            resolve()
            if (res.status) {
              sessionStorage.setItem('avatar', res.icon || '')
              sessionStorage.setItem('UserID', res.UserID)
              sessionStorage.setItem('SessionUid', Utils.getuuid())
              sessionStorage.setItem('LoginUID', res.LoginUID)
              sessionStorage.setItem('User_Name', res.UserName)
              sessionStorage.setItem('Full_Name', res.FullName)
              sessionStorage.setItem('avatar', res.icon || '')
              sessionStorage.setItem('dataM', res.dataM ? 'true' : '')
              sessionStorage.setItem('debug', res.debug || '')
              sessionStorage.setItem('role_id', res.role_id || '')
              sessionStorage.removeItem('CloudAvatar')
              sessionStorage.removeItem('cloudDataM')
              sessionStorage.removeItem('CloudUserID')
              sessionStorage.removeItem('CloudUserName')
              sessionStorage.removeItem('CloudLoginUID')
              sessionStorage.removeItem('CloudFullName')
              
              window.location.reload()
            } else {
@@ -118,35 +131,43 @@
                message: res.message || res.ErrMesg,
                duration: btn.verify && btn.verify.ntime ? btn.verify.ntime : 10
              })
              _this.props.updateStatus('over')
              _this.setState({loading: false})
            }
          }, () => {
            resolve()
            _this.props.updateStatus('over')
            _this.setState({loading: false})
          })
        })
      },
      onCancel() {
        _this.props.updateStatus('over')
        _this.setState({loading: false})
      }
    })
  }
  render() {
    const { btn, show } = this.props
    const { loading } = this.state
    return (
      <div className="mk-btn-wrap">
        {!show ? <Button
          className={'mk-btn mk-' + btn.class}
    if (show === 'actionList') {
      return (
        <Button
          icon={btn.icon}
          onClick={() => {this.actionTrigger()}}
        >{btn.label}</Button> : null}
        {show === 'icon' ? <Button className="action-cell" icon={btn.icon || 'dash'} onClick={() => {this.actionTrigger()}}></Button> : null}
        {show === 'text' ? <Button className="action-cell" onClick={() => {this.actionTrigger()}}>{btn.label}</Button> : null}
        {show === 'all' ? <Button className="action-cell" icon={btn.icon || ''} onClick={() => {this.actionTrigger()}}>{btn.label}</Button> : null}
      </div>
    )
          loading={loading}
          className={'mk-btn mk-' + btn.class}
          onClick={(e) => {e.stopPropagation(); this.actionTrigger()}}
        >{btn.label}</Button>
      )
    } else { // icon、text、 all 卡片
      return (
        <Button
          type="link"
          loading={loading}
          icon={show === 'text' ? '' : (btn.icon || '')}
          onClick={(e) => {e.stopPropagation(); this.actionTrigger()}}
        >{show === 'icon' && btn.icon ? '' : btn.label}</Button>
      )
    }
  }
}