|
|
@@ -1,17 +1,20 @@
|
|
|
import { useEffect, useState } from "react";
|
|
|
import { useIntl } from "react-intl";
|
|
|
-import { Divider, Form, Select, Input, AutoComplete } from "antd";
|
|
|
+import { Form, Input, AutoComplete, Button, Popover, Space, Badge } from "antd";
|
|
|
import { Collapse } from "antd";
|
|
|
+import { MoreOutlined } from "@ant-design/icons";
|
|
|
|
|
|
import SelectCase from "../../dict/SelectCase";
|
|
|
-import { IWbw } from "./WbwWord";
|
|
|
+import { IWbw, IWbwField } from "./WbwWord";
|
|
|
import WbwMeaningSelect from "./WbwMeaningSelect";
|
|
|
import { useAppSelector } from "../../../hooks";
|
|
|
import { inlineDict as _inlineDict } from "../../../reducers/inline-dict";
|
|
|
import { getFactorsInDict } from "./WbwFactors";
|
|
|
import { IApiResponseDictData } from "../../api/Dict";
|
|
|
+import WbwDetailFm from "./WbwDetailFm";
|
|
|
+import WbwDetailParent2 from "./WbwDetailParent2";
|
|
|
+import WbwDetailRelation from "./WbwDetailRelation";
|
|
|
|
|
|
-const { Option } = Select;
|
|
|
const { Panel } = Collapse;
|
|
|
|
|
|
interface ValueType {
|
|
|
@@ -49,6 +52,7 @@ export const getParentInDict = (
|
|
|
return [];
|
|
|
}
|
|
|
};
|
|
|
+
|
|
|
interface IWidget {
|
|
|
data: IWbw;
|
|
|
onChange?: Function;
|
|
|
@@ -61,6 +65,12 @@ const Widget = ({ data, showRelation = true, onChange }: IWidget) => {
|
|
|
const inlineDict = useAppSelector(_inlineDict);
|
|
|
const [factorOptions, setFactorOptions] = useState<ValueType[]>([]);
|
|
|
const [parentOptions, setParentOptions] = useState<ValueType[]>([]);
|
|
|
+ const [factors, setFactors] = useState<string[]>([]);
|
|
|
+ const [openCreate, setOpenCreate] = useState(false);
|
|
|
+ const [_meaning, setMeaning] = useState<string[] | undefined>(
|
|
|
+ data.meaning?.value
|
|
|
+ );
|
|
|
+
|
|
|
const onMeaningChange = (value: string | string[]) => {
|
|
|
console.log(`Selected: ${value}`);
|
|
|
if (typeof onChange !== "undefined") {
|
|
|
@@ -100,6 +110,10 @@ const Widget = ({ data, showRelation = true, onChange }: IWidget) => {
|
|
|
setParentOptions(parentOptions);
|
|
|
}, [inlineDict, data]);
|
|
|
|
|
|
+ const relationCount = data.relation
|
|
|
+ ? JSON.parse(data.relation.value).length
|
|
|
+ : 0;
|
|
|
+
|
|
|
return (
|
|
|
<>
|
|
|
<Form
|
|
|
@@ -114,6 +128,8 @@ const Widget = ({ data, showRelation = true, onChange }: IWidget) => {
|
|
|
factorMeaning: data.factorMeaning?.value,
|
|
|
parent: data.parent?.value,
|
|
|
case: data.case?.value,
|
|
|
+ parent2: data.parent2?.value,
|
|
|
+ grammar2: data.grammar2?.value,
|
|
|
}}
|
|
|
>
|
|
|
<Form.Item
|
|
|
@@ -122,20 +138,21 @@ const Widget = ({ data, showRelation = true, onChange }: IWidget) => {
|
|
|
label={intl.formatMessage({ id: "forms.fields.meaning.label" })}
|
|
|
tooltip={intl.formatMessage({ id: "forms.fields.meaning.tooltip" })}
|
|
|
>
|
|
|
- <Select
|
|
|
- allowClear
|
|
|
- mode="tags"
|
|
|
- onChange={onMeaningChange}
|
|
|
- style={{ width: "100%" }}
|
|
|
- options={items.map((item) => ({ label: item, value: item }))}
|
|
|
- dropdownRender={(menu) => (
|
|
|
- <>
|
|
|
- {menu}
|
|
|
- <Divider style={{ margin: "8px 0" }}>更多</Divider>
|
|
|
+ <div style={{ display: "flex" }}>
|
|
|
+ <Input
|
|
|
+ value={_meaning?.join(";")}
|
|
|
+ allowClear
|
|
|
+ onChange={(e) => {
|
|
|
+ console.log(e.target.value);
|
|
|
+ setMeaning(e.target.value.split(";"));
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ <Popover
|
|
|
+ content={
|
|
|
<WbwMeaningSelect
|
|
|
data={data}
|
|
|
onSelect={(meaning: string) => {
|
|
|
- const currMeanings = form.getFieldValue("meaning") || [];
|
|
|
+ const currMeanings = _meaning ? _meaning : [];
|
|
|
console.log(meaning);
|
|
|
if (!items.includes(meaning)) {
|
|
|
setItems([...items, meaning]);
|
|
|
@@ -144,15 +161,25 @@ const Widget = ({ data, showRelation = true, onChange }: IWidget) => {
|
|
|
currMeanings.push(meaning);
|
|
|
console.log("it push", meaning);
|
|
|
}
|
|
|
+ setMeaning(currMeanings);
|
|
|
form.setFieldsValue({
|
|
|
meaning: currMeanings,
|
|
|
});
|
|
|
onMeaningChange(currMeanings);
|
|
|
}}
|
|
|
/>
|
|
|
- </>
|
|
|
- )}
|
|
|
- />
|
|
|
+ }
|
|
|
+ overlayStyle={{ width: 500 }}
|
|
|
+ placement="bottom"
|
|
|
+ trigger="click"
|
|
|
+ open={openCreate}
|
|
|
+ onOpenChange={(open: boolean) => {
|
|
|
+ setOpenCreate(open);
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <Button type="text" icon={<MoreOutlined />} onClick={() => {}} />
|
|
|
+ </Popover>
|
|
|
+ </div>
|
|
|
</Form.Item>
|
|
|
<Form.Item
|
|
|
style={{ marginBottom: 6 }}
|
|
|
@@ -162,7 +189,8 @@ const Widget = ({ data, showRelation = true, onChange }: IWidget) => {
|
|
|
>
|
|
|
<AutoComplete
|
|
|
options={factorOptions}
|
|
|
- onChange={(value: any, option: ValueType | ValueType[]) => {
|
|
|
+ onChange={(value: string, option: ValueType | ValueType[]) => {
|
|
|
+ setFactors(value.split("+"));
|
|
|
if (typeof onChange !== "undefined") {
|
|
|
onChange({ field: "factors", value: value });
|
|
|
}
|
|
|
@@ -181,7 +209,16 @@ const Widget = ({ data, showRelation = true, onChange }: IWidget) => {
|
|
|
id: "forms.fields.factor.meaning.tooltip",
|
|
|
})}
|
|
|
>
|
|
|
- <Input allowClear />
|
|
|
+ <WbwDetailFm
|
|
|
+ factors={factors}
|
|
|
+ initValue={data.factorMeaning?.value.split("+")}
|
|
|
+ onChange={(value: string[]) => {
|
|
|
+ console.log("fm change", value);
|
|
|
+ if (typeof onChange !== "undefined") {
|
|
|
+ onChange({ field: "factorMeaning", value: value.join("+") });
|
|
|
+ }
|
|
|
+ }}
|
|
|
+ />
|
|
|
</Form.Item>
|
|
|
<Form.Item
|
|
|
style={{ marginBottom: 6 }}
|
|
|
@@ -190,9 +227,9 @@ const Widget = ({ data, showRelation = true, onChange }: IWidget) => {
|
|
|
name="case"
|
|
|
>
|
|
|
<SelectCase
|
|
|
- onCaseChange={(value: (string | number)[]) => {
|
|
|
+ onCaseChange={(value: string) => {
|
|
|
if (typeof onChange !== "undefined") {
|
|
|
- onChange({ field: "case", value: value.join("$") });
|
|
|
+ onChange({ field: "case", value: value });
|
|
|
}
|
|
|
}}
|
|
|
/>
|
|
|
@@ -219,37 +256,27 @@ const Widget = ({ data, showRelation = true, onChange }: IWidget) => {
|
|
|
</AutoComplete>
|
|
|
</Form.Item>
|
|
|
<Collapse bordered={false}>
|
|
|
- <Panel header="词源" key="1">
|
|
|
- <Form.Item
|
|
|
- name="parent1"
|
|
|
- label={intl.formatMessage({ id: "forms.fields.parent.label" })}
|
|
|
- tooltip={intl.formatMessage({
|
|
|
- id: "forms.fields.parent.tooltip",
|
|
|
- })}
|
|
|
- >
|
|
|
- <Input
|
|
|
- allowClear
|
|
|
- placeholder={intl.formatMessage({
|
|
|
- id: "forms.fields.parent.label",
|
|
|
- })}
|
|
|
- addonAfter={
|
|
|
- <Form.Item name="suffix" noStyle>
|
|
|
- <Select style={{ width: 100 }} allowClear>
|
|
|
- <Option value="prp">现在分词</Option>
|
|
|
- <Option value="pp">过去分词</Option>
|
|
|
- <Option value="fpp">未来分词</Option>
|
|
|
- </Select>
|
|
|
- </Form.Item>
|
|
|
+ <Panel header="词源" key="parent2">
|
|
|
+ <WbwDetailParent2
|
|
|
+ data={data}
|
|
|
+ onChange={(e: IWbwField) => {
|
|
|
+ if (typeof onChange !== "undefined") {
|
|
|
+ onChange(e);
|
|
|
}
|
|
|
- />
|
|
|
- </Form.Item>
|
|
|
+ }}
|
|
|
+ />
|
|
|
</Panel>
|
|
|
<Panel
|
|
|
- header="关系"
|
|
|
- key="2"
|
|
|
+ header={
|
|
|
+ <Space>
|
|
|
+ {"关联"}
|
|
|
+ <Badge color="geekblue" count={relationCount} />
|
|
|
+ </Space>
|
|
|
+ }
|
|
|
+ key="relation"
|
|
|
style={{ display: showRelation ? "block" : "none" }}
|
|
|
>
|
|
|
- 关系语法
|
|
|
+ <WbwDetailRelation data={data} />
|
|
|
</Panel>
|
|
|
</Collapse>
|
|
|
</Form>
|