优化:请求接口全局处理loading和错误提示
This commit is contained in:
@@ -230,70 +230,43 @@ function initScrollHeight() {
|
||||
|
||||
// 加载书籍详情
|
||||
async function loadBookInfo() {
|
||||
try {
|
||||
const res = await bookApi.getBookInfo(bookId.value)
|
||||
|
||||
if (res.bookInfo) {
|
||||
bookInfo.value = res.bookInfo
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to load book info:', error)
|
||||
}
|
||||
const res = await bookApi.getBookInfo(bookId.value)
|
||||
bookInfo.value = res.bookInfo
|
||||
}
|
||||
|
||||
// 加载购买商品信息
|
||||
async function loadGoodsInfo() {
|
||||
try {
|
||||
const res = await bookApi.getBookGoods(bookId.value)
|
||||
if (res.code === 0) {
|
||||
goodsList.value = res.productList || []
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to load goods info:', error)
|
||||
}
|
||||
const res = await bookApi.getBookGoods(bookId.value)
|
||||
goodsList.value = res.productList || []
|
||||
}
|
||||
|
||||
// 加载统计数据
|
||||
async function loadBookCount() {
|
||||
try {
|
||||
const res = await bookApi.getBookReadCount(bookId.value)
|
||||
if (res.code === 0) {
|
||||
readCount.value = res.readCount || 0
|
||||
listenCount.value = res.listenCount || 0
|
||||
buyCount.value = res.buyCount || 0
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to load book count:', error)
|
||||
const res = await bookApi.getBookReadCount(bookId.value)
|
||||
if (res.code === 0) {
|
||||
readCount.value = res.readCount || 0
|
||||
listenCount.value = res.listenCount || 0
|
||||
buyCount.value = res.buyCount || 0
|
||||
}
|
||||
}
|
||||
|
||||
// 加载评论
|
||||
async function loadComments() {
|
||||
try {
|
||||
const res = await bookApi.getBookComments(bookId.value, 1, 10)
|
||||
if (res.commentsTree && res.commentsTree.length > 0) {
|
||||
commentList.value = res.commentsTree
|
||||
} else {
|
||||
nullText.value = t('common.data_null')
|
||||
}
|
||||
} catch (error) {
|
||||
const res = await bookApi.getBookComments(bookId.value, 1, 10)
|
||||
if (res.commentsTree && res.commentsTree.length > 0) {
|
||||
commentList.value = res.commentsTree
|
||||
} else {
|
||||
nullText.value = t('common.data_null')
|
||||
console.error('Failed to load comments:', error)
|
||||
}
|
||||
}
|
||||
|
||||
// 加载推荐书籍
|
||||
async function loadRecommendBooks() {
|
||||
try {
|
||||
const res = await bookApi.getRecommendBook(bookId.value)
|
||||
if (res.bookList && res.bookList.length > 0) {
|
||||
relatedBooks.value = res.bookList
|
||||
} else {
|
||||
nullBookText.value = t('common.data_null')
|
||||
}
|
||||
} catch (error) {
|
||||
const res = await bookApi.getRecommendBook(bookId.value)
|
||||
if (res.bookList && res.bookList.length > 0) {
|
||||
relatedBooks.value = res.bookList
|
||||
} else {
|
||||
nullBookText.value = t('common.data_null')
|
||||
console.error('Failed to load recommend books:', error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user