Quellcode durchsuchen

:fire: 多余的格位选择

visuddhinanda vor 3 Jahren
Ursprung
Commit
721084cbd2
1 geänderte Dateien mit 54 neuen und 60 gelöschten Zeilen
  1. 54 60
      dashboard/src/components/template/Wbw/WbwDetailBasic.tsx

+ 54 - 60
dashboard/src/components/template/Wbw/WbwDetailBasic.tsx

@@ -1,15 +1,24 @@
-import { useState } from "react";
+import { useEffect, useState } from "react";
 import { useIntl } from "react-intl";
 import { useIntl } from "react-intl";
-import { Divider, Form, Select, Input, Cascader } from "antd";
+import { Divider, Form, Select, Input, Cascader, AutoComplete } from "antd";
 import { Collapse } from "antd";
 import { Collapse } from "antd";
 
 
 import SelectCase from "../../dict/SelectCase";
 import SelectCase from "../../dict/SelectCase";
 import { IWbw } from "./WbwWord";
 import { IWbw } from "./WbwWord";
 import WbwMeaningSelect from "./WbwMeaningSelect";
 import WbwMeaningSelect from "./WbwMeaningSelect";
+import { useAppSelector } from "../../../hooks";
+import { inlineDict as _inlineDict } from "../../../reducers/inline-dict";
+import { getFactorsInDict } from "./WbwFactors";
 
 
 const { Option } = Select;
 const { Option } = Select;
 const { Panel } = Collapse;
 const { Panel } = Collapse;
 
 
