Yansen 2 years ago
parent
commit
a19f88f71a

+ 2
- 1
package.json View File

@@ -10,8 +10,9 @@
10 10
   },
11 11
   "dependencies": {
12 12
     "@ant-design/icons": "^4.7.0",
13
+    "@ant-design/pro-components": "^2.3.13",
13 14
     "@zjxpcyc/react-tiny-store": "^2.0.1",
14
-    "antd": "^4.22.3",
15
+    "antd": "^4.23.4",
15 16
     "react": "18.1.0",
16 17
     "react-dom": "18.1.0",
17 18
     "react-helmet": "^6.1.0",

+ 638
- 81
pnpm-lock.yaml
File diff suppressed because it is too large
View File


+ 10
- 0
src/components/page/Container.jsx View File

@@ -0,0 +1,10 @@
1
+import React from 'react';
2
+import './style.less'
3
+
4
+export default (props) => {
5
+  return (
6
+    <div className="page-container">
7
+      {props.children}
8
+    </div>
9
+  )
10
+}

+ 8
- 4
src/components/page/index.jsx View File

@@ -1,7 +1,7 @@
1 1
 import React from 'react';
2 2
 import { PageHeader } from 'antd';
3 3
 import useRoute from '@/routes/useRoute';
4
-import './style.less'
4
+import Container from './Container';
5 5
 
6 6
 export default (props) => {
7 7
   const { children, ...headerProps } = props;
@@ -11,10 +11,14 @@ export default (props) => {
11 11
 
12 12
   return (
13 13
     <>
14
-      <PageHeader ghost={false} title={title} {...headerProps}></PageHeader>
15
-      <div className="page-container">
14
+      <PageHeader
15
+        ghost={false}
16
+        title={title}
17
+        {...headerProps}
18
+      />
19
+      <Container>
16 20
         {children}
17
-      </div>
21
+      </Container>
18 22
     </>
19 23
   )
20 24
 }

+ 22
- 0
src/index.less View File

@@ -34,3 +34,25 @@ html, body, #root {
34 34
   color: var(--theme-front);
35 35
 }
36 36
 
37
+
38
+// 兼容 360
39
+.ant-pro-sider-collapsed-button {
40
+  top: 18px;
41
+  right: -13px;
42
+}
43
+
44
+.ant-pro .ant-pro-layout .ant-pro-sider-logo {
45
+  padding: 16px;
46
+}
47
+
48
+.ant-pro-page-container .ant-pro-page-container-warp-page-header ~ .ant-pro-grid-content .ant-pro-page-container-children-content {
49
+  margin: 8px 40px 40px 40px;
50
+}
51
+
52
+.ant-pro-table-list-toolbar-container {
53
+  padding: 16px 0;
54
+}
55
+
56
+.ant-pro-card .ant-pro-card-body {
57
+  padding: 16px 24px;
58
+}

+ 42
- 2
src/pages/Home.jsx View File

@@ -1,7 +1,47 @@
1
-import React from 'react'
1
+import React from 'react';
2
+import { Row, Col, Card, Space, Statistic } from 'antd';
3
+import { ArrowDownOutlined, ArrowUpOutlined, LikeOutlined } from '@ant-design/icons';
4
+import Container from '@/components/page/Container';
2 5
 
3 6
 export default (props) => {
4 7
   return (
5
-    <div>adfasdfasdfasdf</div>
8
+    <Container>
9
+      <Row gutter={24}>
10
+        <Col span={6}>
11
+          <Card>
12
+            <Statistic title="Feedback" value={1128} prefix={<LikeOutlined />} />
13
+          </Card>
14
+        </Col>
15
+        <Col span={6}>
16
+          <Card>
17
+            <Statistic title="Unmerged" value={93} suffix="/ 100" />
18
+          </Card>
19
+        </Col>
20
+        <Col span={6}>
21
+          <Card>
22
+            <Statistic
23
+              title="Active"
24
+              value={11.28}
25
+              precision={2}
26
+              valueStyle={{ color: '#3f8600' }}
27
+              prefix={<ArrowUpOutlined />}
28
+              suffix="%"
29
+            />
30
+          </Card>
31
+        </Col>
32
+        <Col span={6}>
33
+          <Card>
34
+            <Statistic
35
+              title="Idle"
36
+              value={9.3}
37
+              precision={2}
38
+              valueStyle={{ color: '#cf1322' }}
39
+              prefix={<ArrowDownOutlined />}
40
+              suffix="%"
41
+            />
42
+          </Card>
43
+        </Col>
44
+      </Row>
45
+    </Container>
6 46
   )
7 47
 }

+ 167
- 0
src/pages/sample/table/index.jsx View File

@@ -0,0 +1,167 @@
1
+import { EllipsisOutlined, PlusOutlined } from '@ant-design/icons';
2
+import { ProTable, TableDropdown } from '@ant-design/pro-components';
3
+import { Button, Dropdown, Menu, Space, Tag } from 'antd';
4
+import { useRef } from 'react';
5
+import Page from '@/components/page';
6
+
7
+// import request from 'umi-request';
8
+const columns = [
9
+    {
10
+        dataIndex: 'index',
11
+        valueType: 'indexBorder',
12
+        width: 48,
13
+    },
14
+    {
15
+        title: '标题',
16
+        dataIndex: 'title',
17
+        copyable: true,
18
+        ellipsis: true,
19
+        tip: '标题过长会自动收缩',
20
+        formItemProps: {
21
+            rules: [
22
+                {
23
+                    required: true,
24
+                    message: '此项为必填项',
25
+                },
26
+            ],
27
+        },
28
+    },
29
+    {
30
+        disable: true,
31
+        title: '状态',
32
+        dataIndex: 'state',
33
+        filters: true,
34
+        onFilter: true,
35
+        ellipsis: true,
36
+        valueType: 'select',
37
+        valueEnum: {
38
+            all: { text: '超长'.repeat(50) },
39
+            open: {
40
+                text: '未解决',
41
+                status: 'Error',
42
+            },
43
+            closed: {
44
+                text: '已解决',
45
+                status: 'Success',
46
+                disabled: true,
47
+            },
48
+            processing: {
49
+                text: '解决中',
50
+                status: 'Processing',
51
+            },
52
+        },
53
+    },
54
+    {
55
+        disable: true,
56
+        title: '标签',
57
+        dataIndex: 'labels',
58
+        search: false,
59
+        renderFormItem: (_, { defaultRender }) => {
60
+            return defaultRender(_);
61
+        },
62
+        render: (_, record) => (<Space>
63
+        {record.labels.map(({ name, color }) => (<Tag color={color} key={name}>
64
+            {name}
65
+          </Tag>))}
66
+      </Space>),
67
+    },
68
+    {
69
+        title: '创建时间',
70
+        key: 'showTime',
71
+        dataIndex: 'created_at',
72
+        valueType: 'date',
73
+        sorter: true,
74
+        hideInSearch: true,
75
+    },
76
+    {
77
+        title: '创建时间',
78
+        dataIndex: 'created_at',
79
+        valueType: 'dateRange',
80
+        hideInTable: true,
81
+        search: {
82
+            transform: (value) => {
83
+                return {
84
+                    startTime: value[0],
85
+                    endTime: value[1],
86
+                };
87
+            },
88
+        },
89
+    },
90
+    {
91
+        title: '操作',
92
+        valueType: 'option',
93
+        key: 'option',
94
+        render: (text, record, _, action) => [
95
+            <a key="editable" onClick={() => {
96
+                    var _a;
97
+                    (_a = action === null || action === void 0 ? void 0 : action.startEditable) === null || _a === void 0 ? void 0 : _a.call(action, record.id);
98
+                }}>
99
+        编辑
100
+      </a>,
101
+            <a href={record.url} target="_blank" rel="noopener noreferrer" key="view">
102
+        查看
103
+      </a>,
104
+            <TableDropdown key="actionGroup" onSelect={() => action === null || action === void 0 ? void 0 : action.reload()} menus={[
105
+                    { key: 'copy', name: '复制' },
106
+                    { key: 'delete', name: '删除' },
107
+                ]}/>,
108
+        ],
109
+    },
110
+];
111
+const menu = (<Menu items={[
112
+        {
113
+            label: '1st item',
114
+            key: '1',
115
+        },
116
+        {
117
+            label: '2nd item',
118
+            key: '1',
119
+        },
120
+        {
121
+            label: '3rd item',
122
+            key: '1',
123
+        },
124
+    ]}/>);
125
+export default () => {
126
+    const actionRef = useRef();
127
+    return (<Page><ProTable columns={columns} actionRef={actionRef} cardBordered request={async (params = {}, sort, filter) => {
128
+            console.log(sort, filter);
129
+            // return request('https://proapi.azurewebsites.net/github/issues', {
130
+            //     params,
131
+            // });
132
+        }} editable={{
133
+            type: 'multiple',
134
+        }} columnsState={{
135
+            persistenceKey: 'pro-table-singe-demos',
136
+            persistenceType: 'localStorage',
137
+            onChange(value) {
138
+                console.log('value: ', value);
139
+            },
140
+        }} rowKey="id" search={{
141
+            labelWidth: 'auto',
142
+        }} options={{
143
+            setting: {
144
+                listsHeight: 400,
145
+            },
146
+        }} form={{
147
+            // 由于配置了 transform,提交的参与与定义的不同这里需要转化一下
148
+            syncToUrl: (values, type) => {
149
+                if (type === 'get') {
150
+                    return Object.assign(Object.assign({}, values), { created_at: [values.startTime, values.endTime] });
151
+                }
152
+                return values;
153
+            },
154
+        }} pagination={{
155
+            pageSize: 5,
156
+            onChange: (page) => console.log(page),
157
+        }} dateFormatter="string" headerTitle="高级表格" toolBarRender={() => [
158
+            <Button key="button" icon={<PlusOutlined />} type="primary">
159
+          新建
160
+        </Button>,
161
+            <Dropdown key="menu" overlay={menu}>
162
+          <Button>
163
+            <EllipsisOutlined />
164
+          </Button>
165
+        </Dropdown>,
166
+        ]}/></Page>);
167
+};

+ 8
- 0
src/routes/routes.jsx View File

@@ -3,6 +3,7 @@ import Home from "@/pages/Home";
3 3
 import Login from '@/pages/login';
4 4
 import Page404 from '@/pages/404';
5 5
 import BasicForm from '@/pages/sample/form';
6
+import BasicTable from '@/pages/sample/table';
6 7
 
7 8
 /**
8 9
  * meta 用来扩展自定义数据数据
@@ -28,6 +29,13 @@ export default [
28 29
           title: '表单',
29 30
         },
30 31
       },
32
+      {
33
+        path: "table",
34
+        element: <BasicTable />,
35
+        meta: {
36
+          title: '表格',
37
+        },
38
+      },
31 39
       {
32 40
         path: "home",
33 41
         element: <Home />,