2
0
Эх сурвалжийг харах

Merge pull request #1978 from visuddhinanda/agile

confidence <1 按100算
visuddhinanda 2 жил өмнө
parent
commit
e8a89bb5b6

+ 1 - 0
dashboard/src/components/api/Dict.ts

@@ -9,6 +9,7 @@ export interface IDictRequest {
   grammar?: string | null;
   mean?: string | null;
   parent?: string | null;
+  parent2?: string | null;
   note?: string | null;
   factors?: string | null;
   factormean?: string | null;

+ 4 - 3
dashboard/src/components/attachment/AttachmentList.tsx

@@ -180,6 +180,8 @@ const AttachmentWidget = ({
             },
           },
           description: {
+            editable: false,
+            search: false,
             render: (dom, entity, index, action, schema) => {
               return (
                 <Text type="secondary">
@@ -195,12 +197,10 @@ const AttachmentWidget = ({
                 </Text>
               );
             },
-            editable: false,
-            search: false,
           },
           content:
             list === "list"
-              ? undefined
+              ? { editable: false, search: false }
               : {
                   editable: false,
                   search: false,
@@ -323,6 +323,7 @@ const AttachmentWidget = ({
           },
           content_type: {
             // 自己扩展的字段,主要用于筛选,不在列表中显示
+            editable: false,
             title: "类型",
             valueType: "select",
             valueEnum: {

+ 1 - 0
dashboard/src/components/channel/Channel.tsx

@@ -4,6 +4,7 @@ export interface IChannel {
   name: string;
   id: string;
   type?: TChannelType;
+  lang?: string;
 }
 const ChannelWidget = ({ name, id }: IChannel) => {
   return <span>{name}</span>;

+ 5 - 3
dashboard/src/components/dict/Community.tsx

@@ -64,9 +64,11 @@ const CommunityWidget = ({ word }: IWidget) => {
           let score: number | undefined;
           if (it.exp) {
             //分数计算
-            const currScore = Math.floor(
-              (it.exp / 3600) * (it.confidence / 100)
-            );
+            let conf = it.confidence / 100;
+            if (it.confidence <= 1) {
+              conf = 1;
+            }
+            const currScore = Math.floor((it.exp / 3600) * conf);
             if (it.mean) {
               score = meaning.get(it.mean);
               meaning.set(it.mean, score ? score + currScore : currScore);

+ 63 - 6
dashboard/src/components/dict/MyCreate.tsx

@@ -9,6 +9,7 @@ import { IWbw, IWbwField, TFieldName } from "../template/Wbw/WbwWord";
 import { get, post } from "../../request";
 import {
   IApiResponseDictList,
+  IDictRequest,
   IDictResponse,
   IUserDictCreate,
 } from "../api/Dict";
@@ -17,6 +18,65 @@ import { add, updateIndex, wordIndex } from "../../reducers/inline-dict";
 import store from "../../store";
 import { get as getUiLang } from "../../locales";
 
+export const UserWbwPost = (data: IDictRequest[], view: string) => {
+  let wordData: IDictRequest[] = data;
+  data.forEach((value: IDictRequest) => {
+    if (value.parent && value.type !== "") {
+      if (!value.type?.includes("base") && value.type !== ".ind.") {
+        let pFactors = "";
+        let pFm;
+        const orgFactors = value.factors?.split("+");
+        if (
+          orgFactors &&
+          orgFactors.length > 0 &&
+          orgFactors[orgFactors.length - 1].includes("[")
+        ) {
+          pFactors = orgFactors.slice(0, -1).join("+");
+          pFm = value.factormean
+            ?.split("+")
+            .slice(0, orgFactors.length - 1)
+            .join("+");
+        }
+        let grammar = value.grammar?.split("$").slice(0, 1).join("");
+        if (value.type?.includes(".v")) {
+          grammar = "";
+        }
+        wordData.push({
+          word: value.parent,
+          type: "." + value.type?.replaceAll(".", "") + ":base.",
+          grammar: grammar,
+          mean: value.mean,
+          parent: value.parent2 ?? undefined,
+          factors: pFactors,
+          factormean: pFm,
+          confidence: value.confidence,
+          language: value.language,
+        });
+      }
+    }
+    if (value.factors && value.factors.split("+").length > 0) {
+      const fm = value.factormean?.split("+");
+      const factors: IDictRequest[] = value.factors
+        .split("+")
+        .map((item, id) => {
+          return {
+            word: item,
+            type: ".part.",
+            grammar: "",
+            mean: fm ? fm[id] ?? "" : "",
+            confidence: value.confidence,
+            language: value.language,
+          };
+        });
+      wordData = [...wordData, ...factors];
+    }
+  });
+  return post<IUserDictCreate, IDictResponse>("/v2/userdict", {
+    view: view,
+    data: JSON.stringify(wordData),
+  });
+};
+
 interface IWidget {
   word?: string;
 }
@@ -152,7 +212,7 @@ const MyCreateWidget = ({ word }: IWidget) => {
           icon={<SaveOutlined />}
           onClick={() => {
             setLoading(true);
-            const data = [
+            const data: IDictRequest[] = [
               {
                 word: editWord.word.value,
                 type: editWord.type?.value,
@@ -163,13 +223,10 @@ const MyCreateWidget = ({ word }: IWidget) => {
                 factors: editWord.factors?.value,
                 factormean: editWord.factorMeaning?.value,
                 language: getUiLang(),
-                confidence: editWord.confidence,
+                confidence: 100,
               },
             ];
-            post<IUserDictCreate, IDictResponse>("/v2/userdict", {
-              view: "dict",
-              data: JSON.stringify(data),
-            })
+            UserWbwPost(data, "dict")
               .finally(() => {
                 setLoading(false);
               })

+ 0 - 1
dashboard/src/components/template/SentEdit/EditInfo.tsx

@@ -136,7 +136,6 @@ interface IWidget {
   compact?: boolean;
 }
 const EditInfoWidget = ({ data, isPr = false, compact = false }: IWidget) => {
-  console.debug("EditInfo", data);
   return (
     <div style={{ fontSize: "80%" }}>
       <Text type="secondary">

+ 2 - 0
dashboard/src/components/template/SentEdit/SentContent.tsx

@@ -134,6 +134,8 @@ const SentContentWidget = ({
                 wordEnd={wordEnd}
                 magicDict={magicDict}
                 channelId={item.channel.id}
+                channelType={item.channel.type}
+                channelLang={item.channel.lang}
                 data={JSON.parse(item.content ? item.content : "")}
                 mode={mode}
                 wbwProgress={wbwProgress}

+ 1 - 0
dashboard/src/components/template/SentEdit/SentWbwEdit.tsx

@@ -92,6 +92,7 @@ const SentWbwEditWidget = ({ data, onSave, onClose }: IWidget) => {
         }}
         channelId={data.channel.id}
         channelType={data.channel.type}
+        channelLang={data.channel.lang}
         onChange={(wbwData: IWbw[]) => {
           let newSent = data;
           newSent.content = JSON.stringify(wbwData);

+ 9 - 7
dashboard/src/components/template/Wbw/WbwDetail.tsx

@@ -236,13 +236,15 @@ const WbwDetailWidget = ({
           checkedChildren={<LockIcon />}
           unCheckedChildren={<UnLockIcon />}
         />
-        <Rate
-          allowHalf
-          defaultValue={data.confidence * 5}
-          onChange={(value: number) => {
-            fieldChanged("confidence", (value / 5).toString());
-          }}
-        />
+        <div>
+          {"信心指数"}
+          <Rate
+            defaultValue={data.confidence * 5}
+            onChange={(value: number) => {
+              fieldChanged("confidence", (value / 5).toString());
+            }}
+          />
+        </div>
       </div>
       <Divider style={{ margin: "4px 0" }}></Divider>
       <div style={{ display: "flex", justifyContent: "space-between" }}>

+ 13 - 21
dashboard/src/components/template/WbwSent.tsx

@@ -14,7 +14,7 @@ import WbwWord, {
   WbwStatus,
 } from "./Wbw/WbwWord";
 import { TChannelType } from "../api/Channel";
-import { IDictRequest, IDictResponse, IUserDictCreate } from "../api/Dict";
+import { IDictRequest } from "../api/Dict";
 import { useIntl } from "react-intl";
 import { add } from "../../reducers/sent-word";
 import store from "../../store";
@@ -22,6 +22,7 @@ import { settingInfo } from "../../reducers/setting";
 import { GetUserSetting } from "../auth/setting/default";
 import { getGrammar } from "../../reducers/term-vocabulary";
 import modal from "antd/lib/modal";
+import { UserWbwPost } from "../dict/MyCreate";
 
 export const paraMark = (wbwData: IWbw[]): IWbw[] => {
   //处理段落标记,支持点击段落引用弹窗
@@ -139,6 +140,7 @@ interface IWidget {
   wordEnd: number;
   channelId: string;
   channelType?: TChannelType;
+  channelLang?: string;
   display?: TWbwDisplayMode;
   fields?: IWbwFields;
   layoutDirection?: "h" | "v";
@@ -153,6 +155,7 @@ export const WbwSentCtl = ({
   data,
   channelId,
   channelType,
+  channelLang,
   book,
   para,
   wordStart,
@@ -177,6 +180,8 @@ export const WbwSentCtl = ({
   const [progress, setProgress] = useState(0);
   const [showProgress, setShowProgress] = useState(false);
 
+  console.debug("wbw sent lang", channelLang);
+
   useEffect(() => setShowProgress(wbwProgress), [wbwProgress]);
 
   const settings = useAppSelector(settingInfo);
@@ -481,7 +486,10 @@ export const WbwSentCtl = ({
       const [wordType, wordGrammar] = data.case?.value
         ? data.case?.value?.split("#")
         : ["", ""];
-
+      let conf = data.confidence * 100;
+      if (data.confidence.toString() === "0.5") {
+        conf = 100;
+      }
       wordData.push({
         word: data.real.value ? data.real.value : "",
         type: wordType,
@@ -490,28 +498,12 @@ export const WbwSentCtl = ({
         parent: data.parent?.value,
         factors: data.factors?.value,
         factormean: data.factorMeaning?.value,
-        confidence: data.confidence,
+        confidence: conf,
+        language: channelLang,
       });
-      if (data.parent?.value && wordType !== "") {
-        if (!wordType.includes("base") && wordType !== ".ind.") {
-          wordData.push({
-            word: data.parent.value,
-            type: "." + wordType.replaceAll(".", "") + ":base.",
-            grammar: wordGrammar,
-            mean: data.meaning?.value,
-            parent: data.parent2?.value ? data.parent2?.value : undefined,
-            factors: data.factors?.value,
-            factormean: data.factorMeaning?.value,
-            confidence: data.confidence,
-          });
-        }
-      }
     });
 
-    post<IUserDictCreate, IDictResponse>("/v2/userdict", {
-      view: "wbw",
-      data: JSON.stringify(wordData),
-    })
+    UserWbwPost(wordData, "wbw")
       .finally(() => {
         setLoading(false);
       })