lisenzhou 2 年之前
父節點
當前提交
515660ec82

+ 61
- 40
src/components/UploadFile/index.jsx 查看文件

@@ -1,64 +1,85 @@
1
-import React, { useCallback, useState } from 'react'
2
-import { UploadOutlined } from '@ant-design/icons';
3
-import { Upload, Button } from 'antd';
4
-import { uploadFile } from '@/services/rotationChart';
1
+import React, { useCallback, useState } from "react";
2
+import { UploadOutlined } from "@ant-design/icons";
3
+import { Upload, Button } from "antd";
4
+import { uploadFile } from "@/services/rotationChart";
5 5
 
6 6
 const customRequest = ({ file, onError, onSuccess }) => {
7 7
   const data = new FormData();
8
-  data.append('file', file);
8
+  data.append("file", file);
9 9
 
10
-  uploadFile(data).then((res) => {
11
-    onSuccess(res.url)
12
-  }).catch((err) => {
13
-    onError(err);
14
-  })
10
+  uploadFile(data)
11
+    .then((res) => {
12
+      onSuccess(res.url);
13
+    })
14
+    .catch((err) => {
15
+      onError(err);
16
+    });
15 17
 
16 18
   return {
17 19
     abort() {
18
-      console.log('upload progress is aborted.');
20
+      console.log("upload progress is aborted.");
19 21
     },
20 22
   };
21
-}
23
+};
22 24
 
23 25
 export default (props) => {
24 26
   const { value, onChange, preview, ...inputProps } = props;
25 27
   const [loading, setLoading] = useState(false);
26 28
 
27
-  const onUpload = useCallback((e) => {
28
-    const { files } = e.target;
29
-    if (!files || files.length < 1) return;
30
-
31
-    setLoading(true);
32
-    const data = new FormData();
33
-    data.append('file', files[0]);
29
+  const onUpload = useCallback(
30
+    (e) => {
31
+      const { files } = e.target;
32
+      if (!files || files.length < 1) return;
34 33
 
35
-    uploadFile(data).then((res) => {
36
-      setLoading(false);
37
-      if (typeof onChange === 'function') {
38
-        onChange(res.url)
39
-      }
40
-    }).catch((err) => {
41
-      setLoading(false);
42
-      // onError(err);
43
-    })
34
+      setLoading(true);
35
+      const data = new FormData();
36
+      data.append("file", files[0]);
44 37
 
45
-  }, [onChange])
38
+      uploadFile(data)
39
+        .then((res) => {
40
+          setLoading(false);
41
+          if (typeof onChange === "function") {
42
+            onChange(res.url);
43
+          }
44
+        })
45
+        .catch((err) => {
46
+          setLoading(false);
47
+          // onError(err);
48
+        });
49
+    },
50
+    [onChange]
51
+  );
46 52
 
47 53
   const onClick = () => {
48
-    const input = document.createElement('input');
49
-    input.type = 'file';
50
-    Object.assign(input, inputProps);    
51
-    input.addEventListener('change', onUpload);
54
+    const input = document.createElement("input");
55
+    input.type = "file";
56
+    Object.assign(input, inputProps);
57
+    input.addEventListener("change", onUpload);
52 58
     // input.removeEventListener('change', onUpload);
53 59
     input.click();
54
-  }
60
+  };
55 61
 
56 62
   return (
57 63
     <div>
58
-      <Button icon={<UploadOutlined />} onClick={onClick}>上传文件</Button>
59
-      {
60
-        value && typeof preview === 'function' && preview(value)
61
-      }
64
+      <Button icon={<UploadOutlined />} onClick={onClick}>
65
+        上传文件
66
+      </Button>
67
+      {value &&
68
+        preview &&
69
+        (typeof preview === "function" ? (
70
+          preview(value)
71
+        ) : (
72
+          <div style={{ marginTop: "1em" }}>
73
+            <a
74
+              href={`${value}`}
75
+              download
76
+              // rel="noopener noreferrer"
77
+              // key="link"
78
+            >
79
+              {value?.substring(value?.lastIndexOf("/") + 1)}
80
+            </a>
81
+          </div>
82
+        ))}
62 83
     </div>
63
-  )
64
-}
84
+  );
85
+};

+ 10
- 6
src/components/Wangeditor/index.jsx 查看文件

@@ -2,6 +2,9 @@ import React, { useState, useEffect } from "react";
2 2
 import "@wangeditor/editor/dist/css/style.css";
3 3
 import { Editor, Toolbar } from "@wangeditor/editor-for-react";
4 4
 
