图书馆小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

495 lines
14 KiB

2 months ago
2 months ago
1 month ago
2 months ago
1 month ago
1 month ago
2 months ago
1 month ago
1 month ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
1 month ago
2 months ago
1 month ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
1 month ago
1 month ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
2 months ago
1 month ago
1 month ago
2 months ago
1 month ago
1 month ago
1 month ago
1 month ago
2 months ago
1 month ago
1 month ago
2 months ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
2 months ago
1 month ago
1 month ago
1 month ago
2 months ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
2 months ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
2 months ago
1 month ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
1 month ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
  1. <template>
  2. <view class="detail-container">
  3. <!-- 书籍头部信息 -->
  4. <view class="article-detail-container">
  5. <view class="article-detail-left">
  6. <view class="article-detail-title">{{ bookInfo.title || bookInfo.name || '暂无书名' }}</view>
  7. <view class="article-detail-info">
  8. <view class="article-detail-author">作者{{ bookInfo.author || '暂无' }}</view>
  9. <view class="article-detail-time">出版社{{ bookInfo.publisher || '暂无' }}</view>
  10. <view class="article-detail-time">ISBN{{ bookInfo.isbn || '暂无' }}</view>
  11. <view class="article-detail-time">出版时间{{ bookInfo.pubdate || '暂无' }}</view>
  12. </view>
  13. </view>
  14. <view class="article-detail-right">
  15. <image
  16. class="img-item"
  17. :src="bookInfo.cover || bookInfo.base64Cover || '/static/images/default-book.png'"
  18. mode="widthFix"
  19. @error="onImgError"
  20. ></image>
  21. </view>
  22. </view>
  23. <!-- 馆藏信息 -->
  24. <view v-if="holdingsData.length!==0" class="book-store-info">
  25. <view class="book-store-info-item">
  26. <text class="store-txt1">{{ holdingsData.length || 0 }}</text>
  27. <text class="store-txt2">馆藏总数</text>
  28. </view>
  29. <view class="book-store-info-item">
  30. <text class="store-txt1">{{ inLibraryCount }}</text>
  31. <text class="store-txt2">在馆</text>
  32. </view>
  33. <view class="book-store-info-item">
  34. <text class="store-txt1">{{ lendCount }}</text>
  35. <text class="store-txt2">借出</text>
  36. </view>
  37. </view>
  38. <!-- 索书号/条码号 -->
  39. <view v-if="holdingsData.length!==0" class="store-info-list">
  40. <view class="store-info-item" v-for="(item, index) in holdingsData" :key="index">
  41. <view>
  42. <text class="info-item-title">条码号</text>
  43. <text>{{ item.barcode || '暂无' }}</text>
  44. </view>
  45. <view >
  46. <text class="info-item-title">索书号</text>
  47. <text>{{ item.callno || '暂无' }}</text>
  48. </view>
  49. <view>
  50. <text class="info-item-title">馆藏状态</text>
  51. <text>{{ getStateText(item.state) }}</text>
  52. </view>
  53. <view>
  54. <text class="info-item-title">所在馆</text>
  55. <text>{{ getLibraryName(item.orglib) }}</text>
  56. </view>
  57. <view>
  58. <text class="info-item-title">当前馆藏地</text>
  59. <text>{{ getLocationName(item.orglocal) }}</text>
  60. </view>
  61. </view>
  62. </view>
  63. <!-- TAB 选项卡 -->
  64. <view class="content-tab">
  65. <view class="tab-item" :class="{active: currentTab === 0}" @click="currentTab = 0">
  66. 内容简介
  67. </view>
  68. <view class="tab-item" :class="{active: currentTab === 1}" @click="currentTab = 1">
  69. 作者简介
  70. </view>
  71. </view>
  72. <!-- TAB 内容 -->
  73. <view class="content-item" v-if="currentTab === 0">
  74. {{ bookInfo.summary || bookInfo.explain || '暂无内容简介' }}
  75. </view>
  76. <view class="content-item" v-if="currentTab === 1">
  77. {{ bookInfo.authorbio || '暂无作者简介' }}
  78. </view>
  79. <view class="detail-bottom">
  80. <button open-type="share" class="handle-btn">
  81. <uni-icons custom-prefix="iconfont" type="icon-fenxiang01" size="20"></uni-icons>
  82. <text class="share-text">分享</text>
  83. </button>
  84. <button v-if="!fromRecommend" class="handle-btn" @click="toggleCollect">
  85. <uni-icons :type="isCollected ? 'heart-filled' : 'heart'" size="20" color="#ff4444"></uni-icons>
  86. <text class="share-text">{{ isCollected ? '已收藏' : '收藏' }}</text>
  87. </button>
  88. </view>
  89. </view>
  90. </template>
  91. <script>
  92. import { FetchInitScreenSetting } from '@/api/user';
  93. import { FetchFindbookByQuery, FetchDictionaryTree,FetchCollectionBook,FetchCancelCollectionBook } from '@/api/book';
  94. import { getOpenId } from '@/utils/storage';
  95. import config from '@/utils/config';
  96. import { fetchBookCoverBase64 } from '@/utils/bookCover';
  97. export default {
  98. data() {
  99. return {
  100. baseUrl: config.baseUrl,
  101. currentTab: 0,
  102. isCollected: false,
  103. bookrecno: '',
  104. opacUrl: '',
  105. fromRecommend: false,
  106. bookInfo: {},
  107. searchListInfo: {},
  108. holdingsData: [],
  109. dictionaryTree: {},
  110. libraryMap: {},
  111. locationMap: {}
  112. };
  113. },
  114. onLoad(options) {
  115. // 1. 首页/列表页 直接带完整 bookData 过来,优先走这个
  116. if (options.bookData) {
  117. const bookData = JSON.parse(decodeURIComponent(options.bookData));
  118. this.bookInfo = bookData;
  119. this.bookrecno = bookData.bookrecno || "";
  120. this.fromRecommend = options.fromRecommend === 'true';
  121. this.holdingsData = [];
  122. this.checkCollectStatus();
  123. return;
  124. }
  125. console.log('options',options)
  126. // 2. 检索页只传 bookrecno,请求接口拿详情
  127. if(options.searchData){
  128. const bookData = JSON.parse(decodeURIComponent(options.searchData));
  129. this.searchListInfo = bookData;
  130. this.bookrecno = bookData.bookrecno || "";
  131. this.bookInfo = bookData;
  132. }
  133. // 3. 如果从收藏列表进入,直接设置为已收藏状态
  134. if (options.isCollected === 'true') {
  135. this.isCollected = true;
  136. }
  137. this.fromRecommend = false;
  138. this.getOpacUrl();
  139. this.getDictionaryTree();
  140. },
  141. computed: {
  142. // 在馆数量
  143. // 馆藏状态,编目=1,在馆=2,借出=3,丢失=4,剔除=5,交换=6,赠送=7,装订=8,锁定=9,预借=10, 清点=12
  144. inLibraryCount() {
  145. return this.holdingsData.filter(item => item.state === 2).length;
  146. },
  147. // 借出数量(新增)
  148. lendCount() {
  149. return this.holdingsData.filter(item => item.state === 3).length;
  150. },
  151. // 第一个馆藏状态
  152. firstStateText() {
  153. if (this.holdingsData.length === 0) return '无馆藏';
  154. return this.getStateText(this.holdingsData[0].state);
  155. }
  156. },
  157. methods: {
  158. onImgError(e) {
  159. e.target.src = "/static/images/default-book.png";
  160. },
  161. // 加载图书封面
  162. async loadBookCover() {
  163. console.log('this.bookInfo',this.bookInfo)
  164. if (!this.bookInfo.isbn) return;
  165. try {
  166. const coverUrl = await fetchBookCoverBase64(this.bookInfo.isbn);
  167. if (coverUrl) {
  168. this.$set(this.bookInfo, 'cover', coverUrl);
  169. }
  170. } catch (error) {
  171. console.error('获取封面失败:', error);
  172. }
  173. },
  174. // 获取字典项 - 馆代码
  175. async getDictionaryTree() {
  176. try {
  177. const res = await FetchDictionaryTree();
  178. console.log('dictionaryTree',res);
  179. const data = res.data || [];
  180. // 1. 找到分馆字典项
  181. const fgItem = data.find(item => item.dictionaryCode === 'FG' && item.dictionaryName === '分馆');
  182. if (fgItem && fgItem.childDictionarys) {
  183. // 建立分馆映射:dictionaryCode -> dictionaryName
  184. this.libraryMap = {};
  185. fgItem.childDictionarys.forEach(child => {
  186. this.libraryMap[child.dictionaryCode] = child.dictionaryName;
  187. });
  188. }
  189. // 2. 找到馆藏地点字典项
  190. const gcdItem = data.find(item => item.dictionaryCode === 'GCD' && item.dictionaryName === '馆藏地点');
  191. if (gcdItem && gcdItem.childDictionarys) {
  192. // 建立馆藏地点映射:dictionaryCode -> dictionaryName
  193. this.locationMap = {};
  194. gcdItem.childDictionarys.forEach(child => {
  195. this.locationMap[child.dictionaryCode] = child.dictionaryName;
  196. });
  197. }
  198. this.dictionaryTree = data;
  199. } catch (err) {
  200. console.error('获取字典树失败', err);
  201. }
  202. },
  203. // 获取配置
  204. async getOpacUrl() {
  205. try {
  206. const res = await FetchInitScreenSetting({ libcode: config.LIB_CODE });
  207. this.opacUrl = res.data.opac_url?.context || '';
  208. this.getBookDetail();
  209. } catch (err) {}
  210. },
  211. // 获取图书详情
  212. async getBookDetail() {
  213. if (!this.bookrecno || !this.opacUrl) return;
  214. uni.showLoading({ title: '加载中...' });
  215. try {
  216. const params = {
  217. opacUrl: this.opacUrl,
  218. bookrecno: this.bookrecno
  219. };
  220. const res = await FetchFindbookByQuery(params);
  221. // console.log('bookrecno详情',res);
  222. const apiData = res.data || {};
  223. this.bookInfo = apiData.biblios || {};
  224. // console.log('bookrecno-bookInfo详情',this.bookInfo);
  225. this.holdingsData = apiData.holdings || [];
  226. // console.log('bookrecno-holdingsData详情',this.holdingsData);
  227. // 加载封面
  228. await this.loadBookCover();
  229. // 检查收藏状态
  230. this.checkCollectStatus();
  231. } catch (err) {
  232. console.error(err);
  233. } finally {
  234. uni.hideLoading();
  235. }
  236. },
  237. // 馆藏状态文字
  238. getStateText(state) {
  239. const map = {
  240. 1: '编目',
  241. 2: '在馆',
  242. 3: '借出',
  243. 4: '丢失',
  244. 5: '剔除',
  245. 6: '交换',
  246. 7: '赠送',
  247. 8: '装订',
  248. 9: '锁定',
  249. 10: '预借',
  250. 12: '清点'
  251. }
  252. return map[state] || '未知';
  253. },
  254. // 获取所在馆名称
  255. getLibraryName(orglib) {
  256. if (!orglib) return '葛店经济技术开发区图书馆';
  257. return this.libraryMap[orglib] || orglib || '葛店经济技术开发区图书馆';
  258. },
  259. // 获取馆藏地名称
  260. getLocationName(orglocal) {
  261. if (!orglocal) return '葛店图书馆';
  262. return this.locationMap[orglocal] || orglocal || '葛店图书馆';
  263. },
  264. // 收藏状态检查(如果已经通过参数传入则跳过)
  265. checkCollectStatus() {
  266. if (this.isCollected) return;
  267. const list = uni.getStorageSync('collectList') || [];
  268. this.isCollected = list.includes(this.bookrecno);
  269. },
  270. async toggleCollect() {
  271. const openId = await getOpenId();
  272. if (!openId) {
  273. uni.showToast({ title: '获取用户信息失败', icon: 'none' });
  274. return;
  275. }
  276. if (this.isCollected) {
  277. try {
  278. console.log(' this.searchListInfo.id',this.searchListInfo.id);
  279. const res = await FetchCancelCollectionBook({id: this.searchListInfo.id});
  280. if (res.code === 200) {
  281. this.isCollected = false;
  282. // 清空收藏记录 id,避免影响后续收藏操作
  283. if (this.searchListInfo) {
  284. this.searchListInfo.id = null;
  285. }
  286. // 设置取消收藏标记,通知收藏列表页面刷新
  287. uni.setStorageSync('needRefreshCollect', true);
  288. uni.showToast({ title: '取消收藏', icon: 'success' });
  289. } else {
  290. uni.showToast({ title: res.message || '取消收藏失败', icon: 'none' });
  291. }
  292. } catch (err) {
  293. console.error('取消收藏图书失败', err);
  294. uni.showToast({ title: '取消收藏失败', icon: 'none' });
  295. }
  296. } else {
  297. try {
  298. const params = {
  299. ...this.searchListInfo,
  300. openid: openId,
  301. libcode: config.LIB_CODE
  302. };
  303. const res = await FetchCollectionBook(params);
  304. if (res.code === 200) {
  305. this.isCollected = true;
  306. // 保存收藏记录的 id,供后续取消收藏使用
  307. if (res.data && res.data.id) {
  308. this.searchListInfo.id = res.data.id;
  309. }
  310. uni.showToast({ title: '收藏成功', icon: 'success' });
  311. } else {
  312. uni.showToast({ title: res.message || '收藏失败', icon: 'none' });
  313. }
  314. } catch (err) {
  315. console.error('收藏图书失败', err);
  316. uni.showToast({ title: '收藏失败', icon: 'none' });
  317. }
  318. }
  319. }
  320. },
  321. onShareAppMessage() {
  322. return {
  323. title: this.bookInfo.title || '图书详情',
  324. path: '/subpkg/pages/book-detail/book-detail?bookrecno=' + this.bookrecno,
  325. imageUrl: this.bookInfo.cover
  326. };
  327. }
  328. };
  329. </script>
  330. <style lang="scss" scoped>
  331. .detail-container {
  332. padding: 15px;
  333. background-color: #f5f5f5;
  334. min-height: 100vh;
  335. padding-bottom: 60px;
  336. }
  337. .article-detail-container {
  338. display: flex;
  339. background-color: #fff;
  340. border-radius: 10px;
  341. padding: 20px;
  342. margin-bottom: 12px;
  343. }
  344. .article-detail-left {
  345. flex: 1;
  346. }
  347. .article-detail-title {
  348. font-size: 20px;
  349. font-weight: bold;
  350. color: #333;
  351. margin-bottom: 10px;
  352. }
  353. .article-detail-info {
  354. font-size: 14px;
  355. color: #666;
  356. line-height: 1.5;
  357. }
  358. .article-detail-right {
  359. width: 110px;
  360. height: 150px;
  361. margin-left: 15px;
  362. }
  363. .article-detail-right image {
  364. width: 100%;
  365. height: 100%;
  366. border-radius: 6px;
  367. box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  368. }
  369. .book-store-info {
  370. background-color: #fff;
  371. border-radius: 10px;
  372. padding: 20px;
  373. display: flex;
  374. justify-content: space-around;
  375. margin-bottom: 12px;
  376. }
  377. .book-store-info-item {
  378. display: flex;
  379. flex-direction: column;
  380. align-items: center;
  381. }
  382. .store-txt1 {
  383. font-size: 22px;
  384. font-weight: bold;
  385. color: #2b85e4;
  386. }
  387. .store-txt2 {
  388. font-size: 13px;
  389. color: #999;
  390. margin-top: 4px;
  391. }
  392. .store-info-list {
  393. background-color: #fff;
  394. border-radius: 10px;
  395. padding: 10px;
  396. margin-bottom: 15px;
  397. }
  398. .store-info-item {
  399. display: flex;
  400. flex-direction: column;
  401. font-size: 14px;
  402. color: #666;
  403. padding: 10px;
  404. margin-bottom: 10px;
  405. border: 1px solid #eee;
  406. border-radius: 10px;
  407. &:last-child {
  408. margin-bottom: 0;
  409. }
  410. }
  411. .store-info-item view {
  412. display: flex;
  413. align-items: center;
  414. justify-content: flex-start;
  415. line-height: 28px;
  416. .info-item-title{
  417. width: 80px;
  418. font-weight: bold;
  419. color: #333;
  420. }
  421. }
  422. .content-tab {
  423. display: flex;
  424. background-color: #fff;
  425. border-radius: 10px;
  426. overflow: hidden;
  427. margin-bottom: 12px;
  428. }
  429. .tab-item {
  430. flex: 1;
  431. text-align: center;
  432. padding: 15px 0;
  433. font-size: 15px;
  434. color: #666;
  435. position: relative;
  436. }
  437. .tab-item.active {
  438. color: #2b85e4;
  439. font-weight: bold;
  440. }
  441. .tab-item.active::after {
  442. content: "";
  443. position: absolute;
  444. bottom: 0;
  445. left: 50%;
  446. transform: translateX(-50%);
  447. width: 30px;
  448. height: 3px;
  449. background-color: #2b85e4;
  450. border-radius: 2px;
  451. }
  452. .content-item {
  453. background-color: #fff;
  454. border-radius: 10px;
  455. padding: 20px;
  456. font-size: 15px;
  457. color: #333;
  458. line-height: 1.6;
  459. }
  460. .detail-bottom{
  461. justify-content: space-around;
  462. }
  463. </style>