From 0ab55b538b3c14fd5e41071df55a267332feeb20 Mon Sep 17 00:00:00 2001 From: chenghuan Date: Mon, 1 Dec 2025 17:58:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=B9=A6=E7=B1=8D=E8=B4=AD=E4=B9=B0=E8=B7=B3=E8=BD=AC=E5=92=8C?= =?UTF-8?q?=E7=AB=A0=E8=8A=82=E9=94=81=E5=AE=9A=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/book/BookPrice.vue | 2 +- pages/book/detail.vue | 2 +- pages/book/index.vue | 2 +- pages/book/listen/index.vue | 50 ++++++++++++++++++++++++++++------- pages/book/reader.vue | 8 +++--- pages/user/myBook/index.vue | 2 +- 6 files changed, 49 insertions(+), 17 deletions(-) diff --git a/components/book/BookPrice.vue b/components/book/BookPrice.vue index 9306db0..5c186c3 100644 --- a/components/book/BookPrice.vue +++ b/components/book/BookPrice.vue @@ -3,7 +3,7 @@ 已购买 免费 VIP免费 - {{ item.minPrice }} {{ $t('global.coin') }} + {{ data.minPrice }} {{ $t('global.coin') }} {{ `${data.readCount}${$t('bookHome.readingCount')}` }} {{ `${data.buyCount}${$t('bookHome.purchased')}` }} diff --git a/pages/book/detail.vue b/pages/book/detail.vue index 1c16ead..acab442 100644 --- a/pages/book/detail.vue +++ b/pages/book/detail.vue @@ -264,7 +264,7 @@ function handlePurchase(goods: IGoods) { // 页面跳转 function goToReader() { - const isBuy = bookInfo.value.isBuy ? 0 : 1 + const isBuy = bookInfo.value.isBuy ? 1 : 0 const count = bookInfo.value.freeChapterCount || 0 uni.navigateTo({ url: `/pages/book/reader?isBuy=${isBuy}&bookId=${bookId.value}&count=${count}` diff --git a/pages/book/index.vue b/pages/book/index.vue index 9a7e60b..cc56798 100644 --- a/pages/book/index.vue +++ b/pages/book/index.vue @@ -329,7 +329,7 @@ const handleSearch = ({ value }: { value: string }) => { */ const handleMyBookClick = (bookId: number) => { uni.navigateTo({ - url: `/pages/book/reader?isBuy=0&bookId=${bookId}` + url: `/pages/book/reader?isBuy=1&bookId=${bookId}` }) } diff --git a/pages/book/listen/index.vue b/pages/book/listen/index.vue index 85261d5..67e2bdb 100644 --- a/pages/book/listen/index.vue +++ b/pages/book/listen/index.vue @@ -19,7 +19,7 @@ v-if="!bookInfo.isBuy" type="primary" size="small" - @click="goToPurchase" + @click="purchaseVisible = true" > {{ $t('bookDetails.buy') }} @@ -42,13 +42,21 @@ {{ chapter.chapter }}{{ chapter.content ? ' - ' + chapter.content : '' }} - + {{ nullText }} + + + @@ -58,7 +66,8 @@ import { onLoad } from '@dcloudio/uni-app' import { useI18n } from 'vue-i18n' import { bookApi } from '@/api/modules/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() @@ -80,11 +89,6 @@ const activeIndex = ref(-1) const nullText = ref('') const scrollHeight = ref(0) -// 计算属性 -const isLocked = computed(() => (index: number) => { - return !bookInfo.value.isBuy && index + 1 > bookInfo.value.freeChapterCount -}) - // 生命周期 onLoad((options: any) => { if (options.bookId) { @@ -98,8 +102,31 @@ onLoad((options: any) => { initScrollHeight() loadBookInfo() loadChapterList() + loadGoodsInfo() }) +// 购买弹窗状态 +const purchaseVisible = ref(false) +const goodsList = ref([]) + +// 关闭购买弹窗 +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() { 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) { // 检查是否锁定 - if (isLocked.value(index)) { + if (isLocked(index)) { uni.showToast({ title: t('book.afterPurchase'), icon: 'none' diff --git a/pages/book/reader.vue b/pages/book/reader.vue index 038ba87..b804534 100644 --- a/pages/book/reader.vue +++ b/pages/book/reader.vue @@ -111,7 +111,7 @@ {{ chapter.chapter }}{{ chapter.content ? ' - ' + chapter.content : '' }} - + @@ -201,7 +201,7 @@ const bookStore = useBookStore() // 路由参数 const bookId = ref(0) -const isBuy = ref('0') +const isBuy = ref(false) const count = ref(0) // 数据状态 @@ -273,7 +273,7 @@ const currentChapterTitle = computed(() => { onLoad((options: any) => { 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) // 获取刘海高度 @@ -430,7 +430,7 @@ async function switchChapter(chapter: IChapter, index: number) { // 判断章节是否锁定 function isLocked(index: number): boolean { - return isBuy.value === '1' && index + 1 > count.value + return !isBuy.value && index + 1 > count.value } // 判断是否是图片 diff --git a/pages/user/myBook/index.vue b/pages/user/myBook/index.vue index 75ac5da..3142c46 100644 --- a/pages/user/myBook/index.vue +++ b/pages/user/myBook/index.vue @@ -68,7 +68,7 @@ function goToDetail(bookId: number) { function goToReader(bookId: number) { uni.navigateTo({ - url: `/pages/book/reader?isBuy=0&bookId=${bookId}` + url: `/pages/book/reader?isBuy=1&bookId=${bookId}` }) }