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

Merge pull request #1893 from visuddhinanda/agile

语法手册增加新建按钮
visuddhinanda 2 лет назад
Родитель
Сommit
7735490d7e

+ 49 - 0
dashboard/src/components/term/GrammarBook.tsx

@@ -4,6 +4,7 @@ import {
   ArrowLeftOutlined,
   FieldTimeOutlined,
   MoreOutlined,
+  FileAddOutlined,
 } from "@ant-design/icons";
 
 import { ITerm, getGrammar } from "../../reducers/term-vocabulary";
@@ -21,6 +22,14 @@ import GrammarRecent, {
   popRecent,
   pushRecent,
 } from "./GrammarRecent";
+import { useIntl } from "react-intl";
+import TermModal from "./TermModal";
+import { get } from "../../request";
+import {
+  IApiResponseChannelData,
+  IApiResponseChannelList,
+} from "../api/Channel";
+import { grammarTermFetch } from "../../load";
 
 const { Search } = Input;
 
@@ -29,14 +38,30 @@ interface IGrammarList {
   weight: number;
 }
 const GrammarBookWidget = () => {
+  const intl = useIntl();
+
   const [result, setResult] = useState<IGrammarList[]>();
   const [termId, setTermId] = useState<string>();
   const [termSearch, setTermSearch] = useState<string>();
   const [showRecent, setShowRecent] = useState(false);
+  const [create, setCreate] = useState(false);
+  const [grammarChannel, setGrammarChannel] =
+    useState<IApiResponseChannelData>();
   const sysGrammar = useAppSelector(getGrammar);
   const searchWord = useAppSelector(grammarWord);
   const searchWordId = useAppSelector(grammarWordId);
 
+  useEffect(() => {
+    const url = `/v2/channel?view=system`;
+    get<IApiResponseChannelList>(url).then((json) => {
+      if (json.ok) {
+        const channel = json.data.rows.find(
+          (value) => value.name === "_System_Grammar_Term_zh-hans_"
+        );
+        setGrammarChannel(channel);
+      }
+    });
+  }, []);
   useEffect(() => {
     console.debug("grammar book", searchWord);
     if (searchWord && searchWord.length > 0) {
@@ -137,12 +162,26 @@ const GrammarBookWidget = () => {
                 label: "最近查询",
                 icon: <FieldTimeOutlined />,
               },
+              {
+                key: "create",
+                label: intl.formatMessage({ id: "buttons.create" }),
+                icon: <FileAddOutlined />,
+                children: [
+                  {
+                    key: "create_collection",
+                    label: "固定搭配",
+                  },
+                ],
+              },
             ],
             onClick: (e) => {
               switch (e.key) {
                 case "recent":
                   setShowRecent(true);
                   break;
+                case "create_collection":
+                  setCreate(true);
+                  break;
               }
             },
           }}
@@ -197,6 +236,16 @@ const GrammarBookWidget = () => {
           />
         )}
       </div>
+      <TermModal
+        parentChannelId={grammarChannel?.uid}
+        tags={[":collection:"]}
+        open={create}
+        onClose={() => setCreate(false)}
+        onUpdate={() => {
+          //获取语法术语表
+          grammarTermFetch();
+        }}
+      />
     </div>
   );
 };

+ 4 - 2
dashboard/src/components/term/TermEdit.tsx

@@ -61,6 +61,7 @@ export interface ITerm {
 interface IWidget {
   id?: string;
   word?: string;
+  tags?: string[];
   studioName?: string;
   channelId?: string;
   parentChannelId?: string;
@@ -71,6 +72,7 @@ interface IWidget {
 const TermEditWidget = ({
   id,
   word,
+  tags,
   channelId,
   studioName,
   parentChannelId,
@@ -210,7 +212,7 @@ const TermEditWidget = ({
           let url: string;
           let data: ITerm = {
             word: word ? word : "",
-            tag: "",
+            tag: tags?.join(),
             meaning: "",
             meaning2: [],
             note: "",
@@ -276,7 +278,7 @@ const TermEditWidget = ({
             console.log(res);
             data = {
               word: word ? word : "",
-              tag: "",
+              tag: tags?.join(),
               meaning: "",
               meaning2: [],
               note: "",

+ 3 - 0
dashboard/src/components/term/TermModal.tsx

@@ -9,6 +9,7 @@ interface IWidget {
   open?: boolean;
   id?: string;
   word?: string;
+  tags?: string[];
   studioName?: string;
   channelId?: string;
   parentChannelId?: string;
@@ -22,6 +23,7 @@ const TermModalWidget = ({
   open = false,
   id,
   word,
+  tags,
   studioName,
   channelId,
   parentChannelId,
@@ -91,6 +93,7 @@ const TermModalWidget = ({
         <TermEdit
           id={id}
           word={word}
+          tags={tags}
           studioName={studioName}
           channelId={channelId}
           parentChannelId={parentChannelId}

+ 15 - 8
dashboard/src/load.ts

@@ -51,6 +51,18 @@ interface INissayaEndingResponse {
     count: number;
   };
 }
+
+export const grammarTermFetch = () => {
+  //获取语法术语表
+  get<ITermResponse>(`/v2/term-vocabulary?view=grammar&lang=` + getLang()).then(
+    (json) => {
+      if (json.ok) {
+        console.debug("grammar dispatch", json.data.rows);
+        store.dispatch(grammar(json.data.rows));
+      }
+    }
+  );
+};
 const init = () => {
   get<ISiteInfoResponse | IErrorResponse>("/v2/siteinfo/en").then(
     (response) => {
@@ -97,15 +109,10 @@ const init = () => {
     const json: ISettingItem[] = JSON.parse(setting);
     store.dispatch(refreshSetting(json));
   }
+
   //获取语法术语表
-  get<ITermResponse>(`/v2/term-vocabulary?view=grammar&lang=` + getLang()).then(
-    (json) => {
-      if (json.ok) {
-        console.debug("grammar dispatch", json.data.rows);
-        store.dispatch(grammar(json.data.rows));
-      }
-    }
-  );
+  grammarTermFetch();
+
   //获取术语表
   get<ITermResponse>(
     `/v2/term-vocabulary?view=community&lang=` + getLang()