+interface ValueType {
+  key?: string;
+  label: React.ReactNode;
+  value: string | number;
+}
+
 export interface IWordBasic {
 export interface IWordBasic {
   meaning?: string[];
   meaning?: string[];
   case?: string;
   case?: string;
@@ -31,12 +40,9 @@ interface IWidget {
 const Widget = ({ data, onChange }: IWidget) => {
 const Widget = ({ data, onChange }: IWidget) => {
   const [form] = Form.useForm();
   const [form] = Form.useForm();
   const intl = useIntl();
   const intl = useIntl();
-  const [items, setItems] = useState(["jack", "lucy"]);
-
-  const formItemLayout = {
-    labelCol: { span: 4 },
-    wrapperCol: { span: 20 },
-  };
+  const [items, setItems] = useState<string[]>([]);
+  const inlineDict = useAppSelector(_inlineDict);
+  const [factorOptions, setFactorOptions] = useState<ValueType[]>([]);
   const onMeaningChange = (value: string | string[]) => {
   const onMeaningChange = (value: string | string[]) => {
     console.log(`Selected: ${value}`);
     console.log(`Selected: ${value}`);
     if (typeof onChange !== "undefined") {
     if (typeof onChange !== "undefined") {
@@ -48,37 +54,26 @@ const Widget = ({ data, onChange }: IWidget) => {
     }
     }
   };
   };
 
 
-  const options: CascaderOption[] = [
-    {
-      value: "n",
-      label: intl.formatMessage({ id: "dict.fields.type.n.label" }),
-    },
-    {
-      value: "ti",
-      label: intl.formatMessage({ id: "dict.fields.type.ti.label" }),
-    },
-    {
-      value: "v",
-      label: intl.formatMessage({ id: "dict.fields.type.v.label" }),
-    },
-    {
-      value: "ind",
-      label: intl.formatMessage({ id: "dict.fields.type.ind.label" }),
-    },
-    {
-      value: "un",
-      label: intl.formatMessage({ id: "dict.fields.type.un.label" }),
-    },
-    {
-      value: "adj",
-      label: intl.formatMessage({ id: "dict.fields.type.adj.label" }),
-    },
-  ];
+  useEffect(() => {
+    const factors = getFactorsInDict(
+      data.word.value,
+      inlineDict.wordIndex,
+      inlineDict.wordList
+    );
+    const options = factors.map((item) => {
+      return {
+        label: item,
+        value: item,
+      };
+    });
+    setFactorOptions(options);
+  }, [inlineDict, data]);
 
 
   return (
   return (
     <>
     <>
       <Form
       <Form
-        {...formItemLayout}
+        labelCol={{ span: 4 }}
+        wrapperCol={{ span: 20 }}
         className="wbw_detail_basic"
         className="wbw_detail_basic"
         name="basic"
         name="basic"
         form={form}
         form={form}
@@ -88,10 +83,10 @@ const Widget = ({ data, onChange }: IWidget) => {
           factorMeaning: data.factorMeaning?.value,
           factorMeaning: data.factorMeaning?.value,
           parent: data.parent?.value,
           parent: data.parent?.value,
           case: data.case?.value,
           case: data.case?.value,
-          case1: data.case?.value,
         }}
         }}
       >
       >
         <Form.Item
         <Form.Item
+          style={{ marginBottom: 6 }}
           name="meaning"
           name="meaning"
           label={intl.formatMessage({ id: "forms.fields.meaning.label" })}
           label={intl.formatMessage({ id: "forms.fields.meaning.label" })}
           tooltip={intl.formatMessage({ id: "forms.fields.meaning.tooltip" })}
           tooltip={intl.formatMessage({ id: "forms.fields.meaning.tooltip" })}
@@ -132,28 +127,42 @@ const Widget = ({ data, onChange }: IWidget) => {
           />
           />
         </Form.Item>
         </Form.Item>
         <Form.Item
         <Form.Item
+          style={{ marginBottom: 6 }}
           name="factors"
           name="factors"
           label={intl.formatMessage({ id: "forms.fields.factors.label" })}
           label={intl.formatMessage({ id: "forms.fields.factors.label" })}
           tooltip={intl.formatMessage({ id: "forms.fields.factors.tooltip" })}
           tooltip={intl.formatMessage({ id: "forms.fields.factors.tooltip" })}
+        >
+          <AutoComplete options={factorOptions}>
+            <Input
+              allowClear
+              placeholder={intl.formatMessage({
+                id: "forms.fields.factors.label",
+              })}
+            />
+          </AutoComplete>
+        </Form.Item>
+        <Form.Item
+          style={{ marginBottom: 6 }}
+          name="factorMeaning"
+          label={intl.formatMessage({
+            id: "forms.fields.factor.meaning.label",
+          })}
+          tooltip={intl.formatMessage({
+            id: "forms.fields.factor.meaning.tooltip",
+          })}
         >
         >
           <Input
           <Input
             allowClear
             allowClear
             placeholder={intl.formatMessage({
             placeholder={intl.formatMessage({
-              id: "forms.fields.factors.label",
+              id: "forms.fields.factor.meaning.label",
             })}
             })}
           />
           />
         </Form.Item>
         </Form.Item>
         <Form.Item
         <Form.Item
+          style={{ marginBottom: 6 }}
           label={intl.formatMessage({ id: "forms.fields.case.label" })}
           label={intl.formatMessage({ id: "forms.fields.case.label" })}
           tooltip={intl.formatMessage({ id: "forms.fields.case.tooltip" })}
           tooltip={intl.formatMessage({ id: "forms.fields.case.tooltip" })}
           name="case"
           name="case"
-        >
-          <Cascader options={options} placeholder="Please select case" />
-        </Form.Item>
-        <Form.Item
-          label={intl.formatMessage({ id: "forms.fields.case.label" })}
-          tooltip={intl.formatMessage({ id: "forms.fields.case.tooltip" })}
-          name="case1"
         >
         >
           <SelectCase
           <SelectCase
             onCaseChange={(value: (string | number)[]) => {
             onCaseChange={(value: (string | number)[]) => {
@@ -164,22 +173,7 @@ const Widget = ({ data, onChange }: IWidget) => {
           />
           />
         </Form.Item>
         </Form.Item>
         <Form.Item
         <Form.Item
-          name="factorMeaning"
-          label={intl.formatMessage({
-            id: "forms.fields.factor.meaning.label",
-          })}
-          tooltip={intl.formatMessage({
-            id: "forms.fields.factor.meaning.tooltip",
-          })}
-        >
-          <Input
-            allowClear
-            placeholder={intl.formatMessage({
-              id: "forms.fields.factor.meaning.label",
-            })}
-          />
-        </Form.Item>
-        <Form.Item
+          style={{ marginBottom: 6 }}
           name="parent"
           name="parent"
           label={intl.formatMessage({
           label={intl.formatMessage({
             id: "forms.fields.parent.label",
             id: "forms.fields.parent.label",