1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- import { query, update, remove } from '../../services/product';
- import modelExtend from 'dva-model-extend';
- import queryString from 'query-string';
- import { pageModel } from '../common';
- import { pageSize } from '../../utils/config';
- import { checkSearchParams } from '../../utils/utils';
- import { Codes } from '../../utils/config';
- export default modelExtend(pageModel, {
- namespace: 'course',
- state: {
- listLoading: false,
- },
- subscriptions: {
- setup({ dispatch, history }) {
- history.listen((location) => {
- if (location.pathname === '/product/course') {
- const payload = checkSearchParams(queryString.parse(location.search));
- dispatch({ type: 'query', payload });
- }
- });
- }
- },
- effects: {
- * query ({ payload = {} }, { call, put }) {
- yield put({ type: 'changeLoading', payload: { listLoading: true }});
- const { data, success } = yield call(query, { ...payload, type: Codes.CODE_COURSE });
- if (success) {
- yield put({
- type: 'querySuccess',
- payload: {
- list: data.list,
- pagination: {
- current: Number(payload.pageNo) || 1,
- pageSize: Number(payload.pageSize) || pageSize,
- total: data.totalSize,
- }
- }
- });
- }
- yield put({ type: 'changeLoading', payload: { listLoading: false }});
- },
- * delete ({ payload, callback }, { call, put }) {
- const { data, success } = yield call(remove, payload);
- if (success) {
- if (callback) callback();
- }
- },
- * recover ({ payload, callback }, { call, put }) {
- const { data, success } = yield call(update, payload);
- if (success) {
- if (callback) callback();
- }
- },
- },
- reducers: {
- changeLoading(state, action) {
- return { ...state, ...action.payload };
- },
- }
- })
|