Yansen 2 年 前
コミット
be09c80705
共有7 個のファイルを変更した166 個の追加75 個の削除を含む
  1. 0
    2
      src/App.jsx
  2. 60
    61
      src/components/Page/List.jsx
  3. 79
    0
      src/pages/issue/index.jsx
  4. 0
    4
      src/pages/issueType/list/index.jsx
  5. 1
    1
      src/routes/menus.jsx
  6. 25
    6
      src/routes/routes.jsx
  7. 1
    1
      src/utils/request.js

+ 0
- 2
src/App.jsx ファイルの表示

@@ -10,8 +10,6 @@ function App() {
10 10
   const { antThemeData } = useModel('system');
11 11
   const theme = React.useMemo(() => ({token: antThemeData}), [antThemeData]);
12 12
 
13
-  console.log(theme)
14
-
15 13
   return (
16 14
     <ConfigProvider locale={locale} theme={theme}>
17 15
       <Antd>

+ 60
- 61
src/components/Page/List.jsx ファイルの表示

@@ -1,90 +1,89 @@
1
-import React, { useRef, useMemo } from 'react';
1
+import React from 'react';
2 2
 import { Button, Popconfirm, message } from 'antd';
3 3
 import { ProTable } from '@ant-design/pro-components';
4
-import { Link, useNavigate } from "react-router-dom";
5
-import { queryTable, restful } from '@/utils/request';
4
+import { queryTable } from '@/utils/request';
6 5
 import Page from './index';
7 6
 
8
-export default (props) => {
7
+export default React.forwardRef((props, ref) => {
9 8
   /**
10
-   * resource 用来确定应该调用哪个接口
11
-   * rowKey 标识数据每一行的唯一键, 只能是字符串
12
-   * columns 定义表格每一列, 符合 ProTable 定义
13
-   * editURL 编辑页路由
9
+   * request 与 ProTable 定义不同,这个只是普通的接口即可
14 10
    */
15
-  const { resource, rowKey, columns, editURL } = props;
16
-  const actionRef = useRef();
17
-  const navigate = useNavigate();
11
+  const { request, rowKey, columns, onAdd, onDelete, onEdit, toolBarRender, optionRender, ...leftProps } = props;
12
+  const actionRef = React.useRef();
13
+  const hideRef = React.useRef();
18 14
 
19
-  // 接口汇总
20
-  const api = useMemo(() => {
21
-    // 通过 resource 知道是哪个接口
22
-    // 通过 restfule 生成 增删改查的接口
23
-    const apis = restful(resource);
24
-
25
-    // 返回两个,一个是列表查询, 一个是删除
26
-    return {
27
-      list: apis[0],
28
-      delete: apis[4],
29
-    }
30
-  }, [resource]);
31
-
32
-  // 响应 删除 操作
33
-  const onDelete = (row) => {
34
-    const hide = message.loading('操作中, 请稍候...');
35
-    api.delete(row[rowKey]).then(() => {
36
-      hide();
37
-      actionRef.current.reload();
38
-    }).catch(hide);
39
-  }
15
+  const api = React.useMemo(() => queryTable(request), [request]);
40 16
 
41 17
   // 统一实现操作列
42
-  const cols = [
18
+  const cols = React.useMemo(() => [
43 19
     ...columns,
44 20
     {
45 21
       title: '操作',
46 22
       valueType: 'option',
47 23
       key: 'option',
48
-      ellipsis: true,
24
+      width: 120,
49 25
       render: (_, record) => [
50
-        <Button style={{ padding: 0 }} type="link" key={1} onClick={() => { navigate(`${editURL}?id=${record[rowKey]}`) }}>
51
-          编辑
52
-        </Button>,
53
-        <Popconfirm
54
-          key={3}
55
-          title="您是否确认删除 ?"
56
-          onConfirm={() => onDelete(record)}
57
-          okText="确定"
58
-          cancelText="取消"
59
-        >
60
-          <Button style={{ padding: 0 }} type="link">
61
-            删除
26
+        (
27
+          onEdit && 
28
+          <Button style={{ padding: 0 }} type="link" key={1} onClick={() => onEdit(record) }>
29
+            编辑
62 30
           </Button>
63
-        </Popconfirm>,
64
-      ],
31
+        ),
32
+        (
33
+          onDelete &&
34
+          <Popconfirm
35
+            key={3}
36
+            title="您是否确认删除 ?"
37
+            onConfirm={() => onDelete(record)}
38
+            okText="确定"
39
+            cancelText="取消"
40
+          >
41
+            <Button style={{ padding: 0 }} type="link">
42
+              删除
43
+            </Button>
44
+          </Popconfirm>
45
+        ),
46
+        ...(optionRender ? optionRender(_, record) : []),
47
+      ].filter(Boolean),
65 48
     },
66
-  ]
49
+  ], [columns, onEdit, onDelete]);
50
+
51
+  React.useImperativeHandle(ref, () => {
52
+    const showLoading = msg => (hideRef.current = message.loading(msg || '操作中, 请稍候...'));
53
+    const hideLoading = () => hideRef.current && hideRef.current();
54
+    const reload = () => actionRef.current?.reload && actionRef.current.reload();
55
+
56
+    return {
57
+      showLoading,
58
+      hideLoading,
59
+      reload,
60
+      actionRef: actionRef,
61
+    }
62
+  }, []);
67 63
 
68 64
   return (
69 65
     <Page>
70 66
       <ProTable
71 67
         rowKey={rowKey}
72 68
         columns={cols}
73
-        request={queryTable(api.list)}
69
+        request={api}
74 70
         cardBordered
75 71
         actionRef={actionRef}
76 72
         toolBarRender={() => [
77
-          <Button
78
-            key="1"
79
-            type="primary"
80
-            onClick={() => {
81
-              navigate(editURL);
82
-            }}
83
-          >
84
-            新增
85
-          </Button>,
86
-        ]}
73
+          (
74
+            onAdd && 
75
+            <Button
76
+              key="1"
77
+              type="primary"
78
+              onClick={onAdd}
79
+            >
80
+              新增
81
+            </Button>
82
+          ),
83
+          ...(toolBarRender ? toolBarRender() : []),
84
+        ].filter(Boolean)}
85
+        {...leftProps}
87 86
       />
88 87
     </Page>
89 88
   )
90
-}
89
+});

