user.js 837B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import request from '../utils/request';
  2. import apis from '../services/apis';
  3. const UserModel = {
  4. namespace: 'user',
  5. state: {
  6. currentUser: {},
  7. },
  8. effects: {
  9. *fetchCurrent(_, { call, put }) {
  10. const response = yield call(request, apis.user.current);
  11. yield put({
  12. type: 'saveCurrentUser',
  13. payload: response,
  14. });
  15. },
  16. },
  17. reducers: {
  18. saveCurrentUser(state, action) {
  19. return { ...state, currentUser: action.payload || {} };
  20. },
  21. changeNotifyCount(
  22. state = {
  23. currentUser: {},
  24. },
  25. action,
  26. ) {
  27. return {
  28. ...state,
  29. currentUser: {
  30. ...state.currentUser,
  31. notifyCount: action.payload.totalCount,
  32. unreadCount: action.payload.unreadCount,
  33. },
  34. };
  35. },
  36. },
  37. };
  38. export default UserModel;