/* * @Author: yehuozhili * @Date: 2021-08-09 15:15:25 * @LastEditors: yehuozhili * @LastEditTime: 2021-08-11 17:03:54 * @FilePath: \dooringx\packages\dooringx-lib\src\components\timeLine\timeline.tsx */ import deepcopy from 'deepcopy'; import React, { CSSProperties, useState } from 'react'; import { SortableContainer, SortableElement, SortableHandle, SortEnd } from 'react-sortable-hoc'; import UserConfig from '../../config'; import { IBlockType, IStoreData } from '../../core/store/storetype'; import { arrayMove } from '../../core/utils'; import { MenuOutlined, PlayCircleOutlined } from '@ant-design/icons'; import { TimeLineItem, itemHeight, TimeLineItemMouseMove, TimeLineItemMouseOver, interval, } from './timelineItem'; export interface TimeLineProps { style?: CSSProperties; classes?: string; config: UserConfig; } const iter = 500; const animateTicker = new Array(iter).fill(1).map((_, y) => y); const DragHandle = SortableHandle(() => ); const leftWidth = 200; let WAIT = false; const widthInterval = interval * 10 + 9; const ruleWidth = (widthInterval * iter) / 10 + 10; const borderColor = '1px solid rgb(204, 204, 204)'; const SortableItem = SortableElement( ({ value }: { value: { value: IBlockType; config: UserConfig } }) => (
{value.config.getComponentRegister().getMap()[value.value.name].display}
{value.value.id.slice(-6)}
) ); const SortableList = SortableContainer( ({ items }: { items: { data: IBlockType[]; config: UserConfig } }) => { return (
{items.data.map((value, index: number) => ( ))}
); } ); export function TimeLine(props: TimeLineProps) { const store = props.config.getStore(); const data = store.getData().block; const forceUpdate = useState(0)[1]; const onSortEnd = (sort: SortEnd) => { const { oldIndex, newIndex } = sort; const newblocks: IBlockType[] = arrayMove(data, oldIndex, newIndex); 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 [state, setState] = useState(0); const [scrollx, setScrollx] = useState(0); const content = (
); return (
<>
组件名称 { //缓存所有animate后执行 if (!WAIT) { WAIT = true; const cache = data.map((v) => { return v.animate; }); const cloneData: IStoreData = deepcopy(store.getData()); cloneData.block.forEach((v) => { v.animate = []; }); store.setData(cloneData); setTimeout(() => { const cloneData: IStoreData = deepcopy(store.getData()); cloneData.block.forEach((v, i) => { v.animate = cache[i]; }); WAIT = false; store.setData(cloneData); }); } }} >
{content}
{animateTicker.map((v) => { if (v % 10 === 0) { return (
{v}
); } else { return (
); } })}
{ const target = e.target as HTMLDivElement; setState(target.scrollTop); setScrollx(target.scrollLeft); }} style={{ overflow: 'auto', height: `calc(100% - ${itemHeight}px)` }} > {data.map((v) => { return (
{ TimeLineItemMouseMove(e, v.animate, forceUpdate); }} onMouseLeave={() => TimeLineItemMouseOver()} onMouseUp={() => TimeLineItemMouseOver()} > {animateTicker.map((v) => { if (v % 10 === 0) { return (
); } else { return null; } })}
); })}
); } export default TimeLine;