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

635 lines
17 KiB

2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
1 month ago
2 months ago
2 months 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
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 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
1 month ago
2 months ago
2 months 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
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
2 months ago
1 month 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
2 months ago
1 month ago
2 months ago
2 months ago
2 months ago
1 month ago
2 months ago
  1. <template>
  2. <view style="padding-bottom: 20px;">
  3. <view class="top-bar">
  4. <image class="top-bar-bg" src="@/static/images/mingqi-beij@2x.png" mode="aspectFill"></image>
  5. <view class="library-info">
  6. <image class="avatar" src="@/static/images/avatar.png" mode="aspectFill"></image>
  7. <view class="library-name">葛店经济技术开发区图书馆</view>
  8. </view>
  9. <uni-icons class="search-icon" type="search" size="30" @click="onToSearch"></uni-icons>
  10. </view>
  11. <view class="status-cards">
  12. <view class="status-card" @click="toBorrowPage(1)">
  13. <view class="status-icon icon-color1" >
  14. <uni-icons custom-prefix="iconfont" type="icon-daiban02" size="22"></uni-icons>
  15. </view>
  16. <view class="status-label">在借中</view>
  17. </view>
  18. <view class="status-card" @click="toBorrowPage(2)">
  19. <view class="status-icon icon-color2" >
  20. <uni-icons custom-prefix="iconfont" type="icon-zuofei05" size="22"></uni-icons>
  21. </view>
  22. <view class="status-label">将过期</view>
  23. </view>
  24. <view class="status-card" @click="toBorrowPage(3)">
  25. <view class="status-icon icon-color3" >
  26. <uni-icons custom-prefix="iconfont" type="icon-yuqi04" size="22"></uni-icons>
  27. </view>
  28. <view class="status-label">已过期</view>
  29. </view>
  30. <view class="status-card" @click="toBorrowCar">
  31. <view class="status-icon icon-color4" >
  32. <uni-icons custom-prefix="iconfont" type="icon-a-zhidu4" size="22"></uni-icons>
  33. </view>
  34. <view class="status-label">借阅清单</view>
  35. </view>
  36. </view>
  37. <swiper class="banner-swiper" interval="3000" circular :vertical="false" :indicator-dots="true" :autoplay="true">
  38. <swiper-item>
  39. <image data-post-id="3" src="https://qiniu.aiyxlib.com/1605060269830"></image>
  40. </swiper-item>
  41. <swiper-item>
  42. <image data-post-id="4" src="https://qiniu.aiyxlib.com/1605060269830"></image>
  43. </swiper-item>
  44. </swiper>
  45. <swiper class="menu-swiper" interval="6000" :vertical="false" :indicator-dots="true" :autoplay="false">
  46. <swiper-item>
  47. <view class="menu-grid">
  48. <view class="menu-item" @click="onToSearch">
  49. <view class="menu-icon">
  50. <uni-icons custom-prefix="iconfont" type="icon-ziyuan" size="22"></uni-icons>
  51. </view>
  52. <view class="menu-label">书目检索</view>
  53. </view>
  54. <view class="menu-item">
  55. <view class="menu-icon">
  56. <uni-icons custom-prefix="iconfont" type="icon-z_renew_normal" size="24"></uni-icons>
  57. </view>
  58. <view class="menu-label">图书续借</view>
  59. </view>
  60. <view class="menu-item" >
  61. <view class="menu-icon">
  62. <uni-icons custom-prefix="iconfont" type="icon-guanwaizhuanjie1" size="26"></uni-icons>
  63. </view>
  64. <view class="menu-label">图书转借</view>
  65. </view>
  66. <view class="menu-item" @click="toRanking">
  67. <view class="menu-icon">
  68. <uni-icons custom-prefix="iconfont" type="icon-paihangbang" size="22"></uni-icons>
  69. </view>
  70. <view class="menu-label">借阅排行</view>
  71. </view>
  72. <view class="menu-item" @click="toActivityList">
  73. <view class="menu-icon">
  74. <uni-icons custom-prefix="iconfont" type="icon-remenhuodong" size="26"></uni-icons>
  75. </view>
  76. <view class="menu-label">活动报名</view>
  77. </view>
  78. <view class="menu-item" @click="toFeedback">
  79. <view class="menu-icon">
  80. <uni-icons custom-prefix="iconfont" type="icon-duzheliuyan" size="26"></uni-icons>
  81. </view>
  82. <view class="menu-label">读者留言</view>
  83. </view>
  84. <view class="menu-item" @click="toLibraryCard">
  85. <view class="menu-icon">
  86. <uni-icons custom-prefix="iconfont" type="icon-duzhezheng" size="26"></uni-icons>
  87. </view>
  88. <view class="menu-label">电子证</view>
  89. </view>
  90. <view class="menu-item" @click="onToUser">
  91. <view class="menu-icon">
  92. <uni-icons custom-prefix="iconfont" type="icon-yonghuxinxi-gerenxinxi" size="20"></uni-icons>
  93. </view>
  94. <view class="menu-label">个人中心</view>
  95. </view>
  96. </view>
  97. </swiper-item>
  98. </swiper>
  99. <!-- 已有绑定滑动切换多个借阅证 -->
  100. <view v-if="isBindLibraryCard" class="library-card-has">
  101. <view class="section-title">我的借阅证</view>
  102. <!-- 左右滑动切换证件 -->
  103. <!-- :indicator-dots="readerCardList.length > 1"
  104. indicator-color="#d1d1d1"
  105. indicator-active-color="#01a4fe" -->
  106. <swiper
  107. class="card-swiper"
  108. :circular="false"
  109. >
  110. <swiper-item v-for="item in readerCardList" :key="item.id">
  111. <view class="card-item">
  112. <image class="card-left-img" src="@/static/images/card-img2.png" mode="widthFix" />
  113. <view class="card-right-info">
  114. <text class="info-title">读者证号</text>
  115. <text class="info-num">{{ item.bindValue }}</text>
  116. </view>
  117. <view class="default-tag" v-if="item.bindDefault">默认证</view>
  118. </view>
  119. </swiper-item>
  120. </swiper>
  121. </view>
  122. <!-- 未绑定借阅证 -->
  123. <view class="library-card-section" @click="toCheckLogin" v-else>
  124. <view class="section-title">借阅证</view>
  125. <image class="card-icon" src="@/static/images/card-img2.png"></image>
  126. <view class="card-tip">您还没有绑定读者证哦</view>
  127. <button class="bind-btn">立即绑定</button>
  128. </view>
  129. <view class="recommendation-section">
  130. <view class="section-title">
  131. <text class="left-txt">图书推荐</text>
  132. <view class="more-link" @click="getMoreBoook">
  133. <text style="margin-right: 5px;">查看更多</text>
  134. <uni-icons custom-prefix="iconfont" type="icon-gengduo" size="12"></uni-icons>
  135. </view>
  136. </view>
  137. <view class="recommendation-list">
  138. <uni-load-more status="loading" v-if="isLoading"></uni-load-more>
  139. <view v-else class="book-item" v-for="(item,index) in recommendedBooks.slice(0,3)" @click="goToBookDetail(item)" :key="index" >
  140. <image
  141. class="book-cover"
  142. :src="item.imgPath ? baseUrl + '/api/fileRelevant/getImg?imgType=2&imgId=' + item.imgPath : '' "
  143. ></image>
  144. <view class="book-title">{{item.name}}</view>
  145. </view>
  146. </view>
  147. </view>
  148. </view>
  149. </template>
  150. <script>
  151. import { FetchOpenId, FetchFindAllReaderBindByOpenId} from '@/api/user';
  152. import { FetchInitScreenBookRecommend } from '@/api/book';
  153. import config from '@/utils/config';
  154. const READLIST = 'reader-card-list';
  155. export default {
  156. data() {
  157. return {
  158. isLoading: true,
  159. recommendedBooks: [],
  160. token: "",
  161. userInfo: {},
  162. isBindLibraryCard: false,
  163. readerCardList: [], // 多个借阅证
  164. baseUrl: config.baseUrl,
  165. };
  166. },
  167. onLoad() {
  168. this.getRecommendBooks();
  169. },
  170. onShow() {
  171. this.initUserAndCheckBind();
  172. },
  173. methods:{
  174. // 初始化:登录 → 获取openid → 查是否绑定
  175. async initUserAndCheckBind() {
  176. try {
  177. // 1. 先看缓存有没有 openId
  178. let openId = uni.getStorageSync('wx_login_code');
  179. // 2. 没有 → 走微信登录流程
  180. if (!openId) {
  181. const loginRes = await new Promise((resolve, reject) => {
  182. uni.login({
  183. success: resolve,
  184. fail: reject
  185. });
  186. });
  187. if (!loginRes.code) {
  188. uni.showToast({ title: '授权失败', icon: 'none' });
  189. return;
  190. }
  191. // 3. 获取 openId
  192. const openRes = await FetchOpenId({
  193. libcode: '1201',
  194. code: loginRes.code
  195. });
  196. if (openRes.code !== 200 || !openRes.data) {
  197. return;
  198. }
  199. openId = openRes.data;
  200. uni.setStorageSync('wx_login_code', openId);
  201. }
  202. // 4. 有了 openId → 查绑定状态
  203. const res = await FetchFindAllReaderBindByOpenId({
  204. libcode: '1201',
  205. openId: openId
  206. });
  207. if (res.code === 200 && res.data.length > 0) {
  208. this.isBindLibraryCard = true;
  209. // 👉 默认证排第一位
  210. const defaultCard = res.data.find(item => item.bindDefault === true);
  211. const otherCards = res.data.filter(item => !item.bindDefault);
  212. // 合并:默认在前,其他在后
  213. this.readerCardList = defaultCard ? [defaultCard, ...otherCards] : res.data;
  214. uni.setStorageSync(READLIST, this.readerCardList);
  215. } else {
  216. this.isBindLibraryCard = false;
  217. this.readerCardList = [];
  218. uni.setStorageSync(READLIST, []);
  219. }
  220. } catch (err) {
  221. console.error('初始化失败:', err);
  222. const list = uni.getStorageSync(READLIST) || [];
  223. // 同样默认排第一
  224. const defaultCard = list.find(item => item.bindDefault === true);
  225. const otherCards = list.filter(item => !item.bindDefault);
  226. this.readerCardList = defaultCard ? [defaultCard, ...otherCards] : list;
  227. this.isBindLibraryCard = list.length > 0;
  228. }
  229. },
  230. async getRecommendBooks() {
  231. try {
  232. const res = await FetchInitScreenBookRecommend({ libcode: '1201' });
  233. this.recommendedBooks = res.data || [];
  234. console.log('图书推荐', this.recommendedBooks);
  235. this.isLoading = false
  236. } catch (err) {
  237. console.error('获取图书推荐失败:', err);
  238. this.isLoading = false
  239. }
  240. },
  241. goToBookDetail(item) {
  242. uni.navigateTo({
  243. url: "/subpkg/pages/book-detail/book-detail?isbn=" + item.isbn
  244. })
  245. },
  246. // 查看更多 → 进入图书列表页
  247. getMoreBoook(){
  248. uni.navigateTo({
  249. url: "/subpkg/pages/book-list/book-list"
  250. })
  251. },
  252. // 去图书检索页
  253. onToSearch() {
  254. uni.switchTab({
  255. url: "/pages/search/search"
  256. });
  257. },
  258. // 点击未绑定借阅证区域 触发跳转
  259. toCheckLogin() {
  260. uni.navigateTo({
  261. url: "/pages/login/login"
  262. });
  263. },
  264. toRanking(){
  265. uni.navigateTo({
  266. url: "/subpkg/pages/ranking/ranking"
  267. })
  268. },
  269. toActivityList(){
  270. uni.navigateTo({
  271. url: "/subpkg/pages/activity-list/activity-list"
  272. })
  273. },
  274. toBorrowPage(index) {
  275. uni.setStorageSync('switch_tab_index', index);
  276. uni.navigateTo({
  277. url: '/subpkg/pages/myLending/myLending'
  278. });
  279. },
  280. toBorrowCar() {
  281. uni.switchTab({
  282. url: '/pages/lendCar/lendCar'
  283. });
  284. },
  285. toFeedback() {
  286. uni.navigateTo({
  287. url: '/subpkg/pages/feedback-list/feedback-list'
  288. });
  289. },
  290. // 去借阅证列表页
  291. toLibraryCard() {
  292. // 已绑定 → 进列表
  293. if (this.isBindLibraryCard) {
  294. uni.navigateTo({ url: '/subpkg/pages/reader-card/reader-card' });
  295. }
  296. // 未绑定 → 进绑定页
  297. else {
  298. uni.navigateTo({ url: "/pages/login/login" });
  299. }
  300. },
  301. // 去个人中心页
  302. onToUser() {
  303. uni.switchTab({
  304. url: "/pages/user/user"
  305. });
  306. },
  307. onToScan() {
  308. uni.scanCode({
  309. onlyFromCamera: true,
  310. scanType: ['barCode'],
  311. success: (res) => {
  312. uni.showToast({
  313. title: '扫码结果:'+ res.result,
  314. icon: 'none'
  315. })
  316. let isbn = res.result || ''
  317. if (!isbn || isbn.length < 10) {
  318. isbn = '9787020167319'
  319. }
  320. uni.navigateTo({
  321. url: '/subpkg/pages/book-detail/book-detail?isbn=' + isbn
  322. })
  323. },
  324. fail: (err) => {
  325. console.log('扫码失败:', err)
  326. uni.showToast({
  327. title: '扫码取消或失败',
  328. icon: 'none'
  329. })
  330. }
  331. })
  332. }
  333. }
  334. }
  335. </script>
  336. <style lang="scss" scoped>
  337. .top-bar{
  338. .search-icon{
  339. position: absolute;
  340. right: 16px;
  341. top: 15px;
  342. z-index: 22;
  343. ::v-deep .uni-icons{
  344. color: #fff !important;
  345. }
  346. }
  347. }
  348. .status-cards {
  349. display: flex;
  350. background-color: #fff;
  351. margin: 10px;
  352. border-radius: 8px;
  353. padding: 20px 10px;
  354. box-shadow: 0 1px 5px rgba(0, 0, 0, 0.05);
  355. .status-card {
  356. flex: 1;
  357. display: flex;
  358. flex-direction: column;
  359. align-items: center;
  360. }
  361. .status-icon {
  362. display: flex;
  363. justify-content: center;
  364. align-items: center;
  365. width: 40px;
  366. height: 40px;
  367. margin-bottom: 6px;
  368. border-radius: 50%;
  369. }
  370. .icon-color1{
  371. background-color: #e4f2ff;
  372. }
  373. .icon-color2{
  374. background-color: #ffeff0;
  375. }
  376. .icon-color3{
  377. background-color: #e4fff4;
  378. }
  379. .icon-color4{
  380. background-color: #fef8e2;
  381. }
  382. .status-label {
  383. font-size: 12px;
  384. color: #333;
  385. }
  386. }
  387. swiper.banner-swiper{
  388. width: 100%;
  389. height: 130px;
  390. }
  391. swiper.banner-swiper image{
  392. width: 100%;
  393. height: 130px;
  394. }
  395. swiper.menu-swiper{
  396. width:100%;
  397. margin-top: 10px;
  398. background-color: #fff;
  399. }
  400. .menu-grid {
  401. display: grid;
  402. grid-template-columns: repeat(4, 1fr);
  403. .menu-item {
  404. flex: 1;
  405. display: flex;
  406. flex-direction: column;
  407. align-items: center;
  408. padding: 10px 0;
  409. .menu-icon{
  410. display: flex;
  411. flex-direction: column;
  412. justify-content: center;
  413. height: 30px;
  414. ::v-deep .uni-icons{
  415. color: #01a4fe !important;
  416. }
  417. }
  418. .menu-label {
  419. font-size: 12px;
  420. color: #333;
  421. text-align: center;
  422. }
  423. }
  424. }
  425. .library-card-section {
  426. display: flex;
  427. flex-direction: column;
  428. justify-content: space-between;
  429. align-items: center;
  430. width: 100%;
  431. padding: 20px 0;
  432. .section-title {
  433. font-size: 22px;
  434. font-weight: bold;
  435. background: linear-gradient(140deg, #01a4ff, #2ec8fe);
  436. -webkit-background-clip: text;
  437. color: transparent;
  438. letter-spacing: 0.1em;
  439. margin-bottom: 5px;
  440. }
  441. .card-icon {
  442. width: 80px;
  443. height: 80px;
  444. }
  445. .card-tip {
  446. font-size: 12px;
  447. color: #999;
  448. margin: 5px 0;
  449. }
  450. .bind-btn {
  451. display: flex;
  452. flex-direction: row;
  453. align-items: center;
  454. justify-content: center;
  455. border: 1px solid #06a8ff ;
  456. width: 128px !important;
  457. height: 28px;
  458. border-radius: 28px;
  459. background: linear-gradient(140deg, #01a4ff, #2ec8fe);
  460. font-size: 14px;
  461. color: #fff;
  462. line-height: 28px;
  463. }
  464. }
  465. .recommendation-section {
  466. background-color: #fff;
  467. margin: 10px;
  468. border-radius: 8px;
  469. padding: 0 0 10px 0;
  470. box-shadow: 0 1px 5px rgba(0, 0, 0, 0.05);
  471. .section-title{
  472. display: flex;
  473. flex-direction: row;
  474. justify-content: space-between;
  475. align-items: center;
  476. height: 40px;
  477. padding: 0 10px;
  478. .left-txt{
  479. color: #343434;
  480. font-size: 15px;
  481. font-weight: 700;
  482. }
  483. .more-link{
  484. display: flex;
  485. flex-direction: row;
  486. justify-content: flex-start;
  487. align-items: center;
  488. color: #999;
  489. font-size: 11px;
  490. }
  491. }
  492. }
  493. .library-card-has {
  494. width: 100%;
  495. padding: 20px 10px;
  496. box-sizing: border-box;
  497. .section-title {
  498. font-size: 22px;
  499. font-weight: bold;
  500. background: linear-gradient(140deg, #01a4ff, #2ec8fe);
  501. -webkit-background-clip: text;
  502. color: transparent;
  503. letter-spacing: 0.1em;
  504. margin-bottom: 10px;
  505. padding-left: 5px;
  506. }
  507. .card-list {
  508. width: 100%;
  509. }
  510. // .card-item {
  511. // position: relative;
  512. // background: #fff;
  513. // border-radius: 10px;
  514. // padding: 15px;
  515. // margin-bottom: 10px;
  516. // box-shadow: 0 1px 6px rgba(0,0,0,0.06);
  517. // .item-row {
  518. // display: flex;
  519. // margin-bottom: 8px;
  520. // font-size: 13px;
  521. // .label {
  522. // color: #666;
  523. // width: 85px;
  524. // }
  525. // .value {
  526. // flex: 1;
  527. // color: #333;
  528. // }
  529. // }
  530. // .default-tag {
  531. // position: absolute;
  532. // right: 12px;
  533. // top: 12px;
  534. // font-size: 11px;
  535. // color: #01a4fe;
  536. // border: 1px solid #01a4fe;
  537. // border-radius: 4px;
  538. // padding: 2px 6px;
  539. // }
  540. // }
  541. }
  542. .card-swiper {
  543. height: 106px; /* 固定高度,保证滑动流畅 */
  544. .card-item{
  545. display: flex;
  546. justify-content: space-between;
  547. align-items: center;
  548. padding: 10px;
  549. border: 2px solid #C6C6E2;
  550. border-radius: 8px;
  551. background: rgba(241,241,249,0.4);
  552. cursor: pointer;
  553. &.active{
  554. border-color: #01a4fe;
  555. background: rgba(1, 164, 254, 0.1);
  556. }
  557. .card-left-img{
  558. width: 80px;
  559. margin-right: 12px;
  560. display: block;
  561. }
  562. .card-right-info{
  563. flex: 1;
  564. display: flex;
  565. flex-direction: column;
  566. .info-title{
  567. font-size: 16px;
  568. color: #333;
  569. font-weight: bold;
  570. padding-bottom: 12px;
  571. }
  572. .info-num{
  573. font-size: 14px;
  574. color: #999;
  575. }
  576. }
  577. .default-tag {
  578. position: absolute;
  579. right: 12px;
  580. top: 12px;
  581. font-size: 11px;
  582. color: #01a4fe;
  583. border: 1px solid #01a4fe;
  584. border-radius: 4px;
  585. padding: 2px 6px;
  586. }
  587. }
  588. }
  589. </style>