update 0.9.1
This commit is contained in:
		| @@ -1,461 +0,0 @@ | ||||
| import { | ||||
| 	CompressOutlined, | ||||
| 	DeleteOutlined, | ||||
| 	FullscreenExitOutlined, | ||||
| 	FullscreenOutlined, | ||||
| 	GatewayOutlined, | ||||
| 	LayoutOutlined, | ||||
| 	MenuOutlined, | ||||
| 	SyncOutlined, | ||||
| 	UnorderedListOutlined, | ||||
| 	VideoCameraOutlined, | ||||
| } from '@ant-design/icons'; | ||||
| import { Button, Divider, Form, Input, List, message, Modal, Popconfirm, Popover } from 'antd'; | ||||
| import React, { CSSProperties, PropsWithChildren, useState } from 'react'; | ||||
| import { UserConfig } from '..'; | ||||
| import { IBlockType, IStoreData } from '../core/store/storetype'; | ||||
| import { deepCopy, arrayMove, changeItem, changeLayer, focusEle } from '../core/utils'; | ||||
| import { SortEnd, SortableContainer, SortableElement, SortableHandle } from 'react-sortable-hoc'; | ||||
| import { wrapperMoveState } from './wrapperMove/event'; | ||||
| import { FormattedMessage, IntlShape, useIntl } from 'react-intl'; | ||||
| export interface ControlProps { | ||||
| 	config: UserConfig; | ||||
| 	style?: CSSProperties; | ||||
| } | ||||
|  | ||||
| const DragHandle = SortableHandle(() => <MenuOutlined />); | ||||
| const SortableItem = SortableElement( | ||||
| 	({ value }: { value: { value: IBlockType; config: UserConfig; intl: IntlShape } }) => ( | ||||
| 		<div | ||||
| 			style={{ | ||||
| 				userSelect: 'none', | ||||
| 				display: 'flex', | ||||
| 				alignItems: 'center', | ||||
| 				width: 430, | ||||
| 			}} | ||||
| 		> | ||||
| 			<div style={{ width: 30, textAlign: 'center', cursor: 'move' }}> | ||||
| 				<DragHandle></DragHandle> | ||||
| 			</div> | ||||
| 			<Divider type="vertical"></Divider> | ||||
| 			<div style={{ width: 100, textAlign: 'center' }}> | ||||
| 				{value.config.getComponentRegister().getMap()[value.value.name].display} | ||||
| 			</div> | ||||
| 			<Divider type="vertical"></Divider> | ||||
| 			<div style={{ width: 80, textAlign: 'center' }}>{value.value.id.slice(-6)}</div> | ||||
| 			<Divider type="vertical"></Divider> | ||||
| 			<div style={{ width: 50, textAlign: 'center' }}>{value.value.position}</div> | ||||
| 			<Divider type="vertical"></Divider> | ||||
| 			<div style={{ width: 200 }}> | ||||
| 				<Popconfirm | ||||
| 					title={value.intl.formatMessage({ | ||||
| 						id: 'contorl.popup.absolute', | ||||
| 						defaultMessage: '确认变更为绝对定位吗', | ||||
| 					})} | ||||
| 					onConfirm={() => { | ||||
| 						changeItem(value.config.getStore(), value.value.id, 'position', 'absolute'); | ||||
| 					}} | ||||
| 					okText={value.intl.formatMessage({ id: 'yes' })} | ||||
| 					cancelText={value.intl.formatMessage({ id: 'no' })} | ||||
| 				> | ||||
| 					<Button | ||||
| 						type="link" | ||||
| 						title={value.intl.formatMessage({ | ||||
| 							id: 'contorl.absolute', | ||||
| 							defaultMessage: '切换绝对定位', | ||||
| 						})} | ||||
| 						icon={<FullscreenOutlined />} | ||||
| 					></Button> | ||||
| 				</Popconfirm> | ||||
| 				<Popconfirm | ||||
| 					title={value.intl.formatMessage({ | ||||
| 						id: 'contorl.popup.static', | ||||
| 						defaultMessage: '确认变更为静态定位吗', | ||||
| 					})} | ||||
| 					onConfirm={() => { | ||||
| 						changeItem(value.config.getStore(), value.value.id, 'position', 'static'); | ||||
| 					}} | ||||
| 					okText={value.intl.formatMessage({ id: 'yes' })} | ||||
| 					cancelText={value.intl.formatMessage({ id: 'no' })} | ||||
| 				> | ||||
| 					<Button | ||||
| 						type="link" | ||||
| 						title={value.intl.formatMessage({ | ||||
| 							id: 'contorl.static', | ||||
| 							defaultMessage: '切换静态定位', | ||||
| 						})} | ||||
| 						icon={<FullscreenExitOutlined />} | ||||
| 					></Button> | ||||
| 				</Popconfirm> | ||||
| 				<Button | ||||
| 					type="link" | ||||
| 					title={value.intl.formatMessage({ id: 'control.focus', defaultMessage: '选中聚焦' })} | ||||
| 					icon={<CompressOutlined />} | ||||
| 					onClick={() => { | ||||
| 						focusEle(value.config.getStore(), value.value.id); | ||||
| 					}} | ||||
| 				></Button> | ||||
| 				<Popconfirm | ||||
| 					title={value.intl.formatMessage({ | ||||
| 						id: 'control.popup.delete', | ||||
| 						defaultMessage: '确认删除吗', | ||||
| 					})} | ||||
| 					onConfirm={() => { | ||||
| 						changeLayer(value.config.getStore(), value.value.id, 'delete'); | ||||
| 					}} | ||||
| 					okText={value.intl.formatMessage({ id: 'yes' })} | ||||
| 					cancelText={value.intl.formatMessage({ id: 'no' })} | ||||
| 				> | ||||
| 					<Button | ||||
| 						icon={<DeleteOutlined />} | ||||
| 						title={value.intl.formatMessage({ id: 'control.delete', defaultMessage: '删除' })} | ||||
| 						type="link" | ||||
| 					></Button> | ||||
| 				</Popconfirm> | ||||
| 			</div> | ||||
| 		</div> | ||||
| 	) | ||||
| ); | ||||
| const SortableList = SortableContainer( | ||||
| 	({ items }: { items: { data: IBlockType[]; config: UserConfig; intl: IntlShape } }) => { | ||||
| 		return ( | ||||
| 			<div> | ||||
| 				{items.data.map((value, index: number) => ( | ||||
| 					<SortableItem | ||||
| 						key={value.id} | ||||
| 						index={index} | ||||
| 						value={{ value, config: items.config, intl: items.intl }} | ||||
| 					/> | ||||
| 				))} | ||||
| 			</div> | ||||
| 		); | ||||
| 	} | ||||
| ); | ||||
|  | ||||
| const moveState = { | ||||
| 	startX: 0, | ||||
| 	startY: 0, | ||||
| 	isMove: false, | ||||
| }; | ||||
|  | ||||
| const mouseUp = () => { | ||||
| 	if (moveState.isMove) { | ||||
| 		moveState.isMove = false; | ||||
| 	} | ||||
| }; | ||||
|  | ||||
| export function Control(props: PropsWithChildren<ControlProps>) { | ||||
| 	const { style } = props; | ||||
| 	const [visible, setVisible] = useState(false); | ||||
| 	const [configVisible, setConfigVisible] = useState(false); | ||||
| 	const [form] = Form.useForm(); | ||||
|  | ||||
| 	const data = props.config.getStore().getData().block; | ||||
|  | ||||
| 	const onSortEnd = (sort: SortEnd) => { | ||||
| 		const { oldIndex, newIndex } = sort; | ||||
| 		const newblocks: IBlockType[] = arrayMove(data, oldIndex, newIndex); | ||||
| 		// 这里要判断是否edit ,如果edit时,只要看第一个是不是container,不是则不移动 | ||||
| 		const isEdit = props.config.getStoreChanger().isEdit(); | ||||
| 		if (isEdit) { | ||||
| 			const firstType = newblocks[0].name; | ||||
| 			if (firstType !== 'modalMask') { | ||||
| 				return; | ||||
| 			} | ||||
| 		} | ||||
| 		const store = props.config.getStore(); | ||||
| 		const cloneData: IStoreData = deepCopy(store.getData()); | ||||
| 		cloneData.block = newblocks; | ||||
| 		store.setData(cloneData); | ||||
| 	}; | ||||
|  | ||||
| 	const intl = useIntl(); | ||||
|  | ||||
| 	const content = | ||||
| 		data.length === 0 ? ( | ||||
| 			<div> | ||||
| 				<FormattedMessage id="control.no-component" defaultMessage="暂无组件"></FormattedMessage> | ||||
| 			</div> | ||||
| 		) : ( | ||||
| 			<div style={{ maxHeight: 300, overflow: 'auto' }}> | ||||
| 				<SortableList | ||||
| 					distance={2} | ||||
| 					useDragHandle | ||||
| 					items={{ | ||||
| 						data, | ||||
| 						config: props.config, | ||||
| 						intl: intl, | ||||
| 					}} | ||||
| 					onSortEnd={onSortEnd} | ||||
| 					axis="y" | ||||
| 				></SortableList> | ||||
| 			</div> | ||||
| 		); | ||||
| 	const [xy, setXy] = useState({ x: 0, y: 0 }); | ||||
| 	return ( | ||||
| 		<> | ||||
| 			<div | ||||
| 				className="ant-menu" | ||||
| 				onMouseDown={(e) => { | ||||
| 					moveState.startX = e.clientX; | ||||
| 					moveState.startY = e.clientY; | ||||
| 					moveState.isMove = true; | ||||
| 				}} | ||||
| 				onMouseMove={(e) => { | ||||
| 					if (moveState.isMove) { | ||||
| 						const diffx = e.clientX - moveState.startX; | ||||
| 						const diffy = e.clientY - moveState.startY; | ||||
| 						setXy((pre) => ({ x: pre.x + diffx, y: pre.y + diffy })); | ||||
| 						moveState.startX = e.clientX; | ||||
| 						moveState.startY = e.clientY; | ||||
| 					} | ||||
| 				}} | ||||
| 				onMouseUp={mouseUp} | ||||
| 				onMouseLeave={mouseUp} | ||||
| 				style={{ | ||||
| 					display: 'flex', | ||||
| 					flexDirection: 'column', | ||||
| 					justifyContent: 'center', | ||||
| 					alignItems: 'center', | ||||
| 					transform: `translate(${xy.x}px,${xy.y}px)`, | ||||
| 					...style, | ||||
| 				}} | ||||
| 			> | ||||
| 				<Popover style={{ minWidth: '208px' }} content={content} trigger="click"> | ||||
| 					<Button icon={<UnorderedListOutlined />}></Button> | ||||
| 				</Popover> | ||||
| 				<Button | ||||
| 					icon={<LayoutOutlined />} | ||||
| 					onClick={() => { | ||||
| 						props.config.ticker = !props.config.ticker; | ||||
| 						props.config.getStore().forceUpdate(); | ||||
| 					}} | ||||
| 				></Button> | ||||
| 				<Popover | ||||
| 					placement="left" | ||||
| 					content={ | ||||
| 						<div | ||||
| 							style={{ | ||||
| 								display: 'flex', | ||||
| 								justifyContent: 'center', | ||||
| 								alignItems: 'center', | ||||
| 								flexDirection: 'column', | ||||
| 							}} | ||||
| 						> | ||||
| 							<Button | ||||
| 								onClick={() => { | ||||
| 									setVisible(true); | ||||
| 								}} | ||||
| 								style={{ width: '100px', overflow: 'hidden', textOverflow: 'ellipsis' }} | ||||
| 							> | ||||
| 								<FormattedMessage id="modal.new" defaultMessage="新建弹窗"></FormattedMessage> | ||||
| 							</Button> | ||||
| 							<Button | ||||
| 								onClick={() => { | ||||
| 									setConfigVisible(true); | ||||
| 								}} | ||||
| 								style={{ width: '100px', overflow: 'hidden', textOverflow: 'ellipsis' }} | ||||
| 							> | ||||
| 								<FormattedMessage id="modal.control" defaultMessage="弹窗配置"></FormattedMessage> | ||||
| 							</Button> | ||||
| 						</div> | ||||
| 					} | ||||
| 				> | ||||
| 					<Button icon={<GatewayOutlined />}></Button> | ||||
| 				</Popover> | ||||
|  | ||||
| 				<Button | ||||
| 					icon={<VideoCameraOutlined />} | ||||
| 					onClick={() => { | ||||
| 						props.config.timeline = !props.config.timeline; | ||||
| 						props.config.getStore().forceUpdate(); | ||||
| 					}} | ||||
| 				></Button> | ||||
| 				<Button | ||||
| 					icon={<SyncOutlined />} | ||||
| 					onClick={() => { | ||||
| 						wrapperMoveState.needX = 0; | ||||
| 						wrapperMoveState.needY = 0; | ||||
| 						props.config.getStore().forceUpdate(); | ||||
| 					}} | ||||
| 				></Button> | ||||
| 			</div> | ||||
|  | ||||
| 			<Modal | ||||
| 				title={intl.formatMessage({ id: 'modal.control', defaultMessage: '弹窗配置' })} | ||||
| 				visible={configVisible} | ||||
| 				onOk={() => setConfigVisible(false)} | ||||
| 				onCancel={() => setConfigVisible(false)} | ||||
| 				footer={null} | ||||
| 			> | ||||
| 				<List> | ||||
| 					{props.config.getStoreChanger().getState().modalEditName !== '' && ( | ||||
| 						<div> | ||||
| 							<FormattedMessage | ||||
| 								id="modal.popup.exit" | ||||
| 								defaultMessage="请退出编辑弹窗后再打开该配置" | ||||
| 							></FormattedMessage> | ||||
| 						</div> | ||||
| 					)} | ||||
| 					{props.config.getStoreChanger().getState().modalEditName === '' && | ||||
| 						Object.keys(props.config.getStore().getData().modalMap).map((v) => { | ||||
| 							return ( | ||||
| 								<List.Item | ||||
| 									key={v} | ||||
| 									actions={[ | ||||
| 										<Popconfirm | ||||
| 											title={intl.formatMessage({ | ||||
| 												id: 'modal.popup.edit', | ||||
| 												defaultMessage: '是否切换至该弹窗并进行编辑?', | ||||
| 											})} | ||||
| 											onConfirm={() => { | ||||
| 												const sign = props.config | ||||
| 													.getStoreChanger() | ||||
| 													.updateModal(props.config.getStore(), v); | ||||
| 												if (!sign.success && sign.sign === 0) { | ||||
| 													message.error( | ||||
| 														intl.formatMessage({ | ||||
| 															id: 'modal.popup.save', | ||||
| 															defaultMessage: '请保存弹窗后编辑其他弹窗', | ||||
| 														}) | ||||
| 													); | ||||
| 												} | ||||
| 												if (!sign.success && sign.sign === 1) { | ||||
| 													message.error( | ||||
| 														intl.formatMessage( | ||||
| 															{ | ||||
| 																id: 'modal.popup.notfond', | ||||
| 																defaultMessage: '未找到该弹窗 {name}', | ||||
| 															}, | ||||
| 															{ | ||||
| 																name: sign.param, | ||||
| 															} | ||||
| 														) | ||||
| 													); | ||||
| 												} | ||||
| 												setConfigVisible(false); | ||||
| 											}} | ||||
| 											okText={intl.formatMessage({ id: 'yes' })} | ||||
| 											cancelText={intl.formatMessage({ id: 'no' })} | ||||
| 										> | ||||
| 											<Button type="link">修改</Button> | ||||
| 										</Popconfirm>, | ||||
|  | ||||
| 										<Popconfirm | ||||
| 											title="您确定要删除这个弹窗吗?" | ||||
| 											onConfirm={() => { | ||||
| 												const sign = props.config | ||||
| 													.getStoreChanger() | ||||
| 													.removeModal(props.config.getStore(), v); | ||||
| 												if (!sign.success && sign.sign === 0) { | ||||
| 													message.error( | ||||
| 														intl.formatMessage({ | ||||
| 															id: 'modal.popup.save', | ||||
| 															defaultMessage: '请保存弹窗后编辑其他弹窗', | ||||
| 														}) | ||||
| 													); | ||||
| 												} | ||||
| 												if (!sign.success && sign.sign === 1) { | ||||
| 													message.error( | ||||
| 														intl.formatMessage( | ||||
| 															{ | ||||
| 																id: 'modal.popup.notfond', | ||||
| 																defaultMessage: '未找到该弹窗 {name}', | ||||
| 															}, | ||||
| 															{ | ||||
| 																name: sign.param, | ||||
| 															} | ||||
| 														) | ||||
| 													); | ||||
| 												} | ||||
|  | ||||
| 												setConfigVisible(false); | ||||
| 											}} | ||||
| 											okText={intl.formatMessage({ id: 'yes' })} | ||||
| 											cancelText={intl.formatMessage({ id: 'no' })} | ||||
| 										> | ||||
| 											<Button type="link"> | ||||
| 												<FormattedMessage | ||||
| 													id="control.delete" | ||||
| 													defaultMessage="删除" | ||||
| 												></FormattedMessage> | ||||
| 											</Button> | ||||
| 										</Popconfirm>, | ||||
| 									]} | ||||
| 								> | ||||
| 									{v} | ||||
| 								</List.Item> | ||||
| 							); | ||||
| 						})} | ||||
| 					{props.config.getStoreChanger().getState().modalEditName === '' && | ||||
| 						Object.keys(props.config.getStore().getData().modalMap).length === 0 && ( | ||||
| 							<div style={{ textAlign: 'center' }}> | ||||
| 								<FormattedMessage id="modal.popup.nomodal"></FormattedMessage> | ||||
| 							</div> | ||||
| 						)} | ||||
| 				</List> | ||||
| 			</Modal> | ||||
| 			<Modal | ||||
| 				onOk={() => { | ||||
| 					form | ||||
| 						.validateFields() | ||||
| 						.then((values) => { | ||||
| 							form.resetFields(); | ||||
| 							const modalName = values.modalName; | ||||
| 							const sign = props.config | ||||
| 								.getStoreChanger() | ||||
| 								.newModalMap(props.config.getStore(), modalName); | ||||
| 							if (sign.succeess && sign.sign === 0) { | ||||
| 								message.error( | ||||
| 									intl.formatMessage({ | ||||
| 										id: 'modal.popup.save', | ||||
| 										defaultMessage: '请保存弹窗后编辑其他弹窗', | ||||
| 									}) | ||||
| 								); | ||||
| 							} | ||||
| 							if (sign.succeess && sign.sign === 1) { | ||||
| 								message.error( | ||||
| 									intl.formatMessage( | ||||
| 										{ | ||||
| 											id: 'modal.popup.repeat', | ||||
| 											defaultMessage: '已有重名弹窗 {name}', | ||||
| 										}, | ||||
| 										{ | ||||
| 											name: sign.param, | ||||
| 										} | ||||
| 									) | ||||
| 								); | ||||
| 							} | ||||
| 							setVisible(false); | ||||
| 						}) | ||||
| 						.catch((info) => { | ||||
| 							console.log('Validate Failed:', info); | ||||
| 						}); | ||||
| 				}} | ||||
| 				title={intl.formatMessage({ id: 'modal.new', defaultMessage: '新增弹窗' })} | ||||
| 				onCancel={() => setVisible(false)} | ||||
| 				visible={visible} | ||||
| 			> | ||||
| 				<Form layout="vertical" name="basic" form={form}> | ||||
| 					<Form.Item | ||||
| 						label={intl.formatMessage({ id: 'modal.name', defaultMessage: '弹窗名称' })} | ||||
| 						name="modalName" | ||||
| 						rules={[ | ||||
| 							{ | ||||
| 								required: true, | ||||
| 								message: intl.formatMessage({ | ||||
| 									id: 'modal.popup.name', | ||||
| 									defaultMessage: '请输入弹窗名称!', | ||||
| 								}), | ||||
| 							}, | ||||
| 						]} | ||||
| 					> | ||||
| 						<Input /> | ||||
| 					</Form.Item> | ||||
| 				</Form> | ||||
| 			</Modal> | ||||
| 		</> | ||||
| 	); | ||||
| } | ||||
|  | ||||
| export default Control; | ||||
							
								
								
									
										276
									
								
								packages/dooringx-lib/src/components/control/control.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										276
									
								
								packages/dooringx-lib/src/components/control/control.tsx
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,276 @@ | ||||
| import { | ||||
| 	GatewayOutlined, | ||||
| 	LayoutOutlined, | ||||
| 	SyncOutlined, | ||||
| 	UnorderedListOutlined, | ||||
| 	VideoCameraOutlined, | ||||
| } from '@ant-design/icons'; | ||||
| import { Button, Form, Input, List, message, Modal, Popconfirm, Popover } from 'antd'; | ||||
| import React, { CSSProperties, PropsWithChildren, useState } from 'react'; | ||||
| import { UserConfig } from '../..'; | ||||
| import { wrapperMoveState } from '../wrapperMove/event'; | ||||
| import { replaceLocale } from '../../locale'; | ||||
| import { mouseUp, moveState } from './state'; | ||||
|  | ||||
| export interface ControlProps { | ||||
| 	config: UserConfig; | ||||
| 	style?: CSSProperties; | ||||
| } | ||||
|  | ||||
| export function Control(props: PropsWithChildren<ControlProps>) { | ||||
| 	const { style } = props; | ||||
| 	const [visible, setVisible] = useState(false); | ||||
| 	const [configVisible, setConfigVisible] = useState(false); | ||||
| 	const [form] = Form.useForm(); | ||||
|  | ||||
| 	const [xy, setXy] = useState({ x: 0, y: 0 }); | ||||
| 	return ( | ||||
| 		<> | ||||
| 			<div | ||||
| 				className="ant-menu" | ||||
| 				onMouseUp={mouseUp} | ||||
| 				style={{ | ||||
| 					display: 'flex', | ||||
| 					flexDirection: 'column', | ||||
| 					justifyContent: 'center', | ||||
| 					alignItems: 'center', | ||||
| 					transform: `translate(${xy.x}px,${xy.y}px)`, | ||||
| 					...style, | ||||
| 				}} | ||||
| 			> | ||||
| 				<Button | ||||
| 					onMouseDown={(e) => { | ||||
| 						moveState.startX = e.clientX; | ||||
| 						moveState.startY = e.clientY; | ||||
| 						moveState.fn = setXy; | ||||
| 						moveState.isMove = true; | ||||
| 					}} | ||||
| 					type="text" | ||||
| 					style={{ cursor: 'move' }} | ||||
| 					icon={<UnorderedListOutlined />} | ||||
| 				></Button> | ||||
| 				<Button | ||||
| 					icon={<LayoutOutlined />} | ||||
| 					onClick={() => { | ||||
| 						props.config.ticker = !props.config.ticker; | ||||
| 						props.config.getStore().forceUpdate(); | ||||
| 					}} | ||||
| 				></Button> | ||||
| 				<Popover | ||||
| 					placement="left" | ||||
| 					content={ | ||||
| 						<div | ||||
| 							style={{ | ||||
| 								display: 'flex', | ||||
| 								justifyContent: 'center', | ||||
| 								alignItems: 'center', | ||||
| 								flexDirection: 'column', | ||||
| 							}} | ||||
| 						> | ||||
| 							<Button | ||||
| 								onClick={() => { | ||||
| 									setVisible(true); | ||||
| 								}} | ||||
| 								style={{ width: '100px', overflow: 'hidden', textOverflow: 'ellipsis' }} | ||||
| 							> | ||||
| 								{replaceLocale('modal.new', '新建弹窗', props.config)} | ||||
| 							</Button> | ||||
| 							<Button | ||||
| 								onClick={() => { | ||||
| 									setConfigVisible(true); | ||||
| 								}} | ||||
| 								style={{ width: '100px', overflow: 'hidden', textOverflow: 'ellipsis' }} | ||||
| 							> | ||||
| 								{replaceLocale('modal.control', '弹窗配置', props.config)} | ||||
| 							</Button> | ||||
| 						</div> | ||||
| 					} | ||||
| 				> | ||||
| 					<Button icon={<GatewayOutlined />}></Button> | ||||
| 				</Popover> | ||||
|  | ||||
| 				<Button | ||||
| 					icon={<VideoCameraOutlined />} | ||||
| 					onClick={() => { | ||||
| 						props.config.timeline = !props.config.timeline; | ||||
| 						props.config.getStore().forceUpdate(); | ||||
| 					}} | ||||
| 				></Button> | ||||
| 				<Button | ||||
| 					icon={<SyncOutlined />} | ||||
| 					onClick={() => { | ||||
| 						wrapperMoveState.needX = 0; | ||||
| 						wrapperMoveState.needY = 0; | ||||
| 						props.config.getStore().forceUpdate(); | ||||
| 					}} | ||||
| 				></Button> | ||||
| 			</div> | ||||
|  | ||||
| 			<Modal | ||||
| 				title={replaceLocale('modal.control', '弹窗配置', props.config)} | ||||
| 				visible={configVisible} | ||||
| 				onOk={() => setConfigVisible(false)} | ||||
| 				onCancel={() => setConfigVisible(false)} | ||||
| 				footer={null} | ||||
| 			> | ||||
| 				<List> | ||||
| 					{props.config.getStoreChanger().getState().modalEditName !== '' && ( | ||||
| 						<div> | ||||
| 							{replaceLocale('modal.popup.exit', '请退出编辑弹窗后再打开该配置', props.config)} | ||||
| 						</div> | ||||
| 					)} | ||||
| 					{props.config.getStoreChanger().getState().modalEditName === '' && | ||||
| 						Object.keys(props.config.getStore().getData().modalMap).map((v) => { | ||||
| 							return ( | ||||
| 								<List.Item | ||||
| 									key={v} | ||||
| 									actions={[ | ||||
| 										<Popconfirm | ||||
| 											title={replaceLocale( | ||||
| 												'modal.popup.edit', | ||||
| 												'是否切换至该弹窗并进行编辑?', | ||||
| 												props.config | ||||
| 											)} | ||||
| 											onConfirm={() => { | ||||
| 												const sign = props.config | ||||
| 													.getStoreChanger() | ||||
| 													.updateModal(props.config.getStore(), v); | ||||
| 												if (!sign.success && sign.sign === 0) { | ||||
| 													message.error( | ||||
| 														replaceLocale( | ||||
| 															'modal.popup.save', | ||||
| 															'请保存弹窗后编辑其他弹窗', | ||||
| 															props.config | ||||
| 														) | ||||
| 													); | ||||
| 												} | ||||
| 												if (!sign.success && sign.sign === 1) { | ||||
| 													message.error( | ||||
| 														replaceLocale( | ||||
| 															'modal.popup.notfond', | ||||
| 															`未找到该弹窗 ${sign.param}`, | ||||
| 															props.config, | ||||
| 															{ name: sign.param }, | ||||
| 															'未找到该弹窗 {name}' | ||||
| 														) | ||||
| 													); | ||||
| 												} | ||||
| 												setConfigVisible(false); | ||||
| 											}} | ||||
| 											okText={replaceLocale('yes', '确定', props.config)} | ||||
| 											cancelText={replaceLocale('no', '取消', props.config)} | ||||
| 										> | ||||
| 											<Button type="link">修改</Button> | ||||
| 										</Popconfirm>, | ||||
|  | ||||
| 										<Popconfirm | ||||
| 											title="您确定要删除这个弹窗吗?" | ||||
| 											onConfirm={() => { | ||||
| 												const sign = props.config | ||||
| 													.getStoreChanger() | ||||
| 													.removeModal(props.config.getStore(), v); | ||||
| 												if (!sign.success && sign.sign === 0) { | ||||
| 													message.error( | ||||
| 														replaceLocale( | ||||
| 															'modal.popup.save', | ||||
| 															'请保存弹窗后编辑其他弹窗', | ||||
| 															props.config | ||||
| 														) | ||||
| 													); | ||||
| 												} | ||||
| 												if (!sign.success && sign.sign === 1) { | ||||
| 													message.error( | ||||
| 														replaceLocale( | ||||
| 															'modal.popup.notfond', | ||||
| 															`未找到该弹窗 ${sign.param}`, | ||||
| 															props.config, | ||||
| 															{ name: sign.param }, | ||||
| 															'未找到该弹窗 {name}' | ||||
| 														) | ||||
| 													); | ||||
| 												} | ||||
|  | ||||
| 												setConfigVisible(false); | ||||
| 											}} | ||||
| 											okText={replaceLocale('yes', '确定', props.config)} | ||||
| 											cancelText={replaceLocale('no', '取消', props.config)} | ||||
| 										> | ||||
| 											<Button type="link"> | ||||
| 												{replaceLocale('control.delete', `删除`, props.config)} | ||||
| 											</Button> | ||||
| 										</Popconfirm>, | ||||
| 									]} | ||||
| 								> | ||||
| 									{v} | ||||
| 								</List.Item> | ||||
| 							); | ||||
| 						})} | ||||
| 					{props.config.getStoreChanger().getState().modalEditName === '' && | ||||
| 						Object.keys(props.config.getStore().getData().modalMap).length === 0 && ( | ||||
| 							<div style={{ textAlign: 'center' }}> | ||||
| 								{replaceLocale('modal.popup.nomodal', `暂时没有弹窗`, props.config)} | ||||
| 							</div> | ||||
| 						)} | ||||
| 				</List> | ||||
| 			</Modal> | ||||
| 			<Modal | ||||
| 				okText={replaceLocale('yes', '确定', props.config)} | ||||
| 				cancelText={replaceLocale('no', '取消', props.config)} | ||||
| 				onOk={() => { | ||||
| 					form | ||||
| 						.validateFields() | ||||
| 						.then((values) => { | ||||
| 							form.resetFields(); | ||||
| 							const modalName = values.modalName; | ||||
| 							const sign = props.config | ||||
| 								.getStoreChanger() | ||||
| 								.newModalMap(props.config.getStore(), modalName); | ||||
|  | ||||
| 							if (!sign.succeess && sign.sign === 0) { | ||||
| 								message.error( | ||||
| 									replaceLocale('modal.popup.save', `请保存弹窗后编辑其他弹窗`, props.config) | ||||
| 								); | ||||
| 							} | ||||
| 							if (!sign.succeess && sign.sign === 1) { | ||||
| 								message.error( | ||||
| 									replaceLocale( | ||||
| 										'modal.popup.repeat', | ||||
| 										`已有重名弹窗 ${sign.param}`, | ||||
| 										props.config, | ||||
| 										{ | ||||
| 											name: sign.param, | ||||
| 										}, | ||||
| 										'已有重名弹窗 {name}' | ||||
| 									) | ||||
| 								); | ||||
| 							} | ||||
| 							setVisible(false); | ||||
| 						}) | ||||
| 						.catch((info) => { | ||||
| 							console.log('Validate Failed:', info); | ||||
| 						}); | ||||
| 				}} | ||||
| 				title={replaceLocale('modal.new', '新增弹窗', props.config)} | ||||
| 				onCancel={() => setVisible(false)} | ||||
| 				visible={visible} | ||||
| 			> | ||||
| 				<Form layout="vertical" name="basic" form={form}> | ||||
| 					<Form.Item | ||||
| 						label={replaceLocale('modal.name', '弹窗名称', props.config)} | ||||
| 						name="modalName" | ||||
| 						rules={[ | ||||
| 							{ | ||||
| 								required: true, | ||||
| 								message: replaceLocale('modal.popup.name', '请输入弹窗名称!', props.config), | ||||
| 							}, | ||||
| 						]} | ||||
| 					> | ||||
| 						<Input /> | ||||
| 					</Form.Item> | ||||
| 				</Form> | ||||
| 			</Modal> | ||||
| 		</> | ||||
| 	); | ||||
| } | ||||
|  | ||||
| export default Control; | ||||
							
								
								
									
										10
									
								
								packages/dooringx-lib/src/components/control/index.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								packages/dooringx-lib/src/components/control/index.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,10 @@ | ||||
