修复:图书详情和课程详情无数据问题

This commit is contained in:
2025-12-26 11:39:06 +08:00
parent 89e77864a3
commit e76e6da008
11 changed files with 459 additions and 409 deletions

View File

@@ -91,7 +91,7 @@ export const courseApi = {
* @param id 目录ID * @param id 目录ID
*/ */
getCatalogueChapterList(id: number) { getCatalogueChapterList(id: number) {
return skeletonClient.request<IChapterListResponse>({ return mainClient.request<IChapterListResponse>({
url: 'sociology/course/getCourseCatalogueChapterList', url: 'sociology/course/getCourseCatalogueChapterList',
method: 'POST', method: 'POST',
data: { id } data: { id }

View File

@@ -2,8 +2,8 @@
"name" : "吴门国际", "name" : "吴门国际",
"appid" : "__UNI__1250B39", "appid" : "__UNI__1250B39",
"description" : "吴门国际", "description" : "吴门国际",
"versionName" : "1.1.8", "versionName" : "1.1.10",
"versionCode" : 118, "versionCode" : 1110,
"transformPx" : false, "transformPx" : false,
/* 5+App */ /* 5+App */
"app-plus" : { "app-plus" : {

View File

@@ -3,6 +3,8 @@
{ {
"path": "pages/course/index", "path": "pages/course/index",
"style": { "style": {
"enablePullDownRefresh": true,
"navigationStyle": "custom",
"navigationBarTitleText": "%index.title%" "navigationBarTitleText": "%index.title%"
} }
}, { }, {
@@ -23,7 +25,8 @@
"path": "pages/user/index", "path": "pages/user/index",
"style": { "style": {
"navigationBarTitleText": "%user.title%", "navigationBarTitleText": "%user.title%",
"navigationStyle": "custom" "navigationStyle": "custom",
"enablePullDownRefresh": true
} }
}, { }, {
"path": "pages/user/order/index", "path": "pages/user/order/index",
@@ -112,6 +115,7 @@
}, { }, {
"path": "pages/book/index", "path": "pages/book/index",
"style": { "style": {
"enablePullDownRefresh": true,
"navigationStyle": "custom", "navigationStyle": "custom",
"navigationBarTitleText": "%book.title%" "navigationBarTitleText": "%book.title%"
} }

View File

@@ -3,76 +3,82 @@
<!-- 导航栏 --> <!-- 导航栏 -->
<nav-bar :title="$t('bookDetails.title')"></nav-bar> <nav-bar :title="$t('bookDetails.title')"></nav-bar>
<Skeleton <scroll-view
ref="bookInfoSkeleton" scroll-y
theme="book-info" class="detail-scroll"
class="p-3" :style="{ height: scrollHeight + 'px' }"
:request="[getBookInfo, getBookReadCount]"
@success="getBookInfoSuccess"
> >
<template #content="{ data }"> <!-- 书籍信息 -->
<!-- 书籍信息 --> <view class="book-info">
<view class="book-info"> <image :src="bookInfo.images" class="cover" mode="aspectFill" />
<image :src="data.getBookInfo.bookInfo.images" class="cover" mode="aspectFill" /> <text class="title">{{ bookInfo.name }}</text>
<text class="title">{{ data.getBookInfo.bookInfo.name }}</text> <text class="author">{{ $t('bookDetails.authorName') }}{{ bookInfo.author?.authorName }}</text>
<text class="author">{{ $t('bookDetails.authorName') }}{{ data.getBookInfo.bookInfo.author?.authorName }}</text>
<!-- 统计信息 -->
<!-- 统计信息 --> <view class="stats">
<view class="stats"> <view class="stat-item">
<view class="stat-item"> <image src="@/static/icon/icon_look_c.png" mode="aspectFit" />
<image src="@/static/icon/icon_look_c.png" mode="aspectFit" /> <text>{{ readCount }}{{ $t('bookHome.readingCount') }}</text>
<text>{{ data.getBookReadCount.readCount }}{{ $t('bookHome.readingCount') }}</text> </view>
</view> <view class="divider" />
<view class="divider" /> <view class="stat-item">
<view class="stat-item"> <image src="@/static/icon/icon_listen_c.png" mode="aspectFit" />
<image src="@/static/icon/icon_listen_c.png" mode="aspectFit" /> <text>{{ listenCount }}{{ $t('bookHome.listenCount') }}</text>
<text>{{ data.getBookReadCount.listenCount }}{{ $t('bookHome.listenCount') }}</text> </view>
</view> <view class="divider" />
<view class="divider" /> <view class="stat-item">
<view class="stat-item"> <image src="@/static/icon/icon_bug_c.png" mode="aspectFit" />
<image src="@/static/icon/icon_bug_c.png" mode="aspectFit" /> <text>{{ buyCount }}{{ $t('bookHome.purchased') }}</text>
<text>{{ data.getBookReadCount.buyCount }}{{ $t('bookHome.purchased') }}</text>
</view>
</view> </view>
</view> </view>
</view>
<!-- 简介 -->
<view class="introduction"> <!-- 简介 -->
<text class="section-title">{{ $t('bookDetails.introduction') }}</text> <view class="introduction">
<text class="content">{{ data.getBookInfo.bookInfo.author?.introduction }}</text> <text class="section-title">{{ $t('bookDetails.introduction') }}</text>
<text class="content">{{ bookInfo.author?.introduction }}</text>
</view>
<!-- 书评列表 (非iOS) -->
<!-- <view v-if="!isIOS" class="comments-section">
<view class="section-header">
<text class="section-title">{{ $t('bookDetails.message') }}</text>
<view v-if="commentList.length > 0" class="more-link" @click="goToReview">
<text>{{ $t('bookDetails.more') }}</text>
<wd-icon name="arrow-right" size="14px" />
</view>
</view> </view>
</template> <view class="comment-wrapper">
</Skeleton> <CommentList
v-if="commentList.length > 0"
:comments="commentList.slice(0, 2)"
/>
<text v-else class="empty-text">{{ nullText }}</text>
</view>
</view> -->
<!-- 相关推荐 --> <!-- 相关推荐 -->
<view class="related-books"> <view class="related-books">
<text class="section-title">{{ $t('bookDetails.relatedBooks') }}</text> <text class="section-title">{{ $t('bookDetails.relatedBooks') }}</text>
<Skeleton <scroll-view v-if="relatedBooks.length > 0" scroll-x class="book-scroll">
theme="image-card" <view class="book-list">
:size="Array(4).fill({ height: '100px', width: '23%' })" <view
:request="getRecommendBook" class="book-item"
> v-for="item in relatedBooks"
<template #content="{ data }"> :key="item.id"
<scroll-view v-if="data.bookList.length > 0" scroll-x class="book-scroll"> @click="goToDetail(item.id)"
<view class="book-list"> >
<view <image :src="item.images" mode="aspectFill" />
class="book-item" <text>{{ item.name }}</text>
v-for="item in data.bookList"
:key="item.id"
@click="goToDetail(item.id)"
>
<image :src="item.images" mode="aspectFill" />
<text>{{ item.name }}</text>
</view>
</view> </view>
</scroll-view> </view>
<text v-else class="empty-text">{{ $t('common.data_null') }}</text> </scroll-view>
</template> <text v-else class="empty-text">{{ nullBookText }}</text>
</Skeleton> </view>
</view> </scroll-view>
<!-- 底部操作栏 --> <!-- 底部操作栏 -->
<view v-if="bookInfoLoading" class="action-bar"> <view class="action-bar">
<template v-if="bookInfo.isBuy || hasVip"> <template v-if="bookInfo.isBuy || hasVip">
<view class="action-btn read" @click="goToReader"> <view class="action-btn read" @click="goToReader">
<text>{{ $t('bookDetails.startReading') }}</text> <text>{{ $t('bookDetails.startReading') }}</text>
@@ -114,12 +120,13 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, computed, onMounted } from 'vue' import { ref, computed, onMounted } from 'vue'
import { onLoad, onShow } from '@dcloudio/uni-app' import { onLoad, onShow } from '@dcloudio/uni-app'
import { t } from '@/utils/i18n'
import { bookApi } from '@/api/modules/book' import { bookApi } from '@/api/modules/book'
import { useUserStore } from '@/stores/user' import { useUserStore } from '@/stores/user'
import type { IBookDetail } from '@/types/book' import type { IBookDetail, IBook, IComment } from '@/types/book'
import type { IGoods } from '@/types/order' import type { IGoods } from '@/types/order'
import GoodsSelector from '@/components/order/GoodsSelector.vue' import GoodsSelector from '@/components/order/GoodsSelector.vue'
import Skeleton from '@/components/Skeleton/Skeleton.vue' import CommentList from '@/components/book/CommentList.vue'
const userStore = useUserStore() const userStore = useUserStore()
@@ -131,8 +138,6 @@ const pageFrom = ref('')
const hasVip = computed(() => userStore.userInfo?.userEbookVip?.length > 0 || false) const hasVip = computed(() => userStore.userInfo?.userEbookVip?.length > 0 || false)
// 数据状态 // 数据状态
const bookInfoSkeleton = ref()
const bookInfoLoading = ref(false)
const bookInfo = ref<IBookDetail>({ const bookInfo = ref<IBookDetail>({
id: 0, id: 0,
name: '', name: '',
@@ -142,7 +147,23 @@ const bookInfo = ref<IBookDetail>({
freeChapterCount: 0 freeChapterCount: 0
}) })
const goodsList = ref<IGoods[]>([]) const goodsList = ref<IGoods[]>([])
const readCount = ref(0)
const listenCount = ref(0)
const buyCount = ref(0)
const commentList = ref<IComment[]>([])
const relatedBooks = ref<IBook[]>([])
const nullText = ref('')
const nullBookText = ref('')
const purchaseVisible = ref(false) const purchaseVisible = ref(false)
const scrollHeight = ref(0)
// 计算属性
const isIOS = computed(() => {
// #ifdef APP-PLUS
return uni.getSystemInfoSync().platform === 'ios'
// #endif
return false
})
// 生命周期 // 生命周期
onLoad((options: any) => { onLoad((options: any) => {
@@ -152,23 +173,45 @@ onLoad((options: any) => {
if (options.page) { if (options.page) {
pageFrom.value = options.page pageFrom.value = options.page
} }
initScrollHeight()
loadBookCount()
loadRecommendBooks()
}) })
onShow(() => { onShow(() => {
bookInfoSkeleton.value?.reload() loadBookInfo()
loadGoodsInfo()
if (!isIOS.value) {
loadComments()
}
}) })
onMounted(() => {
initScrollHeight()
})
// 初始化滚动区域高度
function initScrollHeight() {
const systemInfo = uni.getSystemInfoSync()
const statusBarHeight = systemInfo.statusBarHeight || 0
let navBarHeight = 44
if (systemInfo.model.includes('iPhone')) {
const modelNumber = parseInt(systemInfo.model.match(/\d+/)?.[0] || '0')
if (modelNumber >= 11) {
navBarHeight = 48
}
}
const totalNavHeight = statusBarHeight + navBarHeight
const actionBarHeight = 110 // rpx转px约55
scrollHeight.value = systemInfo.windowHeight - totalNavHeight - actionBarHeight / 2
}
// 加载书籍详情 // 加载书籍详情
const getBookInfo = () => bookApi.getBookInfo(bookId.value) async function loadBookInfo() {
const getBookInfoSuccess = (res: any) => { const res = await bookApi.getBookInfo(bookId.value)
bookInfoLoading.value = true bookInfo.value = res.bookInfo
bookInfo.value = res.getBookInfo.bookInfo || {}
} }
// 加载统计数据
const getBookReadCount = () => bookApi.getBookReadCount(bookId.value)
// 加载推荐书籍
const getRecommendBook = () => bookApi.getRecommendBook(bookId.value)
// 加载购买商品信息 // 加载购买商品信息
async function loadGoodsInfo() { async function loadGoodsInfo() {
@@ -176,9 +219,38 @@ async function loadGoodsInfo() {
goodsList.value = res.productList || [] goodsList.value = res.productList || []
} }
// 加载统计数据
async function loadBookCount() {
const res = await bookApi.getBookReadCount(bookId.value)
if (res.code === 0) {
readCount.value = res.readCount || 0
listenCount.value = res.listenCount || 0
buyCount.value = res.buyCount || 0
}
}
// 加载评论
async function loadComments() {
const res = await bookApi.getBookComments(bookId.value, 1, 10)
if (res.commentsTree && res.commentsTree.length > 0) {
commentList.value = res.commentsTree
} else {
nullText.value = t('common.data_null')
}
}
// 加载推荐书籍
async function loadRecommendBooks() {
const res = await bookApi.getRecommendBook(bookId.value)
if (res.bookList && res.bookList.length > 0) {
relatedBooks.value = res.bookList
} else {
nullBookText.value = t('common.data_null')
}
}
// 显示购买弹窗 // 显示购买弹窗
async function showPurchasePopup() { function showPurchasePopup() {
await loadGoodsInfo()
purchaseVisible.value = true purchaseVisible.value = true
} }
@@ -209,6 +281,12 @@ function goToListen() {
}) })
} }
function goToReview() {
uni.navigateTo({
url: `/pages/book/review?bookId=${bookId.value}&page=0`
})
}
function goToDetail(id: number) { function goToDetail(id: number) {
uni.navigateTo({ uni.navigateTo({
url: `/pages/book/detail?id=${id}` url: `/pages/book/detail?id=${id}`
@@ -223,7 +301,7 @@ function goToDetail(id: number) {
.book-info { .book-info {
text-align: center; text-align: center;
padding-bottom: 40rpx; padding: 40rpx 30rpx;
.cover { .cover {
width: 300rpx; width: 300rpx;
@@ -281,7 +359,9 @@ function goToDetail(id: number) {
} }
} }
.introduction { .introduction {
padding: 40rpx 30rpx 0;
.section-title { .section-title {
display: block; display: block;
font-size: 34rpx; font-size: 34rpx;
@@ -330,7 +410,7 @@ function goToDetail(id: number) {
} }
.related-books { .related-books {
padding: 0rpx 30rpx calc(40rpx + 110rpx); padding: 40rpx 30rpx 40rpx;
.section-title { .section-title {
display: block; display: block;

View File

@@ -1,11 +1,12 @@
<template> <template>
<scroll-view <!-- <scroll-view
class="home-page" class="home-page"
scroll-y scroll-y
refresher-enabled refresher-enabled
:refresher-triggered="isRefreshing" :refresher-triggered="isRefreshing"
@refresherrefresh="handleRefresh" @refresherrefresh="handleRefresh"
> > -->
<view class="home-page">
<!-- 顶部背景区域 --> <!-- 顶部背景区域 -->
<view class="home-bg" :style="{ paddingTop: getNotchHeight() + 'px' }"> <view class="home-bg" :style="{ paddingTop: getNotchHeight() + 'px' }">
<wd-search <wd-search
@@ -250,12 +251,12 @@
</Skeleton> </Skeleton>
</view> </view>
</view> </view>
</scroll-view> </view>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, computed } from 'vue' import { ref, computed } from 'vue'
import { onShow } from '@dcloudio/uni-app' import { onShow, onPullDownRefresh } from '@dcloudio/uni-app'
import { bookHomeApi } from '@/api/modules/book_home' import { bookHomeApi } from '@/api/modules/book_home'
import { getNotchHeight } from '@/utils/system' import { getNotchHeight } from '@/utils/system'
import { useUserStore } from '@/stores/user' import { useUserStore } from '@/stores/user'
@@ -433,14 +434,10 @@ const getPrompt = () => {
} }
} }
// 下拉刷新状态
const isRefreshing = ref(false)
/** /**
* 处理下拉刷新 * 刷新页面数据
*/ */
const handleRefresh = async () => { const handleRefresh = async () => {
isRefreshing.value = true
try { try {
// 刷新所有数据 // 刷新所有数据
await Promise.all([ await Promise.all([
@@ -453,18 +450,25 @@ const handleRefresh = async () => {
} finally { } finally {
// 延迟关闭刷新状态,避免闪烁 // 延迟关闭刷新状态,避免闪烁
setTimeout(() => { setTimeout(() => {
isRefreshing.value = false uni.stopPullDownRefresh();
}, 500) }, 500)
} }
} }
/**
* 下拉刷新
*/
onPullDownRefresh(() => {
handleRefresh()
})
/** /**
* 页面显示 * 页面显示
*/ */
onShow(() => { onShow(() => {
// 刷新数据 // 刷新数据
myBookSkeleton.value?.reload() myBookSkeleton.value?.reload()
categoryLevel1LabelSkeleton.value.reload() categoryLevel1LabelSkeleton.value?.reload()
}) })
</script> </script>

View File

@@ -1,147 +1,135 @@
<template> <template>
<view> <view class="course-content-wrapper">
<Skeleton ref="skeleton" theme="line-list" :request="[getChapters, checkRenewPayment]" :auto="false" @success="getDataSuccess"> <view
<template #loading-top> v-if="catalogues.length > 1"
<wd-skeleton :row-col="[ :class="['catalogue-list', userVip ? 'vip-style' : '']"
[{ width: '45%', height: '35px' }, { width: '45%', height: '35px' }], >
[{ width: '100%', height: '90px' }] <view
]" animation="gradient" class="mb-2.5! mt-5!" /> v-for="(catalogue, index) in catalogues"
</template> :key="catalogue.id"
<template #content> :class="['catalogue-item', currentCatalogueIndex === index ? 'active' : '']"
<view class="course-content-wrapper"> @click="handleSelect(index)"
<view >
v-if="catalogues.length > 1" <text class="catalogue-title">{{ catalogue.title }}</text>
:class="['catalogue-list', userVip ? 'vip-style' : '']" </view>
> </view>
<view
v-for="(catalogue, index) in catalogues"
:key="catalogue.id"
:class="['catalogue-item', currentCatalogueIndex === index ? 'active' : '']"
@click="handleSelect(index)"
>
<text class="catalogue-title">{{ catalogue.title }}</text>
</view>
</view>
<view class="chapter-list"> <view class="chapter-list">
<!-- 目录状态信息 --> <!-- 目录状态信息 -->
<view class="catalogue-status"> <view class="catalogue-status">
<view v-if="currentCatalogue?.isBuy === 1 || userVip" class="purchased-info"> <view v-if="currentCatalogue?.isBuy === 1 || userVip" class="purchased-info">
<view class="info-row"> <view class="info-row">
<text v-if="userVip"> <text v-if="userVip">
VIP畅学权益有效期截止到{{ userVip.endTime }} VIP畅学权益有效期截止到{{ userVip.endTime }}
</text> </text>
<template v-else> <template v-else>
<text v-if="!currentCatalogue.startTime"> <text v-if="!currentCatalogue.startTime">
当前目录还未开始学习 当前目录还未开始学习
</text> </text>
<text v-else> <text v-else>
课程有效期截止到{{ currentCatalogue.endTime }} 课程有效期截止到{{ currentCatalogue.endTime }}
</text> </text>
<!-- <wd-button <!-- <wd-button
v-if="currentCatalogue.startTime" v-if="currentCatalogue.startTime"
size="small" size="small"
@click="handleRenew" @click="handleRenew"
>
续费
</wd-button> -->
</template>
</view>
</view>
<!-- 未购买状态 -->
<view v-else-if="currentCatalogue?.type === 0" class="free-course">
<wd-button type="success" @click="handleGetFreeCourse">
{{ $t('courseDetails.free') }}
</wd-button>
</view>
<view v-else class="unpurchased-info">
<text class="tip-text">
{{ $t('courseDetails.unpurchasedTip') }}
</text>
<view class="action-btns">
<wd-button size="small" type="warning" @click="handlePurchase">
{{ $t('courseDetails.purchase') }}
</wd-button>
<!-- 如果是复读显示复读按钮 -->
<wd-button v-if="canRenlearn" size="small" type="success" @click="handleRenlearn">
{{ $t('courseDetails.relearn') }}
</wd-button>
<wd-button size="small" type="primary" @click="goToVip">
{{ $t('courseDetails.openVip') }}
</wd-button>
</view>
</view>
</view>
<view v-if="chapterList.length > 0" class="chapter-content">
<!-- VIP标识 -->
<view v-if="userVip" class="vip-badge">
<text>VIP畅学权益生效中</text>
</view>
<!-- 章节列表 -->
<view
v-for="(chapter, index) in chapterList"
:key="chapter.id"
class="chapter-item"
@click="handleChapterClick(chapter)"
> >
<view class="chapter-content-wrapper"> 续费
<view :class="['chapter-info', !canAccess(chapter) ? 'locked' : '']"> </wd-button> -->
<text class="chapter-title">{{ chapter.title }}</text> </template>
</view>
<!-- 试听标签 --> </view>
<wd-tag
v-if="chapter.isAudition === 1 && !isPurchased && !userVip" <!-- 未购买状态 -->
type="success" <view v-else-if="currentCatalogue?.type === 0" class="free-course">
plain <wd-button type="success" @click="handleGetFreeCourse">
size="small" {{ $t('courseDetails.free') }}
custom-class="chapter-tag" </wd-button>
> </view>
试听
</wd-tag> <view v-else class="unpurchased-info">
<text class="tip-text">
<!-- 学习状态标签 --> {{ $t('courseDetails.unpurchasedTip') }}
<template v-if="isPurchased || userVip"> </text>
<wd-tag <view class="action-btns">
v-if="chapter.isLearned === 0" <wd-button size="small" type="warning" @click="handlePurchase">
type="primary" {{ $t('courseDetails.purchase') }}
plain </wd-button>
size="small" <!-- 如果是复读显示复读按钮 -->
custom-class="chapter-tag" <wd-button v-if="canRenlearn" size="small" type="success" @click="handleRenlearn">
> {{ $t('courseDetails.relearn') }}
未学 </wd-button>
</wd-tag> <wd-button size="small" type="primary" @click="goToVip">
<wd-tag {{ $t('courseDetails.openVip') }}
v-else </wd-button>
type="success" </view>
plain </view>
size="small" </view>
custom-class="chapter-tag"
> <view v-if="chapterList.length > 0" class="chapter-content">
已学 <!-- VIP标识 -->
</wd-tag> <view v-if="userVip" class="vip-badge">
</template> <text>VIP畅学权益生效中</text>
</view> </view>
<!-- 锁定图标 --> <!-- 章节列表 -->
<view v-if="!canAccess(chapter) && currentCatalogue.type != 0" class="lock-icon"> <view
<wd-icon name="lock-on" size="24px" color="#258feb" /> v-for="(chapter, index) in chapterList"
</view> :key="chapter.id"
</view> class="chapter-item"
</view> @click="handleChapterClick(chapter)"
>
<view class="chapter-content-wrapper">
<view :class="['chapter-info', !canAccess(chapter) ? 'locked' : '']">
<text class="chapter-title">{{ chapter.title }}</text>
<!-- 试听标签 -->
<wd-tag
v-if="chapter.isAudition === 1 && !isPurchased && !userVip"
type="success"
plain
size="small"
custom-class="chapter-tag"
>
试听
</wd-tag>
<!-- 学习状态标签 -->
<template v-if="isPurchased || userVip">
<wd-tag
v-if="chapter.isLearned === 0"
type="primary"
plain
size="small"
custom-class="chapter-tag"
>
未学
</wd-tag>
<wd-tag
v-else
type="success"
plain
size="small"
custom-class="chapter-tag"
>
已学
</wd-tag>
</template>
</view> </view>
<!-- 暂无章节 --> <!-- 锁定图标 -->
<view v-else class="no-chapters"> <view v-if="!canAccess(chapter) && currentCatalogue.type != 0" class="lock-icon">
<text>暂无章节内容</text> <wd-icon name="lock-on" size="24px" color="#258feb" />
</view> </view>
</view> </view>
</view> </view>
</template> </view>
</Skeleton>
<!-- 暂无章节 -->
<view v-else class="no-chapters">
<text>暂无章节内容</text>
</view>
</view>
<!-- 商品选择器 --> <!-- 商品选择器 -->
<GoodsSelector <GoodsSelector
@@ -159,15 +147,12 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, computed, watch } from 'vue' import { ref, computed, watch } from 'vue'
import { onShow } from '@dcloudio/uni-app'
import { courseApi } from '@/api/modules/course' import { courseApi } from '@/api/modules/course'
import GoodsSelector from '@/components/order/GoodsSelector.vue' import GoodsSelector from '@/components/order/GoodsSelector.vue'
import Protocol from './Protocol.vue' import Protocol from './Protocol.vue'
import type { IChapter, ICatalogue, IVipInfo } from '@/types/course' import type { IChapter, ICatalogue, IVipInfo } from '@/types/course'
import type { IGoods } from '@/types/order' import type { IGoods } from '@/types/order'
const skeleton = ref()
interface Props { interface Props {
catalogues: ICatalogue[] catalogues: ICatalogue[]
userVip: IVipInfo | null userVip: IVipInfo | null
@@ -222,43 +207,33 @@ const handleSelect = (index: number) => {
/** /**
* 获取当前目录的章节 * 获取当前目录的章节
*/ */
const getChapters = () => courseApi.getCatalogueChapterList(currentCatalogue.value.id) const getChapters = async () => {
const res = await courseApi.getCatalogueChapterList(currentCatalogue.value.id)
chapterList.value = res.chapterList || []
}
/** /**
* 检查目录是否支持复读 * 检查目录是否支持复读
*/ */
const checkRenewPayment = async () => { const checkRenewPayment = async () => {
if (currentCatalogue.value.isBuy === 0 && !props.userVip) { if (currentCatalogue.value.isBuy === 0 && !props.userVip) {
return courseApi.checkRenewPayment(currentCatalogue.value.id) const renewRes = await courseApi.checkRenewPayment(currentCatalogue.value.id)
canRenlearn.value = renewRes.canRelearn || false
} else { } else {
return null canRenlearn.value = false
} }
} }
/**
* 获取数据完成后处理
*/
const getDataSuccess = (res: any) => {
const { getChapters, checkRenewPayment } = res
chapterList.value = getChapters.chapterList || []
canRenlearn.value = checkRenewPayment.canRelearn || false
}
/** /**
* 监听目录变化 * 监听目录变化
*/ */
watch(() => props.catalogues, (newVal: ICatalogue[]) => { watch(() => props.catalogues, (newVal: ICatalogue[]) => {
if (newVal.length > 0) { if (newVal.length > 0) {
currentCatalogueIndex.value = 0 currentCatalogueIndex.value = 0
skeleton.value.reload() getChapters()
checkRenewPayment()
} }
}, { immediate: true, deep: true }) }, { immediate: true, deep: true })
/**
* 刷新章节数据
*/
onShow(async () => {
skeleton.value && skeleton.value.reload()
})
// 购买 // 购买
const handlePurchase = async () => { const handlePurchase = async () => {

View File

@@ -13,14 +13,11 @@
</view> </view>
<!-- 课程信息 --> <!-- 课程信息 -->
<Skeleton theme="image-text" :request="getCourseDetail" @success="getCourseDetailSuccess"> <CourseInfo v-if="courseDetail" :course="courseDetail" :class="{'pt-10': !!vipTip}" />
<template #content>
<CourseInfo v-if="courseDetail" :course="courseDetail" :class="{'pt-10': !!vipTip}" />
</template>
</Skeleton>
<!-- 课程内容包装器 --> <!-- 课程内容包装器 -->
<CatalogueList <CatalogueList
v-if="catalogueList.length > 0"
:catalogues="catalogueList" :catalogues="catalogueList"
:userVip="userVip" :userVip="userVip"
@toVip="goToVip" @toVip="goToVip"
@@ -180,29 +177,38 @@ const vipTip = computed(() => {
*/ */
onLoad(async (options: any) => { onLoad(async (options: any) => {
courseId.value = parseInt(options.id) courseId.value = parseInt(options.id)
loadPageData() })
/**
* 页面显示
*/
onShow(async () => {
await loadPageData()
}) })
/** /**
* 加载页面数据 * 加载页面数据
*/ */
const getCourseDetail = () => courseApi.getCourseDetail(courseId.value) const loadPageData = async () => {
const getCourseDetailSuccess = async (res: any) => { // 获取课程详情
const res = await courseApi.getCourseDetail(courseId.value)
if (res.code === 0 && res.data) { if (res.code === 0 && res.data) {
courseDetail.value = res.data.course courseDetail.value = res.data.course
catalogueList.value = res.data.catalogues || [] catalogueList.value = res.data.catalogues || []
relatedBooks.value = res.data.shopProductList || [] relatedBooks.value = res.data.shopProductList || []
// 计算学习进度 // 计算学习进度
if (catalogueList.value.length > 0) { if (catalogueList.value.length > 0) {
const totalProgress = catalogueList.value.reduce((sum, cat) => sum + cat.completion, 0) const totalProgress = catalogueList.value.reduce((sum, cat) => sum + cat.completion, 0)
learningProgress.value = Number((totalProgress / catalogueList.value.length).toFixed(2)) learningProgress.value = Number((totalProgress / catalogueList.value.length).toFixed(2))
} }
} }
}
const loadPageData = async () => {
// 检查VIP权益 // 检查VIP权益
await checkVipStatus() await checkVipStatus()
// 加载评论
await loadComments()
} }
/** /**
@@ -442,11 +448,11 @@ onPullDownRefresh(async () => {
/** /**
* 触底加载 * 触底加载
*/ */
// onReachBottom(() => { onReachBottom(() => {
// if (hasMoreComments.value && !commentsLoading.value) { if (hasMoreComments.value && !commentsLoading.value) {
// loadComments() loadComments()
// } }
// }) })
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

View File

@@ -1,11 +1,5 @@
<template> <template>
<scroll-view <view class="course-home-page">
class="course-home-page"
scroll-y
refresher-enabled
:refresher-triggered="isRefreshing"
@refresherrefresh="handleRefresh"
>
<!-- 头部区域 --> <!-- 头部区域 -->
<view class="home-bg" :style="{ paddingTop: getNotchHeight() + 'px' }"> <view class="home-bg" :style="{ paddingTop: getNotchHeight() + 'px' }">
<wd-search <wd-search
@@ -221,7 +215,7 @@
</template> </template>
</Skeleton> </Skeleton>
</view> </view>
</scroll-view> </view>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
@@ -472,8 +466,6 @@ const requestAll = async () => {
* 处理下拉刷新 * 处理下拉刷新
*/ */
const handleRefresh = async () => { const handleRefresh = async () => {
isRefreshing.value = true
try { try {
// 刷新所有数据 // 刷新所有数据
await requestAll() await requestAll()
@@ -482,7 +474,7 @@ const handleRefresh = async () => {
} finally { } finally {
// 延迟关闭刷新状态,避免闪烁 // 延迟关闭刷新状态,避免闪烁
setTimeout(() => { setTimeout(() => {
isRefreshing.value = false uni.stopPullDownRefresh()
}, 500) }, 500)
} }
} }
@@ -535,9 +527,7 @@ onHide(() => {
* 下拉刷新 * 下拉刷新
*/ */
onPullDownRefresh(() => { onPullDownRefresh(() => {
requestAll().then(() => { handleRefresh()
uni.stopPullDownRefresh()
})
}) })
/** /**

View File

@@ -11,7 +11,12 @@
<!-- 子级分类 --> <!-- 子级分类 -->
<view v-if="selectedTab && selectedTab.children && selectedTab.children.length > 0" class="sub-category-list"> <view v-if="selectedTab && selectedTab.children && selectedTab.children.length > 0" class="sub-category-list">
<view v-for="child in selectedTab.children" :key="child.id" :class="{'active': child.id === radio_category_id}" class="sub-category-child-item">{{ child.title }}</view> <view
v-for="child in selectedTab.children"
:key="child.id" :class="{'active': child.id === radio_category_id}"
class="sub-category-child-item"
@click="changeRadioCategoryId(child.id)"
>{{ child.title }}</view>
</view> </view>
<!-- 课程列表 --> <!-- 课程列表 -->
@@ -86,6 +91,17 @@ const changeCategory = ({ name }: { name: number}) => {
radio_category_id.value = selectedTab.value && selectedTab.value.children[0] && selectedTab.value.children[0].id || 0 radio_category_id.value = selectedTab.value && selectedTab.value.children[0] && selectedTab.value.children[0].id || 0
} }
/**
* 子级分类切换
*/
const changeRadioCategoryId = (id: number) => {
radio_category_id.value = id
// 重新加载分页数据
paging.value && paging.value.reload();
}
// 分类下的课程列表 // 分类下的课程列表
const courseList = ref<ICourse[]>([]) // 课程列表 const courseList = ref<ICourse[]>([]) // 课程列表
const selectedCategoryId = computed(() => { const selectedCategoryId = computed(() => {

View File

@@ -1,91 +1,83 @@
<template> <template>
<scroll-view <view class="user-page" :style="{ paddingTop: getNotchHeight() + 30 + 'px' }" v-if="tokenState">
scroll-y <!-- 设置图标 -->
refresher-enabled <view class="settings-icon" :style="{ top: getNotchHeight() + 30 + 'px' }" @click="goSettings">
:refresher-triggered="isRefreshing" <wd-icon name="setting1" size="24px" color="#666" />
@refresherrefresh="handleRefresh" <text>{{ $t('user.settings') }}</text>
v-if="tokenState" </view>
>
<view class="user-page" :style="{ paddingTop: getNotchHeight() + 30 + 'px' }" v-if="tokenState">
<!-- 设置图标 -->
<view class="settings-icon" :style="{ top: getNotchHeight() + 30 + 'px' }" @click="goSettings">
<wd-icon name="setting1" size="24px" color="#666" />
<text>{{ $t('user.settings') }}</text>
</view>
<!-- 用户信息区域 --> <!-- 用户信息区域 -->
<view class="user-info-section"> <view class="user-info-section">
<view class="user-info"> <view class="user-info">
<image :src="userInfo.avatar || defaultAvatar" class="avatar" @click="goProfile" /> <image :src="userInfo.avatar || defaultAvatar" class="avatar" @click="goProfile" />
<view class="user-details"> <view class="user-details">
<text class="nickname">{{ userInfo.nickname || $t('user.notSet') }}</text> <text class="nickname">{{ userInfo.nickname || $t('user.notSet') }}</text>
<text v-if="userInfo.email" class="email">{{ userInfo.email }}</text> <text v-if="userInfo.email" class="email">{{ userInfo.email }}</text>
</view>
</view> </view>
</view> </view>
<!-- VIP订阅卡片 -->
<view class="vip-card-section">
<view class="vip-card">
<view class="vip-card-title">{{ $t('user.vip') }}</view>
<view class="vip-card-content">
<view class="vip-item-list">
<view v-if="vipInfo?.length > 0" v-for="vip in vipInfo">
{{ vipTypeDict[vip.type] }}{{ parseTime(vip.endTime, '{y}-{m}-{d}') }} 截止</view>
<view v-else>办理课程VIP畅享更多权益</view>
</view>
<wd-button v-if="vipInfo?.length > 0" plain type="primary" size="small"
@click="goCourseVipSub">{{ $t('vip.renewal') }}</wd-button>
<wd-button v-else plain type="primary" size="small"
@click="goCourseVipSub">{{ $t('vip.openVip') }}</wd-button>
</view>
<view class="vip-card-content">
<view class="vip-item-list">
<view v-if="vipInfoEbook?.length > 0" v-for="vip in vipInfoEbook">
电子书VIP{{ vipTypeDict[vip.type] }}{{ parseTime(vip.endTime, '{y}-{m}-{d}') }} 截止</view>
<view v-else>办理电子书VIP畅享更多权益</view>
</view>
<wd-button v-if="!vipInfoEbook?.length" plain type="primary" size="small"
@click="goSubscribe">{{ $t('vip.openVip') }}</wd-button>
</view>
</view>
</view>
<!-- 我的资产 -->
<view class="assets-card-section wallet-section">
<view class="assets-card wallet_l">
<view class="assets">
<view @click="goVirtualList">
<view class="assets_row">{{ t('global.coin') }}</view>
<view>{{userInfo.peanutCoin ?? 1}}</view>
</view>
<view @click="goPointsList">
<view class="assets_row">积分</view>
<view>{{userInfo.jf ?? 1}}</view>
</view>
<!-- <view>
<view class="assets_row">优惠卷</view>
<view>0</view>
</view> -->
</view>
<view class="chong_btn" @click="goRecharge"> </view>
<!-- <text class="wallet_title">{{$t('my.coin')}}<uni-icons type="help" size="19" color="#666"></uni-icons></text>
<text class="wallet_count">{{userMes.peanutCoin}}</text> -->
</view>
</view>
<!-- 功能菜单列表 -->
<view class="menu-section">
<wd-cell-group border class="menu-list">
<wd-cell v-for="item in menuItems" :key="item.id" :title="item.name" :label="item.desc" is-link
@click="handleMenuClick(item)">
<text v-if="item.hufenState" class="menu-list-hufen">{{hufenData?.total ?? 0}}<text
style="margin-left: 6rpx;">湖分</text></text>
</wd-cell>
</wd-cell-group>
</view>
</view> </view>
</scroll-view>
<!-- VIP订阅卡片 -->
<view class="vip-card-section">
<view class="vip-card">
<view class="vip-card-title">{{ $t('user.vip') }}</view>
<view class="vip-card-content">
<view class="vip-item-list">
<view v-if="vipInfo?.length > 0" v-for="vip in vipInfo">
{{ vipTypeDict[vip.type] }}{{ parseTime(vip.endTime, '{y}-{m}-{d}') }} 截止</view>
<view v-else>办理课程VIP畅享更多权益</view>
</view>
<wd-button v-if="vipInfo?.length > 0" plain type="primary" size="small"
@click="goCourseVipSub">{{ $t('vip.renewal') }}</wd-button>
<wd-button v-else plain type="primary" size="small"
@click="goCourseVipSub">{{ $t('vip.openVip') }}</wd-button>
</view>
<view class="vip-card-content">
<view class="vip-item-list">
<view v-if="vipInfoEbook?.length > 0" v-for="vip in vipInfoEbook">
电子书VIP{{ vipTypeDict[vip.type] }}{{ parseTime(vip.endTime, '{y}-{m}-{d}') }} 截止</view>
<view v-else>办理电子书VIP畅享更多权益</view>
</view>
<wd-button v-if="!vipInfoEbook?.length" plain type="primary" size="small"
@click="goSubscribe">{{ $t('vip.openVip') }}</wd-button>
</view>
</view>
</view>
<!-- 我的资产 -->
<view class="assets-card-section wallet-section">
<view class="assets-card wallet_l">
<view class="assets">
<view @click="goVirtualList">
<view class="assets_row">{{ t('global.coin') }}</view>
<view>{{userInfo.peanutCoin ?? 1}}</view>
</view>
<view @click="goPointsList">
<view class="assets_row">积分</view>
<view>{{userInfo.jf ?? 1}}</view>
</view>
<!-- <view>
<view class="assets_row">优惠卷</view>
<view>0</view>
</view> -->
</view>
<view class="chong_btn" @click="goRecharge"> </view>
<!-- <text class="wallet_title">{{$t('my.coin')}}<uni-icons type="help" size="19" color="#666"></uni-icons></text>
<text class="wallet_count">{{userMes.peanutCoin}}</text> -->
</view>
</view>
<!-- 功能菜单列表 -->
<view class="menu-section">
<wd-cell-group border class="menu-list">
<wd-cell v-for="item in menuItems" :key="item.id" :title="item.name" :label="item.desc" is-link
@click="handleMenuClick(item)">
<text v-if="item.hufenState" class="menu-list-hufen">{{hufenData?.total ?? 0}}<text
style="margin-left: 6rpx;">湖分</text></text>
</wd-cell>
</wd-cell-group>
</view>
</view>
<visitor v-else></visitor> <visitor v-else></visitor>
</template> </template>
@@ -97,7 +89,7 @@
import { getNotchHeight } from '@/utils/system' import { getNotchHeight } from '@/utils/system'
import { parseTime } from '@/utils/index' import { parseTime } from '@/utils/index'
import { t } from '@/utils/i18n' import { t } from '@/utils/i18n'
import { onShow } from '@dcloudio/uni-app' import { onShow, onPullDownRefresh } from '@dcloudio/uni-app'
import visitor from '@/pages/visitor/index.vue'; import visitor from '@/pages/visitor/index.vue';
const userStore = useUserStore() const userStore = useUserStore()
@@ -174,9 +166,6 @@
// 湖分 // 湖分
const hufenData = ref() const hufenData = ref()
const tokenState = ref(false) const tokenState = ref(false)
// 下拉刷新状态
const isRefreshing = ref(false)
/** /**
* 获取平台信息 * 获取平台信息
@@ -197,28 +186,6 @@
} }
} }
/**
* 处理下拉刷新
*/
const handleRefresh = async () => {
isRefreshing.value = true
try {
// 刷新所有数据
await Promise.all([
getData(),
getHufen()
])
} catch (error) {
console.error('刷新数据失败:', error)
} finally {
// 延迟关闭刷新状态,避免闪烁
setTimeout(() => {
isRefreshing.value = false
}, 500)
}
}
/** /**
* 获取用户湖分 * 获取用户湖分
*/ */
@@ -306,21 +273,35 @@
url: '/pages/user/points/index' url: '/pages/user/points/index'
}) })
} }
onShow(() => { /**
* 刷新数据
*/
const handleRefresh = async () => {
if (uni.getStorageSync('token')) { if (uni.getStorageSync('token')) {
tokenState.value = true tokenState.value = true
getData() await Promise.all([
getHufen() getPlatform(),
getData(),
getHufen()
])
} }
}
onShow(() => {
handleRefresh()
}) })
onMounted(() => { onMounted(() => {
if (uni.getStorageSync('token')) { handleRefresh()
getPlatform() })
getHufen()
} onPullDownRefresh(async () => {
handleRefresh().then(() => {
setTimeout(() => {
uni.stopPullDownRefresh()
}, 500)
})
}) })
</script> </script>

View File

@@ -215,9 +215,6 @@
.mt-2\! { .mt-2\! {
margin-top: calc(var(--spacing) * 2) !important; margin-top: calc(var(--spacing) * 2) !important;
} }
.mt-5\! {
margin-top: calc(var(--spacing) * 5) !important;
}
.mt-\[20rpx\]\! { .mt-\[20rpx\]\! {
margin-top: 20rpx !important; margin-top: 20rpx !important;
} }
@@ -294,9 +291,6 @@
.p-0\! { .p-0\! {
padding: calc(var(--spacing) * 0) !important; padding: calc(var(--spacing) * 0) !important;
} }
.p-3 {
padding: calc(var(--spacing) * 3);
}
.p-\[10rpx\] { .p-\[10rpx\] {
padding: 10rpx; padding: 10rpx;
} }