From d82fec9e2a4238ff1833e67c01bc9b34e525d904 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期五, 25 二月 2022 16:37:12 +0800 Subject: [PATCH] 2022-02-25 --- src/tabviews/zshare/actionList/normalbutton/index.jsx | 187 ++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 161 insertions(+), 26 deletions(-) diff --git a/src/tabviews/zshare/actionList/normalbutton/index.jsx b/src/tabviews/zshare/actionList/normalbutton/index.jsx index ba6f77f..55ca27b 100644 --- a/src/tabviews/zshare/actionList/normalbutton/index.jsx +++ b/src/tabviews/zshare/actionList/normalbutton/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, Drawer } from 'antd' +import { Button, Modal, notification, message, Drawer, Switch, Checkbox } from 'antd' import Api from '@/api' import Utils, { getSysDefaultSql } from '@/utils/utils.js' @@ -32,6 +32,8 @@ columns: PropTypes.any, // 瀛楁鍒� setting: PropTypes.any, // 椤甸潰閫氱敤璁剧疆 ContainerId: PropTypes.any, // tab椤甸潰ID锛岀敤浜庡脊绐楁帶鍒� + disabled: PropTypes.any, // 琛屾寜閽鐢� + lineId: PropTypes.any, // 琛岀储寮�+涓婚敭鍊硷紝鐢ㄤ簬琛屾寜閽弻鍑� } state = { @@ -46,13 +48,14 @@ disabled: false, hidden: false, checkParam: null, - autoMatic: false + autoMatic: false, + check: false } moduleParams = null UNSAFE_componentWillMount () { - const { btn, selectedData } = this.props + const { btn, selectedData, BData } = this.props let disabled = false if (btn.controlField && selectedData && selectedData.length > 0) { // 琛ㄦ牸涓寜閽殣钘忔帶鍒� @@ -62,7 +65,30 @@ 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}) + } + + if (btn.OpenType === 'form') { + let data = selectedData && selectedData[0] ? selectedData[0] : null + this.setState({check: data && data[btn.field] === btn.openVal}) + } else if (btn.OpenType === 'formSubmit') { + this.setState({ + selines: selectedData || [] + }) } } @@ -85,11 +111,10 @@ } 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] + '' @@ -98,7 +123,33 @@ } }) } - this.setState({disabled, hidden: disabled && btn.control === 'hidden'}) + this.setState({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}) + } + + if (btn.OpenType === 'form') { + let data = nextProps.selectedData && nextProps.selectedData[0] ? nextProps.selectedData[0] : null + this.setState({check: data && data[btn.field] === btn.openVal}) + } else if (btn.OpenType === 'formSubmit') { + this.setState({ + selines: nextProps.selectedData || [] + }) } } @@ -121,13 +172,39 @@ } actionSubmit = (res) => { - const { btn } = this.props + const { btn, setting, BID } = this.props + const { selines } = this.state if (btn.uuid !== res.menuId) return + let data = selines || [] + + if (setting.supModule && !BID) { + notification.warning({ + top: 92, + message: '闇�瑕佷笂绾т富閿�硷紒', + duration: 3 + }) + return + } else if (btn.Ot !== 'notRequired' && data.length === 0) { + notification.warning({ + top: 92, + message: '璇烽�夋嫨琛岋紒', + duration: 5 + }) + return + } else if (btn.Ot === 'requiredSgl' && data.length !== 1) { + notification.warning({ + top: 92, + message: '璇烽�夋嫨鍗曡鏁版嵁锛�', + duration: 5 + }) + return + } + this.setState({ loading: true }) - this.execSubmit(this.state.selines, () => {}, res.form) + this.execSubmit(data, () => {}, res.form) } resetModuleParam = (menuId, btnId, param) => { @@ -156,7 +233,13 @@ 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) { + 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({ @@ -251,12 +334,14 @@ }) if (btn.OpenType === 'formSubmit') { - MKEmitter.emit('mkFormSubmit', btn.uuid) + this.setState({}, () => { + MKEmitter.emit('mkFormSubmit', btn.uuid) + }) return } else if (btn.OpenType === 'prompt') { this.setState({loading: true}) confirm({ - title: this.state.dict['main.action.confirm.tip'], + title: btn.tipTitle || this.state.dict['main.action.confirm.tip'], onOk() { return new Promise(resolve => { _this.execSubmit(data, resolve) @@ -280,6 +365,31 @@ btnconfig: modal }, () => { this.improveAction() + }) + } else if (btn.OpenType === 'form') { + this.setState({ + loading: true, + check: !this.state.check + }, () => { + let type = 'text' + let fieldlen = 50 + let value = this.state.check ? btn.openVal : btn.closeVal + + if (typeof(value) === 'number') { + type = 'number' + fieldlen = 0 + } + + let item = { + type: type, + readonly: false, + readin: true, + writein: true, + fieldlen: fieldlen, + key: btn.field, + value: value + } + this.execSubmit(data, () => { this.setState({loading: false})}, [item]) }) } @@ -350,7 +460,7 @@ } param.LText = Utils.formatOptions(param.LText) - } else if (btn.OpenType === 'pop' || btn.OpenType === 'formSubmit') { // 琛ㄥ崟 + } else if (btn.OpenType === 'pop' || btn.OpenType === 'formSubmit' || btn.OpenType === 'form') { // 琛ㄥ崟 if (btn.sqlType === 'insert') { // 绯荤粺鍑芥暟娣诲姞鏃讹紝鐢熸垚uuid primaryId = '' @@ -598,7 +708,7 @@ param[setting.primaryKey] = primaryId // 璁剧疆涓婚敭鍙傛暟 } - if (btn.OpenType === 'pop' || btn.OpenType === 'formSubmit') { // 琛ㄥ崟 + if (btn.OpenType === 'pop' || btn.OpenType === 'formSubmit' || btn.OpenType === 'form') { // 琛ㄥ崟 formdata.forEach(_data => { param[_data.key] = _data.value }) @@ -773,7 +883,7 @@ param.BID = this.props.BID } - if ((btn.OpenType === 'pop' || btn.OpenType === 'formSubmit') && formdata) { // 琛ㄥ崟 + if ((btn.OpenType === 'pop' || btn.OpenType === 'formSubmit' || btn.OpenType === 'form') && formdata) { // 琛ㄥ崟 formdata.forEach(_data => { param[_data.key] = _data.value }) @@ -911,6 +1021,12 @@ _resolve() }) } + // xml璋冪敤鏂瑰紡 + // Api.directRequest('http://localhost:3001/test.xml', 'get', null, 'true').then(res => { + // let $x2js = new x2js() + // let jsonObj = $x2js.xml2js(res); + // console.info(jsonObj) + // }) /** * @description 鑷畾涔夎姹傚惊鐜墽琛� @@ -1375,7 +1491,7 @@ const { btn } = this.props const { btnconfig, 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'], @@ -1411,6 +1527,15 @@ if (btn.output) { id = res.mk_b_id || res[btn.output] || '' } + let tabId = '' + if (btn.refreshTab && btn.refreshTab.length > 0) { + tabId = btn.refreshTab[btn.refreshTab.length - 1] + } + + if (tabId && btn.$MenuID === tabId) { // 鍒锋柊褰撳墠鑿滃崟鏃讹紝鍋滄鍏朵粬鎿嶄綔 + MKEmitter.emit('reloadMenuView', tabId, 'table') + return + } if (btn.execSuccess === 'closetab') { MKEmitter.emit('closeTabView', btn.$MenuID) @@ -1420,9 +1545,10 @@ MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execSuccess, btn, id, this.state.selines) } - if (btn.refreshTab && btn.refreshTab.length > 0) { - MKEmitter.emit('reloadMenuView', btn.refreshTab[btn.refreshTab.length - 1], 'table') + if (tabId) { + MKEmitter.emit('reloadMenuView', tabId, 'table') } + if (btn.switchTab && btn.switchTab.length > 0) { let id = btn.switchTab[btn.switchTab.length - 1] let node = document.getElementById('tab' + id) @@ -1652,6 +1778,9 @@ MKEmitter.emit('popclose') } else if (btn.execError !== 'never') { MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execError, btn, '', this.state.selines) + } else if (btn.OpenType === 'form') { + let data = this.props.selectedData && this.props.selectedData[0] ? this.props.selectedData[0] : null + this.setState({check: data && data[btn.field] === btn.openVal}) } } @@ -1778,7 +1907,7 @@ } modelconfirm = () => { - const { BData } = this.props + const { BData, btn } = this.props const { btnconfig, selines } = this.state let _this = this @@ -1854,7 +1983,7 @@ this.execSubmit(selines, () => {}, result) } else { confirm({ - title: this.state.dict['main.action.confirm.tip'], + title: btn.tipTitle || this.state.dict['main.action.confirm.tip'], onOk() { return new Promise(resolve => { _this.execSubmit(selines, resolve, result) @@ -1877,14 +2006,14 @@ if (!btnconfig || !btnconfig.setting) return null let title = btnconfig.setting.title - let width = btnconfig.setting.width + 'vw' + let width = btnconfig.setting.width > 100 ? btnconfig.setting.width : btnconfig.setting.width + 'vw' let clickouter = btnconfig.setting.clickouter === 'close' if (btnconfig.setting.display === 'drawer') { let height = '100vh' if (btnconfig.setting.placement === 'top' || btnconfig.setting.placement === 'bottom') { width = '100vw' - height = btnconfig.setting.width + 'vh' + height = btnconfig.setting.width > 100 ? btnconfig.setting.width : btnconfig.setting.width + 'vh' } return ( <Drawer @@ -1925,7 +2054,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) } return ( @@ -1958,11 +2087,17 @@ render() { const { btn, show, style } = this.props - const { loadingNumber, loading, disabled, hidden } = this.state + const { loadingNumber, loading, disabled, hidden, check } = this.state if (hidden) return null - if (show === 'actionList') { + if (btn.OpenType === 'form') { + if (btn.formType === 'switch') { + return <Switch loading={loading} checked={check} disabled={disabled || loading} onChange={(val,e) => {e.stopPropagation();this.actionTrigger()}} style={style} size={btn.size} checkedChildren={btn.openText || ''} unCheckedChildren={btn.closeText || ''}/> + } else { + return <Checkbox disabled={disabled || loading} checked={check} onChange={(e) => {e.stopPropagation();this.actionTrigger()}} style={style}></Checkbox> + } + } else if (show === 'actionList') { return <div style={{display: 'inline-block'}} onClick={(e) => e.stopPropagation()}> <Button style={style} -- Gitblit v1.8.0