|
|
@@ -1,6 +1,6 @@
|
|
|
-import { useState } from "react";
|
|
|
-import { Link, useNavigate } from "react-router-dom";
|
|
|
-import { Button, Card, Divider } from "antd";
|
|
|
+import { useEffect, useState } from "react";
|
|
|
+import { Link, useNavigate, useSearchParams } from "react-router-dom";
|
|
|
+import { Button, Card, Divider, message } from "antd";
|
|
|
import { useParams } from "react-router-dom";
|
|
|
import { ArrowLeftOutlined } from "@ant-design/icons";
|
|
|
|
|
|
@@ -9,12 +9,52 @@ import CommentAnchor, {
|
|
|
} from "../../../components/discussion/DiscussionAnchor";
|
|
|
import { IComment } from "../../../components/discussion/DiscussionItem";
|
|
|
import DiscussionTopic from "../../../components/discussion/DiscussionTopic";
|
|
|
+import { TResType } from "../../../components/discussion/DiscussionListCard";
|
|
|
+import { get } from "../../../request";
|
|
|
+import { IArticleResponse } from "../../../components/api/Article";
|
|
|
|
|
|
const Widget = () => {
|
|
|
const { id } = useParams(); //url 参数
|
|
|
const navigate = useNavigate();
|
|
|
+ const [searchParams, setSearchParams] = useSearchParams();
|
|
|
const [discussion, setDiscussion] = useState<IComment>();
|
|
|
+ const [topic, setTopic] = useState<IComment>();
|
|
|
const [anchorInfo, setAnchorInfo] = useState<IAnchor>();
|
|
|
+ const isTpl = searchParams.get("tpl");
|
|
|
+ const resId = searchParams.get("resId");
|
|
|
+ const resType = searchParams.get("resType");
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ if (isTpl) {
|
|
|
+ const url = `/v2/article/${id}`;
|
|
|
+ console.log("url", url);
|
|
|
+ get<IArticleResponse>(url).then((json) => {
|
|
|
+ console.log("json", json);
|
|
|
+ if (!json.ok) {
|
|
|
+ message.error(json.message);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const value = json.data;
|
|
|
+ if (typeof value.editor === "undefined" || resId === null) {
|
|
|
+ console.error("no editor or resId");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const topicInfo: IComment = {
|
|
|
+ resId: resId,
|
|
|
+ resType: resType as TResType,
|
|
|
+ user: value.editor,
|
|
|
+ title: value.title,
|
|
|
+ tplId: id,
|
|
|
+ content: value.content,
|
|
|
+ createdAt: value.created_at,
|
|
|
+ updatedAt: value.updated_at,
|
|
|
+ };
|
|
|
+ console.log("topicInfo", topicInfo);
|
|
|
+ setTopic(topicInfo);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }, [id, isTpl, resId, resType]);
|
|
|
+
|
|
|
const href = window.location.href.split("#");
|
|
|
const anchor = href.length > 1 ? href[1] : undefined;
|
|
|
|
|
|
@@ -37,8 +77,8 @@ const Widget = () => {
|
|
|
{anchorInfo ? <Link to={linkOpen}>在翻译界面中打开</Link> : undefined}
|
|
|
|
|
|
<CommentAnchor
|
|
|
- resId={discussion?.resId}
|
|
|
- resType={discussion?.resType}
|
|
|
+ resId={resId ? resId : discussion?.resId}
|
|
|
+ resType={resType ? (resType as TResType) : discussion?.resType}
|
|
|
onLoad={(value: IAnchor) => {
|
|
|
setAnchorInfo(value);
|
|
|
}}
|
|
|
@@ -48,11 +88,13 @@ const Widget = () => {
|
|
|
title={
|
|
|
<Button
|
|
|
type="link"
|
|
|
- disabled={discussion ? false : true}
|
|
|
+ disabled={resId ? false : discussion ? false : true}
|
|
|
icon={<ArrowLeftOutlined />}
|
|
|
onClick={() =>
|
|
|
navigate(
|
|
|
- `/discussion/show/${discussion?.resType}/${discussion?.resId}`
|
|
|
+ `/discussion/show/${resType ? resType : discussion?.resType}/${
|
|
|
+ resId ? resId : discussion?.resId
|
|
|
+ }`
|
|
|
)
|
|
|
}
|
|
|
>
|
|
|
@@ -61,7 +103,9 @@ const Widget = () => {
|
|
|
}
|
|
|
>
|
|
|
<DiscussionTopic
|
|
|
- topicId={id}
|
|
|
+ resType={resType ? (resType as TResType) : undefined}
|
|
|
+ topicId={isTpl ? undefined : id}
|
|
|
+ topic={topic}
|
|
|
focus={anchor}
|
|
|
onTopicReady={(value: IComment) => {
|
|
|
console.log("onTopicReady");
|