From 46f79b491173d284a4900d19e7aecf7509481438 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期五, 21 一月 2022 17:21:25 +0800 Subject: [PATCH] 2022-01-21 --- src/tabviews/zshare/actionList/exceloutbutton/index.jsx | 83 ++++++++++++++++++++++++++++++++++++----- 1 files changed, 73 insertions(+), 10 deletions(-) diff --git a/src/tabviews/zshare/actionList/exceloutbutton/index.jsx b/src/tabviews/zshare/actionList/exceloutbutton/index.jsx index 376dcc8..891cd34 100644 --- a/src/tabviews/zshare/actionList/exceloutbutton/index.jsx +++ b/src/tabviews/zshare/actionList/exceloutbutton/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, Icon } from 'antd' +import { Button, Modal, notification, message } from 'antd' import * as XLSX from 'xlsx' import Utils from '@/utils/utils.js' @@ -12,24 +12,50 @@ import zhCN from '@/locales/zh-CN/main.js' import enUS from '@/locales/en-US/main.js' import MKEmitter from '@/utils/events.js' +import MkIcon from '@/components/mk-icon' // import './index.scss' class ExcelOutButton extends Component { static propTpyes = { BID: PropTypes.string, // 涓昏〃ID - position: PropTypes.any, // 鎸夐挳浣嶇疆锛屽伐鍏锋爮涓簍oolbar + BData: PropTypes.any, // 涓昏〃鏁版嵁 show: PropTypes.any, // 鏄剧ず鏍峰紡 Tab: PropTypes.any, // 濡傛灉褰撳墠鍏冪礌涓烘爣绛炬椂锛宼ab涓烘爣绛句俊鎭� btn: PropTypes.object, // 鎸夐挳 setting: PropTypes.any, // 椤甸潰閫氱敤璁剧疆 updateStatus: PropTypes.func, // 鎸夐挳鐘舵�佹洿鏂� + disabled: PropTypes.any, // 琛屾寜閽鐢� + lineId: PropTypes.any, // 琛岀储寮�+涓婚敭鍊硷紝鐢ㄤ簬琛屾寜閽弻鍑� } state = { dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, excelName: '', // 鏂囦欢鍚� search: '', // 鎼滅储鏉′欢 - loading: false // 瀵煎嚭涓� + loading: false, // 瀵煎嚭涓� + hidden: false, + disabled: false + } + + UNSAFE_componentWillMount () { + const { btn, BData, disabled } = this.props + + 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 (disabled) { + this.setState({disabled: true}) + } } shouldComponentUpdate (nextProps, nextState) { @@ -39,6 +65,29 @@ componentDidMount () { MKEmitter.addListener('triggerBtnId', this.actionTrigger) MKEmitter.addListener('returnModuleParam', this.triggerExcelout) + } + + UNSAFE_componentWillReceiveProps (nextProps) { + const { btn, BData } = this.props + + 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) { + this.setState({disabled: true}) + } else { + this.setState({disabled: false}) + } } componentWillUnmount () { @@ -68,11 +117,17 @@ /** * @description 瑙﹀彂鎸夐挳鎿嶄綔 */ - actionTrigger = (triggerId) => { + actionTrigger = (triggerId, record) => { const { setting, Tab, BID, btn } = this.props - const { loading } = this.state + const { loading, disabled } = this.state - if ((triggerId && btn.uuid !== triggerId) || loading) 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({ @@ -819,7 +874,9 @@ loading: false }) - if (btn.execSuccess !== 'never') { + if (btn.execSuccess === 'closepoptab') { + MKEmitter.emit('popclose') + } else if (btn.execSuccess !== 'never') { MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execSuccess, btn, '', []) } if (btn.switchTab && btn.switchTab.length > 0) { @@ -863,20 +920,25 @@ loading: false }) - if (btn.execError !== 'never') { + if (btn.execError === 'closepoptab') { + MKEmitter.emit('popclose') + } else if (btn.execError !== 'never') { MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execError, btn, '', []) } } render() { const { btn, show } = this.props - const { loading } = this.state + const { loading, hidden, disabled } = this.state + + if (hidden) return null if (show === 'actionList') { return ( <Button className={'mk-btn mk-' + btn.class} icon={btn.icon} + disabled={disabled} onClick={(e) => {e.stopPropagation(); this.actionTrigger()}} loading={loading} >{btn.label}</Button> @@ -889,7 +951,7 @@ label = btn.label icon = btn.icon || '' } else if (show === 'link') { - label = <span>{btn.label}{btn.icon ? <Icon style={{marginLeft: '8px'}} type={btn.icon}/> : ''}</span> + label = <span>{btn.label}{btn.icon ? <MkIcon style={{marginLeft: '8px'}} type={btn.icon}/> : ''}</span> icon = '' } else if (show === 'icon') { icon = btn.icon || 'download' @@ -903,6 +965,7 @@ type="link" title={show === 'icon' ? btn.label : ''} loading={loading} + disabled={disabled} style={btn.style} icon={icon} onClick={(e) => {e.stopPropagation(); this.actionTrigger()}} -- Gitblit v1.8.0