From 8b6f9a84e5eb704b25c105cce31904381bd81107 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期二, 29 十一月 2022 18:41:58 +0800 Subject: [PATCH] 2022-11-29 --- src/tabviews/zshare/actionList/excelInbutton/index.jsx | 390 +++++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 279 insertions(+), 111 deletions(-) diff --git a/src/tabviews/zshare/actionList/excelInbutton/index.jsx b/src/tabviews/zshare/actionList/excelInbutton/index.jsx index 53fd47f..09ee076 100644 --- a/src/tabviews/zshare/actionList/excelInbutton/index.jsx +++ b/src/tabviews/zshare/actionList/excelInbutton/index.jsx @@ -1,42 +1,67 @@ import React, {Component} from 'react' import PropTypes from 'prop-types' import moment from 'moment' -import {connect} from 'react-redux' import { is, fromJS } from 'immutable' 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 './index.scss' +import MKEmitter from '@/utils/events.js' +import MkIcon from '@/components/mk-icon' +// import './index.scss' + +const { confirm } = Modal class ExcelInButton extends Component { static propTpyes = { - show: PropTypes.any, // 鏄剧ず鏍峰紡 BID: PropTypes.string, // 涓昏〃ID + BData: PropTypes.any, // 涓昏〃鏁版嵁 selectedData: PropTypes.any, // 瀛愯〃涓�夋嫨鏁版嵁 - Tab: PropTypes.any, // 濡傛灉褰撳墠鍏冪礌涓烘爣绛炬椂锛宼ab涓烘爣绛句俊鎭� btn: PropTypes.object, // 鎸夐挳 setting: PropTypes.any, // 椤甸潰閫氱敤璁剧疆 - updateStatus: PropTypes.func, // 鎸夐挳鐘舵�佹洿鏂� - triggerBtn: PropTypes.any, + disabled: PropTypes.any, // 琛屾寜閽鐢� } state = { dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, loading: false, + selines: null, + disabled: false, + hidden: false, 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) + UNSAFE_componentWillMount () { + const { btn, selectedData, BData } = this.props + let disabled = false + + if (btn.controlField && selectedData && selectedData.length > 0) { // 琛ㄦ牸涓寜閽殣钘忔帶鍒� + selectedData.forEach(item => { + let s = item[btn.controlField] !== undefined ? item[btn.controlField] + '' : '' + if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) { + disabled = true + } + }) + this.setState({hidden: disabled && btn.control === 'hidden'}) + } else 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 (this.props.disabled || disabled) { + this.setState({disabled: true}) } } @@ -44,45 +69,73 @@ return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState)) } - /** - * @description 鎸夐挳鐘舵�佹敼鍙� - */ - updateStatus = (type) => { - if (type === 'start') { - this.setState({ - loading: true - }) - this.props.updateStatus('start') - } else if (type === 'over') { - this.setState({ - loading: false - }) - this.props.updateStatus('over') + componentDidMount () { + MKEmitter.addListener('triggerBtnId', this.actionTrigger) + } + + UNSAFE_componentWillReceiveProps (nextProps) { + const { btn, selectedData, BData } = this.props + + let disabled = false + if (btn.controlField && !is(fromJS(nextProps.selectedData || []), fromJS(selectedData || []))) { + if (nextProps.selectedData && nextProps.selectedData.length > 0) { // 琛ㄦ牸涓寜閽殣钘忔帶鍒� + nextProps.selectedData.forEach(item => { + let s = item[btn.controlField] !== undefined ? item[btn.controlField] + '' : '' + if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) { + disabled = true + } + }) + } + this.setState({disabled, hidden: disabled && btn.control === 'hidden'}) + } else 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 || disabled) { + this.setState({disabled: true}) + } else { + this.setState({disabled: false}) + } + } + + componentWillUnmount () { + this.setState = () => { + return + } + MKEmitter.removeListener('triggerBtnId', this.actionTrigger) } /** * @description 瑙﹀彂鎸夐挳鎿嶄綔 */ - actionTrigger = (record) => { - const { setting, Tab, BID, btn, selectedData } = this.props + actionTrigger = (triggerId, record, type) => { + const { setting, BID, btn, selectedData } = this.props + const { loading, disabled } = this.state - if (Tab && Tab.supMenu && !BID) { + if (loading || disabled) return + if (triggerId && btn.uuid !== triggerId) return + + if (setting.supModule && !BID) { notification.warning({ top: 92, message: '闇�瑕佷笂绾т富閿�硷紒', duration: 5 }) return + } else if (type === 'linkbtn' && !btn.$toolbtn && !is(fromJS(selectedData || []), fromJS(record))) { + return } - let data = [] - - if (record) { // 琛ㄦ牸涓Е鍙戞寜閽� - data = [record] - } else { - data = selectedData || [] - } + let data = record || selectedData || [] if (btn.Ot === 'requiredSgl' && data.length !== 1) { // 闇�瑕侀�夋嫨鍗曡鏃讹紝鏍¢獙鏁版嵁 @@ -92,25 +145,29 @@ 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({ + selines: data, + primaryId: primaryId + }, () => { + this.refs.excelIn.exceltrigger() + }) + + if (window.GLOB.systemType === 'production') { + MKEmitter.emit('queryTrigger', {menuId: btn.uuid, name: '瀵煎叆Excel'}) } } @@ -125,7 +182,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'], @@ -143,7 +200,19 @@ loading: false }) - this.props.updateStatus('refresh', btn.execSuccess) + if (btn.execSuccess === 'closepoptab') { + MKEmitter.emit('popclose') + } else if (btn.execSuccess !== 'never') { + MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execSuccess, btn, '', this.state.selines) + } + + btn.syncComponentId && MKEmitter.emit('reloadData', btn.syncComponentId) + + if (btn.switchTab && btn.switchTab.length > 0) { + let id = btn.switchTab[btn.switchTab.length - 1] + let node = document.getElementById('tab' + id) + node && node.click() + } } /** @@ -180,13 +249,17 @@ loading: false }) - this.props.updateStatus('refresh', btn.execError) + if (btn.execError === 'closepoptab') { + MKEmitter.emit('popclose') + } else if (btn.execError !== 'never') { + 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) { @@ -205,12 +278,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 } @@ -220,7 +293,7 @@ message: '鏈幏鍙栧埌宸ヤ綔琛ㄣ��' + sheetName + '銆嬫暟鎹紒', duration: 5 }) - this.updateStatus('over') + this.setState({ loading: false }) return } else if (data.length * btn.verify.columns.length > 30000) { notification.warning({ @@ -230,7 +303,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({ @@ -238,7 +311,7 @@ message: result.errors, duration: 5 }) - this.updateStatus('over') + this.setState({ loading: false }) return } @@ -254,7 +327,7 @@ 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, '/*') @@ -266,23 +339,86 @@ param.excel_in_type = 'true' 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') + param.LText2 = result.bottom + param.LText = result.sql + + let unCheckParam = null + + if (/\$check@|@check\$/ig.test(param.LText2) || /\$check@|@check\$/ig.test(param.LText)) { + unCheckParam = fromJS(param).toJS() + param.LText = param.LText.replace(/\$check@|@check\$/ig, '') + param.LText2 = param.LText2.replace(/\$check@|@check\$/ig, '') + } + + param.LText2 = Utils.formatOptions(param.LText2) + param.LText = Utils.formatOptions(param.LText) param.secretkey = Utils.encrypt(param.LText, param.timestamp) - if (this.props.menuType === 'HS' && param.timestamp) { // 浜戠楠岃瘉 + if (window.GLOB.mkHS && param.timestamp) { // 浜戠楠岃瘉 param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp) } - Api.genericInterface(param).then((res) => { - if (res.status) { - this.execSuccess(res) - } else { - this.execError(res) + param.menuname = btn.logLabel + + if (window.GLOB.probation) { + param.s_debug_type = 'Y' + } + + if (unCheckParam) { + unCheckParam.LText = unCheckParam.LText.replace(/\$check@/ig, '/*').replace(/@check\$/ig, '*/') + unCheckParam.LText = Utils.formatOptions(unCheckParam.LText) + unCheckParam.LText2 = unCheckParam.LText2.replace(/\$check@/ig, '/*').replace(/@check\$/ig, '*/') + unCheckParam.LText2 = Utils.formatOptions(unCheckParam.LText2) + + unCheckParam.secretkey = Utils.encrypt(unCheckParam.LText, unCheckParam.timestamp) + + unCheckParam.menuname = btn.logLabel + + if (window.GLOB.probation) { + unCheckParam.s_debug_type = 'Y' } - }, () => { - this.execError({}) - }) + + Api.genericInterface(param).then(res => { + if (res.status) { + this.execSuccess(res) + } else if (res.ErrCode === 'C') { + const _this = this + confirm({ + title: '缁х画鎵ц锛�', + content: res.message, + onOk() { + return new Promise(resolve => { + Api.genericInterface(unCheckParam).then(result => { + if (result.status) { + _this.execSuccess(result) + } else { + _this.execError(result) + } + resolve() + }) + }) + }, + onCancel() { + _this.execError(res) + } + }) + } else { + this.execError(res) + } + }, () => { + this.execError({}) + }) + } else { + Api.genericInterface(param).then((res) => { + if (res.status) { + this.execSuccess(res) + } else { + this.execError(res) + } + }, () => { + this.execError({}) + }) + } } else if (btn.intertype === 'inner' && btn.innerFunc) { // 鑷畾涔夊瓨鍌ㄨ繃绋� param.func = btn.innerFunc @@ -331,17 +467,39 @@ // 澶栭儴璇锋眰 _outParam = fromJS(res).toJS() - if (this.props.menuType === 'HS') { + if (window.GLOB.mkHS) { if (btn.sysInterface === 'true' && options.cloudServiceApi) { param.rduri = options.cloudServiceApi + param.userid = sessionStorage.getItem('CloudUserID') || '' + param.LoginUID = sessionStorage.getItem('CloudLoginUID') || '' } 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 (btn.sysInterface === 'true') { + if (window.GLOB.mainSystemApi) { + param.rduri = window.GLOB.mainSystemApi + } + } else if (btn.sysInterface === 'external') { + if (window.GLOB.systemType === 'production') { + param.$token = btn.exProInterface || '' + } else { + param.$token = btn.exInterface || '' + } + } else { + if (window.GLOB.systemType === 'production' && btn.proInterface) { + param.rduri = btn.proInterface + } else { + param.rduri = btn.interface + } + let host = window.GLOB.baseurl.replace(/http(s):\/\//, '') + if (param.rduri.indexOf(host) === -1 && /\/dostars/.test(param.rduri)) { + param.$login = true + } } } @@ -349,7 +507,7 @@ res.func = btn.outerFunc } - if (this.props.menuType === 'HS' && res.func === 's_sDataDictb_excelIn') { // s_sDataDictb_excelIn 浜戠楠岃瘉 + if (window.GLOB.mkHS && res.func === 's_sDataDictb_excelIn') { // s_sDataDictb_excelIn 浜戠楠岃瘉 param.LText = Utils.formatOptions(result.sql) param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') param.secretkey = Utils.encrypt(param.LText, param.timestamp) @@ -389,39 +547,49 @@ } render() { - const { btn, show } = this.props - const { loading } = this.state + const { btn } = this.props + const { loading, disabled, hidden } = this.state - return ( - <div className="mk-btn-wrap"> - {!show ? <Button - className={'mk-btn mk-' + btn.class} - icon={btn.icon} - onClick={() => {this.actionTrigger()}} - loading={loading} - >{btn.label}</Button> : null} - {show === 'icon' ? <Button - className="import-icon" - icon="upload" - onClick={() => {this.actionTrigger()}} - loading={loading} - title={btn.label} - ></Button> : null} - <ExcelIn btn={btn} triggerExcelIn={() => this.updateStatus('start')} returndata={this.getexceldata} ref="excelIn" /> - </div> - ) + if (hidden) return null + + let label = '' + let icon = '' + let type = 'link' + let className = '' + + if (btn.show === 'button') { + label = btn.label + icon = btn.icon || '' + } else if (btn.show === 'link') { + label = <span>{btn.label}{btn.icon ? <MkIcon style={{marginLeft: '8px'}} type={btn.icon}/> : ''}</span> + icon = '' + } else if (btn.show === 'icon') { + icon = btn.icon || 'upload' + } else if (!btn.$toolbtn) { + icon = btn.icon || '' + label = btn.label + className = 'mk-btn mk-' + btn.class + } else { + type = '' + icon = btn.icon || '' + label = btn.label + className = 'mk-btn mk-' + btn.class + } + + return <> + <Button + type={type} + title={disabled ? (btn.reason || '') : (btn.show === 'icon' ? btn.label : '')} + loading={loading} + disabled={disabled} + style={btn.style} + icon={icon} + className={className} + onClick={(e) => {e.stopPropagation(); this.actionTrigger()}} + >{label}</Button> + <ExcelIn btn={btn} triggerExcelIn={() => this.setState({ loading: true })} returndata={this.getexceldata} ref="excelIn" /> + </> } } -const mapStateToProps = (state) => { - return { - menuType: state.editLevel, - dataManager: state.dataManager - } -} - -const mapDispatchToProps = () => { - return {} -} - -export default connect(mapStateToProps, mapDispatchToProps)(ExcelInButton) \ No newline at end of file +export default ExcelInButton \ No newline at end of file -- Gitblit v1.8.0