fix: timeline bug

This commit is contained in:
mozzie 2023-03-24 08:04:11 +08:00
parent 5b398e9c7e
commit fe14dda10c
3 changed files with 67 additions and 34 deletions

View File

@ -85,35 +85,65 @@ export default function Guide(props: IProps) {
};
useEffect(() => {
if (props.defaultValue)
vditorRef.current = new Vditor("vditor", {
height: 600,
cache: {
id: props.id,
enable: false,
vditorRef.current = new Vditor("vditor", {
height: 600,
cache: {
id: props.id,
enable: false,
},
toolbar: [...toolbar, "|", submitTool],
value: props.defaultValue ?? "",
hint: { delay: 200, emoji },
counter: { enable: true },
preview: { actions: ["desktop", "mobile"] },
after: () => console.log("[info] vditor init success..."),
upload: {
accept: "image/*",
url: "/api/vod/oss/image/upload",
multiple: false,
success(_, res) {
const { code, data, msg } = JSON.parse(res);
if (code === 10000) {
message.success("上传成功");
const { name, url } = data;
vditorRef.current?.insertValue(`![${name}](${url})`);
} else {
message.error(msg);
}
},
toolbar: [...toolbar, "|", submitTool],
value: props.defaultValue ?? "",
hint: { delay: 200, emoji },
counter: { enable: true },
preview: { actions: ["desktop", "mobile"] },
after: () => console.log("[info] vditor init success..."),
upload: {
accept: "image/*",
url: "/api/vod/oss/image/upload",
multiple: false,
success(_, res) {
const { code, data, msg } = JSON.parse(res);
if (code === 10000) {
message.success("上传成功");
const { name, url } = data;
vditorRef.current?.insertValue(`![${name}](${url})`);
} else {
message.error(msg);
}
},
},
});
}, []);
useEffect(() => {
vditorRef.current = new Vditor("vditor", {
height: 600,
cache: {
id: props.id,
enable: false,
},
toolbar: [...toolbar, "|", submitTool],
value: props.defaultValue ?? "",
hint: { delay: 200, emoji },
counter: { enable: true },
preview: { actions: ["desktop", "mobile"] },
after: () => console.log("[info] vditor init success..."),
upload: {
accept: "image/*",
url: "/api/vod/oss/image/upload",
multiple: false,
success(_, res) {
const { code, data, msg } = JSON.parse(res);
if (code === 10000) {
message.success("上传成功");
const { name, url } = data;
vditorRef.current?.insertValue(`![${name}](${url})`);
} else {
message.error(msg);
}
},
});
},
});
}, [props.defaultValue]);
return (

View File

@ -80,7 +80,7 @@ function Timeline(props: IProps) {
}, [cursorStatic.top]);
useEffect(() => {
if (props.data && orbitRef.current) {
if (props.data.length > 0 && orbitRef.current) {
setTimelineData(filterYearOnce(props.data));
// 全部的月份数数量平均划分
const avg = orbitRef.current.clientHeight / props.data.length;
@ -90,7 +90,7 @@ function Timeline(props: IProps) {
useEffect(() => {
window.addEventListener("resize", () => {
if (props.data && orbitRef.current) {
if (props.data.length > 0 && orbitRef.current) {
setTimelineData(filterYearOnce(props.data));
// 全部的月份数数量平均划分
const avg = orbitRef.current.clientHeight / props.data.length;
@ -98,7 +98,7 @@ function Timeline(props: IProps) {
}
});
return () => window.removeEventListener("resize", () => {});
}, []);
}, [props.data]);
return (
<div

View File

@ -53,10 +53,13 @@ export default function Index() {
*/
const onTimelineScroll = (p: IOnScrollParam) => {
const { top, height } = p;
//左侧区域高度
const { scrollHeight, clientHeight } = thumbnailRef.current!;
scale.current = (scrollHeight - clientHeight) / height;
thumbnailRef.current!.scrollTop = top * scale.current;
if (thumbnailRef.current) {
//左侧区域高度
const { scrollHeight, clientHeight } = thumbnailRef.current;
if (scrollHeight === clientHeight) return;
scale.current = (scrollHeight - clientHeight) / height;
thumbnailRef.current!.scrollTop = top * scale.current;
}
};
/**