const getData = async () => {
setLoading(true);
const currentRequest = Date.now();//加一个时间戳
latestRequestRef.current = currentRequest;//将刚才的时间戳保存到最后一次被点击的钩子函数里面
PerformanceApi.getHistoryPerformance({
assessFormId: assessFormId,
cycletype: cycleType < 0 ? '' : cycleType,
})
.then((res: any) => {
if (res.Code) {
//如果两个相等,说明就是本次的,最新点击的一次获取数据,否则jiu
if (latestRequestRef.current === currentRequest) {
setData(res.Data);
}
}
if (cycleType < 0) {
isPreventMultipleCalls.current = true;
setCycleType(res.Data.formTags[0].cycleType);
}
setLoading(false);
})
.catch((e) => console.log(e));
};