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

646 lines
17 KiB

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