1
0
mirror of https://github.com/chillzhuang/Sword synced 2024-07-01 19:22:34 +08:00
Sword/src/models/code.js

113 lines
2.6 KiB
JavaScript
Raw Normal View History

2019-02-13 17:16:39 +08:00
import { message } from 'antd';
import router from 'umi/router';
import { CODE_NAMESPACE } from '../actions/code';
import { list, submit, detail, remove } from '../services/code';
2019-11-19 17:34:16 +08:00
import { select } from '../services/datasource';
import { dict } from '../services/dict';
2019-02-13 17:16:39 +08:00
export default {
namespace: CODE_NAMESPACE,
state: {
data: {
list: [],
pagination: {},
},
2019-11-19 17:34:16 +08:00
init: {
source: [],
category: [],
},
2019-02-13 17:16:39 +08:00
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,
},
},
});
}
},
2019-11-19 17:34:16 +08:00
*fetchInit({ payload }, { call, put }) {
const responseS = yield call(select, payload);
const responseC = yield call(dict, payload);
if (responseS.success && responseC.success) {
yield put({
type: 'saveInit',
payload: {
source: responseS.data,
category: responseC.data,
},
});
}
},
2019-02-13 17:16:39 +08:00
*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('/tool/code');
}
},
*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,
};
},
2019-11-19 17:34:16 +08:00
saveInit(state, action) {
return {
...state,
init: action.payload,
};
},
2019-02-13 17:16:39 +08:00
saveDetail(state, action) {
return {
...state,
detail: action.payload.detail,
};
},
removeDetail(state) {
return {
...state,
detail: {},
};
},
},
};