From f267d04e0561a0a20d1f2a9f558a273558ece90d Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期一, 24 五月 2021 17:50:19 +0800 Subject: [PATCH] 2021-05-24 --- src/tabviews/zshare/actionList/excelInbutton/index.jsx | 160 ++++++++++++++++++++++++++++++++--------------------- 1 files changed, 96 insertions(+), 64 deletions(-) diff --git a/src/tabviews/zshare/actionList/excelInbutton/index.jsx b/src/tabviews/zshare/actionList/excelInbutton/index.jsx index 49edf75..988d6f9 100644 --- a/src/tabviews/zshare/actionList/excelInbutton/index.jsx +++ b/src/tabviews/zshare/actionList/excelInbutton/index.jsx @@ -6,26 +6,23 @@ import { Button, Modal, notification, message } 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' class ExcelInButton extends Component { static propTpyes = { + show: PropTypes.any, // 鏄剧ず鏍峰紡 + position: PropTypes.any, // 鎸夐挳浣嶇疆锛屽伐鍏锋爮涓簍oolbar BID: PropTypes.string, // 涓昏〃ID - BData: PropTypes.any, // 涓昏〃鏁版嵁 selectedData: PropTypes.any, // 瀛愯〃涓�夋嫨鏁版嵁 Tab: PropTypes.any, // 濡傛灉褰撳墠鍏冪礌涓烘爣绛炬椂锛宼ab涓烘爣绛句俊鎭� - MenuID: PropTypes.string, // 鑿滃崟ID btn: PropTypes.object, // 鎸夐挳 - columns: PropTypes.array, // 瀛楁鍒� setting: PropTypes.any, // 椤甸潰閫氱敤璁剧疆 - ContainerId: PropTypes.any, // tab椤甸潰ID锛岀敤浜庡脊绐楁帶鍒� - updateStatus: PropTypes.func, // 鎸夐挳鐘舵�佹洿鏂� - triggerBtn: PropTypes.any, } state = { @@ -34,17 +31,23 @@ primaryId: '', } - /** - * @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) + shouldComponentUpdate (nextProps, nextState) { + return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState)) + } + + componentDidMount () { + const { position } = this.props + + if (position === 'toolbar') { + MKEmitter.addListener('triggerBtnId', this.actionTrigger) } } - shouldComponentUpdate (nextProps, nextState) { - return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState)) + componentWillUnmount () { + this.setState = () => { + return + } + MKEmitter.removeListener('triggerBtnId', this.actionTrigger) } /** @@ -55,20 +58,21 @@ this.setState({ loading: true }) - this.props.updateStatus('start') } else if (type === 'over') { this.setState({ loading: false }) - this.props.updateStatus('over') } } /** * @description 瑙﹀彂鎸夐挳鎿嶄綔 */ - actionTrigger = (record) => { + actionTrigger = (triggerId, record) => { const { setting, Tab, BID, btn, selectedData } = this.props + const { loading } = this.state + + if ((triggerId && btn.uuid !== triggerId) || loading) return if (Tab && Tab.supMenu && !BID) { notification.warning({ @@ -79,13 +83,7 @@ return } - let data = [] - - if (record) { // 琛ㄦ牸涓Е鍙戞寜閽� - data = [record] - } else { - data = selectedData || [] - } + let data = record || selectedData || [] if (btn.Ot === 'requiredSgl' && data.length !== 1) { // 闇�瑕侀�夋嫨鍗曡鏃讹紝鏍¢獙鏁版嵁 @@ -95,25 +93,28 @@ duration: 5 }) return - } - - if (btn.verify && btn.verify.sheet && btn.verify.columns && btn.verify.columns.length > 0) { - let primaryId = '' // 瀵煎叆鏃惰Id - if (btn.Ot === 'requiredSgl') { - primaryId = data[0][setting.primaryKey] || '' - } - - this.setState({ - primaryId: primaryId - }, () => { - this.refs.excelIn.exceltrigger() - }) - } else { + } else if (!btn.verify || !btn.verify.sheet || !btn.verify.columns || btn.verify.columns.length === 0) { notification.warning({ top: 92, message: 'excel瀵煎叆楠岃瘉淇℃伅鏈缃紒', duration: 5 }) + return + } + + let primaryId = '' // 瀵煎叆鏃惰Id + if (btn.Ot === 'requiredSgl' && setting.primaryKey) { + primaryId = data[0][setting.primaryKey] || '' + } + + this.setState({ + primaryId: primaryId + }, () => { + this.refs.excelIn.exceltrigger() + }) + + if (window.GLOB.systemType === 'production') { + MKEmitter.emit('queryTrigger', {menuId: btn.uuid, name: '瀵煎叆Excel'}) } } @@ -146,7 +147,9 @@ loading: false }) - this.props.updateStatus('refresh', btn.execSuccess) + if (btn.execSuccess !== 'never') { + MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execSuccess, btn) + } } /** @@ -183,32 +186,34 @@ loading: false }) - this.props.updateStatus('refresh', btn.execError) + if (btn.execError !== 'never') { + MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execError, btn) + } } /** * @description Excel 瀵煎叆 */ - getexceldata = (data, errors) => { + getexceldata = (data, errors, sheetName, errDetail) => { const { btn } = this.props if (errors) { if (errors === 'notexit') { notification.warning({ top: 92, - message: '宸ヤ綔琛ㄣ��' + btn.verify.sheet + '銆嬩笉瀛樺湪锛�', + message: '宸ヤ綔琛ㄣ��' + sheetName + '銆嬩笉瀛樺湪锛�', duration: 5 }) } else if (errors === 'empty') { notification.warning({ top: 92, - message: '宸ヤ綔琛ㄣ��' + btn.verify.sheet + '銆嬩负绌猴紒', + message: '宸ヤ綔琛ㄣ��' + sheetName + '銆嬩负绌猴紒', duration: 5 }) } else if (errors === 'headerError') { notification.warning({ top: 92, - message: '宸ヤ綔琛ㄣ��' + btn.verify.sheet + '銆嬭〃澶磋缃敊璇紒', + message: `宸ヤ綔琛ㄣ��${sheetName}銆嬭〃澶撮敊璇紝${errDetail}`, duration: 5 }) } @@ -220,14 +225,20 @@ if (!data || data.length === 0) { notification.warning({ top: 92, - message: '鏈幏鍙栧埌宸ヤ綔琛ㄣ��' + btn.verify.sheet + '銆嬫暟鎹紒', + message: '鏈幏鍙栧埌宸ヤ綔琛ㄣ��' + sheetName + '銆嬫暟鎹紒', duration: 5 }) this.updateStatus('over') return + } else if (data.length * btn.verify.columns.length > 30000) { + notification.warning({ + top: 92, + message: '褰撳墠瀵煎叆鏁版嵁閲忚繃澶э紝濡傞亣閿欒鎻愮ず锛岃鍒嗘壒瀵煎叆锛�', + duration: 5 + }) } - let result = Utils.getExcelInSql(btn, data, this.state.dict) + let result = getExcelInSql(btn, data, this.state.dict, (this.props.BID || '')) if (result.errors) { notification.warning({ @@ -248,10 +259,10 @@ param.BID = this.props.BID } - if (btn.intertype === 'inner' && !btn.innerFunc) { // 绯荤粺瀛樺偍杩囩▼ + if (btn.intertype === 'system') { // 绯荤粺瀛樺偍杩囩▼ param.func = 'sPC_TableData_InUpDe' - if (this.props.dataManager) { // 鏁版嵁鏉冮檺 + if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺 result.sql = result.sql.replace(/\$@/ig, '/*') result.sql = result.sql.replace(/@\$/ig, '*/') result.bottom = result.bottom.replace(/\$@/ig, '/*') @@ -265,11 +276,13 @@ param.LText1 = Utils.formatOptions(result.insert) param.LText2 = Utils.formatOptions(result.bottom) param.LText = Utils.formatOptions(result.sql) - param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000' + param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') param.secretkey = Utils.encrypt(param.LText, param.timestamp) if (this.props.menuType === 'HS' && param.timestamp) { // 浜戠楠岃瘉 - param.open_key = Utils.encrypt(param.secretkey, param.timestamp, true) + param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp) } + + param.menuname = btn.logLabel Api.genericInterface(param).then((res) => { if (res.status) { @@ -332,13 +345,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 + } } } @@ -348,9 +369,9 @@ if (this.props.menuType === 'HS' && res.func === 's_sDataDictb_excelIn') { // s_sDataDictb_excelIn 浜戠楠岃瘉 param.LText = Utils.formatOptions(result.sql) - param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000' + param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') param.secretkey = Utils.encrypt(param.LText, param.timestamp) - param.open_key = Utils.encrypt(param.secretkey, param.timestamp, true) + param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp) } return Api.genericInterface(res) @@ -386,27 +407,38 @@ } render() { - const { btn } = this.props + const { btn, show } = this.props const { loading } = this.state - return ( - <div className="mk-btn-wrap"> + if (show === 'actionList') { + return <div style={{display: 'inline-block'}} onClick={(e) => e.stopPropagation()}> <Button - className={'mk-btn mk-' + btn.class} icon={btn.icon} - onClick={() => {this.actionTrigger()}} loading={loading} + className={'mk-btn mk-' + btn.class} + onClick={() => {this.actionTrigger()}} >{btn.label}</Button> - <ExcelIn MenuID={this.props.MenuID} btn={btn} triggerExcelIn={() => this.updateStatus('start')} returndata={this.getexceldata} ref="excelIn" /> + <ExcelIn btn={btn} triggerExcelIn={() => this.updateStatus('start')} returndata={this.getexceldata} ref="excelIn" /> </div> - ) + } else { // icon銆乼ext銆� all 鍗$墖 + return <div style={{display: 'inline-block'}} onClick={(e) => e.stopPropagation()}> + <Button + type="link" + title={show === 'icon' ? btn.label : ''} + loading={loading} + style={btn.style} + icon={show === 'text' ? '' : (show === 'icon' ? (btn.icon || 'upload') : (btn.icon || ''))} + onClick={() => {this.actionTrigger()}} + >{show === 'icon' ? '' : btn.label}</Button> + <ExcelIn btn={btn} triggerExcelIn={() => this.updateStatus('start')} returndata={this.getexceldata} ref="excelIn" /> + </div> + } } } const mapStateToProps = (state) => { return { - menuType: state.editLevel, - dataManager: state.dataManager + menuType: state.editLevel } } -- Gitblit v1.8.0