优化:请求接口全局处理loading和错误提示

This commit is contained in:
2025-11-26 16:37:47 +08:00
24 changed files with 568 additions and 771 deletions

View File

@@ -70,14 +70,8 @@ onLoad((options: any) => {
* 获取VIP信息
*/
const getVipInfo = async () => {
try {
const res = await homeApi.getVipInfo()
if (res.vipInfo) {
vipInfo.value = res.vipInfo
}
} catch (error) {
console.error('获取VIP信息失败:', error)
}
const res = await homeApi.getVipInfo()
vipInfo.value = res.vipInfo
}
/**
@@ -91,26 +85,19 @@ const handleSearch = async () => {
loading.value = true
isEmpty.value = false
try {
const res = await homeApi.searchBooks({
title: keyword.value.trim(),
page: 1,
limit: 10,
})
if (res.bookList && res.bookList.length > 0) {
searchResults.value = res.bookList
isEmpty.value = false
} else {
searchResults.value = []
isEmpty.value = true
}
} catch (error) {
console.error('搜索失败:', error)
const res = await homeApi.searchBooks({
title: keyword.value.trim(),
page: 1,
limit: 10,
})
if (res.bookList && res.bookList.length > 0) {
searchResults.value = res.bookList
isEmpty.value = false
} else {
searchResults.value = []
isEmpty.value = true
} finally {
loading.value = false
}
loading.value = false
}
/**