Просмотр исходного кода

页面载入时读取url参数设置编辑模式

visuddhinanda 3 лет назад
Родитель
Сommit
08ae4b3e7f

+ 10 - 3
dashboard/src/components/article/Article.tsx

@@ -1,7 +1,9 @@
 import { message } from "antd";
 import { message } from "antd";
 import { useEffect, useState } from "react";
 import { useEffect, useState } from "react";
+import { modeChange } from "../../reducers/article-mode";
 
 
 import { get } from "../../request";
 import { get } from "../../request";
+import store from "../../store";
 import { IArticleDataResponse, IArticleResponse } from "../api/Article";
 import { IArticleDataResponse, IArticleResponse } from "../api/Article";
 import ArticleView from "./ArticleView";
 import ArticleView from "./ArticleView";
 
 
@@ -28,6 +30,7 @@ const Widget = ({
 }: IWidgetArticle) => {
 }: IWidgetArticle) => {
   const [articleData, setArticleData] = useState<IArticleDataResponse>();
   const [articleData, setArticleData] = useState<IArticleDataResponse>();
   const [articleMode, setArticleMode] = useState<ArticleMode>(mode);
   const [articleMode, setArticleMode] = useState<ArticleMode>(mode);
+
   let channels: string[] = [];
   let channels: string[] = [];
   if (typeof articleId !== "undefined") {
   if (typeof articleId !== "undefined") {
     const aId = articleId.split("_");
     const aId = articleId.split("_");
@@ -37,15 +40,19 @@ const Widget = ({
   }
   }
 
 
   useEffect(() => {
   useEffect(() => {
+    console.log("mode", mode, articleMode);
     if (!active) {
     if (!active) {
       return;
       return;
     }
     }
-    if (mode !== "read" && articleMode !== "read") {
-      setArticleMode(mode);
+    setArticleMode(mode);
+    //发布mode变更
+    store.dispatch(modeChange(mode));
+
+    if (mode !== articleMode && mode !== "read" && articleMode !== "read") {
       console.log("set mode", mode, articleMode);
       console.log("set mode", mode, articleMode);
       return;
       return;
     }
     }
-    setArticleMode(mode);
+
     if (typeof type !== "undefined" && typeof articleId !== "undefined") {
     if (typeof type !== "undefined" && typeof articleId !== "undefined") {
       get<IArticleResponse>(`/v2/${type}/${articleId}/${mode}`).then((json) => {
       get<IArticleResponse>(`/v2/${type}/${articleId}/${mode}`).then((json) => {
         if (json.ok) {
         if (json.ok) {

+ 1 - 1
dashboard/src/components/article/ArticleCard.tsx

@@ -59,7 +59,7 @@ const Widget = ({
           value: "read",
           value: "read",
         },
         },
         {
         {
-          label: intl.formatMessage({ id: "buttons.edit" }),
+          label: intl.formatMessage({ id: "buttons.translate" }),
           value: "edit",
           value: "edit",
         },
         },
         {
         {

+ 1 - 0
dashboard/src/pages/library/article/show.tsx

@@ -18,6 +18,7 @@ import ProTabs from "../../../components/article/ProTabs";
  */
  */
 const Widget = () => {
 const Widget = () => {
   const { type, id, mode = "read" } = useParams(); //url 参数
   const { type, id, mode = "read" } = useParams(); //url 参数
+  console.log("mode", mode);
   const [articleMode, setArticleMode] = useState<ArticleMode>(
   const [articleMode, setArticleMode] = useState<ArticleMode>(
     mode as ArticleMode
     mode as ArticleMode
   );
   );