5
+// 工具栏配置参考
6
+// https://www.cnblogs.com/-roc/p/16400965.html
7
+
5 8
 function MyEditor(props) {
6 9
   const {
7 10
     value,
@@ -10,11 +13,9 @@ function MyEditor(props) {
10 13
     },
11 14
     toolbarConfig = {
12 15
       excludeKeys: [
13
-        "insertImage",
14
-        "viewImageLink",
15
-        "editImage",
16
-        "uploadImage",
17
-        "uploadVideo",
16
+
17
+        "group-image",
18
+        "group-video",
18 19
       ],
19 20
     },
20 21
     editorConfig = {
@@ -27,7 +28,10 @@ function MyEditor(props) {
27 28
   console.log(props, "MyEditor");
28 29
   // 模拟 ajax 请求,异步设置 html
29 30
   useEffect(() => {
30
-    console.log(editor     );
31
+    if(editor){
32
+      console.log(editor,editor.getConfig(),editor.getAllMenuKeys(),editor.getMenuConfig('image')) ;
33
+    }
34
+   
31 35
 
32 36
     setHtml(value);
33 37
   }, [value]);

+ 15
- 1
src/pages/cms/emergencyPlan/detail/index.jsx 查看文件

@@ -15,6 +15,7 @@ export default (props) => {
15 15
   const [searchParams] = useSearchParams();
16 16
   const id = searchParams.get("id");
17 17
   const [data, setData] = useState({});
18
+  const [url, setUrl] = useState("");
18 19
   const navigate = useNavigate();
19 20
 
20 21
   const formRef = useRef();
@@ -23,16 +24,29 @@ export default (props) => {
23 24
     if (id) {
24 25
       getPostsDetail(id).then((res) => {
25 26
         setData(res);
27
+        setUrl(res.filesList[0]?.fileAddr);
26 28
       });
27 29
     }
28 30
   }, [id]);
29 31
 
30 32
   return (
31
-    <Card extra={<Button onClick={()=>navigate(-1)}> 返回</Button>}>
33
+    <Card extra={<Button onClick={() => navigate(-1)}> 返回</Button>}>
32 34
       <Title level={2} style={{ marginBottom: "2em" }}>
33 35
         {data.title}
34 36
       </Title>
35 37
       <div dangerouslySetInnerHTML={{ __html: data?.detail }}></div>
38
+      {url && (
39
+        <div style={{marginTop:"2em"}}>
40
+          <a
41
+            href={`${url}`}
42
+            download
43
+            // rel="noopener noreferrer"
44
+            // key="link"
45
+          >
46
+            {url?.substring(url?.lastIndexOf("/") + 1)}
47
+          </a>
48
+        </div>
49
+      )}
36 50
     </Card>
37 51
   );
38 52
 };

+ 31
- 44
src/pages/cms/emergencyPlan/edit/index.jsx 查看文件

@@ -19,21 +19,14 @@ export default (props) => {
19 19
   const navigate = useNavigate();
20 20
 
21 21
   const formRef = useRef();
22
-  // useEffect(() => {
23
-  //   getStoreList({ isDish: 1, pageSize: 9999 }).then((res) => {
24
-  //     setFoodDict(
25
-  //       res?.records?.map((x) => ({
26
-  //         label: x.name,
27
-  //         value: x.id,
28
-  //       }))
29
-  //     );
30
-  //   });
31
-  // }, [id]);
32 22
 
33 23
   useEffect(() => {
34 24
     if (id) {
35 25
       getPostsDetail(id).then((res) => {
36
-        formRef.current.setFieldsValue(res);
26
+        formRef.current.setFieldsValue({
27
+          ...res,
28
+          filesList: res.filesList?.map((x) => x.fileAddr)[0]||null,
29
+        });
37 30
       });
38 31
     }
39 32
   }, [id]);
@@ -41,17 +34,31 @@ export default (props) => {
41 34
   const onFinish = async (values) => {
42 35
     console.log(values, "===");
43 36
 
44
-    if (id) {
45
-      updatePosts(id, { ...values, status: Number(values.status) }).then(
46
-        (res) => {
47
-          navigate(-1);
48
-        }
49
-      );
50
-    } else {
51
-      savePosts({ ...values, status: Number(values.status) }).then((res) => {
52
-        navigate(-1);
53
-      });
54
-    }
37
+    // if (id) {
38
+    //   updatePosts(id, { ...values, status: Number(values.status) }).then(
39
+    //     (res) => {
40
+    //       navigate(-1);
41
+    //     }
42
+    //   );
43
+    // } else {
44
+    savePosts({
45
+      ...values,
46
+      filesList: values.filesList
47
+        ? [
48
+            {
49
+              fileAddr: values.filesList,
50
+              fileName: values.filesList?.substring(
51
+                values.filesList?.lastIndexOf("/") + 1
52
+              ),
53
+            },
54
+          ]
55
+        : null,
56
+      status: Number(values.status),
57
+      ...(id?{id}:{}),
58
+    }).then((res) => {
59
+      navigate(-1);
60
+    });
61
+    // }
55 62
 
56 63
     return false;
57 64
   };
@@ -98,28 +105,8 @@ export default (props) => {
98 105
           >
99 106
             <Wangeditor></Wangeditor>
100 107
           </ProForm.Item>
101
-          <ProForm.Item
102
-            name="file"
103
-            label="文件"
104
-   
105
-           
106
-          >
107
-            <UploadFile
108
-              preview={(value) => {
109
-                return (
110
-                  <div style={{ marginTop: "2em" }}>
111
-                    <a
112
-                      href={value}
113
-                      target="_blank"
114
-                      rel="noopener noreferrer"
115
-                      key="link"
116
-                    >
117
-                      {value}
118
-                    </a>
119
-                  </div>
120
-                );
121
-              }}
122
-            ></UploadFile>
108
+          <ProForm.Item name="filesList" label="文件">
109
+            <UploadFile preview={true}></UploadFile>
123 110
           </ProForm.Item>
124 111
 
125 112
           <ProFormSelect

+ 1
- 1
src/pages/cms/emergencyPlan/list/index.jsx 查看文件

@@ -64,7 +64,7 @@ const EmergencyPlanList = (props) => {
64 64
       width: 200,
65 65
       render: (_, record) => [
66 66
         <Button
67
-          key={3}
67
+          key={4}
68 68
           style={{ padding: 0 }}
69 69
           type="link"
70 70
           onClick={() => {