c9a263f8
王强
init
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
import React, { useEffect, useState } from "react";
import { Form, Input, message, Modal as AntdModal, Spin } from "antd";
import { save<feewee>替换name</feewee>Api } from "../api";
import { useStore } from "../index";
export default function Modal() {
const { pagination, current, setCurrent, open, setOpen } = useStore();
const [form] = Form.useForm();
const [confirmLoading, setConfirmLoading] = useState(false);
useEffect(() => {
if (open && current) {
form.setFieldsValue(current);
} else {
form.resetFields();
}
}, [open, current]);
function onOk(val: any) {
const hide = message.loading('提交中,请稍后...', 0);
setConfirmLoading(true);
const params: <feewee>替换name</feewee>.ListVO = {
...val,
id: current?.id,
};
save<feewee>替换name</feewee>Api(params)
.then((res) => {
hide();
setConfirmLoading(false);
message.success(res.result);
onCancel();
pagination.setLoading(true);
})
.catch((error) => {
hide();
setConfirmLoading(false);
message.error(error.message);
});
}
function onCancel() {
setCurrent(undefined);
setOpen(false);
}
return (
<AntdModal
title={`${current ? '编辑' : '添加'}<feewee>替换name</feewee>`}
open={open}
maskClosable={false}
onOk={form.submit}
confirmLoading={confirmLoading}
onCancel={onCancel}
>
<Spin spinning={confirmLoading}>
<Form form={form} onFinish={onOk}>
<Form.Item label="name" name="name" rules={[{ required: true, message: "请填写name" }]}>
<Input allowClear placeholder="请填写name" />
</Form.Item>
</Form>
</Spin>
</AntdModal>
);
}
|