Commit a395e495 authored by 天马流星拳's avatar 天马流星拳

fix(HomePage): 修复排行榜数据加载问题并添加错误处理

确保在组件挂载时先更新索引再获取排行榜数据
添加数据重置逻辑避免显示旧数据
增加API调用成功检查和错误处理
parent 46a0ae21
...@@ -42,21 +42,37 @@ class HomePage extends React.Component<any, any> { ...@@ -42,21 +42,37 @@ class HomePage extends React.Component<any, any> {
isExpand: false, isExpand: false,
}; };
componentDidMount() { async componentDidMount() {
store.updateIndex() // 确保索引数据更新完成后再获取排行榜信息
await store.updateIndex();
// 获取排行榜信息 // 获取排行榜信息
this.getQueryRankInfo(this.state.rankingTab); this.getQueryRankInfo(this.state.rankingTab);
} }
// 获取排行榜信息 // 获取排行榜信息
getQueryRankInfo = async (type) => { getQueryRankInfo = async (type) => {
console.log("🚀 ~ HomePage ~ type:", type) console.log("🚀 ~ HomePage ~ type:", type);
const {success, code , data , message } = await API.queryRankInfo({type: type}); try {
if (data) { // 先重置数据,避免切换时显示旧数据
this.setState({ this.setState({
rankOptions: data?.rankOptions || [], rankOptions: [],
rankInfos: data?.rankInfos || [], rankInfos: [],
myRank: data?.myRank || {}, myRank: {},
}) });
const {success, code , data , message } = await API.queryRankInfo({type: type});
// 检查API调用是否成功且有数据
if (success && data) {
this.setState({
rankOptions: data?.rankOptions || [],
rankInfos: data?.rankInfos || [],
myRank: data?.myRank || {},
});
} else {
console.warn("获取排行榜数据失败:", message || "未知错误");
}
} catch (error) {
console.error("查询排行榜信息时发生错误:", error);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment