张延森 4 yıl önce
ebeveyn
işleme
7e6160ed51

+ 81
- 0
src/pages/Post/Edit/components/Share.jsx Dosyayı Görüntüle

@@ -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
+};

+ 11
- 0
src/pages/Post/Edit/index.jsx Dosyayı Görüntüle

@@ -6,6 +6,7 @@ import Container from '@/components/Container';
6 6
 import request from '@/utils/request';
7 7
 import PostForm from './components/Form';
8 8
 import Answer from './components/Answer';
9
+import Share from './components/Share';
9 10
 
10 11
 const { TabPane } = Tabs;
11 12
 
@@ -25,6 +26,13 @@ const PostEdit = (props) => {
25 26
     })
26 27
   }
27 28
 
29
+  const handleShareSettingChange = (shareSetting) => {
30
+    setPost({
31
+      ...post,
32
+      shareSetting,
33
+    })
34
+  }
35
+
28 36
   useEffect(() => {
29 37
     if (id) {
30 38
       setLoading(true);
@@ -61,6 +69,9 @@ const PostEdit = (props) => {
61 69
           <TabPane tab="题库设置" key="2">
62 70
             <Answer post={post} onChange={handlePostTestChange} />
63 71
           </TabPane>
72
+          <TabPane tab="分享设置" key="3">
73
+            <Share post={post} onChange={handleShareSettingChange} />
74
+          </TabPane>
64 75
         </Tabs>
65 76
       </Container>
66 77
     </PageContainer>