2
0
visuddhinanda 3 жил өмнө
parent
commit
48c7497078

+ 52 - 0
dashboard/src/components/anthology/AnthologySelect.tsx

@@ -0,0 +1,52 @@
+import { Select } from "antd";
+import { useEffect, useState } from "react";
+import { get } from "../../request";
+import { IAnthologyListResponse } from "../api/Article";
+
+interface IOptions {
+  value: string;
+  label: string;
+}
+interface IWidget {
+  studioName?: string;
+  onSelect?: Function;
+}
+const Widget = ({ studioName, onSelect }: IWidget) => {
+  const [anthology, setAnthology] = useState<IOptions[]>([
+    { value: "all", label: "全部" },
+    { value: "none", label: "没有加入文集的" },
+  ]);
+  useEffect(() => {
+    let url = `/v2/anthology?view=studio&name=${studioName}`;
+    get<IAnthologyListResponse>(url).then((json) => {
+      if (json.ok) {
+        const data = json.data.rows.map((item) => {
+          return {
+            value: item.uid,
+            label: item.title,
+          };
+        });
+        setAnthology([
+          { value: "all", label: "全部" },
+          { value: "none", label: "没有加入文集的" },
+          ...data,
+        ]);
+      }
+    });
+  }, [studioName]);
+  return (
+    <Select
+      defaultValue="all"
+      style={{ width: 180 }}
+      onChange={(value: string) => {
+        console.log(`selected ${value}`);
+        if (typeof onSelect !== "undefined") {
+          onSelect(value);
+        }
+      }}
+      options={anthology}
+    />
+  );
+};
+
+export default Widget;

+ 46 - 0
dashboard/src/components/article/AddToAnthology.tsx

@@ -0,0 +1,46 @@
+import { Button, message } from "antd";
+import React from "react";
+import { post } from "../../request";
+import AnthologyModal from "../anthology/AnthologyModal";
+import { IArticleMapAddRequest, IArticleMapAddResponse } from "../api/Article";
+interface IWidget {
+  trigger?: React.ReactNode;
+  studioName?: string;
+  articleIds?: string[];
+  onFinally?: Function;
+}
+const Widget = ({ trigger, studioName, articleIds, onFinally }: IWidget) => {
+  return (
+    <AnthologyModal
+      studioName={studioName}
+      trigger={trigger ? trigger : <Button type="link">加入文集</Button>}
+      onSelect={(id: string) => {
+        if (typeof articleIds !== "undefined") {
+          post<IArticleMapAddRequest, IArticleMapAddResponse>(
+            "/v2/article-map",
+            {
+              anthology_id: id,
+              article_id: articleIds,
+              operation: "add",
+            }
+          )
+            .finally(() => {
+              if (typeof onFinally !== "undefined") {
+                onFinally();
+              }
+            })
+            .then((json) => {
+              if (json.ok) {
+                message.success(json.data);
+              } else {
+                message.error(json.message);
+              }
+            })
+            .catch((e) => console.error(e));
+        }
+      }}
+    />
+  );
+};
+
+export default Widget;

+ 17 - 0
dashboard/src/components/general/ReadonlyLabel.tsx

@@ -0,0 +1,17 @@
+import { Space, Tooltip, Typography } from "antd";
+import { QuestionCircleOutlined } from "@ant-design/icons";
+const { Text } = Typography;
+const Widget = () => {
+  return (
+    <Tooltip placement="top" title={"您可能没有登录,或者没有修改权限。"}>
+      <Text type="warning">
+        <Space>
+          {"只读"}
+          <QuestionCircleOutlined />
+        </Space>
+      </Text>
+    </Tooltip>
+  );
+};
+
+export default Widget;