complete custom animate
This commit is contained in:
@@ -1,6 +1,18 @@
|
|||||||
import React, { useMemo, useState } from 'react';
|
import React, { useMemo, useState } from 'react';
|
||||||
import { UserConfig, deepCopy, createUid } from 'dooringx-lib';
|
import { UserConfig, deepCopy, createUid } from 'dooringx-lib';
|
||||||
import { Col, Row, Select, InputNumber, Button, Modal, Form, Space, Input } from 'antd';
|
import {
|
||||||
|
Col,
|
||||||
|
Row,
|
||||||
|
Select,
|
||||||
|
InputNumber,
|
||||||
|
Button,
|
||||||
|
Modal,
|
||||||
|
Form,
|
||||||
|
Space,
|
||||||
|
Input,
|
||||||
|
Table,
|
||||||
|
Popconfirm,
|
||||||
|
} from 'antd';
|
||||||
import { FormMap, FormBaseType } from '../formTypes';
|
import { FormMap, FormBaseType } from '../formTypes';
|
||||||
import { CreateOptionsRes } from 'dooringx-lib/dist/core/components/formTypes';
|
import { CreateOptionsRes } from 'dooringx-lib/dist/core/components/formTypes';
|
||||||
import { AnimateItem, IBlockType, IStoreData } from 'dooringx-lib/dist/core/store/storetype';
|
import { AnimateItem, IBlockType, IStoreData } from 'dooringx-lib/dist/core/store/storetype';
|
||||||
@@ -138,7 +150,46 @@ function AnimateControl(props: AnimateControlProps) {
|
|||||||
|
|
||||||
const [customModal, setCustomModal] = useState(false);
|
const [customModal, setCustomModal] = useState(false);
|
||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
const [positionEnable, setPositionEnable] = useState<boolean[]>([]);
|
|
||||||
|
const [deletModal, setDeletModal] = useState(false);
|
||||||
|
const customAnimate = props.config.animateFactory.getCustomAnimateName();
|
||||||
|
|
||||||
|
const columns = [
|
||||||
|
{
|
||||||
|
title: '动画名称',
|
||||||
|
dataIndex: 'animateName',
|
||||||
|
width: 150,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '显示名称',
|
||||||
|
dataIndex: 'displayName',
|
||||||
|
width: 150,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '动画详情',
|
||||||
|
dataIndex: 'keyframe',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
width: 120,
|
||||||
|
render: (_: any, record: any) => (
|
||||||
|
<Space size="middle">
|
||||||
|
<Popconfirm
|
||||||
|
onConfirm={() => {
|
||||||
|
const name = record.animateName;
|
||||||
|
props.config.animateFactory.deleteCustomAnimate(name);
|
||||||
|
props.config.animateFactory.deleteKeyFrameAnimate(name);
|
||||||
|
props.config.animateFactory.syncToStore(props.config);
|
||||||
|
}}
|
||||||
|
title="确定删除吗?"
|
||||||
|
>
|
||||||
|
<a>删除</a>
|
||||||
|
</Popconfirm>
|
||||||
|
</Space>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Space
|
<Space
|
||||||
@@ -154,7 +205,7 @@ function AnimateControl(props: AnimateControlProps) {
|
|||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setCustomModal(true);
|
setDeletModal(true);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
删除自定义动画
|
删除自定义动画
|
||||||
@@ -192,6 +243,13 @@ function AnimateControl(props: AnimateControlProps) {
|
|||||||
</Select.Option>
|
</Select.Option>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
{customAnimate.map((v) => {
|
||||||
|
return (
|
||||||
|
<Select.Option key={v.animateName} value={v.animateName}>
|
||||||
|
{v.displayName}
|
||||||
|
</Select.Option>
|
||||||
|
);
|
||||||
|
})}
|
||||||
</Select>
|
</Select>
|
||||||
</Col>
|
</Col>
|
||||||
<Col span={5} style={{ paddingLeft: '10px' }}>
|
<Col span={5} style={{ paddingLeft: '10px' }}>
|
||||||
@@ -393,27 +451,14 @@ function AnimateControl(props: AnimateControlProps) {
|
|||||||
onOk={() => {
|
onOk={() => {
|
||||||
form.validateFields().then((res) => {
|
form.validateFields().then((res) => {
|
||||||
const values = { ...res };
|
const values = { ...res };
|
||||||
// 根据禁用情况去除xy
|
|
||||||
const result = values.keyframes.map((v: any, i: number) => {
|
|
||||||
if (!positionEnable[i]) {
|
|
||||||
// 做删除处理
|
|
||||||
return {
|
|
||||||
...v,
|
|
||||||
positionX: null,
|
|
||||||
positionY: null,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return v;
|
|
||||||
});
|
|
||||||
values.keyframes = result;
|
|
||||||
props.config.animateFactory.addUserInputIntoCustom(values, props.config);
|
props.config.animateFactory.addUserInputIntoCustom(values, props.config);
|
||||||
setPositionEnable([]);
|
|
||||||
setCustomModal(false);
|
setCustomModal(false);
|
||||||
|
form.resetFields();
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
onCancel={() => {
|
onCancel={() => {
|
||||||
form.resetFields();
|
|
||||||
setCustomModal(false);
|
setCustomModal(false);
|
||||||
|
form.resetFields();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Form labelCol={{ span: 11 }} form={form}>
|
<Form labelCol={{ span: 11 }} form={form}>
|
||||||
@@ -452,28 +497,26 @@ function AnimateControl(props: AnimateControlProps) {
|
|||||||
>
|
>
|
||||||
<InputNumber min={0} max={100} formatter={(value) => `${value}%`} />
|
<InputNumber min={0} max={100} formatter={(value) => `${value}%`} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
{positionEnable[key] && (
|
|
||||||
<>
|
<>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
style={{ width: 180 }}
|
style={{ width: 180 }}
|
||||||
label="坐标x"
|
label="坐标偏移X"
|
||||||
{...restField}
|
{...restField}
|
||||||
name={[name, 'positionX']}
|
name={[name, 'positionX']}
|
||||||
initialValue={0}
|
initialValue={0}
|
||||||
>
|
>
|
||||||
<InputNumber min={0} />
|
<InputNumber />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
style={{ width: 180 }}
|
style={{ width: 180 }}
|
||||||
label="坐标y"
|
label="坐标偏移Y"
|
||||||
{...restField}
|
{...restField}
|
||||||
name={[name, 'positionY']}
|
name={[name, 'positionY']}
|
||||||
initialValue={0}
|
initialValue={0}
|
||||||
>
|
>
|
||||||
<InputNumber min={0} />
|
<InputNumber />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
</>
|
</>
|
||||||
)}
|
|
||||||
|
|
||||||
<Form.Item
|
<Form.Item
|
||||||
style={{ width: 180 }}
|
style={{ width: 180 }}
|
||||||
@@ -502,23 +545,9 @@ function AnimateControl(props: AnimateControlProps) {
|
|||||||
>
|
>
|
||||||
<InputNumber formatter={(value) => `${value}%`} />
|
<InputNumber formatter={(value) => `${value}%`} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Button
|
|
||||||
onClick={() => {
|
|
||||||
setPositionEnable((pre) => {
|
|
||||||
pre[key] = !pre[key];
|
|
||||||
return [...pre];
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
切换坐标修改
|
|
||||||
</Button>
|
|
||||||
<Button
|
<Button
|
||||||
danger
|
danger
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setPositionEnable((pre) => {
|
|
||||||
pre.splice(key, 1);
|
|
||||||
return [...pre];
|
|
||||||
});
|
|
||||||
remove(name);
|
remove(name);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -530,7 +559,6 @@ function AnimateControl(props: AnimateControlProps) {
|
|||||||
<Button
|
<Button
|
||||||
type="dashed"
|
type="dashed"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setPositionEnable((pre) => [...pre, true]);
|
|
||||||
add();
|
add();
|
||||||
}}
|
}}
|
||||||
block
|
block
|
||||||
@@ -544,6 +572,21 @@ function AnimateControl(props: AnimateControlProps) {
|
|||||||
</Form.List>
|
</Form.List>
|
||||||
</Form>
|
</Form>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
<Modal
|
||||||
|
width={800}
|
||||||
|
title={'删除自定义动画'}
|
||||||
|
forceRender
|
||||||
|
visible={deletModal}
|
||||||
|
footer={null}
|
||||||
|
onOk={() => {
|
||||||
|
setDeletModal(false);
|
||||||
|
}}
|
||||||
|
onCancel={() => {
|
||||||
|
setDeletModal(false);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Table columns={columns} dataSource={customAnimate}></Table>
|
||||||
|
</Modal>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
* @Author: yehuozhili
|
* @Author: yehuozhili
|
||||||
* @Date: 2021-03-14 05:40:37
|
* @Date: 2021-03-14 05:40:37
|
||||||
* @LastEditors: yehuozhili
|
* @LastEditors: yehuozhili
|
||||||
* @LastEditTime: 2021-10-10 00:54:55
|
* @LastEditTime: 2022-04-01 14:29:39
|
||||||
* @FilePath: \dooringx\packages\dooringx-lib\src\components\preview.tsx
|
* @FilePath: \dooringx\packages\dooringx-lib\src\components\preview.tsx
|
||||||
*/
|
*/
|
||||||
import Container from './container';
|
import Container from './container';
|
||||||
@@ -62,10 +62,17 @@ function Preview(props: PreviewProps): ReactElement {
|
|||||||
.syncEventMap(props.config.getStore().getData(), props.config.getStoreChanger());
|
.syncEventMap(props.config.getStore().getData(), props.config.getStoreChanger());
|
||||||
|
|
||||||
// 设置全局
|
// 设置全局
|
||||||
const bodyColor = props.config.getStore().getData().globalState?.bodyColor;
|
const global = props.config.getStore().getData().globalState;
|
||||||
|
const bodyColor = global?.bodyColor;
|
||||||
if (bodyColor) {
|
if (bodyColor) {
|
||||||
document.body.style.backgroundColor = bodyColor;
|
document.body.style.backgroundColor = bodyColor;
|
||||||
}
|
}
|
||||||
|
const customAnimate = global?.customAnimate;
|
||||||
|
if (customAnimate && Array.isArray(customAnimate)) {
|
||||||
|
// 插入自定义动画
|
||||||
|
props.config.animateFactory.fromArrInsertKeyFrame(customAnimate);
|
||||||
|
}
|
||||||
|
|
||||||
if (props.completeFn) {
|
if (props.completeFn) {
|
||||||
props.completeFn();
|
props.completeFn();
|
||||||
}
|
}
|
||||||
|
@@ -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: 2022-01-12 17:44:22
|
* @LastEditTime: 2022-04-01 13:41:34
|
||||||
* @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';
|
||||||
@@ -457,7 +457,13 @@ export function TimeLine(props: TimeLineProps) {
|
|||||||
}}
|
}}
|
||||||
onMouseDown={(e) => {
|
onMouseDown={(e) => {
|
||||||
const dom = e.target as HTMLDivElement;
|
const dom = e.target as HTMLDivElement;
|
||||||
if (!(dom.className && dom.className.indexOf('yh-timeline-item-mainblock') > -1)) {
|
if (
|
||||||
|
!(
|
||||||
|
dom.className &&
|
||||||
|
dom.className.indexOf &&
|
||||||
|
dom.className.indexOf('yh-timeline-item-mainblock') > -1
|
||||||
|
)
|
||||||
|
) {
|
||||||
resetCurrentMoveItemId();
|
resetCurrentMoveItemId();
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
@@ -16,8 +16,8 @@ import { deepCopy } from '../utils';
|
|||||||
export interface TransformItemObj {
|
export interface TransformItemObj {
|
||||||
opacity: number;
|
opacity: number;
|
||||||
percent: number;
|
percent: number;
|
||||||
positionX: number | null;
|
positionX: number;
|
||||||
positionY: number | null;
|
positionY: number;
|
||||||
rotate: number;
|
rotate: number;
|
||||||
scale: number;
|
scale: number;
|
||||||
}
|
}
|
||||||
@@ -48,35 +48,62 @@ export class AnimateFactory {
|
|||||||
*
|
*
|
||||||
* 插入动画
|
* 插入动画
|
||||||
* @param {string} ruleText
|
* @param {string} ruleText
|
||||||
* @param {string} keyframeName 动画名称
|
|
||||||
* @memberof AnimateFactory
|
* @memberof AnimateFactory
|
||||||
*/
|
*/
|
||||||
inserKeyframeAnimate(ruleText: string, keyframeName: string) {
|
inserKeyframeAnimate(ruleText: string) {
|
||||||
const sheets = this.getStyleSheets();
|
const sheets = this.getStyleSheets();
|
||||||
if (sheets.length === 0) {
|
if (sheets.length === 0) {
|
||||||
let style = document.createElement('style');
|
let style = document.createElement('style');
|
||||||
style.appendChild(document.createTextNode(''));
|
style.appendChild(document.createTextNode(''));
|
||||||
document.head.appendChild(style);
|
document.head.appendChild(style);
|
||||||
}
|
}
|
||||||
const len = sheets.length;
|
// const len = sheets.length;
|
||||||
let ss: number | null = null;
|
// let ss: number | null = null;
|
||||||
let st: number | null = null;
|
// let st: number | null = null;
|
||||||
|
// for (let i = 0; i < len; i++) {
|
||||||
|
// for (let k = 0; k < sheets[i].cssRules.length; k++) {
|
||||||
|
// const rule = sheets[i].cssRules[k] as CSSKeyframesRule;
|
||||||
|
// const name = rule?.name;
|
||||||
|
// if (name && name === keyframeName) {
|
||||||
|
// // 删除该keyframe
|
||||||
|
// ss = i;
|
||||||
|
// st = k;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// if (ss !== null && st !== null) {
|
||||||
|
// sheets[ss].deleteRule(st);
|
||||||
|
// }
|
||||||
|
// let sheet = sheets[ss ? ss : sheets.length - 1] as CSSStyleSheet;
|
||||||
|
let sheet = sheets[0] as CSSStyleSheet; // 末尾的经常存在重复覆盖的问题
|
||||||
|
sheet.insertRule(ruleText, sheet.cssRules.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 删除keyframe
|
||||||
|
* @param {string} animateName
|
||||||
|
* @returns
|
||||||
|
* @memberof AnimateFactory
|
||||||
|
*/
|
||||||
|
deleteKeyFrameAnimate(animateName: string) {
|
||||||
|
const sheets = this.getStyleSheets();
|
||||||
|
if (sheets.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const sheet = sheets[0] as CSSStyleSheet;
|
||||||
|
const len = sheet.cssRules.length;
|
||||||
|
let ss = null;
|
||||||
for (let i = 0; i < len; i++) {
|
for (let i = 0; i < len; i++) {
|
||||||
for (let k = 0; k < sheets[i].cssRules.length; k++) {
|
const rule = sheet.cssRules[i] as CSSKeyframesRule;
|
||||||
const rule = sheets[i].cssRules[k] as CSSKeyframesRule;
|
|
||||||
const name = rule?.name;
|
const name = rule?.name;
|
||||||
if (name && name === keyframeName) {
|
if (name && name === animateName) {
|
||||||
// 删除该keyframe
|
|
||||||
ss = i;
|
ss = i;
|
||||||
st = k;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (ss !== null) {
|
||||||
|
sheet.deleteRule(ss);
|
||||||
}
|
}
|
||||||
if (ss !== null && st !== null) {
|
|
||||||
sheets[ss].deleteRule(st);
|
|
||||||
}
|
|
||||||
let sheet = sheets[ss ? ss : sheets.length - 1] as CSSStyleSheet;
|
|
||||||
sheet.insertRule(ruleText, sheet.rules ? sheet.rules.length : sheet.cssRules.length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -106,7 +133,7 @@ export class AnimateFactory {
|
|||||||
*/
|
*/
|
||||||
fromArrInsertKeyFrame(customAnimateName: Array<CustomAnimateObj> = this.customAnimateName) {
|
fromArrInsertKeyFrame(customAnimateName: Array<CustomAnimateObj> = this.customAnimateName) {
|
||||||
customAnimateName.forEach((v) => {
|
customAnimateName.forEach((v) => {
|
||||||
this.inserKeyframeAnimate(v.keyframe, v.animateName);
|
this.inserKeyframeAnimate(v.keyframe);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,18 +172,11 @@ export class AnimateFactory {
|
|||||||
addUserInputIntoCustom(item: TransformItem, config: UserConfig) {
|
addUserInputIntoCustom(item: TransformItem, config: UserConfig) {
|
||||||
// 先转换keyframe
|
// 先转换keyframe
|
||||||
const keyframeItem = item.keyframes.map((v) => {
|
const keyframeItem = item.keyframes.map((v) => {
|
||||||
if (v.positionX !== null && v.positionY !== null) {
|
|
||||||
// 带入xy 否则不计算xy
|
|
||||||
return `${v.percent}% {
|
return `${v.percent}% {
|
||||||
transform:translate(${v.positionX}px, ${v.positionY}px) scale(${(v.scale / 100).toFixed(
|
transform:translate(${v.positionX}px, ${v.positionY}px) scale(${(v.scale / 100).toFixed(
|
||||||
2
|
2
|
||||||
)}) rotate(${v.rotate}deg);
|
)}) rotate(${v.rotate}deg);
|
||||||
}`;
|
}`;
|
||||||
} else {
|
|
||||||
return `${v.percent}% {
|
|
||||||
transform: scale(${(v.scale / 100).toFixed(2)}) rotate(${v.rotate}deg);
|
|
||||||
}`;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
const keyframe = `@keyframes ${item.animateName} {
|
const keyframe = `@keyframes ${item.animateName} {
|
||||||
${keyframeItem.join(' ')}
|
${keyframeItem.join(' ')}
|
||||||
@@ -171,7 +191,7 @@ export class AnimateFactory {
|
|||||||
// 添加内置
|
// 添加内置
|
||||||
this.addCustomAnimate(customAnimateNameArr);
|
this.addCustomAnimate(customAnimateNameArr);
|
||||||
// 插入动画
|
// 插入动画
|
||||||
this.inserKeyframeAnimate(keyframe, item.animateName);
|
this.inserKeyframeAnimate(keyframe);
|
||||||
// 写入store
|
// 写入store
|
||||||
this.syncToStore(config);
|
this.syncToStore(config);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user