add timeline resize

This commit is contained in:
hufeixiong
2021-08-16 21:06:23 +08:00
parent 8d23f9477c
commit 085a49b8fc
5 changed files with 140 additions and 23 deletions

View File

@@ -2,7 +2,7 @@
* @Author: yehuozhili * @Author: yehuozhili
* @Date: 2021-03-14 05:00:20 * @Date: 2021-03-14 05:00:20
* @LastEditors: yehuozhili * @LastEditors: yehuozhili
* @LastEditTime: 2021-07-09 01:34:14 * @LastEditTime: 2021-08-16 17:06:51
* @FilePath: \dooringx\packages\dooringx-lib\.eslintrc.js * @FilePath: \dooringx\packages\dooringx-lib\.eslintrc.js
*/ */
module.exports = { module.exports = {

View File

@@ -94,6 +94,18 @@ const SortableList = SortableContainer(
} }
); );
const moveState = {
startX: 0,
startY: 0,
isMove: false,
};
const mouseUp = () => {
if (moveState.isMove) {
moveState.isMove = false;
}
};
export function Control(props: PropsWithChildren<ControlProps>) { export function Control(props: PropsWithChildren<ControlProps>) {
const { style } = props; const { style } = props;
const [visible, setVisible] = useState(false); const [visible, setVisible] = useState(false);
@@ -136,16 +148,33 @@ export function Control(props: PropsWithChildren<ControlProps>) {
></SortableList> ></SortableList>
</div> </div>
); );
const [xy, setXy] = useState({ x: 0, y: 0 });
return ( return (
<> <>
<div <div
className="ant-menu" 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={{ style={{
display: 'flex', display: 'flex',
flexDirection: 'column', flexDirection: 'column',
justifyContent: 'center', justifyContent: 'center',
alignItems: 'center', alignItems: 'center',
transform: `translate(${xy.x}px,${xy.y}px)`,
...style, ...style,
}} }}
> >

View File

@@ -2,7 +2,7 @@
* @Author: yehuozhili * @Author: yehuozhili
* @Date: 2021-02-04 10:32:45 * @Date: 2021-02-04 10:32:45
* @LastEditors: yehuozhili * @LastEditors: yehuozhili
* @LastEditTime: 2021-08-12 15:50:48 * @LastEditTime: 2021-08-16 20:32:23
* @FilePath: \dooringx\packages\dooringx-lib\src\components\leftConfig.tsx * @FilePath: \dooringx\packages\dooringx-lib\src\components\leftConfig.tsx
*/ */
import React, { ReactNode, useEffect, useMemo, useState } from 'react'; import React, { ReactNode, useEffect, useMemo, useState } from 'react';
@@ -158,8 +158,8 @@ function LeftConfig(props: LeftConfigProps) {
style={{ flex: 1 }} style={{ flex: 1 }}
defaultSelectedKeys={[menuSelect]} defaultSelectedKeys={[menuSelect]}
mode="vertical" mode="vertical"
inlineCollapsed={props.showName ? false : true} inlineCollapsed={props.showName ? undefined : true}
className={`${styles.menuWidth} ${styles.menus}`} className={`${styles.menuWidth} ${styles.menus} yh-menu`}
> >
{leftMapRenderListCategory.map((v, i) => { {leftMapRenderListCategory.map((v, i) => {
return ( return (
@@ -167,14 +167,18 @@ function LeftConfig(props: LeftConfigProps) {
key={i} key={i}
onClick={() => setMenuSelect(i + '')} onClick={() => setMenuSelect(i + '')}
icon={v.icon} icon={v.icon}
className={props.mode === 'vertical' ? `${styles.menuStyle} ${styles.menus}` : ''} className={
props.mode === 'vertical'
? `${styles.menuStyle} ${styles.menus} yh-menuitem`
: 'yh-menuitem'
}
> >
{props.showName && v.displayName} {props.showName && v.displayName}
</Menu.Item> </Menu.Item>
); );
})} })}
</Menu> </Menu>
<div className={`${styles.menu_footer}`}>{props.footerConfig}</div> <div className={`${styles.menu_footer} yh-menufooter`}>{props.footerConfig}</div>
<Menu selectedKeys={[]}> <Menu selectedKeys={[]}>
<Menu.Item <Menu.Item
key="1" key="1"

View File

@@ -2,7 +2,7 @@
* @Author: yehuozhili * @Author: yehuozhili
* @Date: 2021-08-09 15:15:25 * @Date: 2021-08-09 15:15:25
* @LastEditors: yehuozhili * @LastEditors: yehuozhili
* @LastEditTime: 2021-08-16 11:20:59 * @LastEditTime: 2021-08-16 20:30:03
* @FilePath: \dooringx\packages\dooringx-lib\src\components\timeLine\timeline.tsx * @FilePath: \dooringx\packages\dooringx-lib\src\components\timeLine\timeline.tsx
*/ */
import deepcopy from 'deepcopy'; import deepcopy from 'deepcopy';
@@ -18,7 +18,9 @@ import {
TimeLineItemMouseMove, TimeLineItemMouseMove,
TimeLineItemMouseOver, TimeLineItemMouseOver,
interval, interval,
iter,
} from './timelineItem'; } from './timelineItem';
import { specialCoList } from '../../core/utils/special';
export interface TimeLineProps { export interface TimeLineProps {
style?: CSSProperties; style?: CSSProperties;
@@ -26,7 +28,6 @@ export interface TimeLineProps {
config: UserConfig; config: UserConfig;
} }
const iter = 500;
const animateTicker = new Array(iter).fill(1).map((_, y) => y); const animateTicker = new Array(iter).fill(1).map((_, y) => y);
const DragHandle = SortableHandle(() => <MenuOutlined />); const DragHandle = SortableHandle(() => <MenuOutlined />);
@@ -50,6 +51,18 @@ const SortableItem = SortableElement(
}} }}
> >
<div <div
onClick={() => {
const store = value.config.getStore();
const clone = deepcopy(store.getData());
clone.block.forEach((v) => {
if (v.id === value.value.id && !specialCoList.includes(value.value.name)) {
v.focus = true;
} else {
v.focus = false;
}
});
store.setData(clone);
}}
style={{ style={{
display: 'flex', display: 'flex',
alignItems: 'center', alignItems: 'center',
@@ -58,6 +71,8 @@ const SortableItem = SortableElement(
minWidth: leftWidth, minWidth: leftWidth,
borderRight: borderColor, borderRight: borderColor,
borderBottom: borderColor, borderBottom: borderColor,
backgroundColor: value.value.focus ? '#eeeeee' : 'initial',
cursor: 'pointer',
}} }}
> >
<div style={{ width: 30, cursor: 'move' }}> <div style={{ width: 30, cursor: 'move' }}>

View File

@@ -2,14 +2,19 @@
* @Author: yehuozhili * @Author: yehuozhili
* @Date: 2021-08-10 20:26:44 * @Date: 2021-08-10 20:26:44
* @LastEditors: yehuozhili * @LastEditors: yehuozhili
* @LastEditTime: 2021-08-11 15:34:46 * @LastEditTime: 2021-08-16 20:29:58
* @FilePath: \dooringx\packages\dooringx-lib\src\components\timeLine\timelineItem.tsx * @FilePath: \dooringx\packages\dooringx-lib\src\components\timeLine\timelineItem.tsx
*/ */
import React from 'react'; import React, { CSSProperties } from 'react';
import { AnimateItem } from '../../core/store/storetype'; import { AnimateItem } from '../../core/store/storetype';
export const iter = 500;
export const itemHeight = 25; export const itemHeight = 25;
export const interval = 19;
const diff = 6; const diff = 6;
const square = 2.5;
const times = interval + 1;
// 需要根据animate属性渲染div // 需要根据animate属性渲染div
export interface TimeLineItemProps { export interface TimeLineItemProps {
@@ -32,18 +37,34 @@ interface MoveStateTypes {
startX: number; startX: number;
isMove: boolean; isMove: boolean;
uid: string; uid: string;
dom: null | HTMLDivElement;
} }
const moveState: MoveStateTypes = { const moveState: MoveStateTypes = {
startX: 0, startX: 0,
isMove: false, isMove: false,
uid: '', uid: '',
dom: null,
}; };
interface resizeStateTypes extends MoveStateTypes {
left: boolean;
}
export const interval = 19; const resizeState: resizeStateTypes = {
const times = interval + 1; startX: 0,
isMove: false,
uid: '',
left: true,
};
const resizeMouseDown = (
e: React.MouseEvent<HTMLDivElement, MouseEvent>,
v: AnimateItem,
left: boolean
) => {
e.stopPropagation();
resizeState.startX = e.screenX;
resizeState.uid = v.uid;
resizeState.isMove = true;
resizeState.left = left;
};
export const TimeLineItemMouseMove = function ( export const TimeLineItemMouseMove = function (
e: React.MouseEvent<HTMLDivElement, MouseEvent>, e: React.MouseEvent<HTMLDivElement, MouseEvent>,
@@ -61,15 +82,51 @@ export const TimeLineItemMouseMove = function (
} }
}); });
moveState.startX = e.screenX; moveState.startX = e.screenX;
} else if (resizeState.isMove) {
const diff = e.screenX - resizeState.startX;
if (resizeState.left) {
animate.forEach((v) => {
if (v.uid === resizeState.uid) {
const count =
v.animationIterationCount === 'infinite' ? 500 : parseInt(v.animationIterationCount);
const f2 = parseFloat((v.animationDelay + diff / times).toFixed(1));
const f = parseFloat((v.animationDuration - (f2 - v.animationDelay) / count).toFixed(1));
v.animationDuration = f2 < 0 ? v.animationDuration : f < 0 ? 0 : f;
v.animationDelay = f2 < 0 ? 0 : f2;
forceUpdate((p) => p + 1);
}
});
} else {
animate.forEach((v) => {
if (v.uid === resizeState.uid) {
const count =
v.animationIterationCount === 'infinite' ? 500 : parseInt(v.animationIterationCount);
const f = parseFloat((v.animationDuration + diff / count / times).toFixed(1));
v.animationDuration = f < 0 ? 0 : f;
forceUpdate((p) => p + 1);
}
});
}
resizeState.startX = e.screenX;
} }
}; };
export const TimeLineItemMouseOver = function () { export const TimeLineItemMouseOver = function () {
moveState.isMove = false; moveState.isMove = false;
moveState.startX = 0; moveState.startX = 0;
moveState.uid = ''; moveState.uid = '';
if (moveState.dom) { resizeState.isMove = false;
moveState.dom.style.cursor = 'default'; resizeState.startX = 0;
} resizeState.uid = '';
};
const commonCss: CSSProperties = {
transform: `rotate(45deg)`,
height: square * 2,
width: square * 2,
position: 'absolute',
background: '#000000',
top: (itemHeight - diff) / 2 - square,
cursor: 'e-resize',
}; };
export function TimeLineItem(props: TimeLineItemProps) { export function TimeLineItem(props: TimeLineItemProps) {
@@ -78,7 +135,7 @@ export function TimeLineItem(props: TimeLineItemProps) {
{props.animate.map((v) => { {props.animate.map((v) => {
const left = v.animationDelay * times + interval; const left = v.animationDelay * times + interval;
const repeat = const repeat =
v.animationIterationCount === 'infinite' ? 500 : parseInt(v.animationIterationCount); v.animationIterationCount === 'infinite' ? iter : parseInt(v.animationIterationCount);
const width = v.animationDuration * times * repeat; const width = v.animationDuration * times * repeat;
const index = v.uid.charCodeAt(0) % 10; const index = v.uid.charCodeAt(0) % 10;
return ( return (
@@ -88,9 +145,6 @@ export function TimeLineItem(props: TimeLineItemProps) {
moveState.startX = e.screenX; moveState.startX = e.screenX;
moveState.uid = v.uid; moveState.uid = v.uid;
moveState.isMove = true; moveState.isMove = true;
const dom = e.target as HTMLDivElement;
dom.style.cursor = 'move';
moveState.dom = dom;
}} }}
style={{ style={{
position: 'absolute', position: 'absolute',
@@ -99,8 +153,23 @@ export function TimeLineItem(props: TimeLineItemProps) {
width: width, width: width,
height: itemHeight - diff, height: itemHeight - diff,
background: bgColor[index], background: bgColor[index],
zIndex: 1,
cursor: 'move',
}} }}
></div> >
<div
style={{ ...commonCss, left: -square }}
onMouseDown={(e) => {
resizeMouseDown(e, v, true);
}}
></div>
<div
style={{ ...commonCss, right: -square }}
onMouseDown={(e) => {
resizeMouseDown(e, v, false);
}}
></div>
</div>
); );
})} })}
</> </>