fangmingyue 2 jaren geleden
bovenliggende
commit
20b557cd9c
5 gewijzigde bestanden met toevoegingen van 216 en 17 verwijderingen
  1. 86
    0
      src/regulation/edit/index.jsx
  2. 75
    7
      src/regulation/index.jsx
  3. 14
    5
      src/routes/routes.jsx
  4. 36
    0
      src/services/regulation.js
  5. 5
    5
      src/services/stock.js

+ 86
- 0
src/regulation/edit/index.jsx Bestand weergeven

@@ -0,0 +1,86 @@
1
+import { addRegulation, updataRegulation, getRegulationById } from '@/services/regulation';
2
+import { PageContainer, ProForm, ProFormSelect, ProFormText } 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
+
7
+export default (props) => {
8
+  const [searchParams, setSearchParams] = useSearchParams();
9
+  const id = searchParams.get('id');
10
+  const formRef = useRef();
11
+  const navigate = useNavigate();
12
+
13
+  useEffect(() => {
14
+    if (id) {
15
+      getRegulationById(id).then((res) => {
16
+        formRef.current.setFieldsValue(res);
17
+      });
18
+    }
19
+  }, [id]);
20
+
21
+  const onFinish = async (values) => {
22
+    console.log(values);
23
+
24
+    if (id) {
25
+      //修改
26
+      updataRegulation({ ...values }, id).then((res) => {
27
+        message.success('修改成功');
28
+        navigate(-1);
29
+      });
30
+
31
+    } else {
32
+      //添加
33
+      addRegulation({ ...values }).then((res) => {
34
+        message.success('添加成功');
35
+        navigate(-1);
36
+      });
37
+    }
38
+    return false;
39
+  };
40
+
41
+  return (
42
+    <PageContainer>
43
+      <Card>
44
+        <ProForm
45
+          formRef={formRef}
46
+          layout={'horizontal'}
47
+          labelCol={{ span: 8 }}
48
+          wrapperCol={{ span: 16 }}
49
+          onFinish={onFinish}
50
+          submitter={{
51
+            searchConfig: {
52
+              resetText: '返回',
53
+            },
54
+            onReset: () => navigate(-1),
55
+            render: (props, doms) => {
56
+              return (
57
+                <Row>
58
+                  <Col span={8} offset={8}>
59
+                    <Space>{doms}</Space>
60
+                  </Col>
61
+                </Row>
62
+              );
63
+            },
64
+          }}
65
+        >
66
+          <ProFormText
67
+            name="detail"
68
+            label="发布内容"
69
+            placeholder="请输入发布内容"
70
+            rules={[{ required: true, message: '请输入发布内容' }]}
71
+            allowClear={false}
72
+            width={460}
73
+          />
74
+          <ProFormText
75
+            name="title"
76
+            label="内容名称"
77
+            placeholder="请输入内容名称"
78
+            rules={[{ required: true, message: '请输入内容名称' }]}
79
+            allowClear={false}
80
+            width={460}
81
+          />
82
+        </ProForm>
83
+      </Card>
84
+    </PageContainer>
85
+  );
86
+}

+ 75
- 7
src/regulation/index.jsx Bestand weergeven

@@ -1,34 +1,91 @@
1
+import { getRegulationList, updataRegulation, deleteRegulation } from '@/services/regulation';
1 2
 import { PageContainer, ProTable } from '@ant-design/pro-components';
2 3
 import { useRef, useState } from 'react';
3 4
 import { useNavigate } from 'react-router-dom';
4 5
 import { queryTable } from '@/utils/request';
6
+import { Button, message, Popconfirm } from 'antd';
5 7
 
