mirror of
https://github.com/chillzhuang/Sword
synced 2024-12-23 09:29:25 +08:00
109 lines
2.4 KiB
JavaScript
109 lines
2.4 KiB
JavaScript
|
import { message } from 'antd';
|
||
|
import router from 'umi/router';
|
||
|
import { POST_NAMESPACE } from '../actions/post';
|
||
|
import { dict } from '../services/dict';
|
||
|
import { list, submit, detail, remove } from '../services/post';
|
||
|
|
||
|
export default {
|
||
|
namespace: POST_NAMESPACE,
|
||
|
state: {
|
||
|
data: {
|
||
|
list: [],
|
||
|
pagination: false,
|
||
|
},
|
||
|
init: {
|
||
|
category: [],
|
||
|
},
|
||
|
detail: {},
|
||
|
},
|
||
|
effects: {
|
||
|
*fetchList({ payload }, { call, put }) {
|
||
|
const response = yield call(list, payload);
|
||
|
if (response.success) {
|
||
|
yield put({
|
||
|
type: 'saveList',
|
||
|
payload: {
|
||
|
list: response.data.records,
|
||
|
pagination: {
|
||
|
total: response.data.total,
|
||
|
current: response.data.current,
|
||
|
pageSize: response.data.size,
|
||
|
},
|
||
|
},
|
||
|
});
|
||
|
}
|
||
|
},
|
||
|
*fetchInit({ payload }, { call, put }) {
|
||
|
const response = yield call(dict, payload);
|
||
|
if (response.success) {
|
||
|
yield put({
|
||
|
type: 'saveInit',
|
||
|
payload: {
|
||
|
category: response.data,
|
||
|
},
|
||
|
});
|
||
|
}
|
||
|
},
|
||
|
*fetchDetail({ payload }, { call, put }) {
|
||
|
const response = yield call(detail, payload);
|
||
|
if (response.success) {
|
||
|
yield put({
|
||
|
type: 'saveDetail',
|
||
|
payload: {
|
||
|
detail: response.data,
|
||
|
},
|
||
|
});
|
||
|
}
|
||
|
},
|
||
|
*clearDetail({ payload }, { put }) {
|
||
|
yield put({
|
||
|
type: 'removeDetail',
|
||
|
payload: { payload },
|
||
|
});
|
||
|
},
|
||
|
*submit({ payload }, { call }) {
|
||
|
const response = yield call(submit, payload);
|
||
|
if (response.success) {
|
||
|
message.success('提交成功');
|
||
|
router.push('/system/post');
|
||
|
}
|
||
|
},
|
||
|
*remove({ payload }, { call }) {
|
||
|
const {
|
||
|
data: { keys },
|
||
|
success,
|
||
|
} = payload;
|
||
|
const response = yield call(remove, { ids: keys });
|
||
|
if (response.success) {
|
||
|
success();
|
||
|
}
|
||
|
},
|
||
|
},
|
||
|
reducers: {
|
||
|
saveList(state, action) {
|
||
|
return {
|
||
|
...state,
|
||
|
data: action.payload,
|
||
|
};
|
||
|
},
|
||
|
saveInit(state, action) {
|
||
|
return {
|
||
|
...state,
|
||
|
init: action.payload,
|
||
|
};
|
||
|
},
|
||
|
saveDetail(state, action) {
|
||
|
return {
|
||
|
...state,
|
||
|
detail: action.payload.detail,
|
||
|
};
|
||
|
},
|
||
|
removeDetail(state) {
|
||
|
return {
|
||
|
...state,
|
||
|
detail: {},
|
||
|
};
|
||
|
},
|
||
|
},
|
||
|
};
|