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

688 lines
19 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
2 months 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
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
2 months 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">
  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. this.readerCardList = res.data;
  210. uni.setStorageSync(READLIST, res.data);
  211. } else {
  212. this.isBindLibraryCard = false;
  213. this.readerCardList = [];
  214. uni.setStorageSync(READLIST, []);
  215. }
  216. } catch (err) {
  217. console.error('初始化失败:', err);
  218. // 兜底读缓存
  219. const list = uni.getStorageSync(READLIST) || [];
  220. this.readerCardList = list;
  221. this.isBindLibraryCard = list.length > 0;
  222. }
  223. },
  224. // 时间戳格式化
  225. formatTime(timestamp) {
  226. if (!timestamp) return ''
  227. const date = new Date(timestamp)
  228. const year = date.getFullYear()
  229. const month = (date.getMonth() + 1).toString().padStart(2, '0')
  230. const day = date.getDate().toString().padStart(2, '0')
  231. return `${year}-${month}-${day}`
  232. },
  233. async getRecommendBooks() {
  234. try {
  235. const res = await FetchInitScreenBookRecommend({ libcode: '1201' });
  236. this.recommendedBooks = res.data || [];
  237. console.log('图书推荐', this.recommendedBooks);
  238. this.isLoading = false
  239. } catch (err) {
  240. console.error('获取图书推荐失败:', err);
  241. this.isLoading = false
  242. }
  243. },
  244. goToBookDetail(item) {
  245. uni.navigateTo({
  246. url: "/subpkg/pages/book-detail/book-detail?isbn=" + item.isbn
  247. })
  248. },
  249. // 查看更多 → 进入图书列表页
  250. getMoreBoook(){
  251. uni.navigateTo({
  252. url: "/subpkg/pages/book-list/book-list"
  253. })
  254. },
  255. onToSearch() {
  256. uni.switchTab({
  257. url: "/pages/search/search"
  258. });
  259. },
  260. // 点击未绑定借阅证区域 触发跳转
  261. toCheckLogin() {
  262. uni.navigateTo({
  263. url: "/pages/login/login"
  264. });
  265. },
  266. // toCheckLogin(pageName) {
  267. // // 未登录:获取微信登录 code,再跳转到登录页
  268. // uni.login({
  269. // success: (res) => {
  270. // if (res.code) {
  271. // console.log('res',res)
  272. // console.log("微信登录凭证 code:", res.code);
  273. // const params = {
  274. // libcode: '1201',
  275. // code: res.code
  276. // }
  277. // FetchOpenId(params).then(res => {
  278. // console.log('获取微信openId',res)
  279. // if(res.code === 200 && res.data){
  280. // uni.setStorageSync("wx_login_code", res.data);
  281. // const data = {
  282. // libcode: '1201',
  283. // openId: res.data
  284. // }
  285. // FetchFindAllReaderBindByOpenId(data).then(res => {
  286. // console.log('获取读者证列表',res)
  287. // if (res.code === 200 && res.data.length > 0) {
  288. // this.isBindLibraryCard = true;
  289. // this.readerCardList = res.data;
  290. // uni.setStorageSync(READLIST, res.data);
  291. // } else {
  292. // this.isBindLibraryCard = false;
  293. // uni.navigateTo({
  294. // url: "/pages/login/login"
  295. // });
  296. // }
  297. // })
  298. // .catch(err => {
  299. // console.error('获取读者证列表失败:', err);
  300. // })
  301. // }
  302. // })
  303. // .catch(err => {
  304. // console.error('获取微信openId失败:', err);
  305. // })
  306. // } else {
  307. // uni.showToast({
  308. // title: "获取登录信息失败",
  309. // icon: "error"
  310. // });
  311. // }
  312. // },
  313. // fail: () => {
  314. // uni.showToast({
  315. // title: "授权失败",
  316. // icon: "error"
  317. // });
  318. // }
  319. // });
  320. // },
  321. toRanking(){
  322. uni.navigateTo({
  323. url: "/subpkg/pages/ranking/ranking"
  324. })
  325. },
  326. toActivityList(){
  327. uni.navigateTo({
  328. url: "/subpkg/pages/activity-list/activity-list"
  329. })
  330. },
  331. toBorrowPage(index) {
  332. uni.setStorageSync('switch_tab_index', index);
  333. uni.navigateTo({
  334. url: '/subpkg/pages/myLending/myLending'
  335. });
  336. },
  337. toBorrowCar() {
  338. uni.switchTab({
  339. url: '/pages/lendCar/lendCar'
  340. });
  341. },
  342. toFeedback() {
  343. uni.navigateTo({
  344. url: '/subpkg/pages/feedback-list/feedback-list'
  345. });
  346. },
  347. toLibraryCard() {
  348. // 已绑定 → 进列表
  349. if (this.isBindLibraryCard) {
  350. uni.navigateTo({ url: '/subpkg/pages/reader-card/reader-card' });
  351. }
  352. // 未绑定 → 进绑定页
  353. else {
  354. uni.navigateTo({ url: "/pages/login/login" });
  355. }
  356. },
  357. onToScan() {
  358. uni.scanCode({
  359. onlyFromCamera: true,
  360. scanType: ['barCode'],
  361. success: (res) => {
  362. uni.showToast({
  363. title: '扫码结果:'+ res.result,
  364. icon: 'none'
  365. })
  366. let isbn = res.result || ''
  367. if (!isbn || isbn.length < 10) {
  368. isbn = '9787020167319'
  369. }
  370. uni.navigateTo({
  371. url: '/subpkg/pages/book-detail/book-detail?isbn=' + isbn
  372. })
  373. },
  374. fail: (err) => {
  375. console.log('扫码失败:', err)
  376. uni.showToast({
  377. title: '扫码取消或失败',
  378. icon: 'none'
  379. })
  380. }
  381. })
  382. }
  383. }
  384. }
  385. </script>
  386. <style lang="scss" scoped>
  387. .top-bar{
  388. .search-icon{
  389. position: absolute;
  390. right: 16px;
  391. top: 15px;
  392. z-index: 22;
  393. ::v-deep .uni-icons{
  394. color: #fff !important;
  395. }
  396. }
  397. }
  398. .status-cards {
  399. display: flex;
  400. background-color: #fff;
  401. margin: 10px;
  402. border-radius: 8px;
  403. padding: 20px 10px;
  404. box-shadow: 0 1px 5px rgba(0, 0, 0, 0.05);
  405. .status-card {
  406. flex: 1;
  407. display: flex;
  408. flex-direction: column;
  409. align-items: center;
  410. }
  411. .status-icon {
  412. display: flex;
  413. justify-content: center;
  414. align-items: center;
  415. width: 40px;
  416. height: 40px;
  417. margin-bottom: 6px;
  418. border-radius: 50%;
  419. }
  420. .icon-color1{
  421. background-color: #e4f2ff;
  422. }
  423. .icon-color2{
  424. background-color: #ffeff0;
  425. }
  426. .icon-color3{
  427. background-color: #e4fff4;
  428. }
  429. .icon-color4{
  430. background-color: #fef8e2;
  431. }
  432. .status-label {
  433. font-size: 12px;
  434. color: #333;
  435. }
  436. }
  437. swiper.banner-swiper{
  438. width: 100%;
  439. height: 130px;
  440. }
  441. swiper.banner-swiper image{
  442. width: 100%;
  443. height: 130px;
  444. }
  445. swiper.menu-swiper{
  446. width:100%;
  447. margin-top: 10px;
  448. background-color: #fff;
  449. }
  450. .menu-grid {
  451. display: grid;
  452. grid-template-columns: repeat(4, 1fr);
  453. .menu-item {
  454. flex: 1;
  455. display: flex;
  456. flex-direction: column;
  457. align-items: center;
  458. padding: 10px 0;
  459. .menu-icon{
  460. display: flex;
  461. flex-direction: column;
  462. justify-content: center;
  463. height: 30px;
  464. ::v-deep .uni-icons{
  465. color: #01a4fe !important;
  466. }
  467. }
  468. .menu-label {
  469. font-size: 12px;
  470. color: #333;
  471. text-align: center;
  472. }
  473. }
  474. }
  475. .library-card-section {
  476. display: flex;
  477. flex-direction: column;
  478. justify-content: space-between;
  479. align-items: center;
  480. width: 100%;
  481. padding: 20px 0;
  482. .section-title {
  483. font-size: 22px;
  484. font-weight: bold;
  485. background: linear-gradient(140deg, #01a4ff, #2ec8fe);
  486. -webkit-background-clip: text;
  487. color: transparent;
  488. letter-spacing: 0.1em;
  489. margin-bottom: 5px;
  490. }
  491. .card-icon {
  492. width: 80px;
  493. height: 80px;
  494. }
  495. .card-tip {
  496. font-size: 12px;
  497. color: #999;
  498. margin: 5px 0;
  499. }
  500. .bind-btn {
  501. display: flex;
  502. flex-direction: row;
  503. align-items: center;
  504. justify-content: center;
  505. border: 1px solid #06a8ff ;
  506. width: 128px !important;
  507. height: 28px;
  508. border-radius: 28px;
  509. background: linear-gradient(140deg, #01a4ff, #2ec8fe);
  510. font-size: 14px;
  511. color: #fff;
  512. line-height: 28px;
  513. }
  514. }
  515. .recommendation-section {
  516. background-color: #fff;
  517. margin: 10px;
  518. border-radius: 8px;
  519. padding: 0 0 10px 0;
  520. box-shadow: 0 1px 5px rgba(0, 0, 0, 0.05);
  521. .section-title{
  522. display: flex;
  523. flex-direction: row;
  524. justify-content: space-between;
  525. align-items: center;
  526. height: 40px;
  527. padding: 0 10px;
  528. .left-txt{
  529. color: #343434;
  530. font-size: 15px;
  531. font-weight: 700;
  532. }
  533. .more-link{
  534. display: flex;
  535. flex-direction: row;
  536. justify-content: flex-start;
  537. align-items: center;
  538. color: #999;
  539. font-size: 11px;
  540. }
  541. }
  542. }
  543. .library-card-has {
  544. width: 100%;
  545. padding: 20px 10px;
  546. box-sizing: border-box;
  547. .section-title {
  548. font-size: 22px;
  549. font-weight: bold;
  550. background: linear-gradient(140deg, #01a4ff, #2ec8fe);
  551. -webkit-background-clip: text;
  552. color: transparent;
  553. letter-spacing: 0.1em;
  554. margin-bottom: 10px;
  555. padding-left: 5px;
  556. }
  557. .card-list {
  558. width: 100%;
  559. }
  560. // .card-item {
  561. // position: relative;
  562. // background: #fff;
  563. // border-radius: 10px;
  564. // padding: 15px;
  565. // margin-bottom: 10px;
  566. // box-shadow: 0 1px 6px rgba(0,0,0,0.06);
  567. // .item-row {
  568. // display: flex;
  569. // margin-bottom: 8px;
  570. // font-size: 13px;
  571. // .label {
  572. // color: #666;
  573. // width: 85px;
  574. // }
  575. // .value {
  576. // flex: 1;
  577. // color: #333;
  578. // }
  579. // }
  580. // .default-tag {
  581. // position: absolute;
  582. // right: 12px;
  583. // top: 12px;
  584. // font-size: 11px;
  585. // color: #01a4fe;
  586. // border: 1px solid #01a4fe;
  587. // border-radius: 4px;
  588. // padding: 2px 6px;
  589. // }
  590. // }
  591. }
  592. .card-swiper {
  593. height: 106px; /* 固定高度,保证滑动流畅 */
  594. .card-item{
  595. display: flex;
  596. justify-content: space-between;
  597. align-items: center;
  598. padding: 10px;
  599. border: 2px solid #C6C6E2;
  600. border-radius: 8px;
  601. background: rgba(241,241,249,0.4);
  602. cursor: pointer;
  603. &.active{
  604. border-color: #01a4fe;
  605. background: rgba(1, 164, 254, 0.1);
  606. }
  607. .card-left-img{
  608. width: 80px;
  609. margin-right: 12px;
  610. display: block;
  611. }
  612. .card-right-info{
  613. flex: 1;
  614. display: flex;
  615. flex-direction: column;
  616. .info-title{
  617. font-size: 16px;
  618. color: #333;
  619. font-weight: bold;
  620. padding-bottom: 12px;
  621. }
  622. .info-num{
  623. font-size: 14px;
  624. color: #999;
  625. }
  626. }
  627. .default-tag {
  628. position: absolute;
  629. right: 12px;
  630. top: 12px;
  631. font-size: 11px;
  632. color: #01a4fe;
  633. border: 1px solid #01a4fe;
  634. border-radius: 4px;
  635. padding: 2px 6px;
  636. }
  637. }
  638. }
  639. </style>