+ 79
- 0
src/pages/issue/index.jsx ファイルの表示

@@ -0,0 +1,79 @@
1
+import React from 'react';
2
+import List from '@/components/Page/List';
3
+import { getTaIssue } from '@/service/taissue';
4
+import { getTdLocType } from '@/service/tdloctype';
5
+import { getSysOrg } from '@/service/sysorg';
6
+import { queryDict } from '@/utils/request';
7
+import { Button } from 'antd';
8
+
9
+const queryOrg = queryDict(getSysOrg, { labelKey: 'name', valueKey: 'orgId' });
10
+const queryLocType = queryDict(getTdLocType, { labelKey: 'name', valueKey: 'typeId' })
11
+
12
+export default (props) => {
13
+
14
+  const columns = [
15
+    {
16
+      title: "上报日期",
17
+      dataIndex: "createDate",
18
+      valueType: 'date',
19
+      hideInSearch: true,
20
+    },
21
+    {
22
+      title: "点位",
23
+      dataIndex: "locId",
24
+      valueType: 'select',
25
+      request: queryLocType,
26
+    },
27
+    {
28
+      title: "位置",
29
+      dataIndex: "addr",
30
+      hideInSearch: true,
31
+    },
32
+    {
33
+      title: "问题详情",
34
+      dataIndex: "content",
35
+      hideInSearch: true,
36
+      ellipsis: true,
37
+    },
38
+    {
39
+      title: "责任单位",
40
+      dataIndex: "orgId",
41
+      valueType: 'select',
42
+      request: queryOrg,
43
+    },
44
+    {
45
+      title: "流程状态",
46
+      dataIndex: "processNode",
47
+      valueEnum: {
48
+        start: {
49
+          text: "待交办",
50
+          status: "Default",
51
+        },
52
+        assigned: {
53
+          text: "已交办",
54
+          status: "Processing",
55
+        },
56
+        end: {
57
+          text: "已办结",
58
+          status: "Success",
59
+        },
60
+      },
61
+    },
62
+    {
63
+      title: "截止日期",
64
+      dataIndex: "expireDate",
65
+      hideInSearch: true,
66
+    }
67
+  ];
68
+
69
+  return (
70
+    <List
71
+      rowKey="issueId"
72
+      request={getTaIssue}
73
+      columns={columns}
74
+      optionRender={(_, row) => [
75
+        <Button key="detail" type="link">详情</Button>
76
+      ]}
77
+    />
78
+  )
79
+}