6 8
 const RegulationList = (props) => {
7
-const actionRef = useRef();
8
-const navigate = useNavigate();
9
+  const actionRef = useRef();
10
+  const navigate = useNavigate();
9 11
 
10
-const columns = [
12
+  // const updata = (row) => {
13
+  //   if (row.id) {
14
+  //     // 修改
15
+  //     updataRegulation(row.id, { ...values }).then((res) => {
16
+  //       message.success('修改成功');
17
+  //       navigate(-1);
18
+  //     });
19
+  //   }
20
+  // };
21
+
22
+  const handleDelete = (id) => {
23
+    if (id) {
24
+      deleteRegulation(id).then((res) => {
25
+        message.success('删除成功');
26
+        actionRef.current.reload();
27
+      });
28
+    }
29
+  };
30
+
31
+  const columns = [
11 32
     {
12 33
       title: 'id',
13 34
       dataIndex: 'id',
35
+      width: 200,
14 36
     },
15 37
     {
16 38
       title: '标题',
17 39
       dataIndex: 'title',
40
+      width: 200,
18 41
     },
19 42
 
20 43
     {
21 44
       title: '内容',
22
-      dataIndex: 'content',
45
+      dataIndex: 'detail',
46
+      width: 200,
23 47
     },
24 48
 
25 49
     {
26 50
       title: '发布人',
27
-      dataIndex: 'faburen',
51
+      dataIndex: 'create_person',
52
+      width: 200,
28 53
     },
29 54
     {
30 55
       title: '发布时间',
31
-      dataIndex: 'fabutime',
56
+      dataIndex: 'create_date',
57
+      width: 200,
58
+    },
59
+    {
60
+      title: '操作',
61
+      valueType: 'option',
62
+      width: 200,
63
+      render: (_, record) => [
64
+        <Button
65
+          key={2}
66
+          style={{ padding: 0 }}
67
+          type="link"
68
+          onClick={() => {
69
+            console.log(record, ']]');
70
+            navigate(`/cms/regulation/add?id=${record.id}`);
71
+          }}
72
+        >
73
+          编辑
74
+        </Button>,
75
+
76
+        <Popconfirm
77
+          key={3}
78
+          title="您是否确认删除 ?"
79
+          onConfirm={() => handleDelete(record.id)}
80
+          okText="确定"
81
+          cancelText="取消"
82
+        >
83
+          {/* manualPush */}
84
+          <Button style={{ padding: 0 }} type="link">
85
+            删除
86
+          </Button>
87
+        </Popconfirm>,
88
+      ],
32 89
     },
33 90
   ];
34 91
 
@@ -38,7 +95,18 @@ const columns = [
38 95
         search={false}
39 96
         actionRef={actionRef}
40 97
         rowKey="id"
41
-        // request={queryTable(getBannerList)}
98
+        toolBarRender={() => [
99
+          <Button
100
+            key="2"
101
+            type="primary"
102
+            onClick={() => {
103
+              navigate('/cms/regulation/add');
104
+            }}
105
+          >
106
+            新增
107
+          </Button>,
108
+        ]}
109
+        request={queryTable(getRegulationList)}
42 110
         columns={columns}
43 111
       />
44 112
     </PageContainer>

+ 14
- 5
src/routes/routes.jsx Bestand weergeven

@@ -32,6 +32,7 @@ import RotationChartEdit from '@/pages/rotationChart/edit';
32 32
 import RotationChartIntroduction from '@/pages/rotationChart/introduction';
33 33
 import Roles from '@/pages/roles/index';
34 34
 import RegulationList from '@/regulation';
35
+import RegulationEdit from '@/regulation/edit';
35 36
 import UserList from '@/pages/user';
36 37
 import UserEdit from '@/pages/user/Edit';
37 38
 import PurchasePlanList from "@/pages/purchase/plan/list";
@@ -198,11 +199,19 @@ export const authRoutes = [
198 199
       },
199 200
       {
200 201
         path: 'regulation',
201
-        element: null,
202
+        element: <RegulationList />,
202 203
         meta: {
203 204
           title: '规章制度',
204 205
         },
205 206
       },
207
+      {
208
+        path: 'regulation/add',
209
+        element: <RegulationEdit />,
210
+        meta: {
211
+          hideInMenu: true,
212
+          title: '规章制度维护',
213
+        },
214
+      },
206 215
       {
207 216
         path: "emergency-plan",
208 217
         element: <EmergencyPlanList />,
@@ -234,7 +243,7 @@ export const authRoutes = [
234 243
           title: "文件管理",
235 244
         },
236 245
       },
237
-     
246
+
238 247
     ],
239 248
   },
240 249
   {
@@ -358,7 +367,7 @@ export const authRoutes = [
358 367
       },
359 368
       {
360 369
         path: "inStore/edit",
361
-        element: <PurchaseInStoreEdit  />,
370
+        element: <PurchaseInStoreEdit />,
362 371
         meta: {
363 372
           title: "采购入库维护",
364 373
           hideInMenu: true,
@@ -411,7 +420,7 @@ export function mergeAuthRoutes (r1, r2) {
411 420
 // 全部路由
412 421
 export const routes = mergeAuthRoutes(defaultRoutes, authRoutes);
413 422
 
414
-function getPath(parent = '/', current = '') {
423
+function getPath (parent = '/', current = '') {
415 424
   if (current.indexOf('/') === 0 || current.indexOf('http') === 0) return current;
416 425
   return `${parent}/${current}`.replace(/\/\//g, '/');
417 426
 }
@@ -422,7 +431,7 @@ export const routeArr = (() => {
422 431
     return routes.reduce((acc, route) => {
423 432
       const path = getPath(parentPath, route.path);
424 433
       const children = route.children ? flatten(route.children, path) : [];
425
-      
434
+
426 435
       return acc.concat([{ ...route, path }].concat(children));
427 436
     }, []);
428 437
   }

+ 36
- 0
src/services/regulation.js Bestand weergeven

@@ -0,0 +1,36 @@
1
+import request from '@/utils/request';
2
+
3
+/**
4
+ * 查询列表
5
+ * @param {*} params
6
+ * @returns
7
+ */
8
+export const getRegulationList = (params) => request('/posts', { params });
9
+
10
+/**
11
+* 新增
12
+* @param {*} data
13
+* @returns
14
+*/
15
+export const addRegulation = (data) => request('/posts', { method: 'post', data });
16
+
17
+/**
18
+ * 更新
19
+ * @param {*} data
20
+ * @returns
21
+ */
22
+export const updataRegulation = (data, id) => request(`/posts/${id}`, { method: 'get', data });
23
+
24
+/**
25
+* 详情
26
+* @param {*} id
27
+* @returns
28
+*/
29
+export const getRegulationById = (id) => request(`/posts/${id}`);
30
+
31
+/**
32
+ * 删除
33
+ * @param {*} id
34
+ * @returns
35
+ */
36
+export const deleteRegulation = (id) => request(`/posts/${id}`, { method: 'delete' });

+ 5
- 5
src/services/stock.js Bestand weergeven

@@ -6,7 +6,7 @@ import request from '@/utils/request';
6 6
  * @param {*} params
7 7
  * @returns
8 8
  */
9
-export const getStoreList = (params) => request('/store', { params,successTip:false });
9
+export const getStoreList = (params) => request('/store', { params, successTip: false });
10 10
 
11 11
 /**
12 12
  * 新增
@@ -42,7 +42,7 @@ export const deleteStore = (id) => request(`/store/${id}`, { method: 'delete' })
42 42
  * @param {*} params
43 43
  * @returns
44 44
  */
45
-export const storeExport = (params) => request('/store/export',  { download: true, params });
45
+export const storeExport = (params) => request('/store/export', { download: true, params });
46 46
 
47 47
 
48 48
 // 库存分类
@@ -51,7 +51,7 @@ export const storeExport = (params) => request('/store/export',  { download: tru
51 51
  * @param {*} params
52 52
  * @returns
53 53
  */
54
-export const getStoreTypeList = (params) => request('/storeType', { params,successTip:false });
54
+export const getStoreTypeList = (params) => request('/storeType', { params, successTip: false });
55 55
 
56 56
 /**
57 57
  * 新增
@@ -73,7 +73,7 @@ export const getStoreTypeById = (id) => request(`/storeType/${id}`);
73 73
  * @param {*} data
74 74
  * @returns
75 75
  */
76
-export const updataStoreType = (id, data) => request(`/storeType/${id}`, { method: 'put', data });
76
+export const updataStoreType = (id, data) => request(`/storeType/${id}`, { method: 'post', data });
77 77
 
78 78
 /**
79 79
  * 删除
@@ -104,4 +104,4 @@ export const addStoreLog = (data) => request('/storeLog', { method: 'post', data
104 104
  * @param {*} params
105 105
  * @returns
106 106
  */
107
- export const storeLogExport = (params) => request('/storeLog/export',  { download: true, params });
107
+export const storeLogExport = (params) => request('/storeLog/export', { download: true, params });