import { Reducer } from 'redux';
import { Effect } from '@/models/connect';
export type DType = '0' | '1' | '2' | '3';
export interface IState {
dataList: {
[key in DType ]: any;
};
listConfig: {
[key in DType]: any;
};
}
export interface IModelType {
namespace: 'wiki';
state: IState;
effects: {
getList: Effect;
};
reducers: {
save: Reducer<IState>;
clear: Reducer<IState>;
};
}
const defState: IState= {
// 表格配置
dataList: {
'0': {} as any,
'1': {} as any,
'2': {} as any,
'3': {} as any,
},
listConfig: {
'0': {
pageNum: 1,
type: '',
} as any,
'1': {
pageNum: 1,
type: '',
} as any,
'2': {
pageNum: 1,
type: '',
} as any,
'3': {
pageNum: 1,
type: '',
} as any,
},
};
const wiki: IModelType = {
namespace: 'wiki',
state: { ...defState },
effects: {
*getList({ payload }, { call, put, select }) {
const { type, pageNum } = payload;
let oldList = yield select((state) => state.wiki.dataList);
// 获取列表配置
let listConfig = yield select((state) => state.wiki.listConfig);
// 判断是否跳转翻页
if (payload.pageNum) {
// 修改配置
listConfig = {
...listConfig,
[type]: {
pageNum,
},
};
}
if (Object.keys(payload).length > 0) {
listConfig = {
...listConfig,
[type]: { ...listConfig[type], ...payload },
};
}
const resData = yield call(请求的接口, 参数);
oldList = {
...oldList,
[type]: resData,
};
if (listConfig[type].pageNum !== 1) {
yield put({
type: 'save',
payload: {
dataList: {
...oldList[type],
records: [...oldList[type].records, ...resData.records],
},
listConfig,
},
});
} else {
yield put({
type: 'save',
payload: {
dataList: oldList,
listConfig,
},
});
}
},
},
reducers: {
save(state, { payload }) {
return { ...state, ...payload };
},
clear() {
return {
...defState,
};
},
},
};
export default wiki;
react+redux tab切换不覆盖之前的数据
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- option配置项(测试用) 设置高亮 注意点:在legend中设置selectedMode:false,否则会有...
- 代码见https://gitee.com/XiaoKunErGe/JianShu.git历史第五次提交1.先安装y...