global.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { queryNotices } from '../services/api';
  2. export default {
  3. namespace: 'global',
  4. state: {
  5. collapsed: false,
  6. notices: [],
  7. fetchingNotices: false,
  8. },
  9. effects: {
  10. *fetchNotices(_, { call, put }) {
  11. yield put({
  12. type: 'changeNoticeLoading',
  13. payload: true,
  14. });
  15. const data = yield call(queryNotices);
  16. yield put({
  17. type: 'saveNotices',
  18. payload: data,
  19. });
  20. },
  21. *clearNotices(_, { put, select }) {
  22. const count = yield select(state => state.global.notices.length);
  23. yield put({
  24. type: 'user/changeNotifyCount',
  25. payload: count,
  26. });
  27. },
  28. },
  29. reducers: {
  30. changeLayoutCollapsed(state, { payload }) {
  31. return {
  32. ...state,
  33. collapsed: payload,
  34. };
  35. },
  36. saveNotices(state, { payload }) {
  37. return {
  38. ...state,
  39. notices: payload,
  40. fetchingNotices: false,
  41. };
  42. },
  43. clearNotices(state, { payload }) {
  44. return {
  45. ...state,
  46. notices: state.notices.filter(item => item.type !== payload),
  47. };
  48. },
  49. changeNoticeLoading(state, { payload }) {
  50. return {
  51. ...state,
  52. fetchingNotices: payload,
  53. };
  54. },
  55. },
  56. };