From 0c84df247914f893ef5e41d57a422e10a2dc814c Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期五, 12 十一月 2021 17:02:06 +0800 Subject: [PATCH] 2021-11-12 --- src/templates/modalconfig/dragelement/card.jsx | 176 ++++++++++++++++++++++++++++++++++++---------------------- 1 files changed, 109 insertions(+), 67 deletions(-) diff --git a/src/templates/modalconfig/dragelement/card.jsx b/src/templates/modalconfig/dragelement/card.jsx index d1fda91..0b25add 100644 --- a/src/templates/modalconfig/dragelement/card.jsx +++ b/src/templates/modalconfig/dragelement/card.jsx @@ -1,36 +1,40 @@ import React from 'react' import { useDrag, useDrop } from 'react-dnd' -import { Icon, Select, DatePicker, Input, InputNumber, Button } from 'antd' +import { Select, DatePicker, Input, InputNumber, Button, Popover, Switch, Radio, Checkbox, Form } from 'antd' +import { QuestionCircleOutlined, UploadOutlined, EditOutlined, CopyOutlined, CloseOutlined } from '@ant-design/icons' import moment from 'moment' -import ItemTypes from './itemtypes' + +import asyncComponent from '@/utils/asyncComponent' import './index.scss' const { MonthPicker } = DatePicker const { TextArea } = Input -const Card = ({ id, card, cols, moveCard, findCard, editCard, closeCard, hasDrop }) => { +const Editor = asyncComponent(() => import('@/components/editor')) +const ColorSketch = asyncComponent(() => import('@/mob/colorsketch')) +const CheckCard = asyncComponent(() => import('../checkCard')) + +const Card = ({ id, card, moveCard, findCard, editCard, closeCard, copyCard, showField }) => { const originalIndex = findCard(id).index const [{ isDragging }, drag] = useDrag({ - item: { type: ItemTypes.form, id, originalIndex }, + item: { type: 'form', id, originalIndex }, collect: monitor => ({ isDragging: monitor.isDragging(), }), }) const [, drop] = useDrop({ - accept: ItemTypes.form, + accept: 'form', canDrop: () => true, drop: (item) => { - if (!item.hasOwnProperty('originalIndex')) { - hasDrop(card) - } - }, - hover({ id: draggedId }) { - if (!draggedId) return - if (draggedId !== id) { + const { id: draggedId, originalIndex } = item + + if (originalIndex === undefined) { + item.dropTargetId = id + } else if (draggedId && draggedId !== id) { const { index: overIndex } = findCard(id) moveCard(draggedId, overIndex) } - }, + } }) const opacity = isDragging ? 0 : 1 @@ -40,6 +44,10 @@ const close = () => { closeCard(id) + } + + const copy = () => { + copyCard(id) } let selectval = '' @@ -52,65 +60,99 @@ selectval = '' } } else if (card.setAll === 'true') { - selectval = '鍏ㄩ儴' - } - } - let labelCol = 'ant-col-sm-8' - let wrapCol = 'ant-col-sm-16' - if (card.type === 'textarea') { - if (cols === '2') { - labelCol = 'ant-col-sm-4' - wrapCol = 'ant-col-sm-20' - } else if (cols === '3') { - labelCol = 'ant-col-cuslabel' - wrapCol = 'ant-col-cuswrap' + selectval = card.emptyText || '绌�' } } + let formItem = null + let className = 'ant-form-item' + if (card.type === 'text') { + formItem = (<Input style={{marginTop: '4px'}} placeholder={card.placeholder || ''} value={card.initval} />) + } else if (card.type === 'number') { + formItem = (<InputNumber value={card.initval} precision={card.decimal} />) + } else if (card.type === 'multiselect' || card.type === 'select' || card.type === 'link') { + formItem = (<Select value={selectval}></Select>) + } else if (card.type === 'color') { + formItem = (<ColorSketch value={card.initval || 'transparent'}/>) + } else if (card.type === 'date') { + formItem = (<DatePicker value={card.initval ? moment().subtract(card.initval, 'days') : null} />) + } else if (card.type === 'datemonth') { + formItem = (<MonthPicker value={card.initval ? moment().subtract(card.initval, 'month') : null} />) + } else if (card.type === 'datetime') { + formItem = (<DatePicker showTime value={card.initval ? moment().subtract(card.initval, 'days') : null} />) + } else if (card.type === 'textarea') { + formItem = (<TextArea value={card.initval} placeholder={card.placeholder || ''} autoSize={{ minRows: 2, maxRows: 6 }} />) + } else if (card.type === 'brafteditor') { + formItem = (<Editor />) + } else if (card.type === 'fileupload') { + formItem = (<Button style={{marginTop: '3px'}}><UploadOutlined /> 鐐瑰嚮涓婁紶 </Button>) + } else if (card.type === 'funcvar') { + formItem = (<Input style={{marginTop: '4px'}} value={card.linkfield} />) + } else if (card.type === 'linkMain') { + formItem = (<Input style={{marginTop: '4px'}} />) + } else if (card.type === 'switch') { + formItem = (<Switch checkedChildren={card.openText || ''} unCheckedChildren={card.closeText || ''} style={{marginTop: '8px'}} checked={card.initval}/>) + } else if (card.type === 'radio') { + formItem = card.options && card.options.length > 0 ? (<Radio.Group value={card.initval}> + {card.options.map(cell => <Radio key={cell.key} value={cell.Value}>{cell.Text}</Radio>)} + </Radio.Group>) : (<Radio.Group value={1}> + <Radio value={1}>A</Radio> + <Radio value={2}>B</Radio> + <Radio value={3}>C</Radio> + <Radio value={4}>D</Radio> + </Radio.Group>) + } else if (card.type === 'checkbox') { + let _val = card.initval ? card.initval.split(',') : [] + formItem = card.options && card.options.length > 0 ? (<Checkbox.Group value={_val}> + {card.options.map(cell => <Checkbox key={cell.key} value={cell.Value}>{cell.Text}</Checkbox>)} + </Checkbox.Group>) : (<Checkbox.Group value={['A', 'C']}> + <Checkbox value="A">A</Checkbox> + <Checkbox value="B">B</Checkbox> + <Checkbox value="C">C</Checkbox> + <Checkbox value="D">D</Checkbox> + </Checkbox.Group>) + } else if (card.type === 'hint') { + formItem = <div style={{marginTop: '10px', color: 'rgba(0, 0, 0, 0.85)', lineHeight: '1.5'}}>{card.message}</div> + } else if (card.type === 'split') { + formItem = <div className="split-line">{card.label}</div> + } else if (card.type === 'checkcard') { + className += ' checkcard' + formItem = <CheckCard config={card} /> + } + + let _label = card.label + if (card.tooltip) { + _label = <span><QuestionCircleOutlined className="mk-form-tip" />{card.label}</span> + } + if (card.type === 'brafteditor' && card.hidelabel === 'true') { + _label = null + } + return ( - <div className="page-card" style={{ opacity: opacity}}> - <div ref={node => drag(drop(node))}> - {<div className="ant-row ant-form-item"> - <div className={'ant-col ant-form-item-label ant-col-xs-24 ' + labelCol}> - <label title={card.label}>{card.label}</label> - </div> - <div className={'ant-col ant-form-item-control-wrapper ant-col-xs-24 ' + wrapCol}> - {card.type === 'text' && - <Input style={{marginTop: '4px'}} defaultValue={card.initval} /> - } - {card.type === 'number' && - <InputNumber defaultValue={card.initval} precision={card.decimal} /> - } - {(card.type === 'multiselect' || card.type === 'select' || card.type === 'link') && - <Select defaultValue={selectval}></Select> - } - {card.type === 'date' && - <DatePicker defaultValue={card.initval ? moment().subtract(card.initval, 'days') : null} /> - } - {card.type === 'datemonth' ? - <MonthPicker defaultValue={card.initval ? moment().subtract(card.initval, 'month') : null} /> : null - } - {card.type === 'datetime' && - <DatePicker showTime defaultValue={card.initval ? moment().subtract(card.initval, 'days') : null} /> - } - {card.type === 'textarea' && - <TextArea autosize={{ minRows: 2, maxRows: 6 }} /> - } - {card.type === 'fileupload' && - <Button> - <Icon type="upload" /> 鐐瑰嚮涓婁紶 - </Button> - } - {card.type === 'funcvar' && - <Input style={{marginTop: '4px'}} defaultValue={card.linkfield} /> - } - <div className="input-mask"></div> - </div> - </div>} + <Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={ + <div className="mk-popover-control"> + <EditOutlined className="edit" onClick={edit} /> + <CopyOutlined className="copy" onClick={copy} /> + <CloseOutlined className="close" onClick={close} /> </div> - <Icon className="edit" type="edit" onClick={edit} /> - <Icon className="edit close" type="close" onClick={close} /> - </div> + } trigger="hover"> + <div className="page-card" style={{ opacity: opacity}}> + <div ref={node => drag(drop(node))} onDoubleClick={edit}> + {card.type === 'split' ? formItem : <Form.Item + className={className} + colon={!!_label} + label={_label} + required={card.required === 'true'} + extra={card.extra || null} + labelCol={card.labelwidth ? {style: {width: card.labelwidth + '%'}} : null} + wrapperCol={card.labelwidth ? {style: {width: (100 - card.labelwidth) + '%'}} : null} + > + {formItem} + {showField ? <div className="field-name">{card.field}{card.hidden === 'true' ? '(闅愯棌)' : ''}</div> : ''} + </Form.Item>} + </div> + </div> + </Popover> ) } export default Card -- Gitblit v1.8.0