mirror of
https://github.com/chillzhuang/SpringBlade.git
synced 2024-11-15 23:19:29 +08:00
85 lines
1.9 KiB
Plaintext
85 lines
1.9 KiB
Plaintext
|
#set($upperEntityPath=$table.entityPath.toUpperCase())
|
||
|
import { message } from 'antd';
|
||
|
import router from 'umi/router';
|
||
|
import { $!{upperEntityPath}_NAMESPACE } from '../actions/$!{table.entityPath}';
|
||
|
import { list, submit, detail, remove } from '../services/$!{table.entityPath}';
|
||
|
|
||
|
export default {
|
||
|
namespace: $!{upperEntityPath}_NAMESPACE,
|
||
|
state: {
|
||
|
data: {
|
||
|
list: [],
|
||
|
pagination: false,
|
||
|
},
|
||
|
detail: {},
|
||
|
},
|
||
|
effects: {
|
||
|
*fetchList({ payload }, { call, put }) {
|
||
|
const response = yield call(list, payload);
|
||
|
if (response.success) {
|
||
|
yield put({
|
||
|
type: 'saveList',
|
||
|
payload: {
|
||
|
list: response.data,
|
||
|
pagination: false,
|
||
|
},
|
||
|
});
|
||
|
}
|
||
|
},
|
||
|
*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('/$!{cfg.servicePackage}/$!{table.entityPath}');
|
||
|
}
|
||
|
},
|
||
|
*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,
|
||
|
};
|
||
|
},
|
||
|
saveDetail(state, action) {
|
||
|
return {
|
||
|
...state,
|
||
|
detail: action.payload.detail,
|
||
|
};
|
||
|
},
|
||
|
removeDetail(state) {
|
||
|
return {
|
||
|
...state,
|
||
|
detail: {},
|
||
|
};
|
||
|
},
|
||
|
},
|
||
|
};
|