From 0c439ced2c97905cb2b02f5f689a37b19369fb8a Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期五, 22 七月 2022 15:00:58 +0800 Subject: [PATCH] 2022-07-22 --- src/tabviews/zshare/actionList/printbutton/index.jsx | 267 +++++++++++++++++++++++++++++++++------------------- 1 files changed, 168 insertions(+), 99 deletions(-) diff --git a/src/tabviews/zshare/actionList/printbutton/index.jsx b/src/tabviews/zshare/actionList/printbutton/index.jsx index 20c7891..5d6bb1f 100644 --- a/src/tabviews/zshare/actionList/printbutton/index.jsx +++ b/src/tabviews/zshare/actionList/printbutton/index.jsx @@ -1,7 +1,6 @@ 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' @@ -22,7 +21,6 @@ class PrintButton extends Component { static propTpyes = { - show: PropTypes.any, // 鎸夐挳鏄剧ず鏍峰紡鎺у埗 BID: PropTypes.string, // 涓昏〃ID BData: PropTypes.any, // 涓昏〃鏁版嵁 selectedData: PropTypes.any, // 瀛愯〃涓�夋嫨鏁版嵁 @@ -31,6 +29,7 @@ btn: PropTypes.object, // 鎸夐挳 setting: PropTypes.any, // 椤甸潰閫氱敤璁剧疆 ContainerId: PropTypes.any, // tab椤甸潰ID锛岀敤浜庡脊绐楁帶鍒� + disabled: PropTypes.any, // 琛屾寜閽鐢� } state = { @@ -42,22 +41,36 @@ loading: false, disabled: false, hidden: false, - loadingNumber: '', autoMatic: false } UNSAFE_componentWillMount () { - const { btn, selectedData } = this.props + const { btn, selectedData, BData } = this.props let disabled = false if (btn.controlField && selectedData && selectedData.length > 0) { // 琛ㄦ牸涓寜閽殣钘忔帶鍒� selectedData.forEach(item => { - let s = item[btn.controlField] + '' + 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'}) + 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}) } } @@ -76,20 +89,36 @@ } UNSAFE_componentWillReceiveProps (nextProps) { - const { btn, selectedData } = this.props + const { btn, selectedData, BData } = this.props + let disabled = false 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] + '' + 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}) } } @@ -116,7 +145,8 @@ const { Tab, BID, btn, selectedData, setting } = this.props const { loading, disabled } = this.state - if ((triggerId && btn.uuid !== triggerId) || loading || disabled) return + if (loading || disabled) return + if (triggerId && btn.uuid !== triggerId) return if (((Tab && Tab.supMenu) || setting.supModule) && !BID) { notification.warning({ @@ -125,10 +155,8 @@ duration: 5 }) return - } else if (type === 'linkbtn' && selectedData && selectedData.length === 1) { - if (record[0].$Index !== selectedData[0].$Index) { - return - } + } else if (type === 'linkbtn' && !btn.$toolbtn && !is(fromJS(selectedData || []), fromJS(record))) { + return } this.setState({autoMatic: type === 'autoMatic'}) @@ -211,38 +239,77 @@ triggerPrint = (data, formlist = []) => { const { btn } = this.props let formdata = {} + let baseCount = 1 + let baseType = '' + let baseTemp = btn.verify.Template || '' formlist.forEach(_data => { formdata[_data.key] = _data.value + + if (!_data.value) return + + if (_data.key.toLowerCase() === 'printcount') { + baseCount = +_data.value + } else if (_data.key.toLowerCase() === 'printtype') { + baseType = _data.value + } else if (_data.key.toLowerCase() === 'templateid') { + baseTemp = _data.value + } }) let printlist = [] let templates = [] - let printCount = +(formdata.printCount || formdata.PrintCount || formdata.printcount || formdata.Printcount || 1) - if (isNaN(printCount) || printCount < 1) { - printCount = 1 + if (isNaN(baseCount) || baseCount < 1) { + baseCount = 1 } new Promise(resolve => { if (btn.intertype === 'system') { // 浣跨敤绯荤粺鏃讹紝鐩存帴浠庤〃鏍兼垨琛ㄥ崟涓�夊彇鏁版嵁 - let printcell = {} - - printcell.printType = formdata.printType || formdata.PrintType || formdata.printtype || formdata.Printtype || '' - printcell.printCount = printCount - printcell.templateID = btn.verify.Template || '' - if (btn.Ot === 'notRequired') { + let printcell = {} + + printcell.printType = baseType + printcell.printCount = baseCount + printcell.templateID = baseTemp printcell.data = [formdata] + + templates.push(printcell.templateID) + + printlist.push(printcell) } else { - printcell.data = data.map(cell => { - return {...cell, ...formdata} + data.forEach(cell => { + let _cell = {...cell, ...formdata} + + let printcell = {data: [_cell]} + + printcell.templateID = baseTemp + printcell.printType = baseType + printcell.printCount = 0 + + Object.keys(_cell).forEach(key => { + if (!_cell[key]) return + + let _key = key.toLowerCase() + + if (_key === 'templateid') { + printcell.templateID = _cell[key] + } else if (_key === 'printtype') { + printcell.printType = _cell[key] + } else if (_key === 'printcount') { + printcell.printCount = +_cell[key] + } + }) + + if (isNaN(printcell.printCount) || printcell.printCount < 1) { + printcell.printCount = baseCount + } + + templates.push(printcell.templateID) + + printlist.push(printcell) }) } - - templates.push(printcell.templateID) - - printlist.push(printcell) resolve(true) } else { @@ -252,16 +319,31 @@ // 绯荤粺鎵撳嵃鏁版嵁锛屾牎楠宒ata瀛楁 if (btn.verify.printMode !== 'custom' && (!cell.data || cell.data.length === 0)) return - cell.templateID = cell.templateID || cell.TemplateID || cell.Templateid || cell.templateid || btn.verify.Template - cell.printType = cell.printType || cell.PrintType || cell.printtype || cell.Printtype || formdata.printType || formdata.PrintType || formdata.printtype || formdata.Printtype || '' + let templateID = baseTemp + let printType = baseType + let printCount = 0 - let _printCount = +(cell.printCount || cell.PrintCount || cell.printcount || cell.Printcount || 0) + Object.keys(cell).forEach(key => { + if (!cell[key]) return - if (isNaN(_printCount) || _printCount < 1) { - _printCount = printCount + let _key = key.toLowerCase() + + if (_key === 'templateid') { + templateID = cell[key] + } else if (_key === 'printtype') { + printType = cell[key] + } else if (_key === 'printcount') { + printCount = +cell[key] + } + }) + + cell.templateID = templateID + cell.printType = printType + cell.printCount = printCount + + if (isNaN(cell.printCount) || cell.printCount < 1) { + cell.printCount = baseCount } - - cell.printCount = _printCount templates.push(cell.templateID) @@ -733,7 +815,7 @@ // 澶栭儴璇锋眰 _outParam = JSON.parse(JSON.stringify(res)) - if (this.props.menuType === 'HS') { + if (window.GLOB.mkHS) { if (btn.sysInterface === 'true' && options.cloudServiceApi) { res.rduri = options.cloudServiceApi } else if (btn.sysInterface !== 'true') { @@ -848,7 +930,8 @@ if (!configParam) { error = '鎵撳嵃妯℃澘瑙f瀽閿欒锛�' } else { - let control = configParam.elements.map(element => { + let control = [] + configParam.elements.forEach(element => { let _field = element.field if (_field === 'other_field') { @@ -884,11 +967,12 @@ item.Trimming = '' if (!item.Width) { item.Width = item.BorderSize - item.Left = item.Left - item.Width + item.Left = item.Left - item.Width + 0.1 } else if (!item.Height) { item.Height = item.BorderSize - item.Top = item.Top - item.Height + item.Top = item.Top - item.Height + 0.1 } + item.BackColor = element.borderColor item.BorderSize = 0 } else if (item.Type === 'image') { item.ImageWidth = element.imgWidth @@ -928,7 +1012,7 @@ } } - return item + control.push(item) }) _configparam = { @@ -1230,7 +1314,7 @@ const { btn } = this.props const { autoMatic } = this.state - if ((res && res.ErrCode === 'S') || autoMatic) { // 鎵ц鎴愬姛 + if ((res && (res.ErrCode === 'S' || !res.ErrCode)) || autoMatic) { // 鎵ц鎴愬姛 notification.success({ top: 92, message: res.ErrMesg || this.state.dict['main.action.confirm.success'], @@ -1524,8 +1608,8 @@ if (!this.state.visible || !btnconfig || !btnconfig.setting) return null - let title = btnconfig.setting.title - let width = btnconfig.setting.width + 'vw' + let title = btn.label + let width = btnconfig.setting.width > 100 ? btnconfig.setting.width : btnconfig.setting.width + 'vw' let clickouter = false let container = document.body @@ -1533,7 +1617,7 @@ (setting.tabType === 'main' && btnconfig.setting.container === 'tab' && this.props.ContainerId) || (btnconfig.setting.container === 'tab' && btn.ContainerId) ) { - width = btnconfig.setting.width + '%' + width = btnconfig.setting.width > 100 ? btnconfig.setting.width : btnconfig.setting.width + '%' container = () => document.getElementById(this.props.ContainerId || btn.ContainerId) } @@ -1556,7 +1640,6 @@ <MutilForm BID={BID} dict={this.state.dict} - menuType={this.props.menuType} action={btnconfig} inputSubmit={this.handleOk} data={this.state.selines[0]} @@ -1568,63 +1651,49 @@ } render() { - const { btn, show } = this.props - const { loadingNumber, loading, disabled, hidden } = this.state + const { btn } = this.props + 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()}} - >{loadingNumber ? `(${loadingNumber})` : '' + btn.label}</Button> - {this.getModels()} - </div> - } else { // icon銆乼ext銆� all 鍗$墖 - let label = '' - let icon = '' + let label = '' + let icon = '' + let type = 'link' + let className = '' - if (show === 'button') { - label = btn.label - icon = btn.icon || '' - } else if (show === 'link') { - label = <span>{btn.label}{btn.icon ? <MkIcon style={{marginLeft: '8px'}} type={btn.icon}/> : ''}</span> - icon = '' - } else if (show === 'icon') { - icon = btn.icon || '' - // } 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} - disabled={disabled} - style={btn.style} - icon={icon} - onClick={() => {this.actionTrigger()}} - >{label}</Button> - {this.getModels()} - </div> + 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 || '' + } 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 || null} + icon={icon} + className={className} + onClick={(e) => {e.stopPropagation(); this.actionTrigger()}} + >{label}</Button> + {this.getModels()} + </> } } -const mapStateToProps = (state) => { - return { - menuType: state.editLevel - } -} - -const mapDispatchToProps = () => { - return {} -} - -export default connect(mapStateToProps, mapDispatchToProps)(PrintButton) \ No newline at end of file +export default PrintButton \ No newline at end of file -- Gitblit v1.8.0