mirror of
https://github.com/zuiidea/antd-admin
synced 2026-11-16 23:45:07 +00:00
✨
adding user page
This commit is contained in:
+4
-1
@@ -5,7 +5,10 @@ const routes: IRoute[] = [
|
||||
exact: false,
|
||||
path: '/',
|
||||
component: '@/layouts',
|
||||
routes: [{ exact: true, path: '/login', component: '@/pages/login' }],
|
||||
routes: [
|
||||
{ exact: true, path: '/login', component: '@/pages/login' },
|
||||
{ exact: true, path: '/user', component: '@/pages/user' },
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
+2
-2
@@ -17,7 +17,6 @@
|
||||
"echarts-for-react": "^3.0.0",
|
||||
"echarts-gl": "^2.0.2",
|
||||
"echarts-liquidfill": "^3.0.0",
|
||||
"enquire-js": "^0.2.1",
|
||||
"json-format": "^1.0.1",
|
||||
"lodash": "^4.17.11",
|
||||
"md5": "^2.2.1",
|
||||
@@ -25,8 +24,9 @@
|
||||
"path-to-regexp": "^6.1.0",
|
||||
"prop-types": "^15.7.0",
|
||||
"qs": "^6.10.0",
|
||||
"react-adsense": "^0.1.0",
|
||||
"react": "^17.0.2",
|
||||
"react-countup": "^4.2.0",
|
||||
"react-dom": "^17.0.2",
|
||||
"react-helmet": "^6.0.0",
|
||||
"react-highcharts": "^16.1.0",
|
||||
"react-perfect-scrollbar": "^1.5.0",
|
||||
|
||||
@@ -12,6 +12,11 @@ const menus = [
|
||||
name: t`Dashboard`,
|
||||
icon: 'dashboard',
|
||||
},
|
||||
{
|
||||
path: '/user',
|
||||
name: t`User`,
|
||||
icon: 'user',
|
||||
},
|
||||
]
|
||||
|
||||
export default menus
|
||||
|
||||
@@ -4,7 +4,6 @@ import styles from './404.less'
|
||||
|
||||
const NotFoundPage: React.FC = () => (
|
||||
<div className={styles.error}>
|
||||
<FrownOutlined />
|
||||
<h1>404 Not Found</h1>
|
||||
</div>
|
||||
)
|
||||
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
import React from 'react'
|
||||
import { Redirect } from 'umi'
|
||||
|
||||
const Index = () => <Redirect to="/dashboard" />
|
||||
const Index: React.FC = () => <Redirect to="/dashboard" />
|
||||
|
||||
export default Index
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
.table {
|
||||
:global {
|
||||
.ant-table td {
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
import React, { useState, useEffect } from 'react'
|
||||
import { Avatar, Button, Table } from 'antd'
|
||||
import { Link } from 'umi'
|
||||
import { useRequest } from '@/hooks'
|
||||
import { queryUserList } from '@/services'
|
||||
import { Trans } from '@lingui/macro'
|
||||
import styles from './index.less'
|
||||
|
||||
const columns = [
|
||||
{
|
||||
title: <Trans>Avatar</Trans>,
|
||||
dataIndex: 'avatar',
|
||||
key: 'avatar',
|
||||
width: '7%',
|
||||
fixed: 'left',
|
||||
render: (text) => <Avatar style={{ marginLeft: 8 }} src={text} />,
|
||||
},
|
||||
{
|
||||
title: <Trans>Name</Trans>,
|
||||
dataIndex: 'name',
|
||||
key: 'name',
|
||||
render: (text, record) => <Link to={`user/${record.id}`}>{text}</Link>,
|
||||
},
|
||||
{
|
||||
title: <Trans>NickName</Trans>,
|
||||
dataIndex: 'nickName',
|
||||
key: 'nickName',
|
||||
},
|
||||
{
|
||||
title: <Trans>Age</Trans>,
|
||||
dataIndex: 'age',
|
||||
width: '6%',
|
||||
key: 'age',
|
||||
},
|
||||
{
|
||||
title: <Trans>Gender</Trans>,
|
||||
dataIndex: 'isMale',
|
||||
key: 'isMale',
|
||||
width: '7%',
|
||||
render: (text) => <span>{text ? 'Male' : 'Female'}</span>,
|
||||
},
|
||||
{
|
||||
title: <Trans>Phone</Trans>,
|
||||
dataIndex: 'phone',
|
||||
key: 'phone',
|
||||
},
|
||||
{
|
||||
title: <Trans>Email</Trans>,
|
||||
dataIndex: 'email',
|
||||
key: 'email',
|
||||
},
|
||||
{
|
||||
title: <Trans>Address</Trans>,
|
||||
dataIndex: 'address',
|
||||
key: 'address',
|
||||
},
|
||||
{
|
||||
title: <Trans>CreateTime</Trans>,
|
||||
dataIndex: 'createTime',
|
||||
key: 'createTime',
|
||||
},
|
||||
{
|
||||
title: <Trans>Operation</Trans>,
|
||||
key: 'operation',
|
||||
fixed: 'right',
|
||||
width: '12%',
|
||||
render: (text, record) => {
|
||||
return (
|
||||
<>
|
||||
<Button type="link">Update</Button>
|
||||
<Button type="link">Delete</Button>
|
||||
</>
|
||||
)
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
const UserPage: React.FC = () => {
|
||||
const [current, setCurrent] = useState(1)
|
||||
const [pageSize, setPageSize] = useState(10)
|
||||
const {
|
||||
data: { data, total },
|
||||
loading,
|
||||
run: runQueryUserList,
|
||||
} = useRequest(queryUserList, {
|
||||
initialData: {
|
||||
data: [],
|
||||
total: 0,
|
||||
},
|
||||
manual: true,
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
runQueryUserList({
|
||||
page: current,
|
||||
pageSize,
|
||||
})
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [current, pageSize])
|
||||
|
||||
const pagination = {
|
||||
current,
|
||||
pageSize,
|
||||
total,
|
||||
showTotal: (total) => `Total ${total} Items`,
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={styles.error}>
|
||||
<Table
|
||||
simple
|
||||
bordered
|
||||
loading={loading}
|
||||
dataSource={data}
|
||||
columns={columns}
|
||||
className={styles.table}
|
||||
scroll={{ x: 1200 }}
|
||||
rowKey={(record) => record.id}
|
||||
pagination={pagination}
|
||||
onChange={(page) => {
|
||||
setCurrent(page.current)
|
||||
setPageSize(page.pageSize)
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default UserPage
|
||||
+27
-1
@@ -17,7 +17,6 @@ for (const key in APIs) {
|
||||
export const {
|
||||
logoutUser,
|
||||
queryUser,
|
||||
queryUserList,
|
||||
updateUser,
|
||||
createUser,
|
||||
removeUser,
|
||||
@@ -42,3 +41,30 @@ export interface ILoginUserParams {
|
||||
}
|
||||
|
||||
export const loginUser = createService<any, ILoginUserParams>(user.loginUser)
|
||||
|
||||
export interface IUserItem {
|
||||
address: string
|
||||
age: number
|
||||
avatar: string
|
||||
createTime: string
|
||||
email: string
|
||||
id: string
|
||||
isMale: boolean
|
||||
name: string
|
||||
nickName: string
|
||||
phone: string
|
||||
}
|
||||
export interface IUserListReault {
|
||||
data: IUserItem[]
|
||||
total: number
|
||||
}
|
||||
|
||||
export interface IQueryUserListParams {
|
||||
page?: number
|
||||
pageSize?: number
|
||||
}
|
||||
|
||||
export const queryUserList = createService<
|
||||
IUserListReault,
|
||||
IQueryUserListParams
|
||||
>(user.queryUserList)
|
||||
|
||||
Reference in New Issue
Block a user