From 3b68983f9ec18bce51de6470dadc4f31dd4d577b Mon Sep 17 00:00:00 2001 From: xuhuajiao <13476289682@163.com> Date: Sat, 9 May 2026 17:31:03 +0800 Subject: [PATCH] 0509999 --- pages/search/search.vue | 34 ++----- subpkg/pages/book-detail/book-detail.vue | 111 ++++++++++++----------- 2 files changed, 68 insertions(+), 77 deletions(-) diff --git a/pages/search/search.vue b/pages/search/search.vue index 8e1ef92..f1bc0da 100644 --- a/pages/search/search.vue +++ b/pages/search/search.vue @@ -134,8 +134,7 @@ export default { this.selectValue = this.range[index].value; this.selectValueText = this.range[index].text; }, - // 真实图书检索接口 - async getBookList() { + async getBookList() { if (!this.value) { uni.showToast({ title: '请输入搜索内容', icon: 'none' }); return; @@ -160,31 +159,17 @@ export default { }; const res = await FetchBookSearch(params); + console.log('res',res) - let result = {}; - if (typeof res.data === 'string') { - try { - result = JSON.parse(res.data); - } catch (e) {} - } else { - result = res.data || {}; - } - - // 如果返回的是 {} → 说明无数据 - const isEmptyData = Object.keys(result).length === 0; - - // 有数据 → 取 list & total - let list = []; - let total = 0; + // 精准适配你当前返回格式 + const apiData = res.data || {}; + const list = apiData.bookList || []; - if (!isEmptyData) { - list = result.data || []; - total = Number(result.total || 0); - } - - this.total = total; + // 赋值总数、总页数 + this.total = apiData.totalCount || 0; this.totalPage = Math.ceil(this.total / this.size); + // 分页拼接列表 if (this.page === 1) { this.listData = list; } else { @@ -194,8 +179,9 @@ export default { this.isSearched = true; } catch (err) { + console.error('搜索接口异常', err); this.listData = []; - uni.showToast({ title: '搜索失败', icon: 'none' }); + this.isSearched = true; } finally { uni.hideLoading(); } diff --git a/subpkg/pages/book-detail/book-detail.vue b/subpkg/pages/book-detail/book-detail.vue index 766799f..9c77a9e 100644 --- a/subpkg/pages/book-detail/book-detail.vue +++ b/subpkg/pages/book-detail/book-detail.vue @@ -8,19 +8,13 @@ 作者:{{ bookInfo.author || '暂无' }} 出版社:{{ bookInfo.publisher || '暂无' }} ISBN:{{ bookInfo.isbn || '暂无' }} - + 出版时间:{{ bookInfo.pubdate || '暂无' }} - @@ -30,23 +24,22 @@ - {{ bookInfo.orglib || '暂无' }} - 所属馆 + {{ holdingsData.length || 0 }} + 馆藏总数 - {{ bookInfo.loancount || 0 }} + {{ inLibraryCount }} 在馆(本) - - {{ stateText }} - 馆藏状态 + {{ lendCount }} + 借出(本) - - + + 索书号 {{ item.callno || '暂无' }} @@ -55,6 +48,10 @@ 条码号 {{ item.barcode || '暂无' }} + + 馆藏状态 + {{ getStateText(item.state) }} + @@ -102,41 +99,39 @@ export default { isCollected: false, bookrecno: '', opacUrl: '', - bookInfo: {} // 图书详情 + bookInfo: {}, // 图书基础信息(biblios) + holdingsData: [], // 馆藏列表(holdings) }; }, onLoad(options) { - // 接收从首页带过来的完整图书数据 + // 1. 首页/列表页 直接带完整 bookData 过来,优先走这个 if (options.bookData) { const bookData = JSON.parse(decodeURIComponent(options.bookData)); - this.bookInfo = bookData; // 直接赋值渲染 + this.bookInfo = bookData; this.bookrecno = bookData.bookrecno || ""; + // 没有馆藏数据就置空 + this.holdingsData = []; this.checkCollectStatus(); return; } - // 如果是从检索页过来(走bookrecno请求) + // 2. 检索页只传 bookrecno,请求接口拿详情 this.bookrecno = options.bookrecno || ""; this.getOpacUrl(); }, computed: { - // 馆藏状态转换:数字 → 文字 - stateText() { - const state = this.bookInfo.state || 0 - const map = { - 1: '编目', - 2: '在馆', - 3: '借出', - 4: '丢失', - 5: '剔除', - 6: '交换', - 7: '赠送', - 8: '装订', - 9: '锁定', - 10: '预借', - 12: '清点' - } - return map[state] || '未知' + // 在馆数量 + inLibraryCount() { + return this.holdingsData.filter(item => item.state === 2).length; + }, + // 借出数量(新增) + lendCount() { + return this.holdingsData.filter(item => item.state === 3).length; + }, + // 第一个馆藏状态 + firstStateText() { + if (this.holdingsData.length === 0) return '无馆藏'; + return this.getStateText(this.holdingsData[0].state); } }, methods: { @@ -152,7 +147,7 @@ export default { } catch (err) {} }, - // 获取图书详情 + // 获取图书详情(适配新接口结构) async getBookDetail() { if (!this.bookrecno || !this.opacUrl) return; @@ -164,23 +159,37 @@ export default { }; const res = await FetchFindbookByQuery(params); - // 解析数据 - let detail = {}; - if (typeof res.data === 'string') { - detail = JSON.parse(res.data); - } else { - detail = res.data || {}; - } - - this.bookInfo = detail; + const apiData = res.data || {}; + this.bookInfo = apiData.biblios || {}; + this.holdingsData = apiData.holdings || []; + this.checkCollectStatus(); } catch (err) { + console.log(err); } finally { uni.hideLoading(); } }, - // 收藏逻辑 + // 馆藏状态文字 + getStateText(state) { + const map = { + 1: '编目', + 2: '在馆', + 3: '借出', + 4: '丢失', + 5: '剔除', + 6: '交换', + 7: '赠送', + 8: '装订', + 9: '锁定', + 10: '预借', + 12: '清点' + } + return map[state] || '未知'; + }, + + // 收藏 checkCollectStatus() { const list = uni.getStorageSync('collectList') || []; this.isCollected = list.includes(this.bookrecno); @@ -217,7 +226,6 @@ export default { padding-bottom: 60px; } -/* 书籍信息 */ .article-detail-container { display: flex; background-color: #fff; @@ -251,7 +259,6 @@ export default { box-shadow: 0 2px 8px rgba(0,0,0,0.1); } -/* 馆藏统计 */ .book-store-info { background-color: #fff; border-radius: 10px; @@ -276,7 +283,6 @@ export default { margin-top: 4px; } -/* 索书号 */ .store-info-list { background-color: #fff; border-radius: 10px; @@ -288,6 +294,7 @@ export default { justify-content: space-between; font-size: 14px; color: #666; + margin-bottom: 10px; } .store-info-item view { display: flex; @@ -295,7 +302,6 @@ export default { align-items: center; } -/* TAB */ .content-tab { display: flex; background-color: #fff; @@ -327,7 +333,6 @@ export default { border-radius: 2px; } -/* 内容区域 */ .content-item { background-color: #fff; border-radius: 10px;