visuddhinanda 1 месяц назад
Родитель
Сommit
ca27db6cb6

+ 5 - 1
api-v12/app/Http/Api/MdRender.php

@@ -346,7 +346,11 @@ class MdRender
                 /**html tex text simple markdown */
                 if (isset($tplProps)) {
                     if (is_array($tplProps)) {
-                        return $tplProps[0];
+                        if (isset($tplProps[0])) {
+                            return $tplProps[0];
+                        } else {
+                            return '';
+                        }
                     } else {
                         return $tplProps;
                     }

+ 34 - 7
api-v12/app/Http/Api/TemplateRender.php

@@ -22,6 +22,8 @@ use App\Http\Api\PaliTextApi;
 
 use App\Tools\Tools;
 
+use App\Services\ArticleService;
+
 class TemplateRender
 {
     protected $param = [];
@@ -159,18 +161,43 @@ class TemplateRender
                 $result = $this->render_ai();
                 break;
             default:
-                # code...
-                $result = [
-                    'props' => base64_encode(\json_encode([])),
-                    'html' => '',
-                    'tag' => 'span',
-                    'tpl' => 'unknown',
-                ];
+                if (mb_substr($tpl_name, 0, 4, "UTF-8") === 'Tpl:') {
+                    $result = $this->render_tpl($tpl_name);
+                } else {
+                    $result = [
+                        'props' => base64_encode(\json_encode([])),
+                        'html' => '',
+                        'tag' => 'span',
+                        'tpl' => 'unknown',
+                    ];
+                }
+
                 break;
         }
         return $result;
     }
 
