lisenzhou 2 年之前
父節點
當前提交
bbfe40081d
共有 4 個文件被更改,包括 83 次插入151 次删除
  1. 35
    34
      src/pages/cms/files/list/addFiles.jsx
  2. 26
    115
      src/pages/cms/files/list/index.jsx
  3. 21
    1
      src/services/posts.js
  4. 1
    1
      vite.config.js

+ 35
- 34
src/pages/cms/files/list/addFiles.jsx 查看文件

@@ -1,55 +1,56 @@
1
-import { PlusOutlined } from '@ant-design/icons';
1
+import { PlusOutlined } from "@ant-design/icons";
2 2
 import {
3 3
   ModalForm,
4 4
   ProForm,
5 5
   ProFormDateRangePicker,
6 6
   ProFormSelect,
7 7
   ProFormText,
8
-} from '@ant-design/pro-components';
9
-import { Button, Form, message } from 'antd';
8
+} from "@ant-design/pro-components";
9
+import { Button, Form, message } from "antd";
10
+import { getPostsFilesList, savePostsFiles } from "@/services/posts";
11
+import UploadFile from "@/components/UploadFile";
10 12
 
11
-
12
-
13
-export default () => {
13
+export default ({onsuccess=()=>{}}) => {
14 14
   const [form] = Form.useForm();
15 15
 
16
+  const onFinish = async (values) => {
17
+    console.log(values);
18
+    // await waitTime(2000);
16 19
 
17
-  const onFinish = ()=>{
18
-
19
-  }
20
+    await savePostsFiles(values);
21
+    onsuccess()
22
+    return true;
23
+  };
20 24
 
21 25
   return (
22 26
     <ModalForm
23
-      title="新建表单"
24
-      trigger={
25
-        <Button type="primary">
26
-          <PlusOutlined />
27
-          新建表单
28
-        </Button>
29
-      }
27
+      title="新增文件"
28
+      trigger={<Button type="primary">新增</Button>}
30 29
       form={form}
31
-      autoFocusFirstInput
30
+      layout={"horizontal"}
31
+      labelCol={{ span: 8 }}
32
+      wrapperCol={{ span: 12 }}
32 33
       modalProps={{
33 34
         destroyOnClose: true,
34
-        onCancel: () => console.log('run'),
35
+        onCancel: () => console.log("run"),
35 36
       }}
36 37
       submitTimeout={2000}
37
-      onFinish={async (values) => {
38
-        await waitTime(2000);
39
-        console.log(values.name);
40
-        message.success('提交成功');
41
-        return true;
42
-      }}
38
+      onFinish={onFinish}
43 39
     >
44
-    
45
-        <ProFormText
46
-          width="md"
47
-          name="name"
48
-          label="文件名称"
49
-
50
-          placeholder="请输入名称"
51
-        />
52
-
40
+      <ProFormText
41
+        width="md"
42
+        name="fileName"
43
+        label="文件名称"
44
+        rules={[{ required: true, message: "请输入文件名称" }]}
45
+        placeholder="请输入名称"
46
+      />
47
+      <ProForm.Item
48
+        name="fileAddr"
49
+        label="文件"
50
+        rules={[{ required: true, message: "请上传文件" }]}
51
+      >
52
+        <UploadFile preview={true}></UploadFile>
53
+      </ProForm.Item>
53 54
     </ModalForm>
54 55
   );
55
-};
56
+};

+ 26
- 115
src/pages/cms/files/list/index.jsx 查看文件

@@ -1,157 +1,68 @@
1
-import { getPostsList, deletePosts, updatePosts } from "@/services/posts";
1
+import { getPostsFilesList, deletePostsFiles } from "@/services/posts";
2 2
 import { queryTable } from "@/utils/request";
3 3
 import { PageContainer, ProTable, ProList } from "@ant-design/pro-components";
4 4
 import { useNavigate } from "react-router-dom";
5 5
 import { Button, message, Popconfirm } from "antd";
6 6
 import { useRef, useState, useEffect } from "react";
7 7
 import { floatMultiply, floatDivide } from "@/utils";
8
-import AddFiles from './addFiles'
8
+import AddFiles from "./addFiles";
9 9
 
