|
@@ -0,0 +1,81 @@
|
|
1
|
+import React, { useEffect } from 'react';
|
|
2
|
+import ProForm, {
|
|
3
|
+ ProFormText,
|
|
4
|
+ ProFormRadio,
|
|
5
|
+} from '@ant-design/pro-form';
|
|
6
|
+import UploadImage from '@/components/UploadImage';
|
|
7
|
+import request from '@/utils/request';
|
|
8
|
+import { notification, Form } from 'antd';
|
|
9
|
+
|
|
10
|
+export default (props) => {
|
|
11
|
+ const [form] = Form.useForm();
|
|
12
|
+
|
|
13
|
+ const handleSubmit = (values) => {
|
|
14
|
+ const data = {
|
|
15
|
+ targetType: 'post',
|
|
16
|
+ targetId: props.post.postId,
|
|
17
|
+ ...props.post?.shareSetting || {},
|
|
18
|
+ ...values,
|
|
19
|
+ }
|
|
20
|
+
|
|
21
|
+ if (!data.serialNo) {
|
|
22
|
+ // 新增
|
|
23
|
+ return request('/share-setting', { method: 'post', data })
|
|
24
|
+ .then((res) => {
|
|
25
|
+ props.onChange(res);
|
|
26
|
+ notification.success({ message: '操作成功' });
|
|
27
|
+ })
|
|
28
|
+ .catch((e) => {
|
|
29
|
+ notification.error({ message: e.message });
|
|
30
|
+ return Promise.reject(e.message);
|
|
31
|
+ });
|
|
32
|
+ }
|
|
33
|
+
|
|
34
|
+ // 编辑
|
|
35
|
+ return request(`/share-setting/${data.serialNo}`, { method: 'put', data })
|
|
36
|
+ .then((res) => {
|
|
37
|
+ props.onChange(res);
|
|
38
|
+ notification.success({ message: '操作成功' });
|
|
39
|
+ })
|
|
40
|
+ .catch((e) => {
|
|
41
|
+ notification.error({ message: e.message });
|
|
42
|
+ return Promise.reject(e.message);
|
|
43
|
+ });
|
|
44
|
+ };
|
|
45
|
+
|
|
46
|
+ useEffect(() => {
|
|
47
|
+ if (props.post?.shareSetting && props.post?.shareSetting.serialNo) {
|
|
48
|
+ form.setFieldsValue(props.post?.shareSetting);
|
|
49
|
+ }
|
|
50
|
+ }, [props.post?.shareSetting, form]);
|
|
51
|
+
|
|
52
|
+ return (
|
|
53
|
+ <ProForm form={form} onFinish={handleSubmit}>
|
|
54
|
+ <ProFormText
|
|
55
|
+ label="分享标题"
|
|
56
|
+ placeholder="请输入分享标题"
|
|
57
|
+ name="title"
|
|
58
|
+ rules={[{ required: true, message: '请填写分享标题' }]}
|
|
59
|
+ />
|
|
60
|
+
|
|
61
|
+ <Form.Item name="imageUrl" label="分享图" placeholder="请设置分享图">
|
|
62
|
+ <UploadImage />
|
|
63
|
+ </Form.Item>
|
|
64
|
+
|
|
65
|
+ <ProFormRadio.Group
|
|
66
|
+ label="状态"
|
|
67
|
+ name="status"
|
|
68
|
+ options={[
|
|
69
|
+ {
|
|
70
|
+ label: '禁用',
|
|
71
|
+ value: 0,
|
|
72
|
+ },
|
|
73
|
+ {
|
|
74
|
+ label: '启用',
|
|
75
|
+ value: 1,
|
|
76
|
+ },
|
|
77
|
+ ]}
|
|
78
|
+ />
|
|
79
|
+ </ProForm>
|
|
80
|
+ );
|
|
81
|
+};
|