修复:修改书籍购买跳转和章节锁定问题
This commit is contained in:
@@ -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>
|
||||||
|
|||||||
@@ -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}`
|
||||||
|
|||||||
@@ -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}`
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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'
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
// 判断是否是图片
|
// 判断是否是图片
|
||||||
|
|||||||
@@ -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}`
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user