rule.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { queryRule, removeRule, addRule, updateRule } from '../services/api';
  2. export default {
  3. namespace: 'rule',
  4. state: {
  5. data: {
  6. list: [],
  7. pagination: {},
  8. },
  9. },
  10. effects: {
  11. *fetch({ payload }, { call, put }) {
  12. const response = yield call(queryRule, payload);
  13. yield put({
  14. type: 'save',
  15. payload: response,
  16. });
  17. },
  18. *add({ payload, callback }, { call, put }) {
  19. const response = yield call(addRule, payload);
  20. yield put({
  21. type: 'save',
  22. payload: response,
  23. });
  24. if (callback) callback();
  25. },
  26. *remove({ payload, callback }, { call, put }) {
  27. const response = yield call(removeRule, payload);
  28. yield put({
  29. type: 'save',
  30. payload: response,
  31. });
  32. if (callback) callback();
  33. },
  34. *update({ payload, callback }, { call, put }) {
  35. const response = yield call(updateRule, payload);
  36. yield put({
  37. type: 'save',
  38. payload: response,
  39. });
  40. if (callback) callback();
  41. },
  42. },
  43. reducers: {
  44. save(state, action) {
  45. return {
  46. ...state,
  47. data: action.payload,
  48. };
  49. },
  50. },
  51. };