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

421 lines
12 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
2 months 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
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
2 months 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 } from '@/api/book';
  94. import config from '@/utils/config';
  95. export default {
  96. data() {
  97. return {
  98. baseUrl: config.baseUrl,
  99. currentTab: 0,
  100. isCollected: false,
  101. bookrecno: '',
  102. opacUrl: '',
  103. fromRecommend: false,
  104. bookInfo: {},
  105. holdingsData: [],
  106. dictionaryTree: {},
  107. libraryMap: {},
  108. locationMap: {}
  109. };
  110. },
  111. onLoad(options) {
  112. // 1. 首页/列表页 直接带完整 bookData 过来,优先走这个
  113. if (options.bookData) {
  114. const bookData = JSON.parse(decodeURIComponent(options.bookData));
  115. this.bookInfo = bookData;
  116. this.bookrecno = bookData.bookrecno || "";
  117. this.fromRecommend = options.fromRecommend === 'true';
  118. this.holdingsData = [];
  119. this.checkCollectStatus();
  120. return;
  121. }
  122. // 2. 检索页只传 bookrecno,请求接口拿详情
  123. this.bookrecno = options.bookrecno || "";
  124. this.fromRecommend = false;
  125. this.getOpacUrl();
  126. this.getDictionaryTree();
  127. },
  128. computed: {
  129. // 在馆数量
  130. // 馆藏状态,编目=1,在馆=2,借出=3,丢失=4,剔除=5,交换=6,赠送=7,装订=8,锁定=9,预借=10, 清点=12
  131. inLibraryCount() {
  132. return this.holdingsData.filter(item => item.state === 2).length;
  133. },
  134. // 借出数量(新增)
  135. lendCount() {
  136. return this.holdingsData.filter(item => item.state === 3).length;
  137. },
  138. // 第一个馆藏状态
  139. firstStateText() {
  140. if (this.holdingsData.length === 0) return '无馆藏';
  141. return this.getStateText(this.holdingsData[0].state);
  142. }
  143. },
  144. methods: {
  145. onImgError(e) {
  146. e.target.src = "/static/images/default-book.png";
  147. },
  148. // 获取字典项 - 馆代码
  149. async getDictionaryTree() {
  150. try {
  151. const res = await FetchDictionaryTree();
  152. console.log('dictionaryTree',res);
  153. const data = res.data || [];
  154. // 1. 找到分馆字典项
  155. const fgItem = data.find(item => item.dictionaryCode === 'FG' && item.dictionaryName === '分馆');
  156. if (fgItem && fgItem.childDictionarys) {
  157. // 建立分馆映射:dictionaryCode -> dictionaryName
  158. this.libraryMap = {};
  159. fgItem.childDictionarys.forEach(child => {
  160. this.libraryMap[child.dictionaryCode] = child.dictionaryName;
  161. });
  162. }
  163. // 2. 找到馆藏地点字典项
  164. const gcdItem = data.find(item => item.dictionaryCode === 'GCD' && item.dictionaryName === '馆藏地点');
  165. if (gcdItem && gcdItem.childDictionarys) {
  166. // 建立馆藏地点映射:dictionaryCode -> dictionaryName
  167. this.locationMap = {};
  168. gcdItem.childDictionarys.forEach(child => {
  169. this.locationMap[child.dictionaryCode] = child.dictionaryName;
  170. });
  171. }
  172. this.dictionaryTree = data;
  173. } catch (err) {
  174. console.error('获取字典树失败', err);
  175. }
  176. },
  177. // 获取配置
  178. async getOpacUrl() {
  179. try {
  180. const res = await FetchInitScreenSetting({ libcode: config.LIB_CODE });
  181. this.opacUrl = res.data.opac_url?.context || '';
  182. this.getBookDetail();
  183. } catch (err) {}
  184. },
  185. // 获取图书详情(适配新接口结构)
  186. async getBookDetail() {
  187. if (!this.bookrecno || !this.opacUrl) return;
  188. uni.showLoading({ title: '加载中...' });
  189. try {
  190. const params = {
  191. opacUrl: this.opacUrl,
  192. bookrecno: this.bookrecno
  193. };
  194. const res = await FetchFindbookByQuery(params);
  195. // console.log('bookrecno详情',res);
  196. const apiData = res.data || {};
  197. this.bookInfo = apiData.biblios || {};
  198. // console.log('bookrecno-bookInfo详情',this.bookInfo);
  199. this.holdingsData = apiData.holdings || [];
  200. // console.log('bookrecno-holdingsData详情',this.holdingsData);
  201. this.checkCollectStatus();
  202. } catch (err) {
  203. console.error(err);
  204. } finally {
  205. uni.hideLoading();
  206. }
  207. },
  208. // 馆藏状态文字
  209. getStateText(state) {
  210. const map = {
  211. 1: '编目',
  212. 2: '在馆',
  213. 3: '借出',
  214. 4: '丢失',
  215. 5: '剔除',
  216. 6: '交换',
  217. 7: '赠送',
  218. 8: '装订',
  219. 9: '锁定',
  220. 10: '预借',
  221. 12: '清点'
  222. }
  223. return map[state] || '未知';
  224. },
  225. // 获取所在馆名称
  226. getLibraryName(orglib) {
  227. if (!orglib) return '葛店经济技术开发区图书馆';
  228. return this.libraryMap[orglib] || orglib || '葛店经济技术开发区图书馆';
  229. },
  230. // 获取馆藏地名称
  231. getLocationName(orglocal) {
  232. if (!orglocal) return '葛店图书馆';
  233. return this.locationMap[orglocal] || orglocal || '葛店图书馆';
  234. },
  235. // 收藏
  236. checkCollectStatus() {
  237. const list = uni.getStorageSync('collectList') || [];
  238. this.isCollected = list.includes(this.bookrecno);
  239. },
  240. toggleCollect() {
  241. let list = uni.getStorageSync('collectList') || [];
  242. if (this.isCollected) {
  243. list = list.filter(i => i !== this.bookrecno);
  244. uni.showToast({ title: '取消收藏', icon: 'success' });
  245. } else {
  246. list.push(this.bookrecno);
  247. uni.showToast({ title: '收藏成功', icon: 'success' });
  248. }
  249. uni.setStorageSync('collectList', list);
  250. this.isCollected = !this.isCollected;
  251. }
  252. },
  253. onShareAppMessage() {
  254. return {
  255. title: this.bookInfo.title || '图书详情',
  256. path: '/subpkg/pages/book-detail/book-detail?bookrecno=' + this.bookrecno,
  257. imageUrl: this.bookInfo.cover
  258. };
  259. }
  260. };
  261. </script>
  262. <style lang="scss" scoped>
  263. .detail-container {
  264. padding: 15px;
  265. background-color: #f5f5f5;
  266. min-height: 100vh;
  267. padding-bottom: 60px;
  268. }
  269. .article-detail-container {
  270. display: flex;
  271. background-color: #fff;
  272. border-radius: 10px;
  273. padding: 20px;
  274. margin-bottom: 12px;
  275. }
  276. .article-detail-left {
  277. flex: 1;
  278. }
  279. .article-detail-title {
  280. font-size: 20px;
  281. font-weight: bold;
  282. color: #333;
  283. margin-bottom: 10px;
  284. }
  285. .article-detail-info {
  286. font-size: 14px;
  287. color: #666;
  288. line-height: 1.5;
  289. }
  290. .article-detail-right {
  291. width: 110px;
  292. height: 150px;
  293. margin-left: 15px;
  294. }
  295. .article-detail-right image {
  296. width: 100%;
  297. height: 100%;
  298. border-radius: 6px;
  299. box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  300. }
  301. .book-store-info {
  302. background-color: #fff;
  303. border-radius: 10px;
  304. padding: 20px;
  305. display: flex;
  306. justify-content: space-around;
  307. margin-bottom: 12px;
  308. }
  309. .book-store-info-item {
  310. display: flex;
  311. flex-direction: column;
  312. align-items: center;
  313. }
  314. .store-txt1 {
  315. font-size: 22px;
  316. font-weight: bold;
  317. color: #2b85e4;
  318. }
  319. .store-txt2 {
  320. font-size: 13px;
  321. color: #999;
  322. margin-top: 4px;
  323. }
  324. .store-info-list {
  325. background-color: #fff;
  326. border-radius: 10px;
  327. padding: 10px;
  328. margin-bottom: 15px;
  329. }
  330. .store-info-item {
  331. display: flex;
  332. flex-direction: column;
  333. font-size: 14px;
  334. color: #666;
  335. padding: 10px;
  336. margin-bottom: 10px;
  337. border: 1px solid #eee;
  338. border-radius: 10px;
  339. &:last-child {
  340. margin-bottom: 0;
  341. }
  342. }
  343. .store-info-item view {
  344. display: flex;
  345. align-items: center;
  346. justify-content: flex-start;
  347. line-height: 28px;
  348. .info-item-title{
  349. width: 80px;
  350. font-weight: bold;
  351. color: #333;
  352. }
  353. }
  354. .content-tab {
  355. display: flex;
  356. background-color: #fff;
  357. border-radius: 10px;
  358. overflow: hidden;
  359. margin-bottom: 12px;
  360. }
  361. .tab-item {
  362. flex: 1;
  363. text-align: center;
  364. padding: 15px 0;
  365. font-size: 15px;
  366. color: #666;
  367. position: relative;
  368. }
  369. .tab-item.active {
  370. color: #2b85e4;
  371. font-weight: bold;
  372. }
  373. .tab-item.active::after {
  374. content: "";
  375. position: absolute;
  376. bottom: 0;
  377. left: 50%;
  378. transform: translateX(-50%);
  379. width: 30px;
  380. height: 3px;
  381. background-color: #2b85e4;
  382. border-radius: 2px;
  383. }
  384. .content-item {
  385. background-color: #fff;
  386. border-radius: 10px;
  387. padding: 20px;
  388. font-size: 15px;
  389. color: #333;
  390. line-height: 1.6;
  391. }
  392. .detail-bottom{
  393. justify-content: space-around;
  394. }
  395. </style>