visuddhinanda 1 年之前
父節點
當前提交
619b5d86c2
共有 1 個文件被更改,包括 51 次插入0 次删除
  1. 51 0
      dashboard-v4/dashboard/src/components/template/Ai.tsx

+ 51 - 0
dashboard-v4/dashboard/src/components/template/Ai.tsx

@@ -0,0 +1,51 @@
+import { useEffect, useState } from "react";
+import { IAiModel, IAiModelResponse } from "../api/ai";
+import { get } from "../../request";
+import { Alert, Tag, Typography } from "antd";
+const { Text } = Typography;
+
+interface IAiCtl {
+  model?: string;
+}
+const AiCtl = ({ model }: IAiCtl) => {
+  const [curr, setCurr] = useState<IAiModel>();
+  useEffect(() => {
+    const url = `/v2/ai-model/${model}`;
+    console.info("api request", url);
+    get<IAiModelResponse>(url).then((json) => {
+      console.info("api response", json);
+      if (json.ok) {
+        setCurr(json.data);
+      }
+    });
+  }, [model]);
+  return (
+    <Alert
+      message={
+        <div>
+          <Text strong style={{ display: "block" }}>
+            {curr?.name}
+          </Text>
+          <Tag>{curr?.model}</Tag>
+          <Text>{curr?.url}</Text>
+        </div>
+      }
+      type="info"
+    />
+  );
+};
+
+interface IWidget {
+  props: string;
+}
+const Widget = ({ props }: IWidget) => {
+  const prop = JSON.parse(atob(props)) as IAiCtl;
+  console.log(prop);
+  return (
+    <>
+      <AiCtl {...prop} />
+    </>
+  );
+};
+
+export default Widget;