+    public function render_tpl($name)
+    {
+        $article = app(ArticleService::class)->getRawByTitle($name);
+        $content = $article->content;
+        if (count($this->param) > 0) {
+            $m = new \Mustache_Engine(array(
+                'entity_flags' => ENT_QUOTES,
+                'escape' => function ($value) {
+                    return $value;
+                }
+            ));
+            $content = $m->render($content, $this->param);
+        }
+        return [
+            'props' => base64_encode(\json_encode(['content' => $content])),
+            'html' => $content,
+            'tag' => 'span',
+            'tpl' => 'tpl',
+        ];
+    }
+
     public function getTermProps($word, $tag = null, $channel = null)
     {
         if ($channel && !empty($channel)) {

+ 18 - 0
api-v12/app/Services/ArticleService.php

@@ -0,0 +1,18 @@
+<?php
+
+namespace App\Services;
+
+use App\Models\Article;
+
+class ArticleService
+{
+    public function getRawById(string $id)
+    {
+        return Article::find($id);
+    }
+    public function getRawByTitle(string $title)
+    {
+        $article = Article::where('title', $title)->first();
+        return $article;
+    }
+}

+ 2 - 1
dashboard-v6/src/api/article.ts

@@ -406,6 +406,7 @@ export const updateArticle = (
   articleId: string,
   data: IArticleDataRequest
 ): Promise<IArticleResponse> => {
+  console.debug("updateArticle", articleId);
   return put<IArticleDataRequest, IArticleResponse>(
     `/api/v2/article/${articleId}`,
     data
@@ -531,7 +532,7 @@ export const fetchArticleList = (
     parts.push(`order=${orderBy}`, `dir=${dir}`);
   }
 
-  const url = `/v2/article?${parts.join("&")}`;
+  const url = `/api/v2/article?${parts.join("&")}`;
   return get<IArticleListResponse>(url);
 };
 

+ 1 - 1
dashboard-v6/src/components/anthology/AddToAnthology.tsx

@@ -49,7 +49,7 @@ const AddToAnthologyWidget = ({
   const handleSelect = (id: string) => {
     if (!articleIds) return;
 
-    post<IArticleMapAddRequest, IArticleMapAddResponse>("/v2/article-map", {
+    post<IArticleMapAddRequest, IArticleMapAddResponse>("/api/v2/article-map", {
       anthology_id: id,
       article_id: articleIds,
       operation: "add",

+ 2 - 2
dashboard-v6/src/components/article/ArticleCreate.tsx

@@ -44,7 +44,7 @@ const ArticleCreateWidget = ({
   console.log("parentId", parentId);
   useEffect(() => {
     if (parentId) {
-      get<IArticleResponse>(`/v2/article/${parentId}`).then((json) => {
+      get<IArticleResponse>(`/api/v2/article/${parentId}`).then((json) => {
         console.log("article", json);
 
         if (json.ok) {
@@ -73,7 +73,7 @@ const ArticleCreateWidget = ({
           values.studio = studio;
           values.parentId = parentId ? parentId : undefined;
           const res = await post<IArticleCreateRequest, IArticleResponse>(
-            `/v2/article`,
+            `/api/v2/article`,
             values
           );
           console.log(res);

+ 11 - 18
dashboard-v6/src/components/article/ArticlePrevDrawer.tsx

@@ -1,5 +1,5 @@
 import { Drawer, Typography } from "antd";
-import React, { useEffect, useState } from "react";
+import React, { useState } from "react";
 import { put } from "../../request";
 import type { IArticleDataResponse, IArticleResponse } from "../../api/article";
 import ArticleLayout from "./components/ArticleLayout";
@@ -16,27 +16,15 @@ interface IWidget {
   articleId: string;
 }
 
-const ArticlePrevDrawerWidget = ({
-  trigger,
-  title,
-  content,
-  articleId,
-}: IWidget) => {
+const ArticlePrevDrawer = ({ trigger, title, content, articleId }: IWidget) => {
   const [articleData, setArticleData] = useState<IArticleDataResponse>();
   const [open, setOpen] = useState(false);
   const [errorMsg, setErrorMsg] = useState<string>();
 
   const showDrawer = () => {
-    setOpen(true);
-  };
-
-  const onClose = () => {
-    setOpen(false);
-  };
-
-  useEffect(() => {
+    console.info("ArticlePrevDrawer save");
     put<IArticlePrevRequest, IArticleResponse>(
-      `/v2/article-preview/${articleId}`,
+      `/api/v2/article-preview/${articleId}`,
       {
         content: content ? content : "",
       }
@@ -52,7 +40,12 @@ const ArticlePrevDrawerWidget = ({
       .catch((e: IArticleResponse) => {
         setErrorMsg(e.message);
       });
-  }, [articleId, content]);
+    setOpen(true);
+  };
+
+  const onClose = () => {
+    setOpen(false);
+  };
 
   return (
     <>
@@ -84,4 +77,4 @@ const ArticlePrevDrawerWidget = ({
   );
 };
 
-export default ArticlePrevDrawerWidget;
+export default ArticlePrevDrawer;

+ 1 - 1
dashboard-v6/src/components/discussion/DiscussionAnchor.tsx

@@ -73,7 +73,7 @@ const DiscussionAnchorWidget = ({
           .finally(() => setLoading(false));
         break;
       case "article":
-        url = `/v2/article/${resId}`;
+        url = `/api/v2/article/${resId}`;
         console.info("url", url);
         setLoading(true);
 

+ 3 - 0
dashboard-v6/src/components/template/MdTpl.tsx

@@ -12,6 +12,7 @@ import SentEdit from "./SentEdit";
 import SentRead from "./SentRead";
 import Term from "./Term";
 import Toggle from "./Toggle";
+import Tpl from "./Tpl";
 import Video from "./Video";
 import WbwSent from "./WbwSent";
 import Wd from "./Wd";
@@ -57,6 +58,8 @@ const Widget = ({ tpl, props, children }: IWidgetMdTpl) => {
       return <Confidence props={props ? props : ""} />;
     case "paragraph":
       return <Paragraph props={props ? props : ""} />;
+    case "tpl":
+      return <Tpl props={props ? props : ""} />;
     default:
       return <>未定义模版({tpl})</>;
   }

+ 22 - 0
dashboard-v6/src/components/template/Tpl.tsx

@@ -0,0 +1,22 @@
+import Marked from "../general/Marked";
+
+interface IWidget {
+  content: string;
+}
+const TplCtl = ({ content }: IWidget) => {
+  return <Marked text={content} />;
+};
+
+interface IWidgetTerm {
+  props: string;
+}
+const Widget = ({ props }: IWidgetTerm) => {
+  const prop = JSON.parse(atob(props)) as IWidget;
+  return (
+    <>
+      <TplCtl {...prop} />
+    </>
+  );
+};
+
+export default Widget;