10 changed files with 631 additions and 461 deletions
-
21api/article.js
-
9api/book.js
-
19api/hot.js
-
21api/video.js
-
99pages/home/home.vue
-
92pages/user/user.vue
-
151subpkg/pages/reader-card/reader-card copy.vue
-
191subpkg/pages/reader-card/reader-card.vue
-
148subpkg/pages/unbind-card/unbind-card.vue
-
245subpkg/pages/user-info/user-info.vue
@ -1,21 +0,0 @@ |
|||||
import request from '../utils/request'; |
|
||||
|
|
||||
/** |
|
||||
* 获取文章详情 |
|
||||
*/ |
|
||||
export function getArticleDetail(data) { |
|
||||
return request({ |
|
||||
url: '/article/details', |
|
||||
data |
|
||||
}); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 获取文章评论列表 |
|
||||
*/ |
|
||||
export function getArticleCommentList(data) { |
|
||||
return request({ |
|
||||
url: '/article/comment/list', |
|
||||
data |
|
||||
}); |
|
||||
} |
|
||||
@ -1,19 +0,0 @@ |
|||||
import request from '../utils/request'; |
|
||||
|
|
||||
export function getHotTabs() { |
|
||||
return request({ |
|
||||
url: '/hot/tabs' |
|
||||
}); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 热搜文章列表 |
|
||||
*/ |
|
||||
export function getHotListFromTabType(type) { |
|
||||
return request({ |
|
||||
url: '/hot/list', |
|
||||
data: { |
|
||||
type |
|
||||
} |
|
||||
}); |
|
||||
} |
|
||||
@ -1,21 +0,0 @@ |
|||||
import request from '../utils/request'; |
|
||||
|
|
||||
/** |
|
||||
* 热播视频列表 |
|
||||
*/ |
|
||||
export function getHotVideoList(data) { |
|
||||
return request({ |
|
||||
url: '/video/list', |
|
||||
data |
|
||||
}); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 获取视频弹幕列表 |
|
||||
*/ |
|
||||
export function getVideoDanmuList(data) { |
|
||||
return request({ |
|
||||
url: '/video/danmu', |
|
||||
data |
|
||||
}); |
|
||||
} |
|
||||
@ -0,0 +1,151 @@ |
|||||
|
<template> |
||||
|
<view class="reader-card"> |
||||
|
<image class="card-top-bg" src="@/static/images/card-img1.png" mode="widthFix" /> |
||||
|
|
||||
|
<view class="card-list"> |
||||
|
<view |
||||
|
class="card-list-item" |
||||
|
v-for="(item, index) in cardList" |
||||
|
:key="item.id" |
||||
|
@click="handleSelectItem(item.bindValue)" |
||||
|
:class="{ active: selectedValue === item.bindValue }" |
||||
|
> |
||||
|
<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> |
||||
|
<radio :value="item.bindValue" :checked="selectedValue === item.bindValue"/> |
||||
|
</view> |
||||
|
|
||||
|
<view class="add-card-btn" @click="toAddReaderCard"> |
||||
|
<uni-icons type="plus" size="20" color="#01a4fe"></uni-icons> |
||||
|
<text>新增读者证</text> |
||||
|
</view> |
||||
|
</view> |
||||
|
</view> |
||||
|
</template> |
||||
|
|
||||
|
<script> |
||||
|
import { FetchFindAllReaderBindByOpenId, FetchSetDefaultReadCard } from '@/api/user'; |
||||
|
const READLIST = 'reader-card-list'; |
||||
|
|
||||
|
export default { |
||||
|
data() { |
||||
|
return { |
||||
|
selectedValue: '', |
||||
|
cardList: [], |
||||
|
} |
||||
|
}, |
||||
|
onLoad() {}, |
||||
|
onShow() { |
||||
|
this.getBindReaderCardList(); |
||||
|
}, |
||||
|
methods: { |
||||
|
async getBindReaderCardList() { |
||||
|
try { |
||||
|
const openId = uni.getStorageSync('wx_login_code'); |
||||
|
if (!openId) { |
||||
|
uni.showToast({ title: '未获取到用户信息', icon: 'none' }); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
const data = { libcode: '1201', openId: openId }; |
||||
|
const res = await FetchFindAllReaderBindByOpenId(data); |
||||
|
|
||||
|
if (res.code === 200 && res.data.length > 0) { |
||||
|
this.cardList = res.data; |
||||
|
uni.setStorageSync(READLIST, res.data); |
||||
|
|
||||
|
// 优先 bindDefault = true |
||||
|
const defaultCard = this.cardList.find(item => item.bindDefault === true); |
||||
|
this.selectedValue = defaultCard ? defaultCard.bindValue : this.cardList[0].bindValue; |
||||
|
} else { |
||||
|
this.cardList = []; |
||||
|
uni.setStorageSync(READLIST, []); |
||||
|
this.selectedValue = ''; |
||||
|
} |
||||
|
} catch (err) { |
||||
|
this.cardList = uni.getStorageSync(READLIST) || []; |
||||
|
const defaultCard = this.cardList.find(item => item.bindDefault === true); |
||||
|
this.selectedValue = defaultCard ? defaultCard.bindValue : this.cardList[0]?.bindValue || ''; |
||||
|
} |
||||
|
}, |
||||
|
|
||||
|
// 点击整个卡片 → 触发切换 |
||||
|
handleSelectItem(value) { |
||||
|
const oldValue = this.selectedValue; |
||||
|
const openId = uni.getStorageSync('wx_login_code'); |
||||
|
|
||||
|
if (value === oldValue) return; |
||||
|
|
||||
|
uni.showModal({ |
||||
|
title: '提示', |
||||
|
content: '确定切换默认读者证吗?', |
||||
|
success: async (res) => { |
||||
|
if (!res.confirm) { |
||||
|
this.selectedValue = oldValue; |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
try { |
||||
|
const result = await FetchSetDefaultReadCard({ |
||||
|
bindType: 'rdid', |
||||
|
bindValue: value, |
||||
|
libcode: '1201', |
||||
|
openid: openId |
||||
|
}); |
||||
|
|
||||
|
if (result.code === 200) { |
||||
|
this.selectedValue = value; |
||||
|
uni.setStorageSync('currentReaderCard', value); |
||||
|
uni.showToast({ title: '默认证切换成功', icon: 'success' }); |
||||
|
} else { |
||||
|
this.selectedValue = oldValue; |
||||
|
uni.showToast({ title: result.msg || '切换失败', icon: 'none' }); |
||||
|
} |
||||
|
} catch (err) { |
||||
|
this.selectedValue = oldValue; |
||||
|
uni.showToast({ title: '切换失败', icon: 'none' }); |
||||
|
} |
||||
|
} |
||||
|
}); |
||||
|
}, |
||||
|
toAddReaderCard() { |
||||
|
uni.navigateTo({ url: "/pages/login/login" }); |
||||
|
}, |
||||
|
} |
||||
|
} |
||||
|
</script> |
||||
|
|
||||
|
<style lang="scss" scoped> |
||||
|
.reader-card{ |
||||
|
position: relative; |
||||
|
min-height: 100vh; |
||||
|
background-color: #f5f5f5; |
||||
|
|
||||
|
.card-top-bg{ |
||||
|
position: absolute; |
||||
|
left: 0; |
||||
|
top: 0; |
||||
|
width: 100%; |
||||
|
display: block; |
||||
|
} |
||||
|
|
||||
|
.add-card-btn { |
||||
|
display: flex; |
||||
|
align-items: center; |
||||
|
justify-content: center; |
||||
|
margin-top: 15px; |
||||
|
height: 44px; |
||||
|
border: 1px dashed #01a4fe; |
||||
|
border-radius: 8px; |
||||
|
color: #01a4fe; |
||||
|
font-size: 15px; |
||||
|
|
||||
|
uni-icons { |
||||
|
margin-right: 6px; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
</style> |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue