tagType.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import { message } from 'antd';
  2. import { routerRedux } from 'dva/router';
  3. import {
  4. queryTagTypeList,
  5. queryTagTypeItem,
  6. createTagTypeItem,
  7. updateTagTypeItem,
  8. deleteTagTypeItem,
  9. } from '../services/tagType';
  10. export default {
  11. namespace: 'tagType',
  12. state: {
  13. list: [],
  14. pageNo: 1,
  15. pageSize: 15,
  16. totalSize: 0,
  17. currentItem: {},
  18. },
  19. effects: {
  20. *fetchTagTypeList({ payload }, { call, put }) {
  21. const response = yield call(queryTagTypeList, payload);
  22. if (response.success) {
  23. yield put({
  24. type: 'querySuccess',
  25. payload: {
  26. list: response.data.list || [],
  27. pageSize: response.data.pageSize,
  28. totalSize: response.data.totalSize,
  29. pageNo: response.data.pageNo,
  30. },
  31. });
  32. }
  33. },
  34. *fetchTagTypeItem({ payload }, { call, put }) {
  35. const response = yield call(queryTagTypeItem, payload);
  36. if (response.success) {
  37. yield put({
  38. type: 'querySuccess',
  39. payload: {
  40. currentItem: response.data || {},
  41. },
  42. });
  43. }
  44. },
  45. *createTagTypeItem({ payload, state }, { call, put }) {
  46. const response = yield call(createTagTypeItem, payload);
  47. if (response.success) {
  48. message.success('创建标签类型成功');
  49. yield put(routerRedux.push({
  50. state,
  51. pathname: '/frontend/tagType',
  52. }));
  53. }
  54. },
  55. *deleteTagTypeItem({ payload, states }, { call, put }) {
  56. const response = yield call(deleteTagTypeItem, payload);
  57. if (response.success) {
  58. message.success('删除标签类型成功');
  59. yield put({
  60. type: 'fetchTagTypeList',
  61. payload: states.Queryers,
  62. });
  63. }
  64. },
  65. *updateTagTypeItem({ payload, states }, { call, put }) {
  66. const response = yield call(updateTagTypeItem, payload);
  67. if (response.success) {
  68. message.success('修改标签类型成功');
  69. yield put(routerRedux.push({
  70. pathname: '/frontend/tagType',
  71. state: states,
  72. }));
  73. }
  74. },
  75. },
  76. reducers: {
  77. querySuccess(state, action) {
  78. return {
  79. ...state,
  80. ...action.payload,
  81. };
  82. },
  83. fixCurrentItem(state, action) {
  84. return {
  85. ...state,
  86. currentItem: {
  87. ...state.currentItem,
  88. ...action.payload,
  89. },
  90. };
  91. },
  92. cleanItemState(state) {
  93. return {
  94. ...state,
  95. currentItem: {},
  96. };
  97. },
  98. },
  99. };