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.
647 lines
17 KiB
647 lines
17 KiB
<template>
|
|
<view style="padding-bottom: 20px;">
|
|
<view class="top-bar">
|
|
<image class="top-bar-bg" src="@/static/images/mingqi-beij@2x.png" mode="aspectFill"></image>
|
|
<view class="library-info">
|
|
<image class="avatar" src="@/static/images/avatar.png" mode="aspectFill"></image>
|
|
<view class="library-name">葛店经济技术开发区图书馆</view>
|
|
</view>
|
|
<uni-icons class="search-icon" type="search" size="30" @click="onToSearch"></uni-icons>
|
|
</view>
|
|
|
|
<view class="status-cards">
|
|
<view class="status-card" @click="toBorrowPage(1)">
|
|
<view class="status-icon icon-color1" >
|
|
<uni-icons custom-prefix="iconfont" type="icon-daiban02" size="22"></uni-icons>
|
|
</view>
|
|
<view class="status-label">在借中</view>
|
|
</view>
|
|
<!-- <view class="status-card" @click="toBorrowPage(2)">
|
|
<view class="status-icon icon-color2" >
|
|
<uni-icons custom-prefix="iconfont" type="icon-zuofei05" size="22"></uni-icons>
|
|
</view>
|
|
<view class="status-label">将过期</view>
|
|
</view>
|
|
<view class="status-card" @click="toBorrowPage(3)">
|
|
<view class="status-icon icon-color3" >
|
|
<uni-icons custom-prefix="iconfont" type="icon-yuqi04" size="22"></uni-icons>
|
|
</view>
|
|
<view class="status-label">已过期</view>
|
|
</view> -->
|
|
<view class="status-card" @click="toBorrowPage(0)">
|
|
<view class="status-icon icon-color4" >
|
|
<uni-icons custom-prefix="iconfont" type="icon-a-zhidu4" size="22"></uni-icons>
|
|
</view>
|
|
<view class="status-label">历史借阅</view>
|
|
</view>
|
|
</view>
|
|
|
|
<swiper class="banner-swiper" interval="3000" circular :vertical="false" :indicator-dots="true" :autoplay="true">
|
|
<swiper-item>
|
|
<image data-post-id="3" src="https://qiniu.aiyxlib.com/1605060269830"></image>
|
|
</swiper-item>
|
|
<swiper-item>
|
|
<image data-post-id="4" src="https://qiniu.aiyxlib.com/1605060269830"></image>
|
|
</swiper-item>
|
|
</swiper>
|
|
|
|
<swiper class="menu-swiper" interval="6000" :vertical="false" :indicator-dots="true" :autoplay="false">
|
|
<swiper-item>
|
|
<view class="menu-grid">
|
|
<view class="menu-item" @click="onToSearch">
|
|
<view class="menu-icon">
|
|
<uni-icons custom-prefix="iconfont" type="icon-ziyuan" size="22"></uni-icons>
|
|
</view>
|
|
<view class="menu-label">书目检索</view>
|
|
</view>
|
|
<view class="menu-item" @click="onToLendCar">
|
|
<view class="menu-icon">
|
|
<uni-icons custom-prefix="iconfont" type="icon-z_renew_normal" size="24"></uni-icons>
|
|
</view>
|
|
<view class="menu-label">图书续借</view>
|
|
</view>
|
|
<!-- <view class="menu-item" >
|
|
<view class="menu-icon">
|
|
<uni-icons custom-prefix="iconfont" type="icon-guanwaizhuanjie1" size="26"></uni-icons>
|
|
</view>
|
|
<view class="menu-label">图书转借</view>
|
|
</view> -->
|
|
<view class="menu-item" @click="toLibraryCard">
|
|
<view class="menu-icon">
|
|
<uni-icons custom-prefix="iconfont" type="icon-duzhezheng" size="26"></uni-icons>
|
|
</view>
|
|
<view class="menu-label">电子证</view>
|
|
</view>
|
|
<view class="menu-item" @click="toRanking">
|
|
<view class="menu-icon">
|
|
<uni-icons custom-prefix="iconfont" type="icon-paihangbang" size="22"></uni-icons>
|
|
</view>
|
|
<view class="menu-label">借阅排行</view>
|
|
</view>
|
|
<view class="menu-item" @click="toActivityList">
|
|
<view class="menu-icon">
|
|
<uni-icons custom-prefix="iconfont" type="icon-remenhuodong" size="26"></uni-icons>
|
|
</view>
|
|
<view class="menu-label">活动报名</view>
|
|
</view>
|
|
<view class="menu-item" @click="toFeedback">
|
|
<view class="menu-icon">
|
|
<uni-icons custom-prefix="iconfont" type="icon-duzheliuyan" size="26"></uni-icons>
|
|
</view>
|
|
<view class="menu-label">读者留言</view>
|
|
</view>
|
|
<view class="menu-item" @click="onToUser">
|
|
<view class="menu-icon">
|
|
<uni-icons custom-prefix="iconfont" type="icon-yonghuxinxi-gerenxinxi" size="20"></uni-icons>
|
|
</view>
|
|
<view class="menu-label">个人中心</view>
|
|
</view>
|
|
</view>
|
|
</swiper-item>
|
|
</swiper>
|
|
|
|
<!-- 已有绑定:滑动切换多个借阅证 -->
|
|
<view v-if="isBindLibraryCard" class="library-card-has">
|
|
<view class="section-title">我的借阅证</view>
|
|
|
|
<!-- 左右滑动切换证件 -->
|
|
<!-- :indicator-dots="readerCardList.length > 1"
|
|
indicator-color="#d1d1d1"
|
|
indicator-active-color="#01a4fe" -->
|
|
<swiper
|
|
class="card-swiper"
|
|
:circular="false"
|
|
>
|
|
<swiper-item v-for="item in readerCardList" :key="item.id">
|
|
<view class="card-item">
|
|
<image class="card-left-img" src="@/static/images/card-img2.png" mode="widthFix" />
|
|
<view class="card-right-info">
|
|
<text class="info-title">读者证号</text>
|
|
<text class="info-num">{{ item.bindValue }}</text>
|
|
</view>
|
|
<view class="default-tag" v-if="item.bindDefault">默认证</view>
|
|
</view>
|
|
</swiper-item>
|
|
</swiper>
|
|
</view>
|
|
|
|
<!-- 未绑定借阅证 -->
|
|
<view class="library-card-section" @click="toCheckLogin" v-else>
|
|
<view class="section-title">借阅证</view>
|
|
<image class="card-icon" src="@/static/images/card-img2.png"></image>
|
|
<view class="card-tip">您还没有绑定读者证哦~</view>
|
|
<button class="bind-btn">立即绑定</button>
|
|
</view>
|
|
|
|
|
|
<view class="recommendation-section">
|
|
<view class="section-title">
|
|
<text class="left-txt">图书推荐</text>
|
|
<view class="more-link" @click="getMoreBoook">
|
|
<text style="margin-right: 5px;">查看更多</text>
|
|
<uni-icons custom-prefix="iconfont" type="icon-gengduo" size="12"></uni-icons>
|
|
</view>
|
|
</view>
|
|
<view class="recommendation-list">
|
|
<uni-load-more status="loading" v-if="isLoading"></uni-load-more>
|
|
|
|
<view v-else class="book-item" v-for="(item,index) in recommendedBooks.slice(0,3)" @click="goToBookDetail(item)" :key="index" >
|
|
<image
|
|
class="book-cover"
|
|
:src="item.imgPath ? baseUrl + '/api/fileRelevant/getImg?imgType=2&imgId=' + item.imgPath : '/static/images/default-book.png'"
|
|
@error="onImgError"
|
|
></image>
|
|
<view class="book-title">{{item.name}}</view>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
import { FetchOpenId, FetchFindAllReaderBindByOpenId} from '@/api/user';
|
|
import { FetchInitScreenBookRecommend } from '@/api/book';
|
|
import config from '@/utils/config';
|
|
|
|
const READLIST = 'reader-card-list';
|
|
|
|
export default {
|
|
data() {
|
|
return {
|
|
isLoading: true,
|
|
recommendedBooks: [],
|
|
token: "",
|
|
userInfo: {},
|
|
isBindLibraryCard: false,
|
|
readerCardList: [], // 多个借阅证
|
|
baseUrl: config.baseUrl,
|
|
};
|
|
},
|
|
onLoad() {
|
|
this.getRecommendBooks();
|
|
},
|
|
onShow() {
|
|
this.initUserAndCheckBind();
|
|
},
|
|
methods:{
|
|
onImgError(e) {
|
|
e.target.src = "/static/images/default-book.png";
|
|
},
|
|
// 初始化:登录 → 获取openid → 查是否绑定
|
|
async initUserAndCheckBind() {
|
|
try {
|
|
// 1. 先看缓存有没有 openId
|
|
let openId = uni.getStorageSync('wx_login_code');
|
|
|
|
// 2. 没有 → 走微信登录流程
|
|
if (!openId) {
|
|
const loginRes = await new Promise((resolve, reject) => {
|
|
uni.login({
|
|
success: resolve,
|
|
fail: reject
|
|
});
|
|
});
|
|
|
|
if (!loginRes.code) {
|
|
uni.showToast({ title: '授权失败', icon: 'none' });
|
|
return;
|
|
}
|
|
|
|
// 3. 获取 openId
|
|
const openRes = await FetchOpenId({
|
|
libcode: '1201',
|
|
code: loginRes.code
|
|
});
|
|
|
|
if (openRes.code !== 200 || !openRes.data) {
|
|
return;
|
|
}
|
|
|
|
openId = openRes.data;
|
|
uni.setStorageSync('wx_login_code', openId);
|
|
}
|
|
|
|
// 4. 有了 openId → 查绑定状态
|
|
const res = await FetchFindAllReaderBindByOpenId({
|
|
libcode: '1201',
|
|
openId: openId
|
|
});
|
|
|
|
if (res.code === 200 && res.data.length > 0) {
|
|
this.isBindLibraryCard = true;
|
|
// 👉 默认证排第一位
|
|
const defaultCard = res.data.find(item => item.bindDefault === true);
|
|
const otherCards = res.data.filter(item => !item.bindDefault);
|
|
// 合并:默认在前,其他在后
|
|
this.readerCardList = defaultCard ? [defaultCard, ...otherCards] : res.data;
|
|
|
|
uni.setStorageSync(READLIST, this.readerCardList);
|
|
} else {
|
|
this.isBindLibraryCard = false;
|
|
this.readerCardList = [];
|
|
uni.setStorageSync(READLIST, []);
|
|
}
|
|
|
|
} catch (err) {
|
|
console.error('初始化失败:', err);
|
|
const list = uni.getStorageSync(READLIST) || [];
|
|
// 同样默认排第一
|
|
const defaultCard = list.find(item => item.bindDefault === true);
|
|
const otherCards = list.filter(item => !item.bindDefault);
|
|
this.readerCardList = defaultCard ? [defaultCard, ...otherCards] : list;
|
|
|
|
this.isBindLibraryCard = list.length > 0;
|
|
}
|
|
},
|
|
async getRecommendBooks() {
|
|
try {
|
|
const res = await FetchInitScreenBookRecommend({ libcode: '1201' });
|
|
this.recommendedBooks = res.data || [];
|
|
console.log('图书推荐', this.recommendedBooks);
|
|
this.isLoading = false
|
|
} catch (err) {
|
|
console.error('获取图书推荐失败:', err);
|
|
this.isLoading = false
|
|
}
|
|
},
|
|
goToBookDetail(item) {
|
|
// 把整个图书对象 转成字符串 带过去
|
|
uni.navigateTo({
|
|
url: "/subpkg/pages/book-detail/book-detail?bookData=" + encodeURIComponent(JSON.stringify(item))
|
|
})
|
|
},
|
|
|
|
// 查看更多 → 进入图书列表页
|
|
getMoreBoook(){
|
|
uni.navigateTo({
|
|
url: "/subpkg/pages/book-list/book-list"
|
|
})
|
|
},
|
|
// 去图书检索页
|
|
onToSearch() {
|
|
uni.switchTab({
|
|
url: "/pages/search/search"
|
|
});
|
|
},
|
|
// 去图书借阅车页
|
|
onToLendCar() {
|
|
uni.switchTab({
|
|
url: "/pages/lendCar/lendCar"
|
|
});
|
|
},
|
|
// 点击未绑定借阅证区域 触发跳转
|
|
toCheckLogin() {
|
|
uni.navigateTo({
|
|
url: "/pages/login/login"
|
|
});
|
|
},
|
|
toRanking(){
|
|
uni.navigateTo({
|
|
url: "/subpkg/pages/ranking/ranking"
|
|
})
|
|
},
|
|
toActivityList(){
|
|
uni.navigateTo({
|
|
url: "/subpkg/pages/activity-list/activity-list"
|
|
})
|
|
},
|
|
toBorrowPage(index) {
|
|
uni.setStorageSync('switch_tab_index', index);
|
|
uni.navigateTo({
|
|
url: '/subpkg/pages/myLending/myLending'
|
|
});
|
|
},
|
|
toBorrowCar() {
|
|
uni.switchTab({
|
|
url: '/pages/lendCar/lendCar'
|
|
});
|
|
},
|
|
toFeedback() {
|
|
uni.navigateTo({
|
|
url: '/subpkg/pages/feedback-list/feedback-list'
|
|
});
|
|
},
|
|
// 去借阅证列表页
|
|
toLibraryCard() {
|
|
// 已绑定 → 进列表
|
|
if (this.isBindLibraryCard) {
|
|
uni.navigateTo({ url: '/subpkg/pages/reader-card/reader-card' });
|
|
}
|
|
// 未绑定 → 进绑定页
|
|
else {
|
|
uni.navigateTo({ url: "/pages/login/login" });
|
|
}
|
|
},
|
|
// 去个人中心页
|
|
onToUser() {
|
|
uni.switchTab({
|
|
url: "/pages/user/user"
|
|
});
|
|
},
|
|
onToScan() {
|
|
uni.scanCode({
|
|
onlyFromCamera: true,
|
|
scanType: ['barCode'],
|
|
success: (res) => {
|
|
uni.showToast({
|
|
title: '扫码结果:'+ res.result,
|
|
icon: 'none'
|
|
})
|
|
let isbn = res.result || ''
|
|
|
|
if (!isbn || isbn.length < 10) {
|
|
isbn = '9787020167319'
|
|
}
|
|
|
|
uni.navigateTo({
|
|
url: '/subpkg/pages/book-detail/book-detail?isbn=' + isbn
|
|
})
|
|
},
|
|
fail: (err) => {
|
|
console.log('扫码失败:', err)
|
|
uni.showToast({
|
|
title: '扫码取消或失败',
|
|
icon: 'none'
|
|
})
|
|
}
|
|
})
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
.top-bar{
|
|
.search-icon{
|
|
position: absolute;
|
|
right: 16px;
|
|
top: 15px;
|
|
z-index: 22;
|
|
::v-deep .uni-icons{
|
|
color: #fff !important;
|
|
}
|
|
}
|
|
}
|
|
|
|
.status-cards {
|
|
display: flex;
|
|
background-color: #fff;
|
|
margin: 10px;
|
|
border-radius: 8px;
|
|
padding: 20px 10px;
|
|
box-shadow: 0 1px 5px rgba(0, 0, 0, 0.05);
|
|
.status-card {
|
|
flex: 1;
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
}
|
|
.status-icon {
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
width: 40px;
|
|
height: 40px;
|
|
margin-bottom: 6px;
|
|
border-radius: 50%;
|
|
}
|
|
.icon-color1{
|
|
background-color: #e4f2ff;
|
|
}
|
|
.icon-color2{
|
|
background-color: #ffeff0;
|
|
}
|
|
.icon-color3{
|
|
background-color: #e4fff4;
|
|
}
|
|
.icon-color4{
|
|
background-color: #fef8e2;
|
|
}
|
|
.status-label {
|
|
font-size: 12px;
|
|
color: #333;
|
|
}
|
|
}
|
|
|
|
swiper.banner-swiper{
|
|
width: 100%;
|
|
height: 130px;
|
|
}
|
|
swiper.banner-swiper image{
|
|
width: 100%;
|
|
height: 130px;
|
|
}
|
|
swiper.menu-swiper{
|
|
width:100%;
|
|
margin-top: 10px;
|
|
background-color: #fff;
|
|
}
|
|
|
|
.menu-grid {
|
|
display: grid;
|
|
grid-template-columns: repeat(4, 1fr);
|
|
.menu-item {
|
|
flex: 1;
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
padding: 10px 0;
|
|
.menu-icon{
|
|
display: flex;
|
|
flex-direction: column;
|
|
justify-content: center;
|
|
height: 30px;
|
|
::v-deep .uni-icons{
|
|
color: #01a4fe !important;
|
|
}
|
|
}
|
|
.menu-label {
|
|
font-size: 12px;
|
|
color: #333;
|
|
text-align: center;
|
|
}
|
|
}
|
|
}
|
|
|
|
.library-card-section {
|
|
display: flex;
|
|
flex-direction: column;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
width: 100%;
|
|
padding: 20px 0;
|
|
.section-title {
|
|
font-size: 22px;
|
|
font-weight: bold;
|
|
background: linear-gradient(140deg, #01a4ff, #2ec8fe);
|
|
-webkit-background-clip: text;
|
|
color: transparent;
|
|
letter-spacing: 0.1em;
|
|
margin-bottom: 5px;
|
|
}
|
|
.card-icon {
|
|
width: 80px;
|
|
height: 80px;
|
|
}
|
|
.card-tip {
|
|
font-size: 12px;
|
|
color: #999;
|
|
margin: 5px 0;
|
|
}
|
|
.bind-btn {
|
|
display: flex;
|
|
flex-direction: row;
|
|
align-items: center;
|
|
justify-content: center;
|
|
border: 1px solid #06a8ff ;
|
|
width: 128px !important;
|
|
height: 28px;
|
|
border-radius: 28px;
|
|
background: linear-gradient(140deg, #01a4ff, #2ec8fe);
|
|
font-size: 14px;
|
|
color: #fff;
|
|
line-height: 28px;
|
|
}
|
|
}
|
|
|
|
.recommendation-section {
|
|
background-color: #fff;
|
|
margin: 10px;
|
|
border-radius: 8px;
|
|
padding: 0 0 10px 0;
|
|
box-shadow: 0 1px 5px rgba(0, 0, 0, 0.05);
|
|
.section-title{
|
|
display: flex;
|
|
flex-direction: row;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
height: 40px;
|
|
padding: 0 10px;
|
|
.left-txt{
|
|
color: #343434;
|
|
font-size: 15px;
|
|
font-weight: 700;
|
|
}
|
|
.more-link{
|
|
display: flex;
|
|
flex-direction: row;
|
|
justify-content: flex-start;
|
|
align-items: center;
|
|
color: #999;
|
|
font-size: 11px;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
.library-card-has {
|
|
width: 100%;
|
|
padding: 20px 10px;
|
|
box-sizing: border-box;
|
|
|
|
.section-title {
|
|
font-size: 22px;
|
|
font-weight: bold;
|
|
background: linear-gradient(140deg, #01a4ff, #2ec8fe);
|
|
-webkit-background-clip: text;
|
|
color: transparent;
|
|
letter-spacing: 0.1em;
|
|
margin-bottom: 10px;
|
|
padding-left: 5px;
|
|
}
|
|
|
|
.card-list {
|
|
width: 100%;
|
|
}
|
|
|
|
// .card-item {
|
|
// position: relative;
|
|
// background: #fff;
|
|
// border-radius: 10px;
|
|
// padding: 15px;
|
|
// margin-bottom: 10px;
|
|
// box-shadow: 0 1px 6px rgba(0,0,0,0.06);
|
|
|
|
// .item-row {
|
|
// display: flex;
|
|
// margin-bottom: 8px;
|
|
// font-size: 13px;
|
|
// .label {
|
|
// color: #666;
|
|
// width: 85px;
|
|
// }
|
|
// .value {
|
|
// flex: 1;
|
|
// color: #333;
|
|
// }
|
|
// }
|
|
|
|
// .default-tag {
|
|
// position: absolute;
|
|
// right: 12px;
|
|
// top: 12px;
|
|
// font-size: 11px;
|
|
// color: #01a4fe;
|
|
// border: 1px solid #01a4fe;
|
|
// border-radius: 4px;
|
|
// padding: 2px 6px;
|
|
// }
|
|
// }
|
|
}
|
|
|
|
.card-swiper {
|
|
height: 106px; /* 固定高度,保证滑动流畅 */
|
|
.card-item{
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
padding: 10px;
|
|
border: 2px solid #C6C6E2;
|
|
border-radius: 8px;
|
|
background: rgba(241,241,249,0.4);
|
|
cursor: pointer;
|
|
|
|
&.active{
|
|
border-color: #01a4fe;
|
|
background: rgba(1, 164, 254, 0.1);
|
|
}
|
|
|
|
.card-left-img{
|
|
width: 80px;
|
|
margin-right: 12px;
|
|
display: block;
|
|
}
|
|
|
|
.card-right-info{
|
|
flex: 1;
|
|
display: flex;
|
|
flex-direction: column;
|
|
|
|
.info-title{
|
|
font-size: 16px;
|
|
color: #333;
|
|
font-weight: bold;
|
|
padding-bottom: 12px;
|
|
}
|
|
|
|
.info-num{
|
|
font-size: 14px;
|
|
color: #999;
|
|
}
|
|
}
|
|
|
|
.default-tag {
|
|
position: absolute;
|
|
right: 12px;
|
|
top: 12px;
|
|
font-size: 11px;
|
|
color: #01a4fe;
|
|
border: 1px solid #01a4fe;
|
|
border-radius: 4px;
|
|
padding: 2px 6px;
|
|
}
|
|
}
|
|
}
|
|
</style>
|