import { useIntl } from "react-intl"; import { Button, Form, message } from "antd"; import { ModalForm, ProForm, ProFormText, ProFormTextArea, } from "@ant-design/pro-components"; import { PlusOutlined } from "@ant-design/icons"; import { ITermResponse } from "../../api/Term"; import { get } from "../../../request"; import LangSelect from "../LangSelect"; interface IFormData { word: string; tag: string; meaning: string; meaning2: string; note: string; channel: string; lang: string; } type IWidgetDictCreate = { studio?: string; isCreate?: boolean; wordId?: string; word?: string; channel?: string; }; const Widget = ({ studio, isCreate, wordId, word, channel, }: IWidgetDictCreate) => { const intl = useIntl(); const [form] = Form.useForm(); const waitTime = (time: number = 100) => { return new Promise((resolve) => { setTimeout(() => { resolve(true); }, time); }); }; const editTrigger = ( {intl.formatMessage({ id: "buttons.edit", })} ); const createTrigger = ( ); return ( <> title={intl.formatMessage({ id: isCreate ? "buttons.create" : "buttons.edit", })} trigger={isCreate ? createTrigger : editTrigger} 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 () => { let url: string; if (typeof isCreate !== "undefined" && isCreate === false) { // 如果是编辑,就从服务器拉取数据。 url = "/v2/terms/" + (isCreate ? "" : wordId); } else if (typeof channel !== "undefined") { //在channel新建 url = `/v2/terms?view=createByChannel&channel=${channel}&word=${word}`; } else if (typeof studio !== "undefined") { //在studio新建 url = `/v2/terms?view=createByStudio&studio=${studio}&word=${word}`; } else { return { word: "", tag: "", meaning: "", meaning2: "", note: "", lang: "", channel: "", }; } console.log(url); const res = await get(url); console.log(res); 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, }; }} > ); }; export default Widget;