|
@@ -1,71 +1,110 @@
|
1
|
|
-import { addRegulation, getRegulationList } 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) => {
|
9
|
|
-
|
10
|
14
|
const [searchParams, setSearchParams] = useSearchParams();
|
11
|
|
- const id = searchParams.get('id');
|
|
15
|
+ const id = searchParams.get("id");
|
12
|
16
|
const [data, setData] = useState({});
|
|
17
|
+ const [isEdit, setIsEdit] = useState(false);
|
|
18
|
+ const [loading,setLoading] = useState(false)
|
13
|
19
|
const formRef = useRef();
|
14
|
20
|
const navigate = useNavigate();
|
15
|
21
|
|
16
|
22
|
useEffect(() => {
|
|
23
|
+ getRegulationData()
|
|
24
|
+ }, []);
|
|
25
|
+
|
|
26
|
+ const getRegulationData =()=>{
|
|
27
|
+ setLoading(true)
|
17
|
28
|
getRegulationList({ type: `station` }).then((res) => {
|
18
|
|
- formRef.current.setFieldsValue(res.records[0]);
|
19
|
|
- console.log('tt', res)
|
|
29
|
+ setData(res.records[0]);
|
|
30
|
+ setLoading(false)
|
|
31
|
+ // formRef.current.setFieldsValue(res.records[0]);
|
|
32
|
+ // console.log('tt', res)
|
20
|
33
|
});
|
21
|
|
- }, []);
|
|
34
|
+ }
|
|
35
|
+ useEffect(() => {
|
|
36
|
+ if (isEdit) {
|
|
37
|
+ formRef.current.setFieldsValue(data);
|
|
38
|
+ }
|
|
39
|
+ }, [isEdit]);
|
22
|
40
|
|
23
|
41
|
const onFinish = async (values) => {
|
24
|
42
|
//添加,修改
|
25
|
|
- addRegulation({ ...values, id }).then((res) => {
|
|
43
|
+ addRegulation({ ...values, id: data.id }).then((res) => {
|
26
|
44
|
// message.success('成功');
|
27
|
|
- navigate(-1);
|
|
45
|
+ getRegulationData()
|
|
46
|
+ setIsEdit(false);
|
28
|
47
|
});
|
29
|
48
|
return false;
|
30
|
49
|
};
|
31
|
50
|
|
32
|
51
|
return (
|
33
|
52
|
<PageContainer>
|
34
|
|
- <Card>
|
35
|
|
- <ProForm
|
36
|
|
- formRef={formRef}
|
37
|
|
- layout={'horizontal'}
|
38
|
|
- labelCol={{ span: 8 }}
|
39
|
|
- wrapperCol={{ span: 16 }}
|
40
|
|
- onFinish={onFinish}
|
41
|
|
- submitter={{
|
42
|
|
- searchConfig: {
|
43
|
|
- resetText: '返回',
|
44
|
|
- },
|
45
|
|
- // onReset: () => navigate(-1),
|
46
|
|
- render: (props, doms) => {
|
47
|
|
- return (
|
48
|
|
- <Row>
|
49
|
|
- <Col span={8} offset={11}>
|
50
|
|
- <Space>{doms}</Space>
|
51
|
|
- </Col>
|
52
|
|
- </Row>
|
53
|
|
- );
|
54
|
|
- },
|
55
|
|
- }}
|
56
|
|
- >
|
57
|
|
- <ProFormTextArea
|
58
|
|
- label="发布内容"
|
59
|
|
- placeholder="请输入发布内容"
|
60
|
|
- rules={[{ required: true, message: '请输入发布内容' }]}
|
61
|
|
- allowClear={false}
|
62
|
|
- width={750}
|
63
|
|
- name="detail"
|
|
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 }}
|
64
|
74
|
onFinish={onFinish}
|
65
|
|
- request={queryTable(getRegulationList)}
|
66
|
|
- />
|
67
|
|
- </ProForm>
|
|
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
|
+ )}
|
68
|
107
|
</Card>
|
69
|
108
|
</PageContainer>
|
70
|
|
- )
|
71
|
|
-}
|
|
109
|
+ );
|
|
110
|
+};
|