123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- import { message } from 'antd';
- import { routerRedux } from 'dva/router';
- import {
- queryLessonList,
- queryLessonItem,
- createLessonItem,
- updateLessonItem,
- deleteLessonItem,
- } from '../services/lesson';
- export default {
- namespace: 'lesson',
- state: {
- list: [],
- pageNo: 1,
- pageSize: 15,
- totalSize: 0,
- currentItem: {},
- },
- effects: {
- *fetchLessonList({ payload }, { call, put }) {
- const response = yield call(queryLessonList, 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,
- },
- });
- }
- },
- *fetchLessonItem({ payload }, { call, put }) {
- const response = yield call(queryLessonItem, payload);
- if (response.success) {
- yield put({
- type: 'querySuccess',
- payload: {
- currentItem: response.data || {},
- },
- });
- }
- },
- *createLessonItem({ payload, state }, { call, put }) {
- const response = yield call(createLessonItem, payload);
- if (response.success) {
- message.success('创建课成功');
- yield put(routerRedux.push({
- state,
- pathname: '/product/lesson/list',
- }));
- }
- },
- *deleteLessonItem({ payload, states }, { call, put }) {
- const response = yield call(deleteLessonItem, payload);
- if (response.success) {
- message.success('删除课成功');
- yield put({
- type: 'fetchLessonList',
- payload: states.Queryers,
- });
- }
- },
- *updateLessonItem({ payload, states }, { call, put }) {
- const response = yield call(updateLessonItem, payload);
- if (response.success) {
- message.success('修改课成功');
- yield put(routerRedux.push({
- pathname: '/product/lesson/list',
- state: states,
- }));
- }
- },
- },
- reducers: {
- querySuccess(state, action) {
- return {
- ...state,
- ...action.payload,
- };
- },
- fixCoursewareList(state, action) {
- return {
- ...state,
- currentItem: {
- ...state.currentItem,
- wareList: action.payload,
- },
- };
- },
- cleanItemState(state) {
- return {
- ...state,
- currentItem: {},
- };
- },
- },
- };
|