|
|
|
|
@ -1,8 +1,8 @@
|
|
|
|
|
<template>
|
|
|
|
|
<view class="library-container">
|
|
|
|
|
<view class="search-bar">
|
|
|
|
|
<u-search placeholder="书名/作者/关键词/完整ISBN..." v-model="keyword" :show-action="false" bg-color="#f5f5f5"
|
|
|
|
|
border-color="#e0e0e0"></u-search>
|
|
|
|
|
<u-search placeholder="书名/作者" v-model="keyword" :show-action="false" bg-color="#f5f5f5"
|
|
|
|
|
border-color="#e0e0e0" @search="searchBooks"></u-search>
|
|
|
|
|
</view>
|
|
|
|
|
|
|
|
|
|
<view class="tabs-container">
|
|
|
|
|
@ -10,23 +10,36 @@
|
|
|
|
|
</view>
|
|
|
|
|
|
|
|
|
|
<view class="book-list">
|
|
|
|
|
<view v-for="book in bookList" :key="book.id" class="book-card">
|
|
|
|
|
<view class="book-item">
|
|
|
|
|
<view class="book-cover">
|
|
|
|
|
<u-image :src="book.image" width="180rpx" height="240rpx" border-radius="8"></u-image>
|
|
|
|
|
</view>
|
|
|
|
|
<view class="book-info">
|
|
|
|
|
<text class="book-title">{{ book.title }}</text>
|
|
|
|
|
<text class="book-author">{{ book.author }}</text>
|
|
|
|
|
<text class="book-publisher">{{ book.publisher }} · {{ book.year }}</text>
|
|
|
|
|
<view class="tags-container">
|
|
|
|
|
<u-tag v-for="(tag, index) in book.tags" :key="index" :text="tag.text" :type="tag.type"
|
|
|
|
|
size="mini" shape="circle" mode="light" />
|
|
|
|
|
<!-- 加载状态 -->
|
|
|
|
|
<view v-if="loading" class="loading-container">
|
|
|
|
|
<view class="loading-text">加载中...</view>
|
|
|
|
|
</view>
|
|
|
|
|
|
|
|
|
|
<!-- 空状态 -->
|
|
|
|
|
<view v-else-if="bookList.length === 0" class="empty-container">
|
|
|
|
|
<view class="empty-text">暂无图书数据</view>
|
|
|
|
|
</view>
|
|
|
|
|
|
|
|
|
|
<!-- 图书列表 -->
|
|
|
|
|
<view v-else>
|
|
|
|
|
<view v-for="book in bookList" :key="book.id" class="book-card">
|
|
|
|
|
<view class="book-item">
|
|
|
|
|
<view class="book-cover">
|
|
|
|
|
<u-image :src="book.image" width="180rpx" height="240rpx" border-radius="8"></u-image>
|
|
|
|
|
</view>
|
|
|
|
|
<view class="book-info">
|
|
|
|
|
<text class="book-title">{{ book.title }}</text>
|
|
|
|
|
<text class="book-author">{{ book.author }}</text>
|
|
|
|
|
<text class="book-publisher">{{ book.publisher }} · {{ book.year }}</text>
|
|
|
|
|
<view class="tags-container">
|
|
|
|
|
<u-tag v-for="(tag, index) in book.tags" :key="index" :text="tag.text" :type="tag.type"
|
|
|
|
|
size="mini" shape="circle" mode="light" />
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
<view class="card-footer">
|
|
|
|
|
<view class="detail-button" @click="viewDetails(book.id)">查看详情</view>
|
|
|
|
|
<view class="card-footer">
|
|
|
|
|
<view class="detail-button" @click="viewDetails(book.id)">查看详情</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
@ -38,6 +51,7 @@
|
|
|
|
|
import uTabs from '@/uview-ui/components/u-tabs/u-tabs.vue';
|
|
|
|
|
import uImage from '@/uview-ui/components/u-image/u-image.vue';
|
|
|
|
|
import uTag from '@/uview-ui/components/u-tag/u-tag.vue';
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
components: {
|
|
|
|
|
uSearch,
|
|
|
|
|
@ -49,75 +63,149 @@
|
|
|
|
|
return {
|
|
|
|
|
keyword: '',
|
|
|
|
|
currentTab: 0,
|
|
|
|
|
loading: false,
|
|
|
|
|
currentPage: 1,
|
|
|
|
|
totalPages: 1,
|
|
|
|
|
hasMore: true,
|
|
|
|
|
tabsList: [{
|
|
|
|
|
name: '全部'
|
|
|
|
|
}, {
|
|
|
|
|
name: '生物医药'
|
|
|
|
|
}, {
|
|
|
|
|
name: '半导体/集成电路'
|
|
|
|
|
}, {
|
|
|
|
|
name: '新能源'
|
|
|
|
|
}, {
|
|
|
|
|
name: '新材料'
|
|
|
|
|
}, {
|
|
|
|
|
name: '技术'
|
|
|
|
|
}],
|
|
|
|
|
bookList: [{
|
|
|
|
|
id: 1,
|
|
|
|
|
title: '股权激励',
|
|
|
|
|
author: '邱清荣著',
|
|
|
|
|
publisher: '中国友谊出版公司',
|
|
|
|
|
year: '2019',
|
|
|
|
|
image: 'https://via.placeholder.com/180x240.png/ffffff/000000?text=股权激励',
|
|
|
|
|
tags: [{
|
|
|
|
|
text: '技术类',
|
|
|
|
|
type: 'primary'
|
|
|
|
|
}, {
|
|
|
|
|
text: '图书馆 3F-A区-125',
|
|
|
|
|
type: 'info'
|
|
|
|
|
}]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 2,
|
|
|
|
|
title: '制造亚洲:一部地图上的历史',
|
|
|
|
|
author: '李四著',
|
|
|
|
|
publisher: '中国友谊出版公司',
|
|
|
|
|
year: '2019',
|
|
|
|
|
image: 'https://via.placeholder.com/180x240.png/ffffff/000000?text=制造亚洲',
|
|
|
|
|
tags: [{
|
|
|
|
|
text: '商业类',
|
|
|
|
|
type: 'primary'
|
|
|
|
|
}, {
|
|
|
|
|
text: '图书馆 3F-A区-125',
|
|
|
|
|
type: 'info'
|
|
|
|
|
}]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 3,
|
|
|
|
|
title: '股权金字塔',
|
|
|
|
|
author: '李四著',
|
|
|
|
|
publisher: '中国友谊出版公司',
|
|
|
|
|
year: '2019',
|
|
|
|
|
image: 'https://via.placeholder.com/180x240.png/ffffff/000000?text=股权金字塔',
|
|
|
|
|
tags: [{
|
|
|
|
|
text: '商业类',
|
|
|
|
|
type: 'primary'
|
|
|
|
|
}, {
|
|
|
|
|
text: '图书馆 3F-A区-125',
|
|
|
|
|
type: 'info'
|
|
|
|
|
}]
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
bookList: []
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
onLoad() {
|
|
|
|
|
this.loadCategories();
|
|
|
|
|
},
|
|
|
|
|
onReachBottom() {
|
|
|
|
|
if (this.hasMore && !this.loading) {
|
|
|
|
|
this.loadMore();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
// 加载分类数据
|
|
|
|
|
loadCategories() {
|
|
|
|
|
this.$u.api.bookOther().then(res => {
|
|
|
|
|
if (res && res.category) {
|
|
|
|
|
// 构建分类列表,第一个是"全部"
|
|
|
|
|
const categories = [{
|
|
|
|
|
name: '全部'
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
// 添加从接口获取的分类
|
|
|
|
|
if (Array.isArray(res.category)) {
|
|
|
|
|
res.category.forEach(categoryName => {
|
|
|
|
|
categories.push({
|
|
|
|
|
name: categoryName
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.tabsList = categories;
|
|
|
|
|
}
|
|
|
|
|
}).catch(err => {
|
|
|
|
|
console.error('获取分类失败:', err);
|
|
|
|
|
// 如果获取分类失败,使用默认分类
|
|
|
|
|
this.tabsList = [{
|
|
|
|
|
name: '全部'
|
|
|
|
|
}];
|
|
|
|
|
}).finally(() => {
|
|
|
|
|
// 分类加载完成后,加载图书列表
|
|
|
|
|
this.loadBookList();
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 加载图书列表
|
|
|
|
|
loadBookList() {
|
|
|
|
|
this.loading = true;
|
|
|
|
|
|
|
|
|
|
const params = {
|
|
|
|
|
page: this.currentPage,
|
|
|
|
|
limit: 20
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 添加搜索关键词
|
|
|
|
|
if (this.keyword.trim()) {
|
|
|
|
|
params.keyword = this.keyword.trim();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 添加分类筛选
|
|
|
|
|
if (this.currentTab > 0) {
|
|
|
|
|
params.category = this.currentTab;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.$u.api.bookIndex(params).then(res => {
|
|
|
|
|
// 处理返回的数据结构
|
|
|
|
|
const bookData = res || {};
|
|
|
|
|
const newBooks = (bookData.data || []).map(book => {
|
|
|
|
|
return {
|
|
|
|
|
id: book.id,
|
|
|
|
|
title: book.title,
|
|
|
|
|
author: book.author,
|
|
|
|
|
publisher: book.publisher,
|
|
|
|
|
year: book.publish_year,
|
|
|
|
|
image: book.cover ? book.cover.url : '',
|
|
|
|
|
tags: [
|
|
|
|
|
{
|
|
|
|
|
text: book.category || '未分类',
|
|
|
|
|
type: 'primary'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
text: `ISBN: ${book.isbn || '未知'}`,
|
|
|
|
|
type: 'info'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 如果是第一页,替换数据;否则追加数据
|
|
|
|
|
if (this.currentPage === 1) {
|
|
|
|
|
this.bookList = newBooks;
|
|
|
|
|
} else {
|
|
|
|
|
this.bookList = [...this.bookList, ...newBooks];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 设置分页信息
|
|
|
|
|
this.currentPage = bookData.current_page || 1;
|
|
|
|
|
this.totalPages = bookData.last_page || 1;
|
|
|
|
|
this.hasMore = this.currentPage < this.totalPages;
|
|
|
|
|
}).catch(err => {
|
|
|
|
|
console.error('获取图书列表失败:', err);
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: '网络错误,请重试',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
});
|
|
|
|
|
}).finally(() => {
|
|
|
|
|
this.loading = false;
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 搜索图书
|
|
|
|
|
searchBooks() {
|
|
|
|
|
this.currentPage = 1;
|
|
|
|
|
this.loadBookList();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 分类切换
|
|
|
|
|
tabChange(index) {
|
|
|
|
|
this.currentTab = index;
|
|
|
|
|
this.currentPage = 1;
|
|
|
|
|
this.loadBookList();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 查看详情
|
|
|
|
|
viewDetails(id) {
|
|
|
|
|
console.log('View details for book ID:', id);
|
|
|
|
|
// uni.navigateTo({ url: `/packages/library/detail?id=${id}` });
|
|
|
|
|
uni.navigateTo({
|
|
|
|
|
url: `/packages/library/detail?id=${id}`
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
tabChange(index) {
|
|
|
|
|
this.currentTab = index;
|
|
|
|
|
console.log('Tab changed to:', index);
|
|
|
|
|
|
|
|
|
|
// 加载更多数据
|
|
|
|
|
loadMore() {
|
|
|
|
|
if (this.hasMore && !this.loading) {
|
|
|
|
|
this.currentPage += 1;
|
|
|
|
|
this.loadBookList();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -142,6 +230,30 @@
|
|
|
|
|
padding: 20rpx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.loading-container {
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
align-items: center;
|
|
|
|
|
min-height: 400rpx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.loading-text {
|
|
|
|
|
font-size: 28rpx;
|
|
|
|
|
color: #999;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.empty-container {
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
align-items: center;
|
|
|
|
|
min-height: 400rpx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.empty-text {
|
|
|
|
|
font-size: 28rpx;
|
|
|
|
|
color: #999;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.book-card {
|
|
|
|
|
background-color: #fff;
|
|
|
|
|
border-radius: 20rpx;
|
|
|
|
|
|