Quellcode durchsuchen

Merge pull request #1910 from visuddhinanda/agile

添加逐词解析按钮
visuddhinanda vor 2 Jahren
Ursprung
Commit
47f45bfb26

+ 6 - 0
dashboard/src/components/api/Corpus.ts

@@ -282,3 +282,9 @@ export interface ISentenceSimListResponse {
   message: string;
   data: { rows: ISimSent[]; count: number };
 }
+
+export interface ISentenceWbwListResponse {
+  ok: boolean;
+  message: string;
+  data: { rows: IWidgetSentEditInner[]; count: number };
+}

+ 5 - 1
dashboard/src/components/dict/Dictionary.tsx

@@ -77,7 +77,11 @@ const DictionaryWidget = ({ word, compact = false, onSearch }: IWidget) => {
   return (
     <div ref={setContainer}>
       <div id="pcd_dict_top"></div>
-      <Affix offsetTop={0} target={compact ? () => container : undefined}>
+      <Affix
+        offsetTop={0}
+        target={compact ? () => container : undefined}
+        className="dict_search_div"
+      >
         <div
           style={{
             backgroundColor: "rgba(100,100,100,0.3)",

+ 5 - 1
dashboard/src/components/dict/SearchVocabulary.tsx

@@ -117,9 +117,13 @@ const SearchVocabularyWidget = ({
     console.log("开始计时");
     intervalRef.current = window.setInterval(search, 500, value);
   };
+
   return (
     <div style={{ width: "100%" }}>
       <AutoComplete
+        getPopupContainer={(node: HTMLElement) =>
+          document.getElementsByClassName("dict_search_div")[0] as HTMLElement
+        }
         value={input}
         style={{ width: "100%" }}
         popupClassName="certain-category-search-dropdown"
@@ -153,7 +157,7 @@ const SearchVocabularyWidget = ({
           }}
         />
       </AutoComplete>
-      <Space>
+      <Space style={{ display: "none" }}>
         {factors.map((item, id) => {
           return (
             <Link

+ 20 - 1
dashboard/src/components/template/ParaHandle.tsx

@@ -1,7 +1,8 @@
-import { Button, Dropdown, MenuProps, message } from "antd";
+import { Button, Dropdown, MenuProps, message, notification } from "antd";
 import { useNavigate, useSearchParams } from "react-router-dom";
 import { fullUrl } from "../../utils";
 import { useIntl } from "react-intl";
+import { addToCart } from "./SentEdit/SentCart";
 
 interface IWidgetParaHandleCtl {
   book: number;
@@ -34,12 +35,21 @@ export const ParaHandleCtl = ({
         id: "labels.curr.paragraph.open",
       }),
     },
+    {
+      type: "divider",
+    },
     {
       key: "copy-sent",
       label: intl.formatMessage({
         id: "labels.curr.paragraph.copy.tpl",
       }),
     },
+    {
+      key: "cart-sent",
+      label: intl.formatMessage({
+        id: "labels.curr.paragraph.cart.tpl",
+      }),
+    },
     {
       key: "quote-link-tpl",
       label: intl.formatMessage({
@@ -103,6 +113,15 @@ export const ParaHandleCtl = ({
       case "copy-sent":
         copyToClipboard(sentences.map((item) => `{{${item}}}`).join(""));
         break;
+      case "cart-sent":
+        const cartData = sentences.map((item) => {
+          return { id: `{{${item}}}`, text: `{{${item}}}` };
+        });
+        addToCart(cartData);
+        notification.success({
+          message: cartData.length + "个句子已经添加到Cart",
+        });
+        break;
       case "quote-link-tpl-c":
         copyToClipboard(`{{ql|type=c|book=${book}|para=${para}}}`);
         break;

+ 17 - 1
dashboard/src/components/template/SentEdit/SentCart.tsx

@@ -1,11 +1,27 @@
 import { Badge, Button, List, Popover, Tooltip, Typography } from "antd";
 import { useEffect, useState } from "react";
 import { ShoppingCartOutlined, DeleteOutlined } from "@ant-design/icons";
-import { ISentCart } from "./SentTabCopy";
+
 import "./style.css";
 
 const { Text } = Typography;
 
+export interface ISentCart {
+  id: string;
+  text: string;
+}
+
+export const addToCart = (add: ISentCart[]): number => {
+  const oldText = localStorage.getItem("cart/text");
+  let cartText: ISentCart[] = [];
+  if (oldText) {
+    cartText = JSON.parse(oldText);
+  }
+  cartText = [...cartText, ...add];
+  localStorage.setItem("cart/text", JSON.stringify(cartText));
+  return cartText.length;
+};
+
 const SentCartWidget = () => {
   const [count, setCount] = useState<number>();
   const [sentences, setSentences] = useState<ISentCart[]>();

+ 22 - 0
dashboard/src/components/template/SentEdit/SentTab.tsx

@@ -18,6 +18,7 @@ import { ArticleMode } from "../../article/Article";
 import { IResNumber } from "../SentEdit";
 import SentTabCopy from "./SentTabCopy";
 import { fullUrl } from "../../../utils";
+import SentWbw from "./SentWbw";
 
 const { Text } = Typography;
 
@@ -341,6 +342,27 @@ const SentTabWidget = ({
             />
           ),
         },
+        {
+          label: (
+            <span style={tabButtonStyle}>
+              <span style={{ marginRight: 12 }}>
+                {intl.formatMessage({
+                  id: "buttons.wbw",
+                })}
+              </span>
+            </span>
+          ),
+          key: "wbw",
+          children: (
+            <SentWbw
+              book={parseInt(sId[0])}
+              para={parseInt(sId[1])}
+              wordStart={parseInt(sId[2])}
+              wordEnd={parseInt(sId[3])}
+              channelsId={channelsId}
+            />
+          ),
+        },
         {
           label: <span style={tabButtonStyle}>{"关系图"}</span>,
           key: "relation-graphic",

+ 7 - 12
dashboard/src/components/template/SentEdit/SentTabCopy.tsx

@@ -1,4 +1,4 @@
-import { Dropdown, Tooltip } from "antd";
+import { Dropdown, Tooltip, notification } from "antd";
 import {
   CopyOutlined,
   ShoppingCartOutlined,
@@ -11,11 +11,8 @@ import store from "../../../store";
 import { modeChange } from "../../../reducers/cart-mode";
 import { useAppSelector } from "../../../hooks";
 import { mode as _mode } from "../../../reducers/cart-mode";
+import { addToCart } from "./SentCart";
 
-export interface ISentCart {
-  id: string;
-  text: string;
-}
 interface IWidget {
   text?: string;
   wbwData?: IWbw[];
@@ -50,17 +47,15 @@ const SentTabCopyWidget = ({ text, wbwData }: IWidget) => {
           setTimeout(() => setSuccess(false), 3000);
         });
       } else {
-        const oldText = localStorage.getItem("cart/text");
-        let cartText: ISentCart[] = [];
-        if (oldText) {
-          cartText = JSON.parse(oldText);
-        }
         const paliText = wbwData
           ?.filter((value) => value.type?.value !== ".ctl.")
           .map((item) => item.word.value)
           .join(" ");
-        cartText.push({ id: text, text: paliText ? paliText : "" });
-        localStorage.setItem("cart/text", JSON.stringify(cartText));
+
+        addToCart([{ id: text, text: paliText ? paliText : "" }]);
+        notification.success({
+          message: "句子已经添加到Cart",
+        });
         setSuccess(true);
         setTimeout(() => setSuccess(false), 3000);
       }

+ 74 - 0
dashboard/src/components/template/SentEdit/SentWbw.tsx

@@ -0,0 +1,74 @@
+import { List, message } from "antd";
+import { useEffect, useState } from "react";
+
+import { get } from "../../../request";
+import { ISentenceWbwListResponse } from "../../api/Corpus";
+import { IWidgetSentEditInner, SentEditInner } from "../SentEdit";
+
+interface IWidget {
+  book: number;
+  para: number;
+  wordStart: number;
+  wordEnd: number;
+  channelsId?: string[];
+  reload?: boolean;
+  onReload?: Function;
+}
+const SentWbwWidget = ({
+  book,
+  para,
+  wordStart,
+  wordEnd,
+  channelsId,
+  reload = false,
+  onReload,
+}: IWidget) => {
+  const [initLoading, setInitLoading] = useState(true);
+
+  const [sentData, setSentData] = useState<IWidgetSentEditInner[]>([]);
+
+  const load = () => {
+    let url = `/v2/wbw-sentence?view=sent-can-read&book=${book}&para=${para}&wordStart=${wordStart}&wordEnd=${wordEnd}`;
+    if (channelsId && channelsId.length > 0) {
+      url += `&exclude=${channelsId[0]}`;
+    }
+
+    console.log("url", url);
+    get<ISentenceWbwListResponse>(url)
+      .then((json) => {
+        if (json.ok) {
+          console.log("sim load", json.data.count);
+          setSentData(json.data.rows);
+        } else {
+          message.error(json.message);
+        }
+      })
+      .finally(() => {
+        setInitLoading(false);
+        if (reload && typeof onReload !== "undefined") {
+          onReload();
+        }
+      });
+  };
+  useEffect(() => {
+    load();
+  }, []);
+
+  return (
+    <>
+      <List
+        loading={initLoading}
+        itemLayout="horizontal"
+        split={false}
+        dataSource={sentData}
+        renderItem={(item, index) => (
+          <List.Item key={index}>
+            <SentEditInner {...item} />
+          </List.Item>
+        )}
+      />
+    </>
+  );
+};
+
+export default SentWbwWidget;

+ 1 - 0
dashboard/src/locales/en-US/label.ts

@@ -35,6 +35,7 @@ const items = {
   "labels.page.number.type.c": "Chapter Title",
   "labels.loading": "loading",
   "labels.empty": "empty",
+  "labels.curr.paragraph.cart.tpl": "Add to Cart",
 };
 
 export default items;

+ 1 - 0
dashboard/src/locales/zh-Hans/label.ts

@@ -35,6 +35,7 @@ const items = {
   "labels.page.number.type.c": "章节名称",
   "labels.loading": "载入中",
   "labels.empty": "无内容",
+  "labels.curr.paragraph.cart.tpl": "Add to Cart",
 };
 
 export default items;