| | |
| | | import React from 'react' |
| | | import { useDrag, useDrop } from 'react-dnd' |
| | | import { Select, DatePicker, Input, Popover, Form } from 'antd' |
| | | import { Select, DatePicker, Input, Popover, Form, Switch, Checkbox } from 'antd' |
| | | import { EditOutlined, CopyOutlined, CloseOutlined } from '@ant-design/icons' |
| | | import moment from 'moment' |
| | | |
| | |
| | | const [, drop] = useDrop({ |
| | | accept: 'search', |
| | | canDrop: () => true, |
| | | drop: ({ id: draggedId }) => { |
| | | if (!draggedId || draggedId === id) return |
| | | |
| | | const { index: originIndex } = findCard(draggedId) |
| | | if (originIndex === -1) return |
| | | |
| | | const { index: overIndex } = findCard(id) |
| | | moveCard(draggedId, overIndex) |
| | | drop: (item) => { |
| | | const { id: draggedId, originalIndex } = item |
| | | |
| | | if (originalIndex === undefined) { |
| | | item.dropTargetId = id |
| | | } else { |
| | | if (!draggedId || draggedId === id) return |
| | | |
| | | const { index: originIndex } = findCard(draggedId) |
| | | if (originIndex === -1) return |
| | | |
| | | const { index: overIndex } = findCard(id) |
| | | moveCard(draggedId, overIndex) |
| | | } |
| | | } |
| | | }) |
| | | const opacity = isDragging ? 0 : 1 |
| | | const opacity = isDragging ? 0.5 : 1 |
| | | |
| | | let _defaultValue = '' // 下拉搜索、时间范围类型,初始值需要预处理 |
| | | |
| | |
| | | _defaultValue = [moment().startOf('week'), moment().endOf('week')] |
| | | } else if (card.initval === 'month') { |
| | | _defaultValue = [moment().startOf('month'), moment().endOf('month')] |
| | | } else if (card.initval === 'lastMonth') { |
| | | _defaultValue = [moment().subtract(1, 'months').startOf('month'), moment().subtract(1, 'months').endOf('month')] |
| | | } else if (card.initval) { |
| | | try { |
| | | let _initval = JSON.parse(card.initval) |
| | |
| | | } |
| | | |
| | | let formItem = null |
| | | let type = '' |
| | | if (card.type === 'text') { |
| | | if (card.inputType !== 'search') { |
| | | formItem = <Input placeholder={card.label} value={card.initval} /> |
| | |
| | | /> |
| | | } else if (card.type === 'group') { |
| | | formItem = <DateGroup card={card} /> |
| | | } else if (card.type === 'switch') { |
| | | formItem = (<Switch checkedChildren={card.openText || ''} unCheckedChildren={card.closeText || ''} style={{marginTop: '8px'}} checked={card.initval === card.openVal}/>) |
| | | } else if (card.type === 'check') { |
| | | formItem = <Checkbox style={{lineHeight: '36px'}} checked={card.initval === card.openVal}>{card.checkTip || ''}</Checkbox> |
| | | } else if (card.type === 'range') { |
| | | type = 'range-wrap' |
| | | let vals = card.initval.split(',') |
| | | formItem = (<> |
| | | <Input style={{marginTop: '4px'}} value={vals[0] || ''} /> |
| | | 至 |
| | | <Input style={{marginTop: '4px'}} value={vals[1] || ''} /> |
| | | </>) |
| | | } |
| | | |
| | | let labelwidth = card.labelwidth || 33.3 |
| | |
| | | <CloseOutlined className="close" title="删除" onClick={() => delCard(id)} /> |
| | | </div> |
| | | } trigger="hover"> |
| | | <div className={'page-card ' + (card.labelShow || '')} style={{ opacity: opacity}}> |
| | | <div className={`page-card ${type} ${card.labelShow || ''}`} style={{ opacity: opacity}}> |
| | | <div ref={node => drag(drop(node))}> |
| | | <Form.Item |
| | | labelCol={{style: {width: labelwidth + '%'}}} |