From e659867fb59ad88f121d446e56df53389d88960d Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期一, 03 四月 2023 12:09:35 +0800 Subject: [PATCH] 2023-04-03 --- src/menu/components/share/pasteforms/index.jsx | 178 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 178 insertions(+), 0 deletions(-) diff --git a/src/menu/components/share/pasteforms/index.jsx b/src/menu/components/share/pasteforms/index.jsx new file mode 100644 index 0000000..6cf98a8 --- /dev/null +++ b/src/menu/components/share/pasteforms/index.jsx @@ -0,0 +1,178 @@ +import React, {Component} from 'react' +import PropTypes from 'prop-types' +import { fromJS } from 'immutable' +import { Modal, notification, Button } from 'antd' +import { SnippetsOutlined, QuestionCircleOutlined } from '@ant-design/icons' + +import Utils from '@/utils/utils.js' +import asyncComponent from '@/utils/asyncComponent' +import './index.scss' + +const PasteForm = asyncComponent(() => import('@/templates/zshare/pasteform')) + +class PasteForms extends Component { + static propTpyes = { + config: PropTypes.object, // 缁勪欢閰嶇疆 + update: PropTypes.func + } + + state = { + visible: false, + choVisible: false, + result: null + } + + pasteSubmit = () => { + const { config } = this.props + + this.pasteFormRef.handleConfirm().then(res => { + if (res.copyType === 'search' && ['text', 'select', 'multiselect', 'link', 'checkcard', 'date', 'datemonth'].includes(res.type)) { + res.copyType = 'form' + } + + if (!['form', 'forms', 'formgroup', 'simpleform'].includes(res.copyType)) { + notification.warning({ top: 92, message: '閰嶇疆淇℃伅鏍煎紡閿欒锛�', duration: 5 }) + return + } + + if (res.copyType === 'form') { + delete res.copyType + res = {fields: [res]} + } + + res.fields = res.fields || [] + res.fields = res.fields.map(item => { + item.uuid = Utils.getuuid() + return item + }) + + let fields = res.fields.map(item => item.field ? item.field.toLowerCase() : '') + + let repeat = false + let forms = [] + if (config.fields) { + forms = fromJS(config.fields).toJS() + forms.forEach(item => { + if (item.field && fields.includes(item.field.toLowerCase())) { + repeat = true + } + }) + } + + if (repeat) { + this.setState({result: res, choVisible: true, visible: false}) + return + } else { + forms.push(...res.fields) + } + + this.props.update(forms, res) + + this.setState({visible: false}) + + notification.success({ + top: 92, + message: '绮樿创鎴愬姛锛�', + duration: 2 + }) + }) + } + + replaceForms = () => { + const { config } = this.props + const { result } = this.state + + let forms = fromJS(config.fields).toJS() + let fields = fromJS(result.fields).toJS() + let repeats = [] + + forms = forms.map(item => { + if (!item.field) return item + + let cell = fields.filter(m => m.field && m.field.toLowerCase() === item.field.toLowerCase())[0] + if (cell) { + repeats.push(cell.field) + return cell + } + + return item + }) + + fields = fields.filter(m => !m.field || !repeats.includes(m.field)) + + forms.push(...fields) + + this.props.update(forms, result) + + this.setState({choVisible: false}) + } + + jumpForms = () => { + const { config } = this.props + const { result } = this.state + + let forms = fromJS(config.fields).toJS() + let fields = fromJS(result.fields).toJS() + let repeats = [] + + forms = forms.map(item => { + if (!item.field) return item + + let cell = fields.filter(m => m.field && m.field.toLowerCase() === item.field.toLowerCase())[0] + if (cell) { + repeats.push(cell.field) + } + + return item + }) + + fields = fields.filter(m => !m.field || !repeats.includes(m.field)) + + forms.push(...fields) + + this.props.update(forms, result) + + this.setState({choVisible: false}) + } + + render() { + const { type } = this.props + const { visible, choVisible } = this.state + + return ( + <div style={{display: 'inline-block'}}> + {type === 'toolbar' ? <Button icon="snippets" style={{color: 'purple'}} onClick={() => {this.setState({visible: true})}} >绮樿创</Button> : + <SnippetsOutlined style={{color: 'purple'}} onClick={() => {this.setState({visible: true})}} />} + <Modal + title="绮樿创" + visible={visible} + width={600} + maskClosable={false} + onOk={this.pasteSubmit} + onCancel={() => {this.setState({visible: false})}} + destroyOnClose + > + <PasteForm wrappedComponentRef={(inst) => this.pasteFormRef = inst} inputSubmit={this.pasteSubmit}/> + </Modal> + <Modal + title="" + visible={choVisible} + width={450} + closable={false} + maskClosable={false} + onCancel={() => {this.setState({choVisible: false, result: null})}} + footer={[ + <Button key="cancel" onClick={() => this.setState({choVisible: false, result: null})}>鍙栨秷</Button>, + <Button key="replace" className="mk-border-purple" style={{color: 'purple'}} onClick={this.replaceForms}>鏇挎崲</Button>, + <Button key="confirm" type="primary" onClick={this.jumpForms}>璺宠繃</Button> + ]} + destroyOnClose + > + <QuestionCircleOutlined style={{color: 'orange', fontSize: '24px', margin: '15px 10px', position: 'relative', top: '2px'}}/>瀛樺湪閲嶅琛ㄥ崟锛岃閫夋嫨澶勭悊鏂瑰紡銆� + </Modal> + </div> + ) + } +} + +export default PasteForms \ No newline at end of file -- Gitblit v1.8.0