| /* | ||||
|  * @Author: yehuozhili | ||||
|  * @Date: 2021-09-27 20:57:27 | ||||
|  * @LastEditors: yehuozhili | ||||
|  * @LastEditTime: 2021-09-27 20:59:34 | ||||
|  * @FilePath: \dooringx\packages\dooringx-lib\src\components\control\index.ts | ||||
|  */ | ||||
|  | ||||
| import Control from './control'; | ||||
| export default Control; | ||||
							
								
								
									
										38
									
								
								packages/dooringx-lib/src/components/control/state.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								packages/dooringx-lib/src/components/control/state.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,38 @@ | ||||
| /* | ||||
|  * @Author: yehuozhili | ||||
|  * @Date: 2021-09-27 20:56:21 | ||||
|  * @LastEditors: yehuozhili | ||||
|  * @LastEditTime: 2021-09-27 20:57:01 | ||||
|  * @FilePath: \dooringx\packages\dooringx-lib\src\components\control\state.ts | ||||
|  */ | ||||
|  | ||||
| interface MoveStateType { | ||||
| 	startX: number; | ||||
| 	startY: number; | ||||
| 	fn: Function; | ||||
| 	isMove: boolean; | ||||
| } | ||||
|  | ||||
| export const moveState: MoveStateType = { | ||||
| 	startX: 0, | ||||
| 	startY: 0, | ||||
| 	fn: () => {}, | ||||
| 	isMove: false, | ||||
| }; | ||||
|  | ||||
| export const mouseUp = () => { | ||||
| 	if (moveState.isMove) { | ||||
| 		moveState.isMove = false; | ||||
| 	} | ||||
| }; | ||||
|  | ||||
| export const controlMouseMove = (e: React.MouseEvent) => { | ||||
| 	if (moveState.isMove) { | ||||
| 		const diffx = e.clientX - moveState.startX; | ||||
| 		const diffy = e.clientY - moveState.startY; | ||||
| 		const setXy = moveState.fn; | ||||
| 		if (setXy) setXy((pre: { x: number; y: number }) => ({ x: pre.x + diffx, y: pre.y + diffy })); | ||||
| 		moveState.startX = e.clientX; | ||||
| 		moveState.startY = e.clientY; | ||||
| 	} | ||||
| }; | ||||
| @@ -2,7 +2,7 @@ | ||||
|  * @Author: yehuozhili | ||||
|  * @Date: 2021-03-14 05:42:13 | ||||
|  * @LastEditors: yehuozhili | ||||
|  * @LastEditTime: 2021-08-27 16:20:29 | ||||
|  * @LastEditTime: 2021-09-27 20:33:04 | ||||
|  * @FilePath: \dooringx\packages\dooringx-lib\src\components\rightConfig.tsx | ||||
|  */ | ||||
| import { CreateOptionsRes } from '../core/components/formTypes'; | ||||
| @@ -14,7 +14,7 @@ import UserConfig from '../config'; | ||||
| import { RGBColor, SketchPicker } from 'react-color'; | ||||
| import { rgba2Obj } from '../core/utils'; | ||||
| import deepcopy from 'deepcopy'; | ||||
| import { FormattedMessage } from 'react-intl'; | ||||
| import { replaceLocale } from '../locale'; | ||||
|  | ||||
| const colStyle: CSSProperties = { | ||||
| 	display: 'flex', | ||||
| @@ -84,14 +84,7 @@ function RightConfig(props: PropsWithChildren<RightConfigProps>) { | ||||
| 						); | ||||
| 					}); | ||||
| 				} else { | ||||
| 					return ( | ||||
| 						<div> | ||||
| 							<FormattedMessage | ||||
| 								id="right.noprops" | ||||
| 								defaultMessage="还没有配置属性" | ||||
| 							></FormattedMessage> | ||||
| 						</div> | ||||
| 					); | ||||
| 					return <div>{replaceLocale('right.noprops', '还没有配置属性', props.config)}</div>; | ||||
| 				} | ||||
| 			} | ||||
| 			return null; | ||||
| @@ -164,11 +157,11 @@ function RightConfig(props: PropsWithChildren<RightConfigProps>) { | ||||
| 			{!current && !isEdit && !customGlobal && ( | ||||
| 				<div style={{ padding: '20px' }}> | ||||
| 					<Row style={{ padding: '10px 0 20px 0', fontWeight: 'bold', userSelect: 'none' }}> | ||||
| 						<FormattedMessage id="right.global" defaultMessage="全局设置"></FormattedMessage> | ||||
| 						{replaceLocale('right.global', '全局设置', props.config)} | ||||
| 					</Row> | ||||
| 					<Row style={{ padding: '10px 0' }}> | ||||
| 						<Col span={6} style={{ userSelect: 'none' }}> | ||||
| 							<FormattedMessage id="title" defaultMessage="标题"></FormattedMessage> | ||||
| 							{replaceLocale('title', '标题', props.config)} | ||||
| 						</Col> | ||||
| 						<Col span={18} style={colStyle}> | ||||
| 							<Input | ||||
| @@ -194,10 +187,7 @@ function RightConfig(props: PropsWithChildren<RightConfigProps>) { | ||||
| 					</Row> | ||||
| 					<Row style={{ padding: '10px 0' }}> | ||||
| 						<Col span={6} style={{ userSelect: 'none' }}> | ||||
| 							<FormattedMessage | ||||
| 								id="right.containerheight" | ||||
| 								defaultMessage="容器高度" | ||||
| 							></FormattedMessage> | ||||
| 							{replaceLocale('right.containerheight', '容器高度', props.config)} | ||||
| 						</Col> | ||||
| 						<Col span={18} style={colStyle}> | ||||
| 							<InputNumber | ||||
| @@ -223,10 +213,7 @@ function RightConfig(props: PropsWithChildren<RightConfigProps>) { | ||||
| 					</Row> | ||||
| 					<Row style={{ padding: '10px 0' }}> | ||||
| 						<Col span={6} style={{ userSelect: 'none' }}> | ||||
| 							<FormattedMessage | ||||
| 								id="right.containerColor" | ||||
| 								defaultMessage="容器底色" | ||||
| 							></FormattedMessage> | ||||
| 							{replaceLocale('right.containerColor', '容器底色', props.config)} | ||||
| 						</Col> | ||||
| 						<Col span={18} style={colStyle}> | ||||
| 							{ | ||||
| @@ -300,7 +287,7 @@ function RightConfig(props: PropsWithChildren<RightConfigProps>) { | ||||
| 					</Row> | ||||
| 					<Row style={{ padding: '10px 0' }}> | ||||
| 						<Col span={6} style={{ userSelect: 'none' }}> | ||||
| 							<FormattedMessage id="right.bodyColor" defaultMessage="body底色"></FormattedMessage> | ||||
| 							{replaceLocale('right.bodyColor', 'body底色', props.config)} | ||||
| 						</Col> | ||||
| 						<Col span={18} style={colStyle}> | ||||
| 							{ | ||||
| @@ -378,14 +365,11 @@ function RightConfig(props: PropsWithChildren<RightConfigProps>) { | ||||
| 			{!current && isEdit && ( | ||||
| 				<div style={{ padding: '20px' }} className="yh-tcsz"> | ||||
| 					<Row style={{ padding: '10 0 20px 0', fontWeight: 'bold' }}> | ||||
| 						<FormattedMessage id="modal.control" defaultMessage="弹窗配置"></FormattedMessage> | ||||
| 						{replaceLocale('modal.control', '弹窗配置', props.config)} | ||||
| 					</Row> | ||||
| 					<Row style={{ padding: '10px 0' }}> | ||||
| 						<Col span={8}> | ||||
| 							<FormattedMessage | ||||
| 								id="modal.control.remove" | ||||
| 								defaultMessage="取消点击删除弹窗" | ||||
| 							></FormattedMessage> | ||||
| 							{replaceLocale('modal.control.remove', '取消点击删除弹窗', props.config)} | ||||
| 						</Col> | ||||
| 						<Col span={16} style={{ ...colStyle }}> | ||||
| 							<Checkbox | ||||
|   | ||||
| @@ -2,7 +2,7 @@ | ||||
|  * @Author: yehuozhili | ||||
|  * @Date: 2021-08-09 15:15:25 | ||||
|  * @LastEditors: yehuozhili | ||||
|  * @LastEditTime: 2021-08-27 14:16:07 | ||||
|  * @LastEditTime: 2021-09-27 21:41:20 | ||||
|  * @FilePath: \dooringx\packages\dooringx-lib\src\components\timeLine\timeline.tsx | ||||
|  */ | ||||
| import deepcopy from 'deepcopy'; | ||||
| @@ -11,7 +11,7 @@ import { SortableContainer, SortableElement, SortableHandle, SortEnd } from 'rea | ||||
| import UserConfig from '../../config'; | ||||
| import { IBlockType, IStoreData } from '../../core/store/storetype'; | ||||
| import { arrayMove } from '../../core/utils'; | ||||
| import { MenuOutlined, PlayCircleOutlined } from '@ant-design/icons'; | ||||
| import { DeleteOutlined, MenuOutlined, PlayCircleOutlined } from '@ant-design/icons'; | ||||
| import { | ||||
| 	TimeLineItem, | ||||
| 	itemHeight, | ||||
| @@ -21,7 +21,8 @@ import { | ||||
| 	iter, | ||||
| } from './timelineItem'; | ||||
| import { specialCoList } from '../../core/utils/special'; | ||||
| import { FormattedMessage } from 'react-intl'; | ||||
| import { replaceLocale } from '../../locale'; | ||||
| import { Popconfirm } from 'antd'; | ||||
|  | ||||
| export interface TimeLineProps { | ||||
| 	style?: CSSProperties; | ||||
| @@ -81,6 +82,23 @@ const SortableItem = SortableElement( | ||||
| 				</div> | ||||
| 				<div>{value.config.getComponentRegister().getMap()[value.value.name].display}</div> | ||||
| 				<div>{value.value.id.slice(-6)}</div> | ||||
| 				<div style={{ marginLeft: 5 }}> | ||||
| 					<Popconfirm | ||||
| 						title={replaceLocale('control.popup.delete', '确认删除么', value.config)} | ||||
| 						onConfirm={() => { | ||||
| 							const store = value.config.getStore(); | ||||
| 							const clone = deepcopy(store.getData()); | ||||
| 							clone.block = clone.block.filter((v) => { | ||||
| 								return !(v.id === value.value.id && !specialCoList.includes(value.value.name)); | ||||
| 							}); | ||||
| 							store.setData(clone); | ||||
| 						}} | ||||
| 						okText={replaceLocale('yes', '确定', value.config)} | ||||
| 						cancelText={replaceLocale('no', '取消', value.config)} | ||||
| 					> | ||||
| 						<DeleteOutlined /> | ||||
| 					</Popconfirm> | ||||
| 				</div> | ||||
| 			</div> | ||||
| 		</div> | ||||
| 	) | ||||
| @@ -182,7 +200,7 @@ export function TimeLine(props: TimeLineProps) { | ||||
| 								height: itemHeight, | ||||
| 							}} | ||||
| 						> | ||||
| 							<FormattedMessage id="timeline.name" defaultMessage="组件名称"></FormattedMessage> | ||||
| 							{replaceLocale('timeline.name', '组件名称', props.config)} | ||||
| 							<span | ||||
| 								title="play" | ||||
| 								style={{ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 yehuozhili
					yehuozhili