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

297 lines
7.8 KiB

6 months ago
​
6 months ago
6 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
​
​
6 months ago
6 months ago
​
6 months ago
​
6 months ago
​
6 months ago
6 months ago
​
​
​
6 months ago
6 months ago
​
6 months ago
6 months ago
6 months ago
​
​
6 months ago
​
​
6 months ago
​
6 months ago
​
6 months ago
​
​
​
​
​
6 months ago
​
​
​
​
​
​
​
6 months ago
​
6 months ago
​
​
​
​
​
​
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
​
6 months ago
​
​
​
​
​
​
​
​
​
​
​
6 months ago
​
​
​
​
6 months ago
​
​
​
​
​
​
​
​
6 months ago
6 months ago
6 months ago
​
6 months ago
​
6 months ago
​
6 months ago
6 months ago
​
​
6 months ago
6 months ago
6 months ago
6 months ago
​
​
6 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
6 months ago
​
6 months ago
​
​
​
​
​
​
​
​
​
​
​
6 months ago
6 months ago
6 months ago
​
6 months ago
​
​
6 months ago
6 months ago
​
​
​
​
6 months ago
​
​
6 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
6 months ago
​
6 months ago
6 months ago
6 months ago
​
​
6 months ago
​
​
6 months ago
​
6 months ago
6 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
6 months ago
6 months ago
​
​
6 months ago
6 months ago
​
6 months ago
​
​
6 months ago
​
​
6 months ago
6 months ago
6 months ago
6 months ago
​
​
​
6 months ago
6 months ago
​
6 months ago
​
​
​
​
6 months ago
​
​
​
​
​
6 months ago
​
​
​
​
​
6 months ago
​
​
​
6 months ago
6 months ago
​
​
6 months ago
6 months ago
​
​
​
​
​
​
6 months ago
6 months ago
​
6 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
6 months ago
6 months ago
  1. <template>
  2. <view class="lending-container">
  3. <!-- 固定只有两个 tab -->
  4. <view class="tab-sticky">
  5. <my-tabs
  6. :tabData="tabData"
  7. :defaultIndex="currentIndex"
  8. :config="{ textColor: '#333' }"
  9. @tabClick="tabClick"
  10. />
  11. </view>
  12. <swiper
  13. class="swiper"
  14. :current="currentIndex"
  15. :style="{ height: currentSwiperHeight + 'px' }"
  16. @animationfinish="onSwiperEnd"
  17. @change="onSwiperChange"
  18. >
  19. <!-- 在借中 -->
  20. <swiper-item>
  21. <view class="list-wrapper">
  22. <uni-load-more status="loading" v-if="loadingLending" />
  23. <view class="empty" v-else-if="lendingList.length === 0">
  24. <uni-icons style="margin-left: 20px;" custom-prefix="iconfont" type="icon-kongshuju" size="80"></uni-icons>
  25. <text style="margin-top: 20px;">暂无在借记录</text>
  26. </view>
  27. <lending-list-item
  28. class="list-item-lending"
  29. v-for="(item, index) in lendingList"
  30. :key="index"
  31. :data="item"
  32. :is-lending="true"
  33. />
  34. </view>
  35. </swiper-item>
  36. <!-- 全部(历史借阅) -->
  37. <swiper-item>
  38. <view class="list-wrapper">
  39. <uni-load-more status="loading" v-if="loadingAll" />
  40. <view class="empty" v-else-if="allList.length === 0">
  41. <uni-icons style="margin-left: 20px;" custom-prefix="iconfont" type="icon-kongshuju" size="80"></uni-icons>
  42. <text style="margin-top: 20px;">暂无历史借阅记录</text>
  43. </view>
  44. <lending-list-item
  45. class="list-item-all"
  46. v-for="(item, index) in allList"
  47. :key="index"
  48. :data="item"
  49. :is-lending="false"
  50. />
  51. <uni-load-more
  52. v-if="allList.length > 0 && hasMoreAll"
  53. :status="loadMoreStatusAll"
  54. />
  55. </view>
  56. </swiper-item>
  57. </swiper>
  58. </view>
  59. </template>
  60. <script>
  61. import { FetchInitScreenSetting } from '@/api/user';
  62. import { FetchHistoryloan, FetchRdloanlist, FetchCoverByISBN } from '@/api/book';
  63. import myTabs from "@/components/my-tabs/my-tabs.vue";
  64. import lendingListItem from "@/components/lending-list-item/lending-list-item.vue";
  65. export default {
  66. components: { myTabs, lendingListItem },
  67. data() {
  68. return {
  69. screenConfig: {},
  70. tabData: [
  71. { label: '在借中', status: 'lending' },
  72. { label: '历史借阅', status: 'all' },
  73. ],
  74. currentIndex: 0,
  75. // 全部(历史)独立数据
  76. allList: [],
  77. loadingAll: false,
  78. pageAll: 1,
  79. hasMoreAll: true,
  80. loadMoreStatusAll: '',
  81. // 在借中 独立数据
  82. lendingList: [],
  83. loadingLending: false,
  84. swiperHeightData: {},
  85. currentSwiperHeight: 400,
  86. };
  87. },
  88. onLoad() {
  89. this.getScreenSetting();
  90. },
  91. onShow() {
  92. const tabIndex = uni.getStorageSync('switch_tab_index');
  93. if (tabIndex !== '') {
  94. this.currentIndex = Number(tabIndex);
  95. uni.removeStorageSync('switch_tab_index');
  96. }
  97. },
  98. onPullDownRefresh() {
  99. if (this.currentIndex === 0) {
  100. this.getLendingList();
  101. } else {
  102. this.getAllList(true);
  103. }
  104. },
  105. onReachBottom() {
  106. if (this.currentIndex === 0 && this.hasMoreAll) {
  107. this.getLendingList();
  108. }
  109. },
  110. methods: {
  111. // 获取封面(你要的格式)
  112. async getBookListWithCovers(bookList) {
  113. const bookWithCovers = await Promise.all(
  114. bookList.map(async (item) => {
  115. if (!item.isbn) return { ...item, cover: '' };
  116. const isbn = item.isbn.replace(/\-/g, '').trim();
  117. try {
  118. const coverRes = await FetchCoverByISBN({ isbn });
  119. return { ...item, cover: coverRes || '' };
  120. } catch (e) {
  121. console.error(`获取ISBN:${isbn}封面失败`, e);
  122. return { ...item, cover: '' };
  123. }
  124. })
  125. );
  126. return bookWithCovers;
  127. },
  128. async getScreenSetting() {
  129. try {
  130. const res = await FetchInitScreenSetting({ libcode: '1201' });
  131. const data = res.data;
  132. this.screenConfig = {
  133. thirdUrl: data.open_lib_http?.context || '',
  134. thirdAppid: data.open_lib_appId?.context || '',
  135. thirdSecret: data.open_lib_secret?.context || '',
  136. sm4Key: data.sm4_key?.context || ''
  137. };
  138. // 默认加载第一个 tab
  139. this.getLendingList(true);
  140. } catch (err) {}
  141. },
  142. async getAllList(isRefresh = false) {
  143. if (this.loadingAll) return;
  144. this.loadingAll = true;
  145. if (isRefresh) {
  146. this.pageAll = 1;
  147. this.allList = [];
  148. this.hasMoreAll = true;
  149. this.loadMoreStatusAll = '';
  150. }
  151. try {
  152. const params = {
  153. ...this.screenConfig,
  154. rdid: uni.getStorageSync('currentReaderCard'),
  155. logtype: '30002',
  156. page: this.pageAll,
  157. rows: 10,
  158. };
  159. const res = await FetchHistoryloan(params);
  160. const result = typeof res.data === 'string' ? JSON.parse(res.data) : res.data;
  161. let list = result.hloanlist || [];
  162. // 插入封面
  163. // list = await this.getBookListWithCovers(list);
  164. this.allList = [...this.allList, ...list];
  165. this.hasMoreAll = list.length === 10;
  166. this.loadMoreStatusAll = this.hasMoreAll ? '' : 'no-more';
  167. if (this.hasMoreAll) this.pageAll++;
  168. } catch (err) {
  169. } finally {
  170. this.loadingAll = false;
  171. uni.stopPullDownRefresh();
  172. setTimeout(() => {
  173. this.calcHeight('all');
  174. }, 100);
  175. }
  176. },
  177. async getLendingList() {
  178. this.loadingLending = true;
  179. try {
  180. const params = {
  181. ...this.screenConfig,
  182. rdid: uni.getStorageSync('currentReaderCard'),
  183. };
  184. const res = await FetchRdloanlist(params);
  185. const result = typeof res.data === 'string' ? JSON.parse(res.data) : res.data;
  186. let list = result.loanlist || [];
  187. // 插入封面
  188. // list = await this.getBookListWithCovers(list);
  189. this.lendingList = list.map(item => ({
  190. ...item,
  191. loantime: item.loandate || '',
  192. returntime: item.returndate || '',
  193. }));
  194. } catch (err) {
  195. } finally {
  196. this.loadingLending = false;
  197. uni.stopPullDownRefresh();
  198. setTimeout(() => {
  199. this.calcHeight('lending');
  200. }, 100);
  201. }
  202. },
  203. // 高度自适应(修复版)
  204. calcHeight(type) {
  205. const selector = `.list-item-${type}`;
  206. const query = uni.createSelectorQuery().in(this);
  207. query.selectAll(selector).boundingClientRect((res) => {
  208. let totalHeight = 200;
  209. if (res && res.length > 0) {
  210. totalHeight = res.reduce((sum, rect) => sum + rect.height, 0);
  211. totalHeight += res.length * 10 + 40;
  212. }
  213. this.swiperHeightData[type] = totalHeight;
  214. this.currentSwiperHeight = totalHeight;
  215. }).exec();
  216. },
  217. tabClick(index) {
  218. this.currentIndex = index;
  219. if (index === 0) {
  220. if (this.lendingList.length === 0) {
  221. this.getLendingList();
  222. } else {
  223. this.currentSwiperHeight = this.swiperHeightData.lending || 600;
  224. }
  225. } else {
  226. if (this.allList.length === 0) {
  227. this.getAllList(true);
  228. } else {
  229. this.currentSwiperHeight = this.swiperHeightData.all || 600;
  230. }
  231. }
  232. },
  233. onSwiperChange(e) {
  234. if (e.detail.source === 'touch') this.currentIndex = e.detail.current;
  235. },
  236. onSwiperEnd() {
  237. this.tabClick(this.currentIndex);
  238. },
  239. }
  240. };
  241. </script>
  242. <style lang="scss" scoped>
  243. .lending-container {
  244. background: #f5f5f5;
  245. min-height: 100vh;
  246. }
  247. .tab-sticky {
  248. position: sticky;
  249. top: 0;
  250. z-index: 99;
  251. background: #fff;
  252. }
  253. .swiper {
  254. width: 100%;
  255. transition: height 0.2s ease;
  256. }
  257. .list-wrapper {
  258. padding: 10px;
  259. box-sizing: border-box;
  260. }
  261. </style>