动态菜单和动态路由的 antd pro

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { queryNotices } from '../services/api';
  2. export default {
  3. namespace: 'global',
  4. state: {
  5. collapsed: false,
  6. notices: [],
  7. },
  8. effects: {
  9. *fetchNotices(_, { call, put }) {
  10. const data = yield call(queryNotices);
  11. yield put({
  12. type: 'saveNotices',
  13. payload: data,
  14. });
  15. yield put({
  16. type: 'user/changeNotifyCount',
  17. payload: data.length,
  18. });
  19. },
  20. *clearNotices({ payload }, { put, select }) {
  21. yield put({
  22. type: 'saveClearedNotices',
  23. payload,
  24. });
  25. const count = yield select(state => state.global.notices.length);
  26. yield put({
  27. type: 'user/changeNotifyCount',
  28. payload: count,
  29. });
  30. },
  31. },
  32. reducers: {
  33. changeLayoutCollapsed(state, { payload }) {
  34. return {
  35. ...state,
  36. collapsed: payload,
  37. };
  38. },
  39. saveNotices(state, { payload }) {
  40. return {
  41. ...state,
  42. notices: payload,
  43. };
  44. },
  45. saveClearedNotices(state, { payload }) {
  46. return {
  47. ...state,
  48. notices: state.notices.filter(item => item.type !== payload),
  49. };
  50. },
  51. },
  52. subscriptions: {
  53. setup({ history }) {
  54. // Subscribe history(url) change, trigger `load` action if pathname is `/`
  55. return history.listen(({ pathname, search }) => {
  56. if (typeof window.ga !== 'undefined') {
  57. window.ga('send', 'pageview', pathname + search);
  58. }
  59. });
  60. },
  61. },
  62. };