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

642 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
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
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 : '' "
  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. // 把整个图书对象 转成字符串 带过去
  243. uni.navigateTo({
  244. url: "/subpkg/pages/book-detail/book-detail?bookData=" + encodeURIComponent(JSON.stringify(item))
  245. })
  246. },
  247. // 查看更多 → 进入图书列表页
  248. getMoreBoook(){
  249. uni.navigateTo({
  250. url: "/subpkg/pages/book-list/book-list"
  251. })
  252. },
  253. // 去图书检索页
  254. onToSearch() {
  255. uni.switchTab({
  256. url: "/pages/search/search"
  257. });
  258. },
  259. // 去图书借阅车页
  260. onToLendCar() {
  261. uni.switchTab({
  262. url: "/pages/lendCar/lendCar"
  263. });
  264. },
  265. // 点击未绑定借阅证区域 触发跳转
  266. toCheckLogin() {
  267. uni.navigateTo({
  268. url: "/pages/login/login"
  269. });
  270. },
  271. toRanking(){
  272. uni.navigateTo({
  273. url: "/subpkg/pages/ranking/ranking"
  274. })
  275. },
  276. toActivityList(){
  277. uni.navigateTo({
  278. url: "/subpkg/pages/activity-list/activity-list"
  279. })
  280. },
  281. toBorrowPage(index) {
  282. uni.setStorageSync('switch_tab_index', index);
  283. uni.navigateTo({
  284. url: '/subpkg/pages/myLending/myLending'
  285. });
  286. },
  287. toBorrowCar() {
  288. uni.switchTab({
  289. url: '/pages/lendCar/lendCar'
  290. });
  291. },
  292. toFeedback() {
  293. uni.navigateTo({
  294. url: '/subpkg/pages/feedback-list/feedback-list'
  295. });
  296. },
  297. // 去借阅证列表页
  298. toLibraryCard() {
  299. // 已绑定 → 进列表
  300. if (this.isBindLibraryCard) {
  301. uni.navigateTo({ url: '/subpkg/pages/reader-card/reader-card' });
  302. }
  303. // 未绑定 → 进绑定页
  304. else {
  305. uni.navigateTo({ url: "/pages/login/login" });
  306. }
  307. },
  308. // 去个人中心页
  309. onToUser() {
  310. uni.switchTab({
  311. url: "/pages/user/user"
  312. });
  313. },
  314. onToScan() {
  315. uni.scanCode({
  316. onlyFromCamera: true,
  317. scanType: ['barCode'],
  318. success: (res) => {
  319. uni.showToast({
  320. title: '扫码结果:'+ res.result,
  321. icon: 'none'
  322. })
  323. let isbn = res.result || ''
  324. if (!isbn || isbn.length < 10) {
  325. isbn = '9787020167319'
  326. }
  327. uni.navigateTo({
  328. url: '/subpkg/pages/book-detail/book-detail?isbn=' + isbn
  329. })
  330. },
  331. fail: (err) => {
  332. console.log('扫码失败:', err)
  333. uni.showToast({
  334. title: '扫码取消或失败',
  335. icon: 'none'
  336. })
  337. }
  338. })
  339. }
  340. }
  341. }
  342. </script>
  343. <style lang="scss" scoped>
  344. .top-bar{
  345. .search-icon{
  346. position: absolute;
  347. right: 16px;
  348. top: 15px;
  349. z-index: 22;
  350. ::v-deep .uni-icons{
  351. color: #fff !important;
  352. }
  353. }
  354. }
  355. .status-cards {
  356. display: flex;
  357. background-color: #fff;
  358. margin: 10px;
  359. border-radius: 8px;
  360. padding: 20px 10px;
  361. box-shadow: 0 1px 5px rgba(0, 0, 0, 0.05);
  362. .status-card {
  363. flex: 1;
  364. display: flex;
  365. flex-direction: column;
  366. align-items: center;
  367. }
  368. .status-icon {
  369. display: flex;
  370. justify-content: center;
  371. align-items: center;
  372. width: 40px;
  373. height: 40px;
  374. margin-bottom: 6px;
  375. border-radius: 50%;
  376. }
  377. .icon-color1{
  378. background-color: #e4f2ff;
  379. }
  380. .icon-color2{
  381. background-color: #ffeff0;
  382. }
  383. .icon-color3{
  384. background-color: #e4fff4;
  385. }
  386. .icon-color4{
  387. background-color: #fef8e2;
  388. }
  389. .status-label {
  390. font-size: 12px;
  391. color: #333;
  392. }
  393. }
  394. swiper.banner-swiper{
  395. width: 100%;
  396. height: 130px;
  397. }
  398. swiper.banner-swiper image{
  399. width: 100%;
  400. height: 130px;
  401. }
  402. swiper.menu-swiper{
  403. width:100%;
  404. margin-top: 10px;
  405. background-color: #fff;
  406. }
  407. .menu-grid {
  408. display: grid;
  409. grid-template-columns: repeat(4, 1fr);
  410. .menu-item {
  411. flex: 1;
  412. display: flex;
  413. flex-direction: column;
  414. align-items: center;
  415. padding: 10px 0;
  416. .menu-icon{
  417. display: flex;
  418. flex-direction: column;
  419. justify-content: center;
  420. height: 30px;
  421. ::v-deep .uni-icons{
  422. color: #01a4fe !important;
  423. }
  424. }
  425. .menu-label {
  426. font-size: 12px;
  427. color: #333;
  428. text-align: center;
  429. }
  430. }
  431. }
  432. .library-card-section {
  433. display: flex;
  434. flex-direction: column;
  435. justify-content: space-between;
  436. align-items: center;
  437. width: 100%;
  438. padding: 20px 0;
  439. .section-title {
  440. font-size: 22px;
  441. font-weight: bold;
  442. background: linear-gradient(140deg, #01a4ff, #2ec8fe);
  443. -webkit-background-clip: text;
  444. color: transparent;
  445. letter-spacing: 0.1em;
  446. margin-bottom: 5px;
  447. }
  448. .card-icon {
  449. width: 80px;
  450. height: 80px;
  451. }
  452. .card-tip {
  453. font-size: 12px;
  454. color: #999;
  455. margin: 5px 0;
  456. }
  457. .bind-btn {
  458. display: flex;
  459. flex-direction: row;
  460. align-items: center;
  461. justify-content: center;
  462. border: 1px solid #06a8ff ;
  463. width: 128px !important;
  464. height: 28px;
  465. border-radius: 28px;
  466. background: linear-gradient(140deg, #01a4ff, #2ec8fe);
  467. font-size: 14px;
  468. color: #fff;
  469. line-height: 28px;
  470. }
  471. }
  472. .recommendation-section {
  473. background-color: #fff;
  474. margin: 10px;
  475. border-radius: 8px;
  476. padding: 0 0 10px 0;
  477. box-shadow: 0 1px 5px rgba(0, 0, 0, 0.05);
  478. .section-title{
  479. display: flex;
  480. flex-direction: row;
  481. justify-content: space-between;
  482. align-items: center;
  483. height: 40px;
  484. padding: 0 10px;
  485. .left-txt{
  486. color: #343434;
  487. font-size: 15px;
  488. font-weight: 700;
  489. }
  490. .more-link{
  491. display: flex;
  492. flex-direction: row;
  493. justify-content: flex-start;
  494. align-items: center;
  495. color: #999;
  496. font-size: 11px;
  497. }
  498. }
  499. }
  500. .library-card-has {
  501. width: 100%;
  502. padding: 20px 10px;
  503. box-sizing: border-box;
  504. .section-title {
  505. font-size: 22px;
  506. font-weight: bold;
  507. background: linear-gradient(140deg, #01a4ff, #2ec8fe);
  508. -webkit-background-clip: text;
  509. color: transparent;
  510. letter-spacing: 0.1em;
  511. margin-bottom: 10px;
  512. padding-left: 5px;
  513. }
  514. .card-list {
  515. width: 100%;
  516. }
  517. // .card-item {
  518. // position: relative;
  519. // background: #fff;
  520. // border-radius: 10px;
  521. // padding: 15px;
  522. // margin-bottom: 10px;
  523. // box-shadow: 0 1px 6px rgba(0,0,0,0.06);
  524. // .item-row {
  525. // display: flex;
  526. // margin-bottom: 8px;
  527. // font-size: 13px;
  528. // .label {
  529. // color: #666;
  530. // width: 85px;
  531. // }
  532. // .value {
  533. // flex: 1;
  534. // color: #333;
  535. // }
  536. // }
  537. // .default-tag {
  538. // position: absolute;
  539. // right: 12px;
  540. // top: 12px;
  541. // font-size: 11px;
  542. // color: #01a4fe;
  543. // border: 1px solid #01a4fe;
  544. // border-radius: 4px;
  545. // padding: 2px 6px;
  546. // }
  547. // }
  548. }
  549. .card-swiper {
  550. height: 106px; /* 固定高度,保证滑动流畅 */
  551. .card-item{
  552. display: flex;
  553. justify-content: space-between;
  554. align-items: center;
  555. padding: 10px;
  556. border: 2px solid #C6C6E2;
  557. border-radius: 8px;
  558. background: rgba(241,241,249,0.4);
  559. cursor: pointer;
  560. &.active{
  561. border-color: #01a4fe;
  562. background: rgba(1, 164, 254, 0.1);
  563. }
  564. .card-left-img{
  565. width: 80px;
  566. margin-right: 12px;
  567. display: block;
  568. }
  569. .card-right-info{
  570. flex: 1;
  571. display: flex;
  572. flex-direction: column;
  573. .info-title{
  574. font-size: 16px;
  575. color: #333;
  576. font-weight: bold;
  577. padding-bottom: 12px;
  578. }
  579. .info-num{
  580. font-size: 14px;
  581. color: #999;
  582. }
  583. }
  584. .default-tag {
  585. position: absolute;
  586. right: 12px;
  587. top: 12px;
  588. font-size: 11px;
  589. color: #01a4fe;
  590. border: 1px solid #01a4fe;
  591. border-radius: 4px;
  592. padding: 2px 6px;
  593. }
  594. }
  595. }
  596. </style>