diff --git a/common/http.api.js b/common/http.api.js
index 987bcab..ef64fc3 100644
--- a/common/http.api.js
+++ b/common/http.api.js
@@ -42,6 +42,11 @@ let apiApp = {
supplyDemandSave: '/api/mobile/supply-demand/save',
supplyDemandList: '/api/mobile/supply-demand/index',
supplyDemandDetail: '/api/mobile/supply-demand/detail',
+
+ // 图书
+ bookIndex: '/api/mobile/book/index',
+ bookDetail: '/api/mobile/book/detail',
+ bookOther: '/api/mobile/book/other',
}
// 此处第二个参数vm,就是我们在页面使用的this,你可以通过vm获取vuex等操作
@@ -95,6 +100,11 @@ const install = (Vue, vm) => {
let supplyDemandList = (params = {}) => vm.$u.get(apiApp.supplyDemandList, params);
let supplyDemandDetail = (params = {}) => vm.$u.get(apiApp.supplyDemandDetail, params);
+ // 图书
+ let bookIndex = (params = {}) => vm.$u.get(apiApp.bookIndex, params);
+ let bookDetail = (params = {}) => vm.$u.get(apiApp.bookDetail, params);
+ let bookOther = (params = {}) => vm.$u.get(apiApp.bookOther, params);
+
// 将各个定义的接口名称,统一放进对象挂载到vm.$u.api(因为vm就是this,也即this.$u.api)下
vm.$u.api = {
// 用户
@@ -138,6 +148,11 @@ const install = (Vue, vm) => {
supplyDemandSave,
supplyDemandList,
supplyDemandDetail,
+
+ // 图书
+ bookIndex,
+ bookDetail,
+ bookOther,
};
}
diff --git a/packages/library/detail.vue b/packages/library/detail.vue
new file mode 100644
index 0000000..bef0551
--- /dev/null
+++ b/packages/library/detail.vue
@@ -0,0 +1,274 @@
+
+
+
+
+ 加载中...
+
+
+
+
+
+
+
+
+
+ 图书简介
+ {{ bookInfo.description || '暂无简介' }}
+
+
+
+
+ 图书状态
+
+ 状态:
+
+
+
+ 创建时间:
+ {{ formatDate(bookInfo.created_at) }}
+
+
+
+
+
+
+ 图书信息不存在
+
+
+
+
+
+
+
diff --git a/packages/library/index.vue b/packages/library/index.vue
index 855e484..38fa2ff 100644
--- a/packages/library/index.vue
+++ b/packages/library/index.vue
@@ -1,8 +1,8 @@
-
+
@@ -10,23 +10,36 @@
-
-
-
-
-
-
- {{ book.title }}
- {{ book.author }}
- {{ book.publisher }} · {{ book.year }}
-
-
+
+
+ 加载中...
+
+
+
+
+ 暂无图书数据
+
+
+
+
+
+
+
+
+
+
+ {{ book.title }}
+ {{ book.author }}
+ {{ book.publisher }} · {{ book.year }}
+
+
+
-
-
@@ -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;
diff --git a/pages.json b/pages.json
index aa64e2e..60b0e34 100644
--- a/pages.json
+++ b/pages.json
@@ -132,6 +132,11 @@
"style": {
"navigationBarTitleText": "图书馆"
}
+ },{
+ "path": "library/detail",
+ "style": {
+ "navigationBarTitleText": "图书详情"
+ }
},{
"path": "supply/index",
"style": {