|
|
@ -1,22 +1,21 @@ |
|
|
<template> |
|
|
<template> |
|
|
<view class="collection-page"> |
|
|
<view class="collection-page"> |
|
|
<view class="content-box"> |
|
|
<view class="content-box"> |
|
|
<view class="empty" v-if="bookCollectList.length === 0"> |
|
|
|
|
|
|
|
|
<view class="empty" v-if="bookCollectList.length === 0 && !isLoading"> |
|
|
<uni-icons style="margin-left: 20px;" custom-prefix="iconfont" type="icon-kongshuju" size="80"></uni-icons> |
|
|
<uni-icons style="margin-left: 20px;" custom-prefix="iconfont" type="icon-kongshuju" size="80"></uni-icons> |
|
|
<text style="margin-top: 20px;">暂无收藏的图书~</text> |
|
|
<text style="margin-top: 20px;">暂无收藏的图书~</text> |
|
|
</view> |
|
|
</view> |
|
|
<view class="recommendation-list" v-else> |
|
|
<view class="recommendation-list" v-else> |
|
|
<view |
|
|
|
|
|
class="book-item" |
|
|
|
|
|
|
|
|
<book-list-item |
|
|
|
|
|
class="hot-list-item" |
|
|
v-for="(item, index) in bookCollectList" |
|
|
v-for="(item, index) in bookCollectList" |
|
|
@click="goToBookDetail(item)" |
|
|
|
|
|
:key="index" |
|
|
:key="index" |
|
|
> |
|
|
|
|
|
<image class="book-cover" :src="item.cover"></image> |
|
|
|
|
|
<view class="book-title">{{ item.title }}</view> |
|
|
|
|
|
</view> |
|
|
|
|
|
|
|
|
:data="item" |
|
|
|
|
|
:ranking="index + 1" |
|
|
|
|
|
@click="onItemClick(item)" |
|
|
|
|
|
></book-list-item> |
|
|
</view> |
|
|
</view> |
|
|
<uni-load-more status="loading" v-if="isLoading"></uni-load-more> |
|
|
|
|
|
|
|
|
<uni-load-more status="loading" v-if="isLoading && bookCollectList.length > 0"></uni-load-more> |
|
|
<view class="no-more" v-if="noMore && bookCollectList.length > 0"> |
|
|
<view class="no-more" v-if="noMore && bookCollectList.length > 0"> |
|
|
没有更多数据了 |
|
|
没有更多数据了 |
|
|
</view> |
|
|
</view> |
|
|
@ -25,61 +24,143 @@ |
|
|
</template> |
|
|
</template> |
|
|
|
|
|
|
|
|
<script> |
|
|
<script> |
|
|
|
|
|
import BookListItem from "@/components/book-list-item/book-list-item.vue"; |
|
|
|
|
|
import { FetchFindAllBookCollectionByOpenId } from '@/api/book'; |
|
|
|
|
|
import { getOpenId } from '@/utils/storage'; |
|
|
|
|
|
import config from '@/utils/config'; |
|
|
|
|
|
|
|
|
export default { |
|
|
export default { |
|
|
|
|
|
components: { |
|
|
|
|
|
BookListItem, |
|
|
|
|
|
}, |
|
|
data() { |
|
|
data() { |
|
|
return { |
|
|
return { |
|
|
isLoading: false, |
|
|
isLoading: false, |
|
|
noMore: false, |
|
|
noMore: false, |
|
|
pageNum: 1, |
|
|
|
|
|
pageSize: 5, |
|
|
|
|
|
|
|
|
|
|
|
bookCollectList: [ |
|
|
|
|
|
{ isbn: '9787544741110', title: '人工智能基础——数学知识', cover: 'https://qiniu.aiyxlib.com/1606124577077' }, |
|
|
|
|
|
{ isbn: '9787539938032', title: 'Vim 8文本处理实战', cover: 'https://qiniu.aiyxlib.com/1606178450151' }, |
|
|
|
|
|
{ isbn: '9787536692930', title: 'Oracle从入门到精通', cover: 'https://qiniu.aiyxlib.com/1606123986028' } |
|
|
|
|
|
], |
|
|
|
|
|
|
|
|
pageNum: 0, |
|
|
|
|
|
pageSize: 10, |
|
|
|
|
|
bookCollectList: [], |
|
|
|
|
|
hasLoadedAll: false, |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
onLoad() { |
|
|
onLoad() { |
|
|
|
|
|
// this.loadData(); |
|
|
}, |
|
|
}, |
|
|
|
|
|
onShow() { |
|
|
|
|
|
// 检查是否需要刷新(从图书详情取消收藏回来) |
|
|
|
|
|
const needRefresh = uni.getStorageSync('needRefreshCollect'); |
|
|
|
|
|
uni.removeStorageSync('needRefreshCollect'); |
|
|
|
|
|
|
|
|
|
|
|
// 如果已经加载到最后,或者有取消收藏操作,需要刷新数据 |
|
|
|
|
|
if (this.hasLoadedAll || needRefresh) { |
|
|
|
|
|
this.refreshData(); |
|
|
|
|
|
} else if (this.bookCollectList.length === 0) { |
|
|
|
|
|
// 如果还没加载过数据,也需要加载 |
|
|
|
|
|
this.refreshData(); |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
onPullDownRefresh() { |
|
|
onPullDownRefresh() { |
|
|
this.refreshData() |
|
|
|
|
|
|
|
|
this.refreshData(); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
onReachBottom() { |
|
|
onReachBottom() { |
|
|
if (this.noMore || this.isLoading) return |
|
|
|
|
|
this.loadMore() |
|
|
|
|
|
|
|
|
if (this.noMore || this.isLoading) return; |
|
|
|
|
|
this.loadMore(); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
methods: { |
|
|
methods: { |
|
|
refreshData() { |
|
|
|
|
|
this.isLoading = true |
|
|
|
|
|
setTimeout(() => { |
|
|
|
|
|
this.bookCollectList = [ |
|
|
|
|
|
{ isbn: '9787544741110', title: '人工智能基础——数学知识', cover: 'https://qiniu.aiyxlib.com/1606124577077' }, |
|
|
|
|
|
{ isbn: '9787539938032', title: 'Vim 8文本处理实战', cover: 'https://qiniu.aiyxlib.com/1606178450151' }, |
|
|
|
|
|
{ isbn: '9787536692930', title: 'Oracle从入门到精通', cover: 'https://qiniu.aiyxlib.com/1606123986028' } |
|
|
|
|
|
] |
|
|
|
|
|
this.isLoading = false |
|
|
|
|
|
uni.stopPullDownRefresh() |
|
|
|
|
|
}, 500) |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
async loadData() { |
|
|
|
|
|
this.isLoading = true; |
|
|
|
|
|
try { |
|
|
|
|
|
const openId = await getOpenId(); |
|
|
|
|
|
if (!openId) { |
|
|
|
|
|
uni.showToast({ title: '获取用户信息失败', icon: 'none' }); |
|
|
|
|
|
this.isLoading = false; |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
loadMore() { |
|
|
|
|
|
this.isLoading = true |
|
|
|
|
|
this.pageNum++ |
|
|
|
|
|
setTimeout(() => { |
|
|
|
|
|
this.noMore = true |
|
|
|
|
|
this.isLoading = false |
|
|
|
|
|
}, 500) |
|
|
|
|
|
|
|
|
const res = await FetchFindAllBookCollectionByOpenId({ |
|
|
|
|
|
libcode: config.LIB_CODE, |
|
|
|
|
|
openId: openId, |
|
|
|
|
|
page: this.pageNum, |
|
|
|
|
|
size: this.pageSize, |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
if (res.code === 200) { |
|
|
|
|
|
this.bookCollectList = res.data.content || []; |
|
|
|
|
|
this.noMore = (res.data.content || []).length < this.pageSize; |
|
|
|
|
|
this.hasLoadedAll = this.noMore; |
|
|
|
|
|
} else { |
|
|
|
|
|
uni.showToast({ title: res.message || '获取收藏列表失败', icon: 'none' }); |
|
|
|
|
|
} |
|
|
|
|
|
} catch (err) { |
|
|
|
|
|
console.error('获取收藏列表失败', err); |
|
|
|
|
|
uni.showToast({ title: '获取收藏列表失败', icon: 'none' }); |
|
|
|
|
|
} finally { |
|
|
|
|
|
this.isLoading = false; |
|
|
|
|
|
} |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
goToBookDetail(item) { |
|
|
|
|
|
uni.navigateTo({ url: "/subpkg/pages/book-detail/book-detail?isbn=" + item.isbn }) |
|
|
|
|
|
|
|
|
async refreshData() { |
|
|
|
|
|
this.pageNum = 0; |
|
|
|
|
|
this.noMore = false; |
|
|
|
|
|
this.bookCollectList = []; |
|
|
|
|
|
await this.loadData(); |
|
|
|
|
|
// 滚动条回到顶部 |
|
|
|
|
|
uni.pageScrollTo({ |
|
|
|
|
|
scrollTop: 0, |
|
|
|
|
|
duration: 300 |
|
|
|
|
|
}); |
|
|
|
|
|
uni.stopPullDownRefresh(); |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
async loadMore() { |
|
|
|
|
|
if (this.noMore || this.isLoading) return; |
|
|
|
|
|
|
|
|
|
|
|
this.pageNum++; |
|
|
|
|
|
this.isLoading = true; |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
const openId = await getOpenId(); |
|
|
|
|
|
if (!openId) { |
|
|
|
|
|
uni.showToast({ title: '获取用户信息失败', icon: 'none' }); |
|
|
|
|
|
this.isLoading = false; |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const res = await FetchFindAllBookCollectionByOpenId({ |
|
|
|
|
|
libcode: config.LIB_CODE, |
|
|
|
|
|
openId: openId, |
|
|
|
|
|
page: this.pageNum, |
|
|
|
|
|
size: this.pageSize, |
|
|
|
|
|
}); |
|
|
|
|
|
console.log('res',res) |
|
|
|
|
|
console.log('res.data',res.data) |
|
|
|
|
|
console.log('res.data.content',res.data.content) |
|
|
|
|
|
|
|
|
|
|
|
if (res.code === 200) { |
|
|
|
|
|
const newData = res.data.content || []; |
|
|
|
|
|
this.bookCollectList = [...this.bookCollectList, ...newData]; |
|
|
|
|
|
this.noMore = newData.length < this.pageSize; |
|
|
|
|
|
} else { |
|
|
|
|
|
this.pageNum--; |
|
|
|
|
|
uni.showToast({ title: res.message || '加载更多失败', icon: 'none' }); |
|
|
|
|
|
} |
|
|
|
|
|
} catch (err) { |
|
|
|
|
|
console.error('加载更多收藏失败', err); |
|
|
|
|
|
this.pageNum--; |
|
|
|
|
|
uni.showToast({ title: '加载更多失败', icon: 'none' }); |
|
|
|
|
|
} finally { |
|
|
|
|
|
this.isLoading = false; |
|
|
|
|
|
} |
|
|
}, |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
onItemClick(item) { |
|
|
|
|
|
console.log('item',item) |
|
|
|
|
|
uni.navigateTo({ |
|
|
|
|
|
url: "/subpkg/pages/book-detail/book-detail?searchData=" + encodeURIComponent(JSON.stringify(item)) + '&isCollected=true' |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
</script> |
|
|
</script> |
|
|
|
|
|
|
|
|
@ -96,7 +177,10 @@ export default { |
|
|
|
|
|
|
|
|
.empty { |
|
|
.empty { |
|
|
padding: 60px 0; |
|
|
padding: 60px 0; |
|
|
|
|
|
text-align: center; |
|
|
|
|
|
color: #999; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
.no-more { |
|
|
.no-more { |
|
|
text-align: center; |
|
|
text-align: center; |
|
|
padding: 20px 0; |
|
|
padding: 20px 0; |
|
|
@ -104,10 +188,57 @@ export default { |
|
|
font-size: 13px; |
|
|
font-size: 13px; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
.recommendation-list{ |
|
|
|
|
|
flex-wrap: wrap; |
|
|
|
|
|
.book-item { |
|
|
|
|
|
margin-bottom: 16px; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
.recommendation-list { |
|
|
|
|
|
display: flex; |
|
|
|
|
|
flex-direction: column; |
|
|
|
|
|
gap: 12px; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
.book-item { |
|
|
|
|
|
display: flex; |
|
|
|
|
|
background: #fff; |
|
|
|
|
|
border-radius: 8px; |
|
|
|
|
|
padding: 12px; |
|
|
|
|
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
.book-cover { |
|
|
|
|
|
width: 80px; |
|
|
|
|
|
height: 100px; |
|
|
|
|
|
border-radius: 4px; |
|
|
|
|
|
flex-shrink: 0; |
|
|
|
|
|
background: #f5f5f5; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
.book-info { |
|
|
|
|
|
flex: 1; |
|
|
|
|
|
display: flex; |
|
|
|
|
|
flex-direction: column; |
|
|
|
|
|
justify-content: center; |
|
|
|
|
|
padding-left: 12px; |
|
|
|
|
|
overflow: hidden; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
.book-title { |
|
|
|
|
|
font-size: 15px; |
|
|
|
|
|
font-weight: 500; |
|
|
|
|
|
color: #333; |
|
|
|
|
|
line-height: 1.4; |
|
|
|
|
|
display: -webkit-box; |
|
|
|
|
|
-webkit-box-orient: vertical; |
|
|
|
|
|
-webkit-line-clamp: 2; |
|
|
|
|
|
overflow: hidden; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
.book-author { |
|
|
|
|
|
font-size: 13px; |
|
|
|
|
|
color: #999; |
|
|
|
|
|
margin-top: 6px; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
.book-publisher { |
|
|
|
|
|
font-size: 12px; |
|
|
|
|
|
color: #ccc; |
|
|
|
|
|
margin-top: 4px; |
|
|
} |
|
|
} |
|
|
</style> |
|
|
</style> |