Kaynağa Gözat

Merge branch 'dev' of http://git.ycjcjy.com/jgz/admin into dev

Yansen 2 yıl önce
ebeveyn
işleme
2f0d59535f
1 değiştirilmiş dosya ile 94 ekleme ve 52 silme
  1. 94
    52
      src/pages/rotationChart/introduction/edit/index.jsx

+ 94
- 52
src/pages/rotationChart/introduction/edit/index.jsx Dosyayı Görüntüle

@@ -1,68 +1,110 @@
1
-import { addRegulation, getRegulationList, getRegulationById } from '@/services/regulation';
2
-import { PageContainer, ProForm, ProFormTextArea } from '@ant-design/pro-components';
3
-import { Card, Col, message, Row, Space } from 'antd';
4
-import { useNavigate, useSearchParams } from 'react-router-dom';
5
-import { useEffect, useRef, useState } from 'react';
6
-import { queryTable } from '@/utils/request';
1
+import { addRegulation, getRegulationList } from "@/services/regulation";
2
+import {
3
+  PageContainer,
4
+  ProForm,
5
+  ProFormTextArea,
6
+} from "@ant-design/pro-components";
7
+import { Card, Col, Button, Row, Space, Typography } from "antd";
8
+import { useNavigate, useSearchParams } from "react-router-dom";
9
+import { useEffect, useRef, useState } from "react";
10
+import Wangeditor from "@/components/Wangeditor";
7 11
 
12
+const { Title } = Typography;
8 13
 export default (props) => {
14
+  const [searchParams, setSearchParams] = useSearchParams();
15
+  const id = searchParams.get("id");
16
+  const [data, setData] = useState({});
17
+  const [isEdit, setIsEdit] = useState(false);
18
+  const [loading,setLoading] = useState(false)
9 19
   const formRef = useRef();
10
-  const idRef = useRef();
11 20
   const navigate = useNavigate();
12 21
 
13 22
   useEffect(() => {
23
+    getRegulationData()
24
+  }, []);
25
+
26
+  const getRegulationData =()=>{
27
+    setLoading(true)
14 28
     getRegulationList({ type: `station` }).then((res) => {
15
-      formRef.current.setFieldsValue(res.records[0]);
16
-      idRef.current = res.records[0].id;
29
+      setData(res.records[0]);
30
+      setLoading(false)
31
+      // formRef.current.setFieldsValue(res.records[0]);
32
+      // console.log('tt', res)
17 33
     });
18
-  }, []);
34
+  }
35
+  useEffect(() => {
36
+    if (isEdit) {
37
+      formRef.current.setFieldsValue(data);
38
+    }
39
+  }, [isEdit]);
19 40
 
20 41
   const onFinish = async (values) => {
21
-    //修改
22
-    const id = idRef.current;
23
-    console.log('id', id)
24
-    addRegulation({ ...values, id }).then((res) => {
25
-      navigate(-1);
26
-      return false;
27
-    })
42
+    //添加,修改
43
+    addRegulation({ ...values, id: data.id }).then((res) => {
44
+      // message.success('成功');
45
+      getRegulationData()
46
+      setIsEdit(false);
47
+    });
48
+    return false;
28 49
   };
29 50
 
30 51
   return (
31 52
     <PageContainer>
32
-      <Card>
33
-        <ProForm
34
-          formRef={formRef}
35
-          layout={'horizontal'}
36
-          labelCol={{ span: 8 }}
37
-          wrapperCol={{ span: 16 }}
38
-          onFinish={onFinish}
39
-          submitter={{
40
-            searchConfig: {
41
-              resetText: '返回',
42
-            },
43
-            onReset: () => navigate(-1),
44
-            render: (props, doms) => {
45
-              return (
46
-                <Row>
47
-                  <Col span={8} offset={11}>
48
-                    <Space>{doms}</Space>
49
-                  </Col>
50
-                </Row>
51
-              );
52
-            },
53
-          }}
54
-        >
55
-          <ProFormTextArea
56
-            label="发布内容"
57
-            placeholder="请输入发布内容"
58
-            rules={[{ required: true, message: '请输入发布内容' }]}
59
-            allowClear={false}
60
-            width={750}
61
-            name="detail"
62
-            request={queryTable(getRegulationList)}
63
-          />
64
-        </ProForm>
53
+      <Card
54
+        title={
55
+          <Button  type="primary" onClick={() => setIsEdit(!isEdit)}>
56
+            {isEdit ? "取消编辑" : "编辑"}
57
+          </Button>
58
+        }
59
+        loading={loading}
60
+      >
61
+        {!isEdit ? (
62
+          <>
63
+            {/* <Title level={2} style={{ marginBottom: "2em" }}>
64
+              {data.title}
65
+            </Title> */}
66
+            <div dangerouslySetInnerHTML={{ __html: data?.detail }}></div>
67
+          </>
68
+        ) : (
69
+          <ProForm
70
+            formRef={formRef}
71
+            layout={"horizontal"}
72
+            labelCol={{ span: 4 }}
73
+            wrapperCol={{ span: 16 }}
74
+            onFinish={onFinish}
75
+            submitter={{
76
+              searchConfig: {
77
+                resetText: "返回",
78
+              },
79
+              resetButtonProps: {
80
+                style: {
81
+                  // 隐藏重置按钮
82
+                  display: "none",
83
+                },
84
+              },
85
+              // onReset: () => navigate(-1),
86
+              render: (props, doms) => {
87
+                return (
88
+                  <Row>
89
+                    <Col span={8} offset={6}>
90
+                      <Space>{doms}</Space>
91
+                    </Col>
92
+                  </Row>
93
+                );
94
+              },
95
+            }}
96
+          >
97
+            <ProForm.Item
98
+              name="detail"
99
+              label="发布内容"
100
+              placeholder="请输入发布内容"
101
+              rules={[{ required: true, message: "请输入发布内容" }]}
102
+            >
103
+              <Wangeditor></Wangeditor>
104
+            </ProForm.Item>
105
+          </ProForm>
106
+        )}
65 107
       </Card>
66 108
     </PageContainer>
67
-  )
68
-}
109
+  );
110
+};