Compare commits

...

2 Commits

8 changed files with 56 additions and 25 deletions

View File

@@ -3,7 +3,7 @@
<view v-if="data.isBuy" class="book-flag">已购买</view> <view v-if="data.isBuy" class="book-flag">已购买</view>
<view v-else-if="data.isVip == '0'" class="book-flag">免费</view> <view v-else-if="data.isVip == '0'" class="book-flag">免费</view>
<view v-else-if="userHasVip && data.isVip == '1'" class="book-price">VIP免费</view> <view v-else-if="userHasVip && data.isVip == '1'" class="book-price">VIP免费</view>
<view v-else class="book-price">{{ item.minPrice }} {{ $t('global.coin') }}</view> <view v-else class="book-price">{{ data.minPrice }} {{ $t('global.coin') }}</view>
<view> <view>
<text v-if="data.readCount" class="book-flag">{{ `${data.readCount}${$t('bookHome.readingCount')}` }}</text> <text v-if="data.readCount" class="book-flag">{{ `${data.readCount}${$t('bookHome.readingCount')}` }}</text>
<text v-else-if="data.buyCount" class="book-flag">{{ `${data.buyCount}${$t('bookHome.purchased')}` }}</text> <text v-else-if="data.buyCount" class="book-flag">{{ `${data.buyCount}${$t('bookHome.purchased')}` }}</text>

View File