10 10
 const FilesList = (props) => {
11
-
12 11
   const [showDetail, setShowDetail] = useState(false);
13 12
   const [activeKey, setActiveKey] = useState("");
14 13
   const actionRef = useRef();
15 14
   const navigate = useNavigate();
16 15
 
17
-
18
-  const updata = (row) => {
19
-    if (row.id) {
20
-      updatePosts(row.id, { status: row.status === 1 ? 0 : 1 }).then((res) => {
21
-        actionRef.current.reload();
22
-      });
23
-    }
24
-  };
25
-
26 16
   const handleDelete = (id) => {
27 17
     if (id) {
28
-      deletePosts(id).then((res) => {
18
+      deletePostsFiles(id).then((res) => {
29 19
         actionRef.current.reload();
30 20
       });
31 21
     }
32 22
   };
33 23
 
34
-  const columns = [
35
-    {
36
-      title: "内容名称",
37
-      dataIndex: "title",
38
-    },
39
-
40
-    {
41
-      title: "状态",
42
-      dataIndex: "status",
43
-      valueType: "select",
44
-      valueEnum: {
45
-        0: { text: "未发布", status: "Error" },
46
-        1: { text: "已发布", status: "Processing" },
47
-      },
48
-    },
49
-    {
50
-      title: "发布人",
51
-      dataIndex: "createPerson",
52
-      search: false,
53
-    },
54
-    {
55
-      title: "操作",
56
-      valueType: "option",
57
-      width: 200,
58
-      render: (_, record) => [
59
-        <Button
60
-          key={3}
61
-          style={{ padding: 0 }}
62
-          type="link"
63
-          onClick={() => {
64
-            updata(record);
65
-          }}
66
-        >
67
-          {record.status === 1 ? "下架" : "发布"}
68
-        </Button>,
69
-        <Button
70
-          key={1}
71
-          style={{ padding: 0 }}
72
-          type="link"
73
-          onClick={() => {
74
-            navigate(`/cms/emergency-plan/detail?id=${record.id}`);
75
-          }}
76
-        >
77
-          详情
78
-        </Button>,
79
-        <Button
80
-          key={2}
81
-          style={{ padding: 0 }}
82
-          type="link"
83
-          onClick={() => {
84
-            navigate(`/cms/emergency-plan/edit?id=${record.id}`);
85
-          }}
86
-        >
87
-          修改
88
-        </Button>,
89
-        <Popconfirm
90
-          key={3}
91
-          title="您是否确认删除 ?"
92
-          onConfirm={() => handleDelete(record.id)}
93
-          okText="确定"
94
-          cancelText="取消"
95
-        >
96
-          {/* manualPush */}
97
-          <Button style={{ padding: 0 }} type="link">
98
-            删除
99
-          </Button>
100
-        </Popconfirm>,
101
-      ],
102
-    },
103
-  ];
104
-
105 24
   return (
106 25
     <PageContainer>
107 26
       <ProList
108 27
         toolBarRender={() => {
109 28
           return [
110
-           <AddFiles />,
29
+            <AddFiles
30
+              onsuccess={() => {
31
+                actionRef.current.reload();
32
+              }}
33
+            />,
111 34
           ];
112 35
         }}
36
+        actionRef={actionRef}
37
+        request={queryTable(getPostsFilesList)}
113 38
         search={{}}
114 39
         rowKey="id"
115 40
         // headerTitle="基础列表"
116
-        pagination={{
117
-          pageSize: 5,
118
-        }}
119
-        showActions="hover"
41
+        pagination={true}
42
+        // showActions="hover"
120 43
         metas={{
121 44
           title: {
122 45
             dataIndex: "fileName",
123 46
             title: "文件名称",
124 47
           },
125
-          description: {
126
-            dataIndex: "title",
127
-            search: false,
128
-          },
48
+
129 49
           actions: {
130 50
             render: (text, row) => [
131
-              <a
132
-                href={row.url}
133
-                target="_blank"
134
-                rel="noopener noreferrer"
135
-                key="link"
136
-              >
137
-                链路
138
-              </a>,
139
-              <a
140
-                href={row.url}
141
-                target="_blank"
142
-                rel="noopener noreferrer"
143
-                key="warning"
144
-              >
145
-                报警
51
+              <a href={row.fileAddr} download>
52
+                下载
146 53
               </a>,
147
-              <a
148
-                href={row.url}
149
-                target="_blank"
150
-                rel="noopener noreferrer"
151
-                key="view"
54
+              <Popconfirm
55
+                key={3}
56
+                title="您是否确认删除 ?"
57
+                onConfirm={() => handleDelete(row.id)}
58
+                okText="确定"
59
+                cancelText="取消"
152 60
               >
153
-                查看
154
-              </a>,
61
+                {/* manualPush */}
62
+                <Button style={{ padding: 0 }} type="link">
63
+                  删除
64
+                </Button>
65
+              </Popconfirm>,
155 66
             ],
156 67
             search: false,
157 68
           },

+ 21
- 1
src/services/posts.js 查看文件

@@ -7,4 +7,24 @@ import { restful } from "@/utils/request";
7 7
 const [getPostsList, getPostsDetail, savePosts, updatePosts, deletePosts] =
8 8
   restful("/posts");
9 9
 
10
-export { getPostsList, getPostsDetail, savePosts, updatePosts, deletePosts };
10
+const [
11
+  getPostsFilesList,
12
+  getPostsFilesDetail,
13
+  savePostsFiles,
14
+  updatePostsFiles,
15
+  deletePostsFiles,
16
+] = restful("/postsFiles");
17
+
18
+export {
19
+  getPostsList,
20
+  getPostsDetail,
21
+  savePosts,
22
+  updatePosts,
23
+  deletePosts,
24
+  
25
+  getPostsFilesList,
26
+  getPostsFilesDetail,
27
+  savePostsFiles,
28
+  updatePostsFiles,
29
+  deletePostsFiles,
30
+};

+ 1
- 1
vite.config.js 查看文件

@@ -9,7 +9,7 @@ export default defineConfig({
9 9
     proxy: {
10 10
       '/api/': {
11 11
         // 要代理的地址
12
-        target: 'http://192.168.89.147:8087',
12
+        target: 'http://jgz.njyunzhi.com',
13 13
         // 配置了这个可以从 http 代理到 https
14 14
         // 依赖 origin 的功能可能需要这个,比如 cookie
15 15
         changeOrigin: true,