user.js 974 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { query as queryUsers, queryCurrent } from '../services/user';
  2. export default {
  3. namespace: 'user',
  4. state: {
  5. list: [],
  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(queryCurrent);
  18. yield put({
  19. type: 'saveCurrentUser',
  20. payload: response,
  21. });
  22. },
  23. },
  24. reducers: {
  25. save(state, action) {
  26. return {
  27. ...state,
  28. list: action.payload,
  29. };
  30. },
  31. saveCurrentUser(state, action) {
  32. return {
  33. ...state,
  34. currentUser: action.payload || {},
  35. };
  36. },
  37. changeNotifyCount(state, action) {
  38. return {
  39. ...state,
  40. currentUser: {
  41. ...state.currentUser,
  42. notifyCount: action.payload,
  43. },
  44. };
  45. },
  46. },
  47. };