authed.js
9.8 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
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
import * as types from '../constants/ActionTypes';
import {loadMyUserInfo,getSmsCode,registerHro,userLogin,getResetSmsCode,modifyPassword,modify_Password,getQuickLoginSmsCode ,getPermission} from '../../utils/authedUtil';
import {getBasicInfoAction,loadSysperms} from '../actions/settingAction'
import {getTenants,changeTenant} from '../../utils/hrUtil';
import {getSysperms} from '../../utils/settingUtil'
import {SubmissionError,change} from 'redux-form';
import {loadTodo,loadDone} from './home';
import {loadOrganizations} from './hr';
import {message} from 'antd';
import moment from 'moment';
export function sendLoginSmsCode(parmas,current){//获取验证码
return dispatch => {
return getSmsCode(parmas)
.then(data => {
if(data.code&&data.code>=300){
if(current==0)
dispatch(change('register_form','current','0'));
else if(current)
dispatch(change('register_form','current',1));
message.error(data.message);
}else{
dispatch(change('register_form','current',1));
}
if(data.error){
throw new SubmissionError({_error:data.error})
}
})
};
}
export function sendResetPwdSmsCode(parmas){//获取重置验证码
return dispatch => {
return getResetSmsCode(parmas)
.then(data => {
if(data&&data.code>=300&&data.message){
message.error(data.message,2)
}else if (data&&data.code == 200){
message.success("验证码发送成功,请注意查收",2)
}
})
.catch(err => { throw err; });
};
}
export function sendQuickLoginSmsCode(parmas){//获取重置验证码
return dispatch => {
return getQuickLoginSmsCode(parmas)
.then(data => {
if(data&&data.code>=300&&data.message){
message.error(data.message,2)
}else if(data&&data.code==200){
message.success("验证码发送成功,请注意查收",2)
}
})
.catch(err => { throw err; });
};
}
export function doRegister(values){
return dispatch => {
return registerHro(values)
.then(data => {
if(data&&data.code>=300){
message.error(data.message,2)
throw new SubmissionError({_error:data.message});
}else {
dispatch({
type: types.REGISTER_SECCESS,
registerSeccess:true
});
}
});
}
}
export function doLogin(parmas){
return dispatch => {
return userLogin(parmas)
.then(data => {
if(data.message){
throw new SubmissionError({_error:data.message})
}
if(data&&data.user_info){
// getTenants().then((tenants)=>{
// const {items=[]}=tenants;
// dispatch({
// type: types.LOAD_TENANTS,
// tenants: items
// });
// if(items.length>1){
// document.location.href="#/choose-tenant";
// }else if(items.length==1){
// changeTenant({'id':items[0].id}).then(back=>{
// document.location.href='#container/home';
// });
// }else{
// message.error('您没有权限登录',2);
// window.location.href="#";
// }
// });
if(window._czc&&window._czc.push)
window._czc.push(["_trackPageview", "登录"]);
dispatch(getTenantsAction())
}
});
};
}
export function getTenantsAction(){
return dispatch => {
return getTenants().then((tenants)=>{
const {items=[]}=tenants;
dispatch({
type : types.LOAD_TENANTS,
tenants: items
});
if(items.length>1){
document.location.href="#/login/choose-tenant";
}else if(items.length==1){
changeTenant({'id':items[0].id}).then(back=>{
document.location.href='#container/home';
});
}else{
message.error('您没有权限登录',2);
window.location.href="#";
}
});
}
}
//登录前重置密码
export function changePassword(values){
return dispatch => {
return modifyPassword(values).then(data => {
if(data&&data.id){
message.success('修改成功',2,()=>{
window.location = '#'
});
}else{
message.error(data.message,2);
}
})
.catch(err => { throw err; });
};
}
//登录后重置密码
export function change_Password(values){
return dispatch => {
return modifyPassword(values).then(data => {
if(data&&data.id){
message.success('修改成功',2);
}else{
message.error(data.message,2);
}
})
.catch(err => { throw err; });
};
}
function addMenus(user_info,name_ref){
const {perms=[]}=user_info,menu1={},menu2={},menus=[];
if(perms){
perms.map((perm,i)=>{
if(!perm.parent_module){
menu1[perm.module]={
...perm,
display_name:perm.module_name
}
}else{
if(menu2[perm.parent_module]){
menu2[perm.parent_module].push({
...perm,
display_name:perm.module_name
})
}else{
menu2[perm.parent_module]=[{
...perm,
display_name:perm.module_name
}]
}
}
});
const keys=Object.keys(menu1);
keys.map((key,i)=>{
if(menu2[key]){
menus.push({
...menu1[key],
children:menu2[key]
})
}else{
menus.push({
...menu1[key]
})
}
});
user_info.menus=menus;
}
return user_info;
}
export function loadMenuForUserInfo(info){
return dispatch => {
return getSysperms()
.then(data => {
const {items=[],name_ref={}}=data;
let {user_info}=info;
dispatch(changeUserInfo(addMenus(user_info,name_ref)));
}).catch(err => { throw err; });
};
}
export function loadUserInfo(){
return dispatch => {
return loadMyUserInfo()
.then(data => {
let {user_info}=data;
dispatch(loadMenuForUserInfo(data));
// dispatch(changeUserInfo(user_info));
return user_info;
}).catch(err => { throw err; });
};
}
export function changeUserInfo(user) {
return dispatch => {
dispatch({
type: types.CHANGE_USER_INFO,
userInfo:user
});
};
}
export function changeAvatar(user) {
return dispatch => {
let time = new Date().getTime();
dispatch({
type: types.CHANGE_AVATAR,
time:time
});
};
}
//切换机构
//切换租户
export function modifyTenant(id,name) {
return dispatch => {
return changeTenant({'id': id}).then(data => {
if (data && data.code == 200) {
message.success('切换成功', 2,()=>{
dispatch(getBasicInfoAction(id));
dispatch({type:types.TENANT_NAME,tenantName:name});
dispatch(changeAvatar());
dispatch(loadUserInfo());
dispatch(loadTodo(moment(new Date())));
dispatch(loadDone(0,15))
dispatch(loadOrganizations());
dispatch(loadSysperms());
document.location.href=`#container/home`;
});
} else if (data && data.code >= 300) {
message.error(data.message,2)
}
}).catch(err => {
throw err;
});
};
}
//选择企业
export function chooseTenant(id) {
return dispatch => {
return changeTenant({'id': id}).then(data => {
if (data && data.code == 200) {
// getSysperms().then(back=>{
// const {items=[]} = back;
// if(items&&items.length>0){
// dispatch(getBasicInfoAction(id));
// document.location.href='#container/home';
// }else{
// message.error('您没有权限登录',2);
// window.location.href="#";
// }
// })
dispatch(getBasicInfoAction(id));
document.location.href='#container/home';
} else if (data && data.code >= 300) {
message.error(data.message,2)
}
}).catch(err => {
throw err;
});
};
}
//选择企业
export function changeRegisterStatus(status) {
return dispatch => {
dispatch({
type: types.REGISTER_SECCESS,
registerSeccess:status
});
};
}
//申报操作权限查询
export function getPermissionAction() {
return dispatch => {
// return getPermission()
// .then(data => {
// dispatch({
// type : types.GETPERMISSION,
// getPermission: data,
// onlySee:data.has_perm == 'y' ? true : false
// });
// return data;
// })
// .catch(err => { throw err; });
};
}