From 5046d0d13dc6a8563b8e54e31913bc44cfa1072f Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期二, 26 四月 2022 19:23:18 +0800 Subject: [PATCH] 2022-04-26 --- src/tabviews/zshare/actionList/exceloutbutton/index.jsx | 100 +++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 83 insertions(+), 17 deletions(-) diff --git a/src/tabviews/zshare/actionList/exceloutbutton/index.jsx b/src/tabviews/zshare/actionList/exceloutbutton/index.jsx index 376dcc8..cbc490b 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({ @@ -423,11 +478,13 @@ exportExcel = (data) => { const { btn } = this.props + let columns = btn.verify.columns.filter(col => col.output !== 'false') + try { - let imgCol = btn.verify.columns.filter(col => col.type === 'image')[0] + let imgCol = columns.filter(col => col.type === 'image')[0] if (imgCol) { - const column = btn.verify.columns.map(item => { + const column = columns.map(item => { let col = { title: item.Text, key: item.Column, @@ -448,7 +505,7 @@ item.$Index = index + 1 + '' - btn.verify.columns.forEach((col, i) => { + columns.forEach((col, i) => { if (item[col.Column] && col.abs === 'true') { _row[col.Column] = Math.abs(item[col.Column]) } else { @@ -473,7 +530,7 @@ let colwidth = [] let abses = [] - btn.verify.columns.forEach(col => { + columns.forEach(col => { if (_topRow[col.Column]) return _header.push(col.Column) @@ -768,7 +825,7 @@ } // 娴嬭瘯绯荤粺鎵撳嵃鏌ヨ璇彞 - if ((options.sysType === 'local' && !window.GLOB.systemType) || window.debugger === true) { + if (window.GLOB.debugger === true || (window.debugger === true && options.sysType !== 'cloud')) { param.custom_script && console.info(`${LText ? '' : '/*涓嶆墽琛岄粯璁ql*/\n'}${param.custom_script}`) LText && console.info(LText) } @@ -801,7 +858,7 @@ execSuccess = (res) => { const { btn } = this.props - if (res && res.ErrCode === 'S') { // 鎵ц鎴愬姛 + if (res && (res.ErrCode === 'S' || !res.ErrCode)) { // 鎵ц鎴愬姛 notification.success({ top: 92, message: res.ErrMesg || this.state.dict['main.action.confirm.success'], @@ -819,7 +876,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 +922,26 @@ 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} + title={disabled ? (btn.reason || '') : ''} onClick={(e) => {e.stopPropagation(); this.actionTrigger()}} loading={loading} >{btn.label}</Button> @@ -889,7 +954,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' @@ -901,8 +966,9 @@ return ( <Button type="link" - title={show === 'icon' ? btn.label : ''} + title={disabled ? (btn.reason || '') : (show === 'icon' ? btn.label : '')} loading={loading} + disabled={disabled} style={btn.style} icon={icon} onClick={(e) => {e.stopPropagation(); this.actionTrigger()}} -- Gitblit v1.8.0