|
@@ -1,9 +1,17 @@
|
|
|
-import { ProForm, ProFormText, ProFormTextArea } from "@ant-design/pro-components";
|
|
|
|
|
-import { Layout } from "antd";
|
|
|
|
|
import { useIntl } from "react-intl";
|
|
import { useIntl } from "react-intl";
|
|
|
-import { message } from "antd";
|
|
|
|
|
|
|
+import { Button, Form, message } from "antd";
|
|
|
|
|
+import {
|
|
|
|
|
+ ModalForm,
|
|
|
|
|
+ ProForm,
|
|
|
|
|
+ ProFormText,
|
|
|
|
|
+ ProFormTextArea,
|
|
|
|
|
+} from "@ant-design/pro-components";
|
|
|
|
|
+import { PlusOutlined } from "@ant-design/icons";
|
|
|
|
|
|
|
|
import SelectLang from "../SelectLang";
|
|
import SelectLang from "../SelectLang";
|
|
|
|
|
+import { ITermResponse } from "../../api/Term";
|
|
|
|
|
+import { get } from "../../../request";
|
|
|
|
|
+import { useState } from "react";
|
|
|
|
|
|
|
|
interface IFormData {
|
|
interface IFormData {
|
|
|
word: string;
|
|
word: string;
|
|
@@ -16,22 +24,101 @@ interface IFormData {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
type IWidgetDictCreate = {
|
|
type IWidgetDictCreate = {
|
|
|
- studio: string | undefined;
|
|
|
|
|
|
|
+ studio?: string;
|
|
|
|
|
+ edit?: boolean;
|
|
|
|
|
+ wordId?: string;
|
|
|
|
|
+ word?: string;
|
|
|
};
|
|
};
|
|
|
-const Widget = (param: IWidgetDictCreate) => {
|
|
|
|
|
|
|
+const Widget = (prop: IWidgetDictCreate) => {
|
|
|
const intl = useIntl();
|
|
const intl = useIntl();
|
|
|
- /*
|
|
|
|
|
- const onLangChange = (value: string) => {
|
|
|
|
|
- console.log(`selected ${value}`);
|
|
|
|
|
|
|
+ const [form] = Form.useForm<IFormData>();
|
|
|
|
|
+ const [lang, setLang] = useState("");
|
|
|
|
|
+
|
|
|
|
|
+ const waitTime = (time: number = 100) => {
|
|
|
|
|
+ return new Promise((resolve) => {
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
|
+ resolve(true);
|
|
|
|
|
+ }, time);
|
|
|
|
|
+ });
|
|
|
};
|
|
};
|
|
|
-*/
|
|
|
|
|
|
|
+ const editTrigger = (
|
|
|
|
|
+ <span>
|
|
|
|
|
+ {intl.formatMessage({
|
|
|
|
|
+ id: "buttons.edit",
|
|
|
|
|
+ })}
|
|
|
|
|
+ </span>
|
|
|
|
|
+ );
|
|
|
|
|
+ const createTrigger = (
|
|
|
|
|
+ <Button type="primary">
|
|
|
|
|
+ <PlusOutlined />
|
|
|
|
|
+ {intl.formatMessage({
|
|
|
|
|
+ id: "buttons.create",
|
|
|
|
|
+ })}
|
|
|
|
|
+ </Button>
|
|
|
|
|
+ );
|
|
|
return (
|
|
return (
|
|
|
- <Layout>
|
|
|
|
|
- <ProForm<IFormData>
|
|
|
|
|
- onFinish={async (values: IFormData) => {
|
|
|
|
|
- // TODO
|
|
|
|
|
- console.log(values);
|
|
|
|
|
- message.success(intl.formatMessage({ id: "flashes.success" }));
|
|
|
|
|
|
|
+ <>
|
|
|
|
|
+ <ModalForm<IFormData>
|
|
|
|
|
+ title={intl.formatMessage({
|
|
|
|
|
+ id: prop.edit ? "buttons.edit" : "buttons.create",
|
|
|
|
|
+ })}
|
|
|
|
|
+ trigger={prop.edit ? editTrigger : createTrigger}
|
|
|
|
|
+ form={form}
|
|
|
|
|
+ autoFocusFirstInput
|
|
|
|
|
+ modalProps={{
|
|
|
|
|
+ destroyOnClose: true,
|
|
|
|
|
+ onCancel: () => console.log("run"),
|
|
|
|
|
+ }}
|
|
|
|
|
+ submitTimeout={2000}
|
|
|
|
|
+ onFinish={async (values) => {
|
|
|
|
|
+ await waitTime(2000);
|
|
|
|
|
+ console.log(values.word);
|
|
|
|
|
+ message.success("提交成功");
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }}
|
|
|
|
|
+ request={async () => {
|
|
|
|
|
+ if (
|
|
|
|
|
+ typeof prop.edit !== "undefined" &&
|
|
|
|
|
+ prop.edit === true
|
|
|
|
|
+ ) {
|
|
|
|
|
+ // 如果是编辑,就从服务器拉取数据。
|
|
|
|
|
+ let url = "/v2/terms/" + (prop.edit ? prop.wordId : "");
|
|
|
|
|
+ console.log(url);
|
|
|
|
|
+ const res = await get<ITermResponse>(url);
|
|
|
|
|
+ console.log(res);
|
|
|
|
|
+ setLang(res.data.language);
|
|
|
|
|
+ return {
|
|
|
|
|
+ word: res.data.word,
|
|
|
|
|
+ tag: res.data.tag,
|
|
|
|
|
+ meaning: res.data.meaning,
|
|
|
|
|
+ meaning2: res.data.other_meaning,
|
|
|
|
|
+ note: res.data.note,
|
|
|
|
|
+ lang: res.data.language,
|
|
|
|
|
+ channel: res.data.channal,
|
|
|
|
|
+ };
|
|
|
|
|
+ } else if (typeof prop.word !== "undefined") {
|
|
|
|
|
+ setLang("zh-Hans");
|
|
|
|
|
+ return {
|
|
|
|
|
+ word: prop.word ? prop.word : "",
|
|
|
|
|
+ tag: "",
|
|
|
|
|
+ meaning: "",
|
|
|
|
|
+ meaning2: "",
|
|
|
|
|
+ note: "",
|
|
|
|
|
+ lang: "zh-Hans",
|
|
|
|
|
+ channel: "",
|
|
|
|
|
+ };
|
|
|
|
|
+ } else {
|
|
|
|
|
+ setLang("zh-Hans");
|
|
|
|
|
+ return {
|
|
|
|
|
+ word: "",
|
|
|
|
|
+ tag: "",
|
|
|
|
|
+ meaning: "",
|
|
|
|
|
+ meaning2: "",
|
|
|
|
|
+ note: "",
|
|
|
|
|
+ lang: "zh-Hans",
|
|
|
|
|
+ channel: "",
|
|
|
|
|
+ };
|
|
|
|
|
+ }
|
|
|
}}
|
|
}}
|
|
|
>
|
|
>
|
|
|
<ProForm.Group>
|
|
<ProForm.Group>
|
|
@@ -39,56 +126,83 @@ const Widget = (param: IWidgetDictCreate) => {
|
|
|
width="md"
|
|
width="md"
|
|
|
name="word"
|
|
name="word"
|
|
|
required
|
|
required
|
|
|
- label={intl.formatMessage({ id: "dict.fields.word.label" })}
|
|
|
|
|
|
|
+ label={intl.formatMessage({
|
|
|
|
|
+ id: "dict.fields.word.label",
|
|
|
|
|
+ })}
|
|
|
rules={[
|
|
rules={[
|
|
|
{
|
|
{
|
|
|
required: true,
|
|
required: true,
|
|
|
- message: intl.formatMessage({ id: "channel.create.message.noname" }),
|
|
|
|
|
|
|
+ message: intl.formatMessage({
|
|
|
|
|
+ id: "channel.create.message.noname",
|
|
|
|
|
+ }),
|
|
|
},
|
|
},
|
|
|
]}
|
|
]}
|
|
|
/>
|
|
/>
|
|
|
- </ProForm.Group>
|
|
|
|
|
- <ProForm.Group>
|
|
|
|
|
<ProFormText
|
|
<ProFormText
|
|
|
width="md"
|
|
width="md"
|
|
|
name="tag"
|
|
name="tag"
|
|
|
- tooltip={intl.formatMessage({ id: "term.fields.description.tooltip" })}
|
|
|
|
|
- label={intl.formatMessage({ id: "term.fields.description.label" })}
|
|
|
|
|
|
|
+ tooltip={intl.formatMessage({
|
|
|
|
|
+ id: "term.fields.description.tooltip",
|
|
|
|
|
+ })}
|
|
|
|
|
+ label={intl.formatMessage({
|
|
|
|
|
+ id: "term.fields.description.label",
|
|
|
|
|
+ })}
|
|
|
/>
|
|
/>
|
|
|
</ProForm.Group>
|
|
</ProForm.Group>
|
|
|
<ProForm.Group>
|
|
<ProForm.Group>
|
|
|
<ProFormText
|
|
<ProFormText
|
|
|
width="md"
|
|
width="md"
|
|
|
name="meaning"
|
|
name="meaning"
|
|
|
- tooltip={intl.formatMessage({ id: "term.fields.meaning.tooltip" })}
|
|
|
|
|
- label={intl.formatMessage({ id: "term.fields.meaning.label" })}
|
|
|
|
|
|
|
+ tooltip={intl.formatMessage({
|
|
|
|
|
+ id: "term.fields.meaning.tooltip",
|
|
|
|
|
+ })}
|
|
|
|
|
+ label={intl.formatMessage({
|
|
|
|
|
+ id: "term.fields.meaning.label",
|
|
|
|
|
+ })}
|
|
|
/>
|
|
/>
|
|
|
- </ProForm.Group>
|
|
|
|
|
- <ProForm.Group>
|
|
|
|
|
<ProFormText
|
|
<ProFormText
|
|
|
width="md"
|
|
width="md"
|
|
|
name="meaning2"
|
|
name="meaning2"
|
|
|
- tooltip={intl.formatMessage({ id: "term.fields.meaning2.tooltip" })}
|
|
|
|
|
- label={intl.formatMessage({ id: "term.fields.meaning2.label" })}
|
|
|
|
|
|
|
+ tooltip={intl.formatMessage({
|
|
|
|
|
+ id: "term.fields.meaning2.tooltip",
|
|
|
|
|
+ })}
|
|
|
|
|
+ label={intl.formatMessage({
|
|
|
|
|
+ id: "term.fields.meaning2.label",
|
|
|
|
|
+ })}
|
|
|
/>
|
|
/>
|
|
|
</ProForm.Group>
|
|
</ProForm.Group>
|
|
|
<ProForm.Group>
|
|
<ProForm.Group>
|
|
|
<ProFormText
|
|
<ProFormText
|
|
|
width="md"
|
|
width="md"
|
|
|
name="channel"
|
|
name="channel"
|
|
|
- tooltip={intl.formatMessage({ id: "term.fields.channel.tooltip" })}
|
|
|
|
|
- label={intl.formatMessage({ id: "term.fields.channel.label" })}
|
|
|
|
|
|
|
+ tooltip={intl.formatMessage({
|
|
|
|
|
+ id: "term.fields.channel.tooltip",
|
|
|
|
|
+ })}
|
|
|
|
|
+ label={intl.formatMessage({
|
|
|
|
|
+ id: "term.fields.channel.label",
|
|
|
|
|
+ })}
|
|
|
/>
|
|
/>
|
|
|
|
|
+
|
|
|
|
|
+ <Form.Item
|
|
|
|
|
+ name="lang"
|
|
|
|
|
+ label={intl.formatMessage({
|
|
|
|
|
+ id: "forms.fields.lang.label",
|
|
|
|
|
+ })}
|
|
|
|
|
+ >
|
|
|
|
|
+ <SelectLang lang={lang} />
|
|
|
|
|
+ </Form.Item>
|
|
|
</ProForm.Group>
|
|
</ProForm.Group>
|
|
|
<ProForm.Group>
|
|
<ProForm.Group>
|
|
|
- <div>语言</div>
|
|
|
|
|
- <SelectLang />
|
|
|
|
|
- </ProForm.Group>
|
|
|
|
|
- <ProForm.Group>
|
|
|
|
|
- <ProFormTextArea name="note" label={intl.formatMessage({ id: "forms.fields.note.label" })} />
|
|
|
|
|
|
|
+ <ProFormTextArea
|
|
|
|
|
+ name="note"
|
|
|
|
|
+ width="xl"
|
|
|
|
|
+ label={intl.formatMessage({
|
|
|
|
|
+ id: "forms.fields.note.label",
|
|
|
|
|
+ })}
|
|
|
|
|
+ />
|
|
|
</ProForm.Group>
|
|
</ProForm.Group>
|
|
|
- </ProForm>
|
|
|
|
|
- </Layout>
|
|
|
|
|
|
|
+ </ModalForm>
|
|
|
|
|
+ </>
|
|
|
);
|
|
);
|
|
|
};
|
|
};
|
|
|
|
|
|