+ 0
- 4
src/pages/issueType/list/index.jsx ファイルの表示

@@ -32,10 +32,6 @@ export default (props) => {
32 32
   };
33 33
 
34 34
   const columns = [
35
-    {
36
-      title: "分类ID",
37
-      dataIndex: "typeId",
38
-    },
39 35
     {
40 36
       title: "分类名称",
41 37
       dataIndex: "name",

+ 1
- 1
src/routes/menus.jsx ファイルの表示

@@ -37,7 +37,7 @@ export const getMenuItems = (routes = [], fullPath = '/') => {
37 37
 
38 38
     return Object.assign(
39 39
       {
40
-        key: path,
40
+        key: route.path ? path : `fake-${Math.random().toString(36).substring(2)}`,
41 41
         label: title,
42 42
         icon,
43 43
         type: menuType,

+ 25
- 6
src/routes/routes.jsx ファイルの表示

@@ -31,6 +31,7 @@ import LocTypeEdit from "@/pages/locType/edit";
31 31
 import IssueTypeList from "@/pages/issueType/list";
32 32
 import IssueTypeEdit from "@/pages/issueType/edit";
33 33
 import QuestionList from "@/pages/question/list";
34
+import IssueList from '@/pages/issue';
34 35
 
35 36
 /**
36 37
  * meta 用来扩展自定义数据数据
@@ -48,15 +49,33 @@ import QuestionList from "@/pages/question/list";
48 49
 
49 50
 export const authRoutes = [
50 51
   {
51
-    path: "check",
52
-    element: <CheckList />,
52
+    path: "",
53
+    element: <Outlet />,
53 54
     meta: {
54
-      title: '模拟测评',
55
-      icon: <ProjectOutlined />,
56
-    }
55
+      title: '业务管理',
56
+      menuType: 'group',
57
+    },
58
+    children: [
59
+      {
60
+        path: "issue",
61
+        element: <IssueList />,
62
+        meta: {
63
+          title: '问 题 单',
64
+          icon: <ProjectOutlined />,
65
+        }
66
+      },
67
+      {
68
+        path: "check",
69
+        element: <CheckList />,
70
+        meta: {
71
+          title: '模拟测评',
72
+          icon: <ProjectOutlined />,
73
+        }
74
+      },
75
+    ],
57 76
   },
58 77
   {
59
-    path: "comm",
78
+    path: "",
60 79
     element: <Outlet />,
61 80
     meta: {
62 81
       title: '基础字典',

+ 1
- 1
src/utils/request.js ファイルの表示

@@ -103,7 +103,7 @@ export function queryTable (apiRequest) {
103 103
   };
104 104
 }
105 105
 
106
-export function queryDict (apiRequest, {labelKey = 'name', valueKey = 'id'}) {
106
+export function queryDict (apiRequest, {labelKey = 'name', valueKey = 'id'} = {}) {
107 107
   return function (params) {
108 108
     const { current, pageSize, ...leftParams } = params || {};
109 109
     return apiRequest({