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
import { message } from 'antd';
import { arrayToStringParams } from '../../utils/request.qs';
import { buildTreeNode, findAllNodes, findCheckedKeys } from '../../utils/tree.utils';
import {
addRole,
updateRole,
deleteRole,
queryRole,
queryRoleResourceTree,
roleAssignResource,
} from '../../services/admin';
export default {
namespace: 'roleList',
state: {
list: [],
count: 0,
pageNo: 0,
pageSize: 10,
roleTreeData: [],
checkedKeys: [],
assignModalLoading: true,
},
effects: {
*add({ payload }, { call, put }) {
const { callback, body, queryParams } = payload;
const response = yield call(addRole, body);
if (callback) {
callback(response);
}
yield put({
type: 'query',
payload: {
...queryParams,
},
});
},
*update({ payload }, { call, put }) {
const { callback, body, queryParams } = payload;
const response = yield call(updateRole, body);
if (callback) {
callback(response);
}
yield put({
type: 'query',
payload: {
...queryParams,
},
});
},
*delete({ payload }, { call, put }) {
const { queryParams, body } = payload;
yield call(deleteRole, body);
message.info('删除成功!');
yield put({
type: 'query',
payload: {
...queryParams,
},
});
},
*query({ payload }, { call, put }) {
const response = yield call(queryRole, payload);
message.info('查询成功!');
const { total, list } = response.data;
yield put({
type: 'querySuccess',
payload: {
list: list,
count: total,
},
});
},
*queryRoleAssign({ payload }, { call, put }) {
yield put({
type: 'changeAssignModalLoading',
payload: true,
});
const response = yield call(queryRoleResourceTree, payload);
const roleResourceTree = response.data;
const roleTreeData = buildTreeNode(roleResourceTree, 'displayName', 'id');
const checkedKeys = findCheckedKeys(roleResourceTree);
yield put({
type: 'querySuccess',
payload: {
checkedKeys,
roleTreeData,
},
});
yield put({
type: 'changeAssignModalLoading',
payload: false,
});
},
*roleAssignResource({ payload }, { call }) {
const { id, resourceIds, roleTreeData } = payload;
const assignNodes = findAllNodes(resourceIds, roleTreeData);
const params = {
id,
resourceIds: arrayToStringParams(assignNodes),
};
const response = yield call(roleAssignResource, params);
if (response.code === 0) {
message.info('操作成功!');
}
},
},
reducers: {
querySuccess(state, { payload }) {
return {
...state,
...payload,
};
},
changeCheckedKeys(state, { payload }) {
return {
...state,
checkedKeys: payload,
};
},
changeAssignModalLoading(state, { payload }) {
return {
...state,
assignModalLoading: payload,
};
},
},
};