1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
import React, { useEffect, useReducer, useState } from "react";
import { Table, Tag, Space } from 'antd';
const mockList = (page,size)=> {
let json = {
key: '1',
name: 'John Brown',
age: 32,
address: 'New York No. 1 Lake Park',
tags: ['nice', 'developer'],
}
let idata = []
let preName = json.name;
for (let i=0;i<size;i++) {
json.key = i;
json.name = `${preName+i}-${page}-${size}`
idata.push({ ...json})
}
return idata
}
const mock = (page,size)=> {
let total = 200;//假设200条
let req = new Promise((resolve, reject)=>{
resolve({
list:mockList(page,size),
total
})
})
return req
}
const InnerTable = (props) => {
const columns = [
{
title: 'Name',
dataIndex: 'name',
key: 'name',
render: text => <a>{text}</a>,
},
{
title: 'Age',
dataIndex: 'age',
key: 'age',
},
{
title: 'Address',
dataIndex: 'address',
key: 'address',
},
{
title: 'Tags',
key: 'tags',
dataIndex: 'tags',
render: tags => (
<>
{tags.map(tag => {
let color = tag.length > 5 ? 'geekblue' : 'green';
if (tag === 'loser') {
color = 'volcano';
}
return (
<Tag color={color} key={tag}>
{tag.toUpperCase()}
</Tag>
);
})}
</>
),
},
{
title: 'Action',
key: 'action',
render: (text, record) => (
<Space size="middle">
<a>Invite {record.name}</a>
<a>Delete</a>
</Space>
),
},
];
// const[list,setList] = useReducer((pre,payload)=>{
// console.log(payload)
// if(payload.list?.push)
// return payload.list
// return pre;
// },[])
const [list,setList] = useState([])
//pageSize -> 请求 5页
const [pageInfo,setPageInfo] = useState({
pageSize:5,
current:1,
total:200,
})
useEffect(()=>{
mock(1,5).then(q=> {
console.log('mock',q);
let { list} = q;
setList(list)
setPageInfo({
...q
})
})
},[])
const RequestPage = (p) => {
let {
current,pageSize
} = p;
console.log(p)
mock(current,pageSize).then(q=> {
// console.log('mock',q);
let {page,size , list} = q;
setList(list)
setPageInfo({
...q
})
})
}
// ReactDOM.render(<Table columns={columns} dataSource={data} />, mountNode);
return (
<Table columns={columns} dataSource={list} {...props}
pagination={
{
...pageInfo,
pageSizeOptions:[5,10,15]
}
}
onChange={RequestPage}
/>
)
}
const TableExample = (props) => {
console.log('table=> props',props)
return (
<div className={"admin_table"}>
<InnerTable {...props} />
</div>
)
}
export default TableExample
|