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 | 134 +++++++++++++++++++++++++++++++++++--------- 1 files changed, 106 insertions(+), 28 deletions(-) diff --git a/src/tabviews/zshare/actionList/exceloutbutton/index.jsx b/src/tabviews/zshare/actionList/exceloutbutton/index.jsx index 7af9862..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 './index.scss' +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) { @@ -37,12 +63,31 @@ } componentDidMount () { - const { position } = this.props - - if (position === 'toolbar') { - MKEmitter.addListener('triggerBtnId', this.actionTrigger) - } + 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 () { @@ -72,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({ @@ -427,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, @@ -452,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 { @@ -477,7 +530,7 @@ let colwidth = [] let abses = [] - btn.verify.columns.forEach(col => { + columns.forEach(col => { if (_topRow[col.Column]) return _header.push(col.Column) @@ -525,7 +578,7 @@ this.execSuccess({ErrCode: 'S', ErrMesg: '瀵煎嚭鎴愬姛锛�'}) } } - } catch { + } catch (e) { this.execError({ErrCode: 'N', message: 'Excel鐢熸垚澶辫触锛�'}) } } @@ -610,10 +663,14 @@ param.exec_type = 'y' // 鍚庡彴瑙g爜 param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') param.secretkey = Utils.encrypt('', param.timestamp) - param.LText = Utils.formatOptions(param.LText) + param.LText = Utils.formatOptions(script) if (this.props.menuType === 'HS') { // 鍑芥暟 sPC_TableData_InUpDe 浜戠楠岃瘉 param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp) + } + + if (window.GLOB.probation) { + param.s_debug_type = 'Y' } Api.genericInterface(param).then((res) => { @@ -685,6 +742,9 @@ let userName = sessionStorage.getItem('User_Name') || '' let fullName = sessionStorage.getItem('Full_Name') || '' + let RoleID = sessionStorage.getItem('role_id') || '' + let departmentcode = sessionStorage.getItem('departmentcode') || '' + let organization = sessionStorage.getItem('organization') || '' let city = sessionStorage.getItem('city') || '' if (sessionStorage.getItem('isEditState') === 'true') { @@ -742,7 +802,7 @@ } if (param.custom_script) { - param.custom_script = `declare @ErrorCode nvarchar(50),@retmsg nvarchar(4000),@UserName nvarchar(50),@FullName nvarchar(50),@login_city nvarchar(50) select @ErrorCode='',@retmsg ='',@UserName='${userName}', @FullName='${fullName}', @login_city='${city}' + param.custom_script = `declare @ErrorCode nvarchar(50),@retmsg nvarchar(4000),@UserName nvarchar(50),@FullName nvarchar(50),@RoleID nvarchar(512),@mk_departmentcode nvarchar(50),@mk_organization nvarchar(50),@login_city nvarchar(50) select @ErrorCode='',@retmsg ='',@UserName='${userName}', @FullName='${fullName}', @RoleID='${RoleID}', @mk_departmentcode='${departmentcode}', @mk_organization='${organization}', @login_city='${city}' ${param.custom_script} ` regoptions.forEach(item => { @@ -765,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) } @@ -778,6 +838,10 @@ if (this.props.menuType === 'HS') { // 浜戠鏁版嵁楠岃瘉 param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp) + } + + if (setting.transaction === 'true') { + param.func = 'sPC_Get_TableData_try' } return param @@ -794,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'], @@ -812,8 +876,15 @@ loading: false }) - if (btn.execSuccess !== 'never') { - MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execSuccess, btn) + 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) { + let id = btn.switchTab[btn.switchTab.length - 1] + let node = document.getElementById('tab' + id) + node && node.click() } } @@ -851,20 +922,26 @@ loading: false }) - if (btn.execError !== 'never') { - MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execError, btn) + 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> @@ -877,7 +954,7 @@ label = btn.label icon = btn.icon || '' } else if (show === 'link') { - label = <span>{btn.label}{btn.icon ? <Icon 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' @@ -889,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