|
@@ -1,15 +1,76 @@
|
|
|
-import { Button } from "antd";
|
|
|
-import React, { useState, forwardRef, useImperativeHandle } from "react";
|
|
|
+import { Button, Spin, Modal } from "antd";
|
|
|
+import React, { useState, forwardRef, useEffect } from "react";
|
|
|
import { useModel } from "umi";
|
|
|
+import {
|
|
|
+ HistoryList,
|
|
|
+ RevertHistory,
|
|
|
+ DeleteHistory,
|
|
|
+} from "@/api/systemDesigner";
|
|
|
+import { useRequest } from "umi";
|
|
|
|
|
|
-export default forwardRef(function HistoryPanel(props, ref) {
|
|
|
- const {
|
|
|
- showHistory,
|
|
|
- setShowHistory
|
|
|
- } = useModel("appModel");
|
|
|
+type HistoryItem = {
|
|
|
+ id: string;
|
|
|
+ title: string;
|
|
|
+ createdTime: string;
|
|
|
+ json: string;
|
|
|
+};
|
|
|
|
|
|
+export default forwardRef(function HistoryPanel(
|
|
|
+ props: {
|
|
|
+ graphId: string;
|
|
|
+ onRevert: () => void;
|
|
|
+ },
|
|
|
+ ref
|
|
|
+) {
|
|
|
+ const { showHistory, setShowHistory } = useModel("appModel");
|
|
|
+ const [data, setData] = useState<HistoryItem[]>();
|
|
|
+ const { confirm } = Modal;
|
|
|
+ const { run, loading } = useRequest(HistoryList, {
|
|
|
+ manual: true,
|
|
|
+ defaultParams: [{ id: props.graphId }],
|
|
|
+ onSuccess(res) {
|
|
|
+ setData(res?.result);
|
|
|
+ },
|
|
|
+ });
|
|
|
|
|
|
- const ItemComponent = () => {
|
|
|
+ useEffect(() => {
|
|
|
+ if (showHistory && props.graphId) {
|
|
|
+ run({
|
|
|
+ id: props.graphId,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }, [props.graphId, showHistory]);
|
|
|
+
|
|
|
+ const handleDeleteHistory = (id: string) => {
|
|
|
+ confirm({
|
|
|
+ title: "确定要删除该记录吗?",
|
|
|
+ content: "删除后不可恢复",
|
|
|
+ onOk() {
|
|
|
+ DeleteHistory({ id }).then(() => {
|
|
|
+ run({
|
|
|
+ id: props.graphId,
|
|
|
+ });
|
|
|
+ });
|
|
|
+ },
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ const handleRevertHistory = (id: string) => {
|
|
|
+ confirm({
|
|
|
+ title: "确定要恢复该记录吗?",
|
|
|
+ content: "",
|
|
|
+ onOk() {
|
|
|
+ RevertHistory({ id }).then(() => {
|
|
|
+ run({
|
|
|
+ id: props.graphId,
|
|
|
+ });
|
|
|
+ props.onRevert?.();
|
|
|
+ });
|
|
|
+ },
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ const ItemComponent = ({ history }: { history: HistoryItem }) => {
|
|
|
const [showBtn, setShowBtn] = useState(false);
|
|
|
|
|
|
return (
|
|
@@ -19,8 +80,8 @@ export default forwardRef(function HistoryPanel(props, ref) {
|
|
|
onMouseOut={() => setShowBtn(false)}
|
|
|
>
|
|
|
<div className="flex-1">
|
|
|
- <div className="text-sm text-#333">标题xxxxxxxxxxxxxx</div>
|
|
|
- <div className="text-xs text-#999">2024-12-12 20:08:30</div>
|
|
|
+ <div className="text-sm text-#333">手动保存</div>
|
|
|
+ <div className="text-xs text-#999">{history.createdTime}</div>
|
|
|
</div>
|
|
|
{showBtn && (
|
|
|
<div>
|
|
@@ -28,11 +89,15 @@ export default forwardRef(function HistoryPanel(props, ref) {
|
|
|
type="text"
|
|
|
size="small"
|
|
|
icon={<i className="iconfont icon-lishijilu" />}
|
|
|
+ onClick={() => {
|
|
|
+ handleRevertHistory(history.id);
|
|
|
+ }}
|
|
|
/>
|
|
|
<Button
|
|
|
type="text"
|
|
|
size="small"
|
|
|
icon={<i className="iconfont icon-shanchu" />}
|
|
|
+ onClick={() => handleDeleteHistory(history.id)}
|
|
|
/>
|
|
|
</div>
|
|
|
)}
|
|
@@ -55,9 +120,11 @@ export default forwardRef(function HistoryPanel(props, ref) {
|
|
|
</div>
|
|
|
</div>
|
|
|
<div className="flex-1 overflow-y-auto">
|
|
|
- {new Array(100).fill(0).map((_, i) => (
|
|
|
- <ItemComponent key={i} />
|
|
|
- ))}
|
|
|
+ <Spin spinning={loading}>
|
|
|
+ {data?.map((item: HistoryItem, i: number) => (
|
|
|
+ <ItemComponent history={item} key={i} />
|
|
|
+ ))}
|
|
|
+ </Spin>
|
|
|
</div>
|
|
|
</div>
|
|
|
);
|