@@ -264,7 +264,7 @@ function handlePurchase(goods: IGoods) {
// 页面跳转 // 页面跳转
function goToReader() { function goToReader() {
const isBuy = bookInfo.value.isBuy ? 0 : 1 const isBuy = bookInfo.value.isBuy ? 1 : 0
const count = bookInfo.value.freeChapterCount || 0 const count = bookInfo.value.freeChapterCount || 0
uni.navigateTo({ uni.navigateTo({
url: `/pages/book/reader?isBuy=${isBuy}&bookId=${bookId.value}&count=${count}` url: `/pages/book/reader?isBuy=${isBuy}&bookId=${bookId.value}&count=${count}`

View File

@@ -329,7 +329,7 @@ const handleSearch = ({ value }: { value: string }) => {
*/ */
const handleMyBookClick = (bookId: number) => { const handleMyBookClick = (bookId: number) => {
uni.navigateTo({ uni.navigateTo({
url: `/pages/book/reader?isBuy=0&bookId=${bookId}` url: `/pages/book/reader?isBuy=1&bookId=${bookId}`
}) })
} }

View File

@@ -19,7 +19,7 @@
v-if="!bookInfo.isBuy" v-if="!bookInfo.isBuy"
type="primary" type="primary"
size="small" size="small"
@click="goToPurchase" @click="purchaseVisible = true"
> >
{{ $t('bookDetails.buy') }} {{ $t('bookDetails.buy') }}
</wd-button> </wd-button>
@@ -42,13 +42,21 @@
<text class="chapter-text" :class="{ locked: isLocked(index) }"> <text class="chapter-text" :class="{ locked: isLocked(index) }">
{{ chapter.chapter }}{{ chapter.content ? ' - ' + chapter.content : '' }} {{ chapter.chapter }}{{ chapter.content ? ' - ' + chapter.content : '' }}
</text> </text>
<wd-icon v-if="isLocked(index)" name="lock" size="20px" /> <wd-icon v-if="isLocked(index)" name="lock-on" size="20px" />
</view> </view>
</view> </view>
<text v-else class="empty-text">{{ nullText }}</text> <text v-else class="empty-text">{{ nullText }}</text>
</view> </view>
</scroll-view> </scroll-view>
<!-- 购买弹窗 -->
<GoodsSelector
:show="purchaseVisible"
:goods="goodsList"
@confirm="handlePurchase"
@close="closePurchasePopup"
/>
</view> </view>
</template> </template>
@@ -58,7 +66,8 @@ import { onLoad } from '@dcloudio/uni-app'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import { bookApi } from '@/api/modules/book' import { bookApi } from '@/api/modules/book'
import type { IBookDetail, IChapter } from '@/types/book' import type { IBookDetail, IChapter } from '@/types/book'
import CustomNavbar from '@/components/book/CustomNavbar.vue' import type { IGoods } from '@/types/order'
import GoodsSelector from '@/components/order/GoodsSelector.vue'
const { t } = useI18n() const { t } = useI18n()
@@ -80,11 +89,6 @@ const activeIndex = ref(-1)
const nullText = ref('') const nullText = ref('')
const scrollHeight = ref(0) const scrollHeight = ref(0)
// 计算属性
const isLocked = computed(() => (index: number) => {
return !bookInfo.value.isBuy && index + 1 > bookInfo.value.freeChapterCount
})
// 生命周期 // 生命周期
onLoad((options: any) => { onLoad((options: any) => {
if (options.bookId) { if (options.bookId) {
@@ -98,8 +102,31 @@ onLoad((options: any) => {
initScrollHeight() initScrollHeight()
loadBookInfo() loadBookInfo()
loadChapterList() loadChapterList()
loadGoodsInfo()
}) })
// 购买弹窗状态
const purchaseVisible = ref(false)
const goodsList = ref<IGoods[]>([])
// 关闭购买弹窗
function closePurchasePopup() {
purchaseVisible.value = false
}
// 确认购买
function handlePurchase(goods: IGoods) {
uni.navigateTo({
url: `/pages/order/goodsConfirm?goods=${goods.productId}`
})
}
// 加载购买商品信息
async function loadGoodsInfo() {
const res = await bookApi.getBookGoods(bookId.value)
goodsList.value = res.productList || []
}
// 初始化滚动区域高度 // 初始化滚动区域高度
function initScrollHeight() { function initScrollHeight() {
const systemInfo = uni.getSystemInfoSync() const systemInfo = uni.getSystemInfoSync()
@@ -134,10 +161,15 @@ async function loadChapterList() {
} }
} }
// 判断章节是否锁定
function isLocked(index: number): boolean {
return !bookInfo.value.isBuy && index + 1 > bookInfo.value.freeChapterCount
}
// 播放章节 // 播放章节
function playChapter(chapter: IChapter, index: number) { function playChapter(chapter: IChapter, index: number) {
// 检查是否锁定 // 检查是否锁定
if (isLocked.value(index)) { if (isLocked(index)) {
uni.showToast({ uni.showToast({
title: t('book.afterPurchase'), title: t('book.afterPurchase'),
icon: 'none' icon: 'none'

View File

@@ -111,7 +111,7 @@
<text class="chapter-text" :class="{ locked: isLocked(index) }"> <text class="chapter-text" :class="{ locked: isLocked(index) }">
{{ chapter.chapter }}{{ chapter.content ? ' - ' + chapter.content : '' }} {{ chapter.chapter }}{{ chapter.content ? ' - ' + chapter.content : '' }}
</text> </text>
<wd-icon v-if="isLocked(index)" name="lock" size="20px" /> <wd-icon v-if="isLocked(index)" name="lock-on" size="20px" />
</view> </view>
</scroll-view> </scroll-view>
</view> </view>
@@ -201,7 +201,7 @@ const bookStore = useBookStore()
// 路由参数 // 路由参数
const bookId = ref(0) const bookId = ref(0)
const isBuy = ref('0') const isBuy = ref(false)
const count = ref(0) const count = ref(0)
// 数据状态 // 数据状态
@@ -273,7 +273,7 @@ const currentChapterTitle = computed(() => {
onLoad((options: any) => { onLoad((options: any) => {
if (options.bookId) bookId.value = Number(options.bookId) if (options.bookId) bookId.value = Number(options.bookId)
if (options.isBuy) isBuy.value = options.isBuy if (options.isBuy) isBuy.value = options.isBuy == 1 ? true : false
if (options.count) count.value = Number(options.count) if (options.count) count.value = Number(options.count)
// 获取刘海高度 // 获取刘海高度
@@ -430,7 +430,7 @@ async function switchChapter(chapter: IChapter, index: number) {
// 判断章节是否锁定 // 判断章节是否锁定
function isLocked(index: number): boolean { function isLocked(index: number): boolean {
return isBuy.value === '1' && index + 1 > count.value return !isBuy.value && index + 1 > count.value
} }
// 判断是否是图片 // 判断是否是图片

View File

@@ -68,7 +68,7 @@ function goToDetail(bookId: number) {
function goToReader(bookId: number) { function goToReader(bookId: number) {
uni.navigateTo({ uni.navigateTo({
url: `/pages/book/reader?isBuy=0&bookId=${bookId}` url: `/pages/book/reader?isBuy=1&bookId=${bookId}`
}) })
} }

View File

@@ -7,7 +7,7 @@
<!-- 头像区域 --> <!-- 头像区域 -->
<view class="avatar-section"> <view class="avatar-section">
<image <image
:src="userInfo.avatar || defaultAvatar" :src="userInfo.avatar"
class="avatar" class="avatar"
@click="editAvatar" @click="editAvatar"
/> />
@@ -148,7 +148,7 @@ const { t } = useI18n()
const userStore = useUserStore() const userStore = useUserStore()
// 默认头像 // 默认头像
const defaultAvatar = '/static/home_icon.png' const defaultAvatar = '/static/logo.png'
// 字段列表 // 字段列表
const fields = computed(() => [ const fields = computed(() => [
@@ -200,10 +200,9 @@ const avatarUrl = ref('')
const userInfo = ref<any>({}) // 用户信息 const userInfo = ref<any>({}) // 用户信息
const getData = async () => { const getData = async () => {
const res = await getUserInfo() const res = await getUserInfo()
if (res.result) { userStore.setUserInfo(res.result)
userStore.setUserInfo(res.result) userInfo.value = res.result
userInfo.value = res.result userInfo.value.avatar = res.result.avatar || defaultAvatar
}
} }
/** /**

View File

@@ -109,10 +109,10 @@ uni-textarea {
// popup // popup
.wd-popup { .wd-popup {
z-index: 9999 !important; z-index: 99 !important;
} }
.wd-overlay { .wd-overlay {
z-index: 9998 !important; z-index: 98 !important;
} }
.wd-popup-wrapper { .wd-popup-wrapper {
.wd-popup { .wd-popup {