فهرست منبع

onTitle 改变网页标题

visuddhinanda 2 سال پیش
والد
کامیت
e94bdd18db
2فایلهای تغییر یافته به همراه15 افزوده شده و 4 حذف شده
  1. 12 0
      dashboard/src/components/article/Article.tsx
  2. 3 4
      dashboard/src/pages/library/article/show.tsx

+ 12 - 0
dashboard/src/components/article/Article.tsx

@@ -57,6 +57,7 @@ interface IWidget {
   onFinal?: Function;
   onLoad?: Function;
   onAnthologySelect?: Function;
+  onTitle?: Function;
 }
 const ArticleWidget = ({
   type,
@@ -75,6 +76,7 @@ const ArticleWidget = ({
   onFinal,
   onLoad,
   onAnthologySelect,
+  onTitle,
 }: IWidget) => {
   return (
     <div>
@@ -143,6 +145,16 @@ const ArticleWidget = ({
               onArticleChange(type, id, target, param);
             }
           }}
+          onLoad={(data: IArticleDataResponse) => {
+            if (typeof onLoad !== "undefined") {
+              onLoad(data);
+            }
+          }}
+          onTitle={(value: string) => {
+            if (typeof onTitle !== "undefined") {
+              onTitle(value);
+            }
+          }}
         />
       ) : type === "page" ? (
         <TypePage

+ 3 - 4
dashboard/src/pages/library/article/show.tsx

@@ -397,12 +397,11 @@ const Widget = () => {
                   navigate(url);
                 }
               }}
+              onTitle={(value: string) => {
+                document.title = value.slice(0, 128);
+              }}
               onLoad={(article: IArticleDataResponse) => {
                 setLoadedArticleData(article);
-                const windowTitle = article.title_text
-                  ? article.title_text
-                  : article.title;
-                document.title = windowTitle.slice(0, 128);
                 const paramTopic = searchParams.get("topic");
                 const paramComment = searchParams.get("comment");
                 const paramType = searchParams.get("dis_type");