({}, { call, put })
| 20 | |
| 21 | effects: { |
| 22 | * login({}, { call, put }) { |
| 23 | const response = yield call(loginByToken); // 通过token登录 |
| 24 | //debugger |
| 25 | if (response.userId) { |
| 26 | yield put({ |
| 27 | type: 'changeLoginStatus', |
| 28 | payload: response, |
| 29 | }); |
| 30 | |
| 31 | // 成功登录后保存用户信息 |
| 32 | yield put({ |
| 33 | type: 'user/saveCurrentUser', |
| 34 | payload: response, |
| 35 | }); |
| 36 | // 成功登录 把当前登录状态保存到localStorage中方式刷新state消失 |
| 37 | localStorage.setItem('currentUser', JSON.stringify(response)) |
| 38 | localStorage.setItem('stageUserAdmin', response.stageUserAdmin) //接口控制 |
| 39 | localStorage.setItem('userRole', response.stageUserAdmin ? 'admin' : 'user') //界面控制 |
| 40 | return true; // 登录成功 返回true |
| 41 | } |
| 42 | // 登陆失败或者认证失败后 |
| 43 | window.location.href = `${baseUrl}${severUrl}/auth/login?location=${encodeURIComponent(window.location.href)}`; |
| 44 | return false; |
| 45 | }, |
| 46 | * logout({ payload }, { call, put }) { |
| 47 | // const { redirect } = getPageQuery(); |
| 48 | yield call(logout) |
nothing calls this directly
no outgoing calls
no test coverage detected