| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- import { queryRule, removeRule, addRule } from '../services/api';
- export default {
- namespace: 'rule',
- state: {
- data: {
- list: [],
- pagination: {},
- },
- loading: true,
- },
- effects: {
- *fetch({ payload }, { call, put }) {
- yield put({
- type: 'changeLoading',
- payload: true,
- });
- const response = yield call(queryRule, payload);
- yield put({
- type: 'save',
- payload: response,
- });
- yield put({
- type: 'changeLoading',
- payload: false,
- });
- },
- *add({ payload, callback }, { call, put }) {
- yield put({
- type: 'changeLoading',
- payload: true,
- });
- const response = yield call(addRule, payload);
- yield put({
- type: 'save',
- payload: response,
- });
- yield put({
- type: 'changeLoading',
- payload: false,
- });
- if (callback) callback();
- },
- *remove({ payload, callback }, { call, put }) {
- yield put({
- type: 'changeLoading',
- payload: true,
- });
- const response = yield call(removeRule, payload);
- yield put({
- type: 'save',
- payload: response,
- });
- yield put({
- type: 'changeLoading',
- payload: false,
- });
- if (callback) callback();
- },
- },
- reducers: {
- save(state, action) {
- return {
- ...state,
- data: action.payload,
- };
- },
- changeLoading(state, action) {
- return {
- ...state,
- loading: action.payload,
- };
- },
- },
- };
|