import * as service from '../services/business'; export default { namespace: 'paramBusiness', state: { list: [], pageData: { pageSize: 10, pageNum: 1, total: 0, current: 1, }, }, reducers: { save( state, { payload: { records: list, pageSize, pageNum, total, current }, }, ) { list.forEach(element => { element.key = element.paramId; }); return { ...state, list: [...list], pageData: { pageSize, pageNum, total, current }, }; }, changeList( state, { payload: { list }, }, ) { return { ...state, list: [...list] }; }, }, effects: { // 获取列表数据 *getList({ payload }, { call, put }) { const { data } = yield call(service.getList, payload); yield put({ type: 'save', payload: { ...data }, }); }, // 增加 *add({ payload }, { call }) { const { code } = yield call(service.add, payload); return code === 'sys.success'; }, // 更改 *update({ payload }, { call, put, select }) { const { code } = yield call(service.update, payload); const result = code === 'sys.success'; if (result) { const list = yield select(({ paramBusiness }) => paramBusiness.list); const index = list.findIndex(element => payload.key === element.key); if (index > -1) { list[index] = { ...list[index], ...payload }; } yield put({ type: 'changeList', payload: { list }, }); } return result; }, // 删除 *remove({ payload }, { call }) { const { code } = yield call(service.remove, payload); return code === 'sys.success'; }, *exportParam({ params }, { call }) { yield call(service.exportParam, { ...params }); }, }, subscriptions: { // setup({ dispatch, history }) { // return history.listen(({ pathname, query, hash }) => { // // 初始化数据加载 也可以在componentDidMount中 // if (pathname === "/parameter" && (hash === "#business" || !hash)) { // dispatch({ type: "getList", payload: query }); // } // }); // }, }, };