-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtable.ts
More file actions
65 lines (57 loc) · 1.29 KB
/
table.ts
File metadata and controls
65 lines (57 loc) · 1.29 KB
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
import { createModel } from '@rematch/core'
import * as services from '../services'
export const table = createModel({
state: {
records: [],
pagination: {
current: 0,
pageSize: 15,
total: 0,
},
modalVisible: false,
tableDetail: {
name: '',
time: '',
info1: '',
info2: '',
},
},
reducers: {
// 在这里写纯函数来改变 state
updateState(state, payload) {
return {
...state,
...payload,
}
},
hideModal(state, _payload) {
return {
...state,
modalVisible: false,
}
},
},
effects: () => ({
// 在这里写"不纯"的函数,比如 ajax 请求获取数据
// 异步请求必须放在此处
// 获取表格数据
async asyncTableList(payload?) {
const result = await services.table.tableList(payload)
this.updateState(result)
},
// 删除用户
async asyncTableDelete(payload) {
const result = await services.table.tableDelete(payload)
if (result) {
this.asyncTableList()
}
},
// 获取用户详情
async asyncTableDetail(payload) {
const result = await services.table.tableDetail({
tableId: payload.tableId,
})
this.updateState(result)
},
}),
})