知与行后台管理端

user.js 1020B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. // *fetch(_, { call, put }) {
  10. // const response = yield call(queryUsers);
  11. // yield put({
  12. // type: 'save',
  13. // payload: response,
  14. // });
  15. // },
  16. *fetchCurrent(_, { call, put }) {
  17. const response = yield call(request, apis.user.current);
  18. yield put({
  19. type: 'saveCurrentUser',
  20. payload: response,
  21. });
  22. },
  23. },
  24. reducers: {
  25. saveCurrentUser(state, action) {
  26. return { ...state, currentUser: action.payload || {} };
  27. },
  28. changeNotifyCount(
  29. state = {
  30. currentUser: {},
  31. },
  32. action,
  33. ) {
  34. return {
  35. ...state,
  36. currentUser: {
  37. ...state.currentUser,
  38. notifyCount: action.payload.totalCount,
  39. unreadCount: action.payload.unreadCount,
  40. },
  41. };
  42. },
  43. },
  44. };
  45. export default UserModel;