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-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 class="book-price">{{ item.minPrice }} {{ $t('global.coin') }}</view>
<view v-else class="book-price">{{ data.minPrice }} {{ $t('global.coin') }}</view>
<view>
<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>

View File

@@ -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}`

View File

@@ -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}`
})
}

View File

@@ -19,7 +19,7 @@
v-if="!bookInfo.isBuy"
type="primary"
size="small"
@click="goToPurchase"
@click="purchaseVisible = true"
>
{{ $t('bookDetails.buy') }}
</wd-button>
@@ -42,13 +42,21 @@
<text class="chapter-text" :class="{ locked: isLocked(index) }">
{{ chapter.chapter }}{{ chapter.content ? ' - ' + chapter.content : '' }}
</text>
<wd-icon v-if="isLocked(index)" name="lock" size="20px" />
<wd-icon v-if="isLocked(index)" name="lock-on" size="20px" />
</view>
</view>
<text v-else class="empty-text">{{ nullText }}</text>
</view>
</scroll-view>
<!-- 购买弹窗 -->
<GoodsSelector
:show="purchaseVisible"
:goods="goodsList"
@confirm="handlePurchase"
@close="closePurchasePopup"
/>
</view>
</template>
@@ -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<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() {
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'

View File

@@ -111,7 +111,7 @@
<text class="chapter-text" :class="{ locked: isLocked(index) }">
{{ chapter.chapter }}{{ chapter.content ? ' - ' + chapter.content : '' }}
</text>
<wd-icon v-if="isLocked(index)" name="lock" size="20px" />
<wd-icon v-if="isLocked(index)" name="lock-on" size="20px" />
</view>
</scroll-view>
</view>
@@ -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
}
// 判断是否是图片

View File

@@ -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}`
})
}

View File

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

View File

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