图书馆小程序
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.

580 lines
16 KiB

5 months ago
5 months ago
4 months ago
5 months ago
4 months ago
4 months ago
5 months ago
4 months ago
4 weeks ago
4 months ago
5 months ago
4 months ago
5 months ago
4 months ago
5 months ago
4 months ago
5 months ago
4 months ago
5 months ago
4 months ago
4 months ago
5 months ago
4 months ago
4 months ago
5 months ago
4 months ago
5 months ago
4 months ago
4 months ago
4 months ago
4 months ago
5 months ago
5 months ago
5 months ago
4 months ago
5 months ago
4 months ago
5 months ago
5 months ago
4 months ago
4 months ago
5 months ago
4 months ago
4 months ago
4 months ago
4 months ago
5 months ago
3 weeks ago
4 months ago
4 months ago
5 months ago
3 weeks ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
5 months ago
4 months ago
4 weeks ago
4 months ago
4 months ago
4 months ago
4 months ago
5 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
5 months ago
4 months ago
3 weeks ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
5 months ago
4 months ago
5 months ago
4 months ago
4 months ago
5 months ago
5 months ago
4 months ago
4 months ago
4 months ago
4 months ago
5 months ago
5 months ago
5 months ago
4 weeks ago
5 months ago
4 months ago
5 months ago
4 months ago
5 months ago
4 months ago
4 months ago
4 months ago
5 months ago
4 months ago
5 months ago
4 months ago
3 weeks ago
4 months ago
4 weeks ago
4 months 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.jpg'"
  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. fondsName: getApp().globalData.fondsName || '',
  101. baseUrl: config.baseUrl,
  102. currentTab: 0,
  103. isCollected: false,
  104. bookrecno: '',
  105. opacUrl: '',
  106. fromRecommend: false,
  107. bookInfo: {},
  108. searchListInfo: {},
  109. holdingsData: [],
  110. dictionaryTree: {},
  111. libraryMap: {},
  112. locationMap: {}
  113. };
  114. },
  115. onLoad(options) {
  116. // console.log('options',options)
  117. const fromShare = options.fromShare === 'true'
  118. // 1. 首页/推荐页 bookData
  119. if (options.bookData) {
  120. const bookData = JSON.parse(decodeURIComponent(options.bookData));
  121. this.bookInfo = bookData;
  122. this.bookrecno = bookData.bookrecno || "";
  123. this.fromRecommend = options.fromRecommend === 'true';
  124. this.holdingsData = [];
  125. this.checkCollectStatus();
  126. // 分享过来,有bookrecno强制拉完整馆藏
  127. if(fromShare && this.bookrecno){
  128. this.getOpacUrl();
  129. }
  130. return;
  131. }
  132. // 2. 分享传入 bookrecno 优先走这里
  133. if(options.bookrecno){
  134. this.bookrecno = options.bookrecno
  135. this.fromRecommend = false
  136. this.bookInfo = {}
  137. this.getOpacUrl();
  138. return;
  139. }
  140. // 3. 搜索列表 searchData
  141. if(options.searchData){
  142. const bookData = JSON.parse(decodeURIComponent(options.searchData));
  143. this.searchListInfo = bookData;
  144. this.bookrecno = bookData.bookrecno || "";
  145. this.bookInfo = bookData;
  146. }
  147. // 4. 收藏列表标记
  148. if (options.isCollected === 'true') {
  149. this.isCollected = true;
  150. }
  151. this.fromRecommend = false;
  152. // 有bookrecno就请求详情,修复原逻辑漏调用getOpacUrl
  153. if(this.bookrecno){
  154. this.getOpacUrl();
  155. }
  156. },
  157. computed: {
  158. // 在馆数量
  159. // 馆藏状态,编目=1,在馆=2,借出=3,丢失=4,剔除=5,交换=6,赠送=7,装订=8,锁定=9,预借=10, 清点=12
  160. inLibraryCount() {
  161. return this.holdingsData.filter(item => item.state === 2).length;
  162. },
  163. // 借出数量(新增)
  164. lendCount() {
  165. return this.holdingsData.filter(item => item.state === 3).length;
  166. },
  167. // 第一个馆藏状态
  168. firstStateText() {
  169. if (this.holdingsData.length === 0) return '无馆藏';
  170. return this.getStateText(this.holdingsData[0].state);
  171. }
  172. },
  173. methods: {
  174. onImgError(e) {
  175. e.target.src = "/static/images/default-book.jpg";
  176. },
  177. // 加载图书封面
  178. async loadBookCover() {
  179. console.log('this.bookInfo',this.bookInfo)
  180. if (!this.bookInfo.isbn) return;
  181. try {
  182. const coverUrl = await fetchBookCoverBase64(this.bookInfo.isbn);
  183. if (coverUrl) {
  184. this.$set(this.bookInfo, 'cover', coverUrl);
  185. }
  186. } catch (error) {
  187. console.error('获取封面失败:', error);
  188. }
  189. },
  190. // 获取字典项 - 馆代码
  191. async getDictionaryTree() {
  192. try {
  193. const res = await FetchDictionaryTree();
  194. console.log('dictionaryTree',res);
  195. const data = res.data || [];
  196. // 1. 找到分馆字典项
  197. const fgItem = data.find(item => item.dictionaryCode === 'FG' && item.dictionaryName === '分馆');
  198. if (fgItem && fgItem.childDictionarys) {
  199. // 建立分馆映射:dictionaryCode -> dictionaryName
  200. this.libraryMap = {};
  201. fgItem.childDictionarys.forEach(child => {
  202. this.libraryMap[child.dictionaryCode] = child.dictionaryName;
  203. });
  204. }
  205. // 2. 找到馆藏地点字典项
  206. const gcdItem = data.find(item => item.dictionaryCode === 'GCD' && item.dictionaryName === '馆藏地点');
  207. if (gcdItem && gcdItem.childDictionarys) {
  208. // 建立馆藏地点映射:dictionaryCode -> dictionaryName
  209. this.locationMap = {};
  210. gcdItem.childDictionarys.forEach(child => {
  211. this.locationMap[child.dictionaryCode] = child.dictionaryName;
  212. });
  213. }
  214. this.dictionaryTree = data;
  215. } catch (err) {
  216. console.error('获取字典树失败', err);
  217. }
  218. },
  219. // 获取配置
  220. async getOpacUrl() {
  221. try {
  222. const res = await FetchInitScreenSetting({ libcode: getApp().globalData.libcode });
  223. this.opacUrl = res.data.opac_url?.context || '';
  224. this.getDictionaryTree();
  225. this.getBookDetail();
  226. } catch (err) {}
  227. },
  228. // 获取图书详情
  229. async getBookDetail() {
  230. if (!this.bookrecno || !this.opacUrl) return;
  231. uni.showLoading({ title: '加载中...' });
  232. try {
  233. const params = {
  234. opacUrl: this.opacUrl,
  235. bookrecno: this.bookrecno
  236. };
  237. const res = await FetchFindbookByQuery(params);
  238. const apiData = res.data || {};
  239. this.bookInfo = apiData.biblios || {};
  240. this.holdingsData = apiData.holdings || [];
  241. // 分享进入场景补齐searchListInfo,防止收藏点击报错
  242. if(!this.searchListInfo || !this.searchListInfo.bookrecno){
  243. this.searchListInfo = {
  244. bookrecno: this.bookInfo.bookrecno,
  245. title: this.bookInfo.title,
  246. author: this.bookInfo.author,
  247. isbn: this.bookInfo.isbn
  248. }
  249. }
  250. // 加载封面
  251. await this.loadBookCover();
  252. // 检查收藏状态
  253. this.checkCollectStatus();
  254. } catch (err) {
  255. console.error(err);
  256. } finally {
  257. uni.hideLoading();
  258. }
  259. },
  260. // 馆藏状态文字
  261. getStateText(state) {
  262. const map = {
  263. 1: '编目',
  264. 2: '在馆',
  265. 3: '借出',
  266. 4: '丢失',
  267. 5: '剔除',
  268. 6: '交换',
  269. 7: '赠送',
  270. 8: '装订',
  271. 9: '锁定',
  272. 10: '预借',
  273. 12: '清点'
  274. }
  275. return map[state] || '未知';
  276. },
  277. // 获取所在馆名称
  278. getLibraryName(orglib) {
  279. if (!orglib) return this.fondsName;
  280. return this.libraryMap[orglib] || orglib || this.fondsName;
  281. },
  282. // 获取馆藏地名称
  283. getLocationName(orglocal) {
  284. if (!orglocal) return '葛店图书馆';
  285. return this.locationMap[orglocal] || orglocal || '葛店图书馆';
  286. },
  287. // 收藏状态检查(如果已经通过参数传入则跳过)
  288. checkCollectStatus() {
  289. if (this.isCollected) return;
  290. const list = uni.getStorageSync('collectList') || [];
  291. this.isCollected = list.includes(this.bookrecno);
  292. },
  293. async toggleCollect() {
  294. const openId = await getOpenId();
  295. if (!openId) {
  296. uni.showToast({ title: '获取用户信息失败', icon: 'none' });
  297. return;
  298. }
  299. // 防御,分享进来searchListInfo为空保护
  300. if(!this.searchListInfo || !this.searchListInfo.bookrecno){
  301. uni.showToast({title:'数据未加载完成,请稍候',icon:'none'})
  302. return
  303. }
  304. if (this.isCollected) {
  305. try {
  306. const res = await FetchCancelCollectionBook({id: this.searchListInfo.id});
  307. if (res.code === 200) {
  308. this.isCollected = false;
  309. // 清空收藏记录 id,避免影响后续收藏操作
  310. if (this.searchListInfo) {
  311. this.searchListInfo.id = null;
  312. }
  313. // 设置取消收藏标记,通知收藏列表页面刷新
  314. uni.setStorageSync('needRefreshCollect', true);
  315. uni.showToast({ title: '取消收藏', icon: 'success' });
  316. } else {
  317. uni.showToast({ title: res.message || '取消收藏失败', icon: 'none' });
  318. }
  319. } catch (err) {
  320. console.error('取消收藏图书失败', err);
  321. uni.showToast({ title: '取消收藏失败', icon: 'none' });
  322. }
  323. } else {
  324. try {
  325. const params = {
  326. ...this.searchListInfo,
  327. openid: openId,
  328. libcode: getApp().globalData.libcode
  329. };
  330. const res = await FetchCollectionBook(params);
  331. if (res.code === 200) {
  332. this.isCollected = true;
  333. // 保存收藏记录的 id,供后续取消收藏使用
  334. if (res.data && res.data.id) {
  335. this.searchListInfo.id = res.data.id;
  336. }
  337. uni.showToast({ title: '收藏成功', icon: 'success' });
  338. } else {
  339. uni.showToast({ title: res.message || '收藏失败', icon: 'none' });
  340. }
  341. } catch (err) {
  342. console.error('收藏图书失败', err);
  343. uni.showToast({ title: '收藏失败', icon: 'none' });
  344. }
  345. }
  346. }
  347. },
  348. onShareAppMessage() {
  349. const title = this.bookInfo.title || this.bookInfo.name || '图书详情';
  350. let path = '';
  351. let imageUrl = '';
  352. const cover = this.bookInfo.cover || this.bookInfo.base64Cover;
  353. // 微信分享不支持base64图片,过滤
  354. if(cover && !cover.startsWith('data:image')){
  355. imageUrl = cover;
  356. }
  357. if(this.bookrecno){
  358. //优先bookrecno,参数短,不会url超长
  359. path = `/subpkg/pages/book-detail/book-detail?bookrecno=${encodeURIComponent(this.bookrecno)}&fromShare=true`
  360. }else{
  361. path = "/subpkg/pages/book-detail/book-detail?bookData=" + encodeURIComponent(JSON.stringify(this.bookInfo)) + "&fromShare=true"
  362. }
  363. return {
  364. title,
  365. path,
  366. imageUrl
  367. };
  368. },
  369. //分享到朋友圈
  370. onShareTimeline(){
  371. const title = this.bookInfo.title || this.bookInfo.name || '图书详情';
  372. let query = ''
  373. if(this.bookrecno){
  374. query = `bookrecno=${encodeURIComponent(this.bookrecno)}&fromShare=true`
  375. }else{
  376. query = `bookData=${encodeURIComponent(JSON.stringify(this.bookInfo))}&fromShare=true`
  377. }
  378. let imageUrl = ''
  379. const cover = this.bookInfo.cover
  380. if(cover && !cover.startsWith('data:image')){
  381. imageUrl = cover
  382. }
  383. return {
  384. title,
  385. query,
  386. imageUrl
  387. }
  388. }
  389. };
  390. </script>
  391. <style lang="scss" scoped>
  392. .detail-container {
  393. padding: 15px;
  394. background-color: #f5f5f5;
  395. min-height: 100vh;
  396. padding-bottom: 70px;
  397. }
  398. .article-detail-container {
  399. display: flex;
  400. background-color: #fff;
  401. border-radius: 10px;
  402. padding: 20px;
  403. margin-bottom: 12px;
  404. }
  405. .article-detail-left {
  406. flex: 1;
  407. }
  408. .article-detail-title {
  409. font-size: 20px;
  410. font-weight: bold;
  411. color: #333;
  412. margin-bottom: 10px;
  413. }
  414. .article-detail-info {
  415. font-size: 14px;
  416. color: #666;
  417. line-height: 1.5;
  418. }
  419. .article-detail-right {
  420. width: 110px;
  421. height: 150px;
  422. margin-left: 15px;
  423. }
  424. .article-detail-right image {
  425. width: 100%;
  426. height: 100%;
  427. border-radius: 6px;
  428. box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  429. }
  430. .book-store-info {
  431. background-color: #fff;
  432. border-radius: 10px;
  433. padding: 20px;
  434. display: flex;
  435. justify-content: space-around;
  436. margin-bottom: 12px;
  437. }
  438. .book-store-info-item {
  439. display: flex;
  440. flex-direction: column;
  441. align-items: center;
  442. }
  443. .store-txt1 {
  444. font-size: 22px;
  445. font-weight: bold;
  446. color: #2b85e4;
  447. }
  448. .store-txt2 {
  449. font-size: 13px;
  450. color: #999;
  451. margin-top: 4px;
  452. }
  453. .store-info-list {
  454. background-color: #fff;
  455. border-radius: 10px;
  456. padding: 10px;
  457. margin-bottom: 15px;
  458. }
  459. .store-info-item {
  460. display: flex;
  461. flex-direction: column;
  462. font-size: 14px;
  463. color: #666;
  464. padding: 10px;
  465. margin-bottom: 10px;
  466. border: 1px solid #eee;
  467. border-radius: 10px;
  468. &:last-child {
  469. margin-bottom: 0;
  470. }
  471. }
  472. .store-info-item view {
  473. display: flex;
  474. align-items: center;
  475. justify-content: flex-start;
  476. line-height: 28px;
  477. .info-item-title{
  478. width: 80px;
  479. font-weight: bold;
  480. color: #333;
  481. }
  482. }
  483. .content-tab {
  484. display: flex;
  485. background-color: #fff;
  486. border-radius: 10px;
  487. overflow: hidden;
  488. margin-bottom: 12px;
  489. }
  490. .tab-item {
  491. flex: 1;
  492. text-align: center;
  493. padding: 15px 0;
  494. font-size: 15px;
  495. color: #666;
  496. position: relative;
  497. }
  498. .tab-item.active {
  499. color: #2b85e4;
  500. font-weight: bold;
  501. }
  502. .tab-item.active::after {
  503. content: "";
  504. position: absolute;
  505. bottom: 0;
  506. left: 50%;
  507. transform: translateX(-50%);
  508. width: 30px;
  509. height: 3px;
  510. background-color: #2b85e4;
  511. border-radius: 2px;
  512. }
  513. .content-item {
  514. background-color: #fff;
  515. border-radius: 10px;
  516. padding: 20px;
  517. font-size: 15px;
  518. color: #333;
  519. line-height: 1.6;
  520. }
  521. .detail-bottom{
  522. position: fixed;
  523. bottom:0;
  524. left:0;
  525. right:0;
  526. height: 50px;
  527. padding: 0 15px;
  528. background:#fff;
  529. display:flex;
  530. justify-content: space-around;
  531. align-items:center;
  532. box-shadow: 0 -2px 5px rgba(0, 0, 0, 0.05);
  533. }
  534. .handle-btn{
  535. display:flex;
  536. align-items:center;
  537. background:#fff;
  538. border:none;
  539. }
  540. .share-text{
  541. margin-left:4px;
  542. font-size:14px;
  543. }
  544. </style>