From c51f5e007a3e03c9d6731ab7f28f0080de009990 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期三, 17 十一月 2021 18:38:32 +0800 Subject: [PATCH] 2021-11-17 --- src/tabviews/zshare/actionList/excelInbutton/index.jsx | 143 +++++++++++++++++++++++++++++++++-------------- 1 files changed, 101 insertions(+), 42 deletions(-) diff --git a/src/tabviews/zshare/actionList/excelInbutton/index.jsx b/src/tabviews/zshare/actionList/excelInbutton/index.jsx index 0ffe673..0961633 100644 --- a/src/tabviews/zshare/actionList/excelInbutton/index.jsx +++ b/src/tabviews/zshare/actionList/excelInbutton/index.jsx @@ -3,16 +3,16 @@ import moment from 'moment' import {connect} from 'react-redux' import { is, fromJS } from 'immutable' -import { Button, Modal, notification, message } from 'antd' +import { Button, Modal, notification, message, Icon } from 'antd' import ExcelIn from './excelin' -import Utils from '@/utils/utils.js' +import Utils, { getExcelInSql } from '@/utils/utils.js' import options from '@/store/options.js' 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' class ExcelInButton extends Component { static propTpyes = { @@ -28,7 +28,25 @@ state = { dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, loading: false, + selines: null, + disabled: false, + hidden: false, primaryId: '', + } + + 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) { @@ -36,10 +54,24 @@ } componentDidMount () { - const { position } = this.props + MKEmitter.addListener('triggerBtnId', this.actionTrigger) + } - if (position === 'toolbar') { - 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'}) } } @@ -49,38 +81,27 @@ } MKEmitter.removeListener('triggerBtnId', this.actionTrigger) } - - /** - * @description 鎸夐挳鐘舵�佹敼鍙� - */ - updateStatus = (type) => { - if (type === 'start') { - this.setState({ - loading: true - }) - } else if (type === 'over') { - this.setState({ - loading: false - }) - } - } /** * @description 瑙﹀彂鎸夐挳鎿嶄綔 */ - actionTrigger = (triggerId, record) => { + actionTrigger = (triggerId, record, type) => { const { setting, Tab, BID, btn, selectedData } = this.props - const { loading } = this.state + const { loading, disabled } = this.state - if ((triggerId && btn.uuid !== triggerId) || loading) return + if ((triggerId && btn.uuid !== triggerId) || loading || disabled) return - if (Tab && Tab.supMenu && !BID) { + if (((Tab && Tab.supMenu) || setting.supModule) && !BID) { notification.warning({ top: 92, message: '闇�瑕佷笂绾т富閿�硷紒', duration: 5 }) return + } else if (type === 'linkbtn' && selectedData && selectedData.length === 1) { + if (record[0].$Index !== selectedData[0].$Index) { + return + } } let data = record || selectedData || [] @@ -103,11 +124,12 @@ } let primaryId = '' // 瀵煎叆鏃惰Id - if (btn.Ot === 'requiredSgl') { + if (btn.Ot === 'requiredSgl' && setting.primaryKey) { primaryId = data[0][setting.primaryKey] || '' } this.setState({ + selines: data, primaryId: primaryId }, () => { this.refs.excelIn.exceltrigger() @@ -148,7 +170,12 @@ }) if (btn.execSuccess !== 'never') { - MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execSuccess, btn) + MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execSuccess, btn, '', this.state.selines) + } + if (btn.switchTab && btn.switchTab.length > 0) { + let id = btn.switchTab[btn.switchTab.length - 1] + let node = document.getElementById('tab' + id) + node && node.click() } } @@ -187,14 +214,14 @@ }) if (btn.execError !== 'never') { - MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execError, btn) + MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execError, btn, '', this.state.selines) } } /** * @description Excel 瀵煎叆 */ - getexceldata = (data, errors, sheetName) => { + getexceldata = (data, errors, sheetName, errDetail) => { const { btn } = this.props if (errors) { @@ -213,12 +240,12 @@ } else if (errors === 'headerError') { notification.warning({ top: 92, - message: '宸ヤ綔琛ㄣ��' + sheetName + '銆嬭〃澶磋缃敊璇紝璇锋鏌ヨ〃澶翠腑鐨勫悕绉板強椤哄簭锛屼笌鎸夐挳Excel鍒椾俊鎭槸鍚︿竴鑷达紒', + message: `宸ヤ綔琛ㄣ��${sheetName}銆嬭〃澶撮敊璇紝${errDetail}`, duration: 5 }) } - this.updateStatus('over') + this.setState({ loading: false }) return } @@ -228,7 +255,7 @@ message: '鏈幏鍙栧埌宸ヤ綔琛ㄣ��' + sheetName + '銆嬫暟鎹紒', duration: 5 }) - this.updateStatus('over') + this.setState({ loading: false }) return } else if (data.length * btn.verify.columns.length > 30000) { notification.warning({ @@ -238,7 +265,7 @@ }) } - let result = Utils.getExcelInSql(btn, data, this.state.dict, (this.props.BID || '')) + let result = getExcelInSql(btn, data, this.state.dict, (this.props.BID || '')) if (result.errors) { notification.warning({ @@ -246,7 +273,7 @@ message: result.errors, duration: 5 }) - this.updateStatus('over') + this.setState({ loading: false }) return } @@ -283,6 +310,10 @@ } param.menuname = btn.logLabel + + if (window.GLOB.probation) { + param.s_debug_type = 'Y' + } Api.genericInterface(param).then((res) => { if (res.status) { @@ -345,13 +376,21 @@ if (btn.sysInterface === 'true' && options.cloudServiceApi) { param.rduri = options.cloudServiceApi } else if (btn.sysInterface !== 'true') { - param.rduri = btn.interface + if (window.GLOB.systemType === 'production' && btn.proInterface) { + param.rduri = btn.proInterface + } else { + param.rduri = btn.interface + } } } else { if (btn.sysInterface === 'true' && window.GLOB.mainSystemApi) { param.rduri = window.GLOB.mainSystemApi } else if (btn.sysInterface !== 'true') { - param.rduri = btn.interface + if (window.GLOB.systemType === 'production' && btn.proInterface) { + param.rduri = btn.proInterface + } else { + param.rduri = btn.interface + } } } @@ -400,29 +439,49 @@ render() { const { btn, show } = this.props - const { loading } = this.state + const { loading, disabled, hidden } = this.state + + if (hidden) return null if (show === 'actionList') { return <div style={{display: 'inline-block'}} onClick={(e) => e.stopPropagation()}> <Button icon={btn.icon} loading={loading} + disabled={disabled} className={'mk-btn mk-' + btn.class} onClick={() => {this.actionTrigger()}} >{btn.label}</Button> - <ExcelIn btn={btn} triggerExcelIn={() => this.updateStatus('start')} returndata={this.getexceldata} ref="excelIn" /> + <ExcelIn btn={btn} triggerExcelIn={() => this.setState({ loading: true })} returndata={this.getexceldata} ref="excelIn" /> </div> } else { // icon銆乼ext銆� 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 || 'upload' + // } else if (show === 'text') { + } else { + label = btn.label + } + return <div style={{display: 'inline-block'}} onClick={(e) => e.stopPropagation()}> <Button type="link" title={show === 'icon' ? btn.label : ''} loading={loading} - style={btn.btnstyle} - icon={show === 'text' ? '' : (show === 'icon' ? (btn.icon || 'upload') : (btn.icon || ''))} + disabled={disabled} + style={btn.style} + icon={icon} onClick={() => {this.actionTrigger()}} - >{show === 'icon' ? '' : btn.label}</Button> - <ExcelIn btn={btn} triggerExcelIn={() => this.updateStatus('start')} returndata={this.getexceldata} ref="excelIn" /> + >{label}</Button> + <ExcelIn btn={btn} triggerExcelIn={() => this.setState({ loading: true })} returndata={this.getexceldata} ref="excelIn" /> </div> } } -- Gitblit v1.8.0