import { message } from 'antd'; import { routerRedux } from 'dva/router'; import { queryTagTypeList, queryTagTypeItem, createTagTypeItem, updateTagTypeItem, deleteTagTypeItem, } from '../services/tagType'; export default { namespace: 'tagType', state: { list: [], pageNo: 1, pageSize: 15, totalSize: 0, currentItem: {}, }, effects: { *fetchTagTypeList({ payload }, { call, put }) { const response = yield call(queryTagTypeList, payload); if (response.success) { yield put({ type: 'querySuccess', payload: { list: response.data.list || [], pageSize: response.data.pageSize, totalSize: response.data.totalSize, pageNo: response.data.pageNo, }, }); } }, *fetchTagTypeItem({ payload }, { call, put }) { const response = yield call(queryTagTypeItem, payload); if (response.success) { yield put({ type: 'querySuccess', payload: { currentItem: response.data || {}, }, }); } }, *createTagTypeItem({ payload, state }, { call, put }) { const response = yield call(createTagTypeItem, payload); if (response.success) { message.success('创建标签类型成功'); yield put(routerRedux.push({ state, pathname: '/frontend/tagType', })); } }, *deleteTagTypeItem({ payload, states }, { call, put }) { const response = yield call(deleteTagTypeItem, payload); if (response.success) { message.success('删除标签类型成功'); yield put({ type: 'fetchTagTypeList', payload: states.Queryers, }); } }, *updateTagTypeItem({ payload, states }, { call, put }) { const response = yield call(updateTagTypeItem, payload); if (response.success) { message.success('修改标签类型成功'); yield put(routerRedux.push({ pathname: '/frontend/tagType', state: states, })); } }, }, reducers: { querySuccess(state, action) { return { ...state, ...action.payload, }; }, fixCurrentItem(state, action) { return { ...state, currentItem: { ...state.currentItem, ...action.payload, }, }; }, cleanItemState(state) { return { ...state, currentItem: {}, }; }, }, };