From 1563e2ef18b013bb7bb5781a22e7d92f40454f69 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期一, 24 三月 2025 18:04:21 +0800 Subject: [PATCH] 2025-03-24 --- src/menu/components/card/doublecardcomponent/index.jsx | 226 +++++++++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 189 insertions(+), 37 deletions(-) diff --git a/src/menu/components/card/doublecardcomponent/index.jsx b/src/menu/components/card/doublecardcomponent/index.jsx index d79d883..ae09b62 100644 --- a/src/menu/components/card/doublecardcomponent/index.jsx +++ b/src/menu/components/card/doublecardcomponent/index.jsx @@ -1,8 +1,8 @@ import React, {Component} from 'react' import PropTypes from 'prop-types' import { is, fromJS } from 'immutable' -import { Popover, Col } from 'antd' -import { PlusOutlined, PlusSquareOutlined, EditOutlined, ToolOutlined, FontColorsOutlined } from '@ant-design/icons' +import { Popover, Col, Modal, Button } from 'antd' +import { UpOutlined, PlusOutlined, PlusSquareOutlined, EditOutlined, ToolOutlined, FontColorsOutlined } from '@ant-design/icons' import asyncComponent from '@/utils/asyncComponent' import asyncIconComponent from '@/utils/asyncIconComponent' @@ -11,6 +11,8 @@ import Utils from '@/utils/utils.js' import MKEmitter from '@/utils/events.js' import './index.scss' + +const { confirm } = Modal const NormalForm = asyncIconComponent(() => import('@/components/normalform')) const CardCellComponent = asyncComponent(() => import('@/menu/components/card/cardcellcomponent')) @@ -28,6 +30,7 @@ card: null, // 鍗$墖淇℃伅锛屽寘鎷鍙嶉潰 appType: sessionStorage.getItem('appType'), visible: false, + timestamp: '', side: '' } @@ -38,7 +41,8 @@ const { card } = this.props this.setState({ - card: fromJS(card).toJS() + card: fromJS(card).toJS(), + timestamp: new Date().getTime() + '' }) } @@ -122,11 +126,12 @@ const { card } = this.state let _style = null - let options = ['height', 'background', 'border', 'padding', 'margin', 'shadow'] + let options = ['height', 'background', 'border', 'padding', 'margin', 'shadow', 'overflow'] if (type === 'sub') { _style = fromJS(card.backStyle).toJS() } else { + options.push('clear') _style = fromJS(card.style).toJS() } @@ -136,6 +141,7 @@ } getSettingForms = () => { + const { cards } = this.props const { card } = this.state let buttons = [] @@ -148,10 +154,11 @@ } }) - return getSettingForm(card.setting, buttons) + return getSettingForm(card.setting, buttons, cards.columns, 'main') } getBackSettingForms = () => { + const { cards } = this.props const { card } = this.state let buttons = [] @@ -164,7 +171,7 @@ } }) - return getSettingForm(card.backSetting, buttons) + return getSettingForm(card.backSetting, buttons, cards.subColumns) } updateSetting = (res, type) => { @@ -205,8 +212,128 @@ this.props.updateElement(_card) } + updateFields = (elements, resolve, position, type) => { + const { card } = this.state + + let items = elements + + if (type === 'form') { + items = [] + + elements.forEach(item => { + let cell = { + uuid: Utils.getuuid(), + eleType: 'text', + height: 1, + innerHeight: 21, + prefix: item.label ? item.label + ': ' : '', + datatype: item.field ? 'dynamic' : 'static', + field: item.field || '', + width: item.span || 12, + value: '', + style: {marginBottom: '15px', color: 'rgba(0, 0, 0, 0.85)'} + } + + if (item.type === 'number') { + cell.eleType = 'number' + cell.decimal = typeof(item.decimal) === 'number' ? item.decimal : '' + } else if (item.type === 'split') { + cell.width = 24 + cell.prefix = '' + cell.value = item.label || '' + cell.style = { + color: '#1890ff', + marginBottom: '15px', + borderBottomWidth: '1px', + borderBottomColor: '#e9e9e9' + } + } + + items.push(cell) + }) + } + + if (items.length === 0) { + resolve({status: false, message: '鍏冪礌涓嶅彲涓虹┖锛�'}) + return + } + + let _card = { ...card } + let _card2 = { ...card } + let pass = false + + if (position === 'sub') { + if (_card.backElements.length === 0) { + _card.backElements = items + pass = true + } else { + _card.backElements = items + _card2.backElements = [...card.backElements, ...items] + } + } else { + if (_card.elements.length === 0) { + _card.elements = items + pass = true + } else { + _card.elements = items + _card2.elements = [...card.elements, ...items] + } + } + + if (pass) { + this.setState({ + card: _card, + timestamp: new Date().getTime() + '' + }) + + this.props.updateElement(_card) + } else { + const that = this + const _modal = confirm({ + title: '鍗$墖涓凡瀛樺湪鍏冪礌锛岃閫夋嫨瑕佽繘琛岀殑鎿嶄綔銆�', + className: 'mk-confirm-modal', + content: <div className="footer"> + <Button key="cancel" onClick={() => _modal.destroy()}>鍙栨秷</Button> + <Button key="replace" className="mk-border-purple" onClick={() => { + that.setState({ + card: _card, + timestamp: new Date().getTime() + '' + }) + + that.props.updateElement(_card) + _modal.destroy() + }}>鏇挎崲</Button> + <Button key="confirm" className="mk-border-green" onClick={() => { + that.setState({ + card: _card2, + timestamp: new Date().getTime() + '' + }) + + that.props.updateElement(_card2) + _modal.destroy() + }}>娣诲姞</Button> + </div> + }) + } + + resolve({status: true}) + } + paste = (element, resolve, type) => { const { card } = this.state + + if (['simpleform', 'forms', 'formgroup', 'cardcell'].includes(element.copyType)) { + if (element.copyType === 'simpleform') { + this.updateFields(element.subcards[0].fields, resolve, type, 'form') + } else if (element.copyType === 'forms') { + this.updateFields(element.fields, resolve, type, 'form') + } else if (element.copyType === 'formgroup') { + this.updateFields(element.fields, resolve, type, 'form') + } else { + this.updateFields(element.elements, resolve, type) + } + return + } let _uuid = Utils.getuuid() @@ -235,24 +362,47 @@ render() { const { cards } = this.props - const { card } = this.state + const { card, timestamp } = this.state let _style = {...card.style} let _backStyle = {...card.backStyle} - - _backStyle.marginLeft = _style.marginLeft - _backStyle.marginRight = _style.marginRight - _backStyle.marginBottom = _style.marginBottom - - delete _style.marginBottom + let _wrapStyle = {} _style = resetStyle(_style) _backStyle = resetStyle(_backStyle) + if (card.setting.position === 'inner') { + Object.keys(_style).forEach(key => { + if (!/^(margin|border|box)/.test(key)) return + _wrapStyle[key] = _style[key] + delete _style[key] + }) + } + + let checkAll = '' + let mainBox = '' + if (cards.wrap.selStyle === 'check') { + checkAll = 'mk-checkable' + } else if (cards.wrap.selStyle === 'check square') { + checkAll = 'mk-checkable square' + } else if (card.setting.display !== 'default' && card.setting.controlIcon === 'left') { + mainBox = 'flex-card ' + } + + let _style_ = null + + if (card.style.clear === 'left') { + _style_ = {clear: 'left'} + } else if (card.style.clear === 'right') { + _style_ = {float: 'right'} + } + return ( - <Col span={card.setting.width || 24}> - <div className="card-item-wrap"> - <div className={'card-item ' + (card.setting.btnControl || '')} style={_style} onDoubleClick={(e) => {e.stopPropagation(); this.doubleClickCard()}} id={card.uuid}> + <Col span={card.setting.width || 24} style={_style_}> + <div className="card-item-wrap" style={_wrapStyle}> + <div className={`card-item ${card.setting.btnControl || ''} ${checkAll} mk-${card.setting.display} ${mainBox}`} style={_style} onDoubleClick={(e) => {e.stopPropagation(); this.doubleClickCard()}} id={card.uuid}> + <span className="circle-select"></span> + {card.setting.controlIcon === 'left' ? <PlusSquareOutlined /> : <UpOutlined />} <div className="card-control" onDoubleClick={(e) => e.stopPropagation()}> <Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={ <div className="mk-popover-control"> @@ -261,35 +411,37 @@ <NormalForm title={'寰幆鍗$墖璁剧疆'} width={950} update={(res) => this.updateSetting(res)} getForms={this.getSettingForms}> <EditOutlined className="edit" title="缂栬緫"/> </NormalForm> - <CopyComponent type="cardcell" card={card}/> - <PasteController options={['action', 'customCardElement']} updateConfig={(element, resolve) => this.paste(element, resolve, 'main')} /> + <CopyComponent type="cardcell" card={{...card, backElements: []}}/> + <PasteController options={['action', 'customCardElement', 'simpleform', 'forms', 'formgroup', 'cardcell']} updateConfig={(element, resolve) => this.paste(element, resolve, 'main')} /> <FontColorsOutlined className="style" title="璋冩暣鏍峰紡" onClick={() => this.changeStyle()} /> </div> } trigger="hover"> <ToolOutlined /> </Popover> </div> - <CardCellComponent cards={cards} cardCell={card} side="main" elements={card.elements} updateElement={(elements, btn) => this.updateCard(elements, btn)}/> + <CardCellComponent cards={cards} cardCell={card} side="main" timestamp={timestamp} elements={card.elements} updateElement={(elements, btn) => this.updateCard(elements, btn)}/> </div> - <div className={'card-item ' + (card.backSetting.btnControl || '')} style={_backStyle} onDoubleClick={(e) => {e.stopPropagation(); this.doubleClickCard('sub')}} id={card.uuid}> - <div className="card-control" onDoubleClick={(e) => e.stopPropagation()}> - <Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={ - <div className="mk-popover-control"> - <PlusOutlined className="plus" title="娣诲姞鍏冪礌" onClick={() => this.addElement('sub')} /> - <PlusSquareOutlined className="plus" title="娣诲姞鎸夐挳" onClick={() => this.addButton('sub')} /> - <NormalForm title={'寰幆瀛愬崱鐗囪缃�'} width={950} update={(res) => this.updateSetting(res, 'sub')} getForms={this.getBackSettingForms}> - <EditOutlined className="edit" title="缂栬緫"/> - </NormalForm> - <CopyComponent type="cardcell" card={card}/> - <PasteController options={['action', 'customCardElement']} updateConfig={(element, resolve) => this.paste(element, resolve, 'sub')} /> - <FontColorsOutlined className="style" title="璋冩暣鏍峰紡" onClick={() => this.changeStyle('sub')} /> - </div> - } trigger="hover"> - <ToolOutlined /> - </Popover> + <Col span={card.backSetting.width || 24}> + <div className={'card-item ' + (card.backSetting.btnControl || '')} style={_backStyle} onDoubleClick={(e) => {e.stopPropagation(); this.doubleClickCard('sub')}} id={card.uuid}> + <div className="card-control" onDoubleClick={(e) => e.stopPropagation()}> + <Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={ + <div className="mk-popover-control"> + <PlusOutlined className="plus" title="娣诲姞鍏冪礌" onClick={() => this.addElement('sub')} /> + <PlusSquareOutlined className="plus" title="娣诲姞鎸夐挳" onClick={() => this.addButton('sub')} /> + <NormalForm title={'寰幆瀛愬崱鐗囪缃�'} width={950} update={(res) => this.updateSetting(res, 'sub')} getForms={this.getBackSettingForms}> + <EditOutlined className="edit" title="缂栬緫"/> + </NormalForm> + <CopyComponent type="cardcell" card={{...card, elements: card.backElements, backElements: []}}/> + <PasteController options={['action', 'customCardElement', 'simpleform', 'forms', 'formgroup', 'cardcell']} updateConfig={(element, resolve) => this.paste(element, resolve, 'sub')} /> + <FontColorsOutlined className="style" title="璋冩暣鏍峰紡" onClick={() => this.changeStyle('sub')} /> + </div> + } trigger="hover"> + <ToolOutlined /> + </Popover> + </div> + <CardCellComponent cards={cards} cardCell={card} side="sub" timestamp={timestamp} elements={card.backElements} updateElement={(elements, btn) => this.updateCard(elements, btn, 'sub')}/> </div> - <CardCellComponent cards={cards} cardCell={card} side="sub" elements={card.backElements} updateElement={(elements, btn) => this.updateCard(elements, btn, 'sub')}/> - </div> + </Col> </div> </Col> ) -- Gitblit v1.8.0