rule.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import { queryRule, removeRule, addRule } from '../services/api';
  2. export default {
  3. namespace: 'rule',
  4. state: {
  5. data: {
  6. list: [],
  7. pagination: {},
  8. },
  9. loading: true,
  10. },
  11. effects: {
  12. *fetch({ payload }, { call, put }) {
  13. yield put({
  14. type: 'changeLoading',
  15. payload: true,
  16. });
  17. const response = yield call(queryRule, payload);
  18. yield put({
  19. type: 'save',
  20. payload: response,
  21. });
  22. yield put({
  23. type: 'changeLoading',
  24. payload: false,
  25. });
  26. },
  27. *add({ payload, callback }, { call, put }) {
  28. yield put({
  29. type: 'changeLoading',
  30. payload: true,
  31. });
  32. const response = yield call(addRule, payload);
  33. yield put({
  34. type: 'save',
  35. payload: response,
  36. });
  37. yield put({
  38. type: 'changeLoading',
  39. payload: false,
  40. });
  41. if (callback) callback();
  42. },
  43. *remove({ payload, callback }, { call, put }) {
  44. yield put({
  45. type: 'changeLoading',
  46. payload: true,
  47. });
  48. const response = yield call(removeRule, payload);
  49. yield put({
  50. type: 'save',
  51. payload: response,
  52. });
  53. yield put({
  54. type: 'changeLoading',
  55. payload: false,
  56. });
  57. if (callback) callback();
  58. },
  59. },
  60. reducers: {
  61. save(state, action) {
  62. return {
  63. ...state,
  64. data: action.payload,
  65. };
  66. },
  67. changeLoading(state, action) {
  68. return {
  69. ...state,
  70. loading: action.payload,
  71. };
  72. },
  73. },
  74. };