From 46f79b491173d284a4900d19e7aecf7509481438 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期五, 21 一月 2022 17:21:25 +0800 Subject: [PATCH] 2022-01-21 --- src/tabviews/zshare/actionList/normalbutton/index.jsx | 157 +++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 124 insertions(+), 33 deletions(-) diff --git a/src/tabviews/zshare/actionList/normalbutton/index.jsx b/src/tabviews/zshare/actionList/normalbutton/index.jsx index 7278fd3..4b71efb 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, Icon } from 'antd' +import { Button, Modal, notification, message, Drawer, Switch, Checkbox } from 'antd' import Api from '@/api' import Utils, { getSysDefaultSql } from '@/utils/utils.js' @@ -13,6 +13,7 @@ import asyncSpinComponent from '@/utils/asyncSpinComponent' import { updateForm } from '@/utils/utils-update.js' import MKEmitter from '@/utils/events.js' +import MkIcon from '@/components/mk-icon' // import './index.scss' const MutilForm = asyncSpinComponent(() => import('@/tabviews/zshare/mutilform')) @@ -31,6 +32,8 @@ columns: PropTypes.any, // 瀛楁鍒� setting: PropTypes.any, // 椤甸潰閫氱敤璁剧疆 ContainerId: PropTypes.any, // tab椤甸潰ID锛岀敤浜庡脊绐楁帶鍒� + disabled: PropTypes.any, // 琛屾寜閽鐢� + lineId: PropTypes.any, // 琛岀储寮�+涓婚敭鍊硷紝鐢ㄤ簬琛屾寜閽弻鍑� } state = { @@ -45,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) { // 琛ㄦ牸涓寜閽殣钘忔帶鍒� @@ -61,7 +65,26 @@ 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}) } } @@ -84,11 +107,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] + '' @@ -97,7 +119,29 @@ } }) } - 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}) } } @@ -155,7 +199,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({ @@ -280,6 +330,31 @@ }, () => { 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]) + }) } if (window.GLOB.systemType === 'production') { @@ -349,7 +424,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 = '' @@ -597,7 +672,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 }) @@ -772,7 +847,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 }) @@ -1413,6 +1488,8 @@ if (btn.execSuccess === 'closetab') { MKEmitter.emit('closeTabView', btn.$MenuID) + } else if (btn.execSuccess === 'closepoptab') { + MKEmitter.emit('popclose') } else if (btn.execSuccess !== 'never') { MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execSuccess, btn, id, this.state.selines) } @@ -1645,8 +1722,13 @@ MKEmitter.emit('mkFC', 'focus', btnconfig.setting.errFocus) } - if (btn.execError !== 'never') { + if (btn.execError === 'closepoptab') { + 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}) } } @@ -1692,7 +1774,7 @@ const { btnconfig, autoMatic } = this.state if (btnconfig) { - if (!autoMatic && btnconfig.setting.display === 'prompt') { // 濡傛灉琛ㄥ崟浠ユ槸鍚︽灞曠ず + if (!autoMatic && (btnconfig.setting.display === 'prompt' || btnconfig.setting.display === 'exec')) { // 濡傛灉琛ㄥ崟浠ユ槸鍚︽灞曠ず this.modelconfirm() } else { this.setState({ @@ -1736,7 +1818,7 @@ this.setState({ btnconfig: _LongParam }, () => { - if (!autoMatic && _LongParam.setting.display === 'prompt') { // 濡傛灉琛ㄥ崟浠ユ槸鍚︽灞曠ず + if (!autoMatic && (_LongParam.setting.display === 'prompt' || _LongParam.setting.display === 'exec')) { // 濡傛灉琛ㄥ崟浠ユ槸鍚︽灞曠ず this.modelconfirm() } else { this.setState({ @@ -1845,17 +1927,21 @@ }) }) - confirm({ - title: this.state.dict['main.action.confirm.tip'], - onOk() { - return new Promise(resolve => { - _this.execSubmit(selines, resolve, result) - }) - }, - onCancel() { - _this.setState({ loading: false }) - } - }) + if (btnconfig.setting.display === 'exec') { + this.execSubmit(selines, () => {}, result) + } else { + confirm({ + title: this.state.dict['main.action.confirm.tip'], + onOk() { + return new Promise(resolve => { + _this.execSubmit(selines, resolve, result) + }) + }, + onCancel() { + _this.setState({ loading: false }) + } + }) + } } /** @@ -1868,14 +1954,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 @@ -1916,7 +2002,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 ( @@ -1949,11 +2035,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} @@ -1984,11 +2076,10 @@ label = btn.label icon = btn.icon || '' } else if (show === 'link') { - label = <span>{btn.label}{btn.icon ? <Icon style={{marginLeft: '8px'}} 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 || '' - // } else if (show === 'text') { } else { label = btn.label } -- Gitblit v1.8.0