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
   const { antThemeData } = useModel('system');
10
   const { antThemeData } = useModel('system');
11
   const theme = React.useMemo(() => ({token: antThemeData}), [antThemeData]);
11
   const theme = React.useMemo(() => ({token: antThemeData}), [antThemeData]);
12
 
12
 
13
-  console.log(theme)
14
-
15
   return (
13
   return (
16
     <ConfigProvider locale={locale} theme={theme}>
14
     <ConfigProvider locale={locale} theme={theme}>
17
       <Antd>
15
       <Antd>

+ 60
- 61
src/components/Page/List.jsx 查看文件

1
-import React, { useRef, useMemo } from 'react';
1
+import React from 'react';
2
 import { Button, Popconfirm, message } from 'antd';
2
 import { Button, Popconfirm, message } from 'antd';
3
 import { ProTable } from '@ant-design/pro-components';
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
 import Page from './index';
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
     ...columns,
19
     ...columns,
44
     {
20
     {
45
       title: '操作',
21
       title: '操作',
46
       valueType: 'option',
22
       valueType: 'option',
47
       key: 'option',
23
       key: 'option',
48
-      ellipsis: true,
24
+      width: 120,
49
       render: (_, record) => [
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
           </Button>
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
   return (
64
   return (
69
     <Page>
65
     <Page>
70
       <ProTable
66
       <ProTable
71
         rowKey={rowKey}
67
         rowKey={rowKey}
72
         columns={cols}
68
         columns={cols}
73
-        request={queryTable(api.list)}
69
+        request={api}
74
         cardBordered
70
         cardBordered
75
         actionRef={actionRef}
71
         actionRef={actionRef}
76
         toolBarRender={() => [
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
     </Page>
87
     </Page>
89
   )
88
   )
90
-}
89
+});

+ 79
- 0
src/pages/issue/index.jsx 查看文件

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
   };
32
   };
33
 
33
 
34
   const columns = [
34
   const columns = [
35
-    {
36
-      title: "分类ID",
37
-      dataIndex: "typeId",
38
-    },
39
     {
35
     {
40
       title: "分类名称",
36
       title: "分类名称",
41
       dataIndex: "name",
37
       dataIndex: "name",

+ 1
- 1
src/routes/menus.jsx 查看文件

37
 
37
 
38
     return Object.assign(
38
     return Object.assign(
39
       {
39
       {
40
-        key: path,
40
+        key: route.path ? path : `fake-${Math.random().toString(36).substring(2)}`,
41
         label: title,
41
         label: title,
42
         icon,
42
         icon,
43
         type: menuType,
43
         type: menuType,

+ 25
- 6
src/routes/routes.jsx 查看文件

31
 import IssueTypeList from "@/pages/issueType/list";
31
 import IssueTypeList from "@/pages/issueType/list";
32
 import IssueTypeEdit from "@/pages/issueType/edit";
32
 import IssueTypeEdit from "@/pages/issueType/edit";
33
 import QuestionList from "@/pages/question/list";
33
 import QuestionList from "@/pages/question/list";
34
+import IssueList from '@/pages/issue';
34
 
35
 
35
 /**
36
 /**
36
  * meta 用来扩展自定义数据数据
37
  * meta 用来扩展自定义数据数据
48
 
49
 
49
 export const authRoutes = [
50
 export const authRoutes = [
50
   {
51
   {
51
-    path: "check",
52
-    element: <CheckList />,
52
+    path: "",
53
+    element: <Outlet />,
53
     meta: {
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
     element: <Outlet />,
79
     element: <Outlet />,
61
     meta: {
80
     meta: {
62
       title: '基础字典',
81
       title: '基础字典',

+ 1
- 1
src/utils/request.js 查看文件

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
   return function (params) {
107
   return function (params) {
108
     const { current, pageSize, ...leftParams } = params || {};
108
     const { current, pageSize, ...leftParams } = params || {};
109
     return apiRequest({
109
     return apiRequest({