修复:内测问题修改:免费课程及课程详情代码优化、积分支付默认值、书籍价格显示
This commit is contained in:
450
pages/course/details/components/CatalogueList.vue
Normal file
450
pages/course/details/components/CatalogueList.vue
Normal file
@@ -0,0 +1,450 @@
|
||||
<template>
|
||||
<view class="course-content-wrapper">
|
||||
<view
|
||||
v-if="catalogues.length > 1"
|
||||
:class="['catalogue-list', userVip ? 'vip-style' : '']"
|
||||
>
|
||||
<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="catalogue-status">
|
||||
<view v-if="currentCatalogue?.isBuy === 1 || userVip" class="purchased-info">
|
||||
<view class="info-row">
|
||||
<text v-if="userVip">
|
||||
VIP畅学权益有效期截止到:{{ userVip.endTime }}
|
||||
</text>
|
||||
<template v-else>
|
||||
<text v-if="!currentCatalogue.startTime">
|
||||
当前目录还未开始学习
|
||||
</text>
|
||||
<text v-else>
|
||||
课程有效期截止到:{{ currentCatalogue.endTime }}
|
||||
</text>
|
||||
<!-- <wd-button
|
||||
v-if="currentCatalogue.startTime"
|
||||
size="small"
|
||||
@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="showRenewBtn"
|
||||
size="small"
|
||||
type="success"
|
||||
@click="handleRenew"
|
||||
>
|
||||
{{ $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' : '']">
|
||||
<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 v-if="!canAccess(chapter)" class="lock-icon">
|
||||
<wd-icon name="lock-on" size="24px" color="#258feb" />
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 暂无章节 -->
|
||||
<view v-else class="no-chapters">
|
||||
<text>暂无章节内容</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, watch } from 'vue'
|
||||
import { courseApi } from '@/api/modules/course'
|
||||
import type { IChapter, ICatalogue, IVipInfo } from '@/types/course'
|
||||
|
||||
interface Props {
|
||||
catalogues: ICatalogue[]
|
||||
userVip: IVipInfo | null
|
||||
showRenewBtn?: boolean
|
||||
}
|
||||
|
||||
const props = defineProps<Props>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
click: [chapter: IChapter],
|
||||
purchase: [catalogue: ICatalogue],
|
||||
renew: [catalogue: ICatalogue],
|
||||
toVip: [catalogue: ICatalogue],
|
||||
change: [index: number]
|
||||
}>()
|
||||
|
||||
// 当前目录索引
|
||||
const currentCatalogueIndex = ref<number>(0)
|
||||
// 当前目录
|
||||
const currentCatalogue = computed(() => {
|
||||
return props.catalogues[currentCatalogueIndex.value]
|
||||
})
|
||||
// 当前目录的章节
|
||||
const chapterList = ref<IChapter[]>([])
|
||||
|
||||
// 显示续费按钮
|
||||
const showRenewBtn = ref<boolean>(false)
|
||||
|
||||
// 判断目录是否已购买
|
||||
const isPurchased = computed(() => {
|
||||
return currentCatalogue.value.isBuy === 1
|
||||
})
|
||||
|
||||
/**
|
||||
* 选择目录
|
||||
*/
|
||||
const handleSelect = (index: number) => {
|
||||
if (index === currentCatalogueIndex.value) return
|
||||
|
||||
currentCatalogueIndex.value = index
|
||||
|
||||
getChapters() // 获取章节列表
|
||||
checkRenewPayment() // 检查是否支持复读
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前目录的章节
|
||||
*/
|
||||
const getChapters = async () => {
|
||||
const res = await courseApi.getCatalogueChapterList(currentCatalogue.value.id)
|
||||
chapterList.value = res.chapterList || []
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查目录是否支持复读
|
||||
*/
|
||||
const checkRenewPayment = async () => {
|
||||
if (currentCatalogue.value.isBuy === 0 && !props.userVip) {
|
||||
const renewRes = await courseApi.checkRenewPayment(currentCatalogue.value.id)
|
||||
showRenewBtn.value = renewRes.canRelearn || false
|
||||
} else {
|
||||
showRenewBtn.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 监听目录变化
|
||||
*/
|
||||
watch(() => props.catalogues, (newVal: ICatalogue[]) => {
|
||||
if (newVal.length > 0) {
|
||||
currentCatalogueIndex.value = 0
|
||||
getChapters()
|
||||
checkRenewPayment()
|
||||
}
|
||||
}, { immediate: true, deep: true })
|
||||
|
||||
// 购买
|
||||
const handlePurchase = () => {
|
||||
emit('purchase', currentCatalogue.value)
|
||||
}
|
||||
|
||||
// 去开通vip
|
||||
const goToVip = () => {
|
||||
emit('toVip', currentCatalogue.value)
|
||||
}
|
||||
|
||||
// 续费/复读
|
||||
const handleRenew = () => {
|
||||
emit('renew', currentCatalogue.value)
|
||||
}
|
||||
|
||||
// 领取免费课程
|
||||
const handleGetFreeCourse = async () => {
|
||||
emit('getFreeCourse', currentCatalogue.value)
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断章节是否可以访问
|
||||
*/
|
||||
const canAccess = (chapter: IChapter): boolean => {
|
||||
// VIP用户可以访问所有章节
|
||||
if (props.userVip) return true
|
||||
|
||||
// 已购买目录可以访问所有章节
|
||||
if (isPurchased.value) return true
|
||||
|
||||
// 试听章节可以访问
|
||||
if (chapter.isAudition === 1) return true
|
||||
|
||||
// 免费课程可以访问
|
||||
if (currentCatalogue.value.type === 0) return true
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* 点击章节
|
||||
*/
|
||||
const handleChapterClick = (chapter: IChapter, catalogue: ICatalogue) => {
|
||||
if (!isPurchased.value && currentCatalogue.value.type === 0) {
|
||||
uni.showToast({
|
||||
title: '请先领取课程',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
if (!canAccess(chapter)) {
|
||||
uni.showToast({
|
||||
title: '请先购买课程',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
emit('toDetail', chapter, currentCatalogue.value)
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.course-content-wrapper {
|
||||
background: linear-gradient(108deg, #c3e7ff 0%, #59bafe 100%);
|
||||
}
|
||||
.catalogue-list {
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
padding: 20rpx;
|
||||
padding-bottom: 0;
|
||||
border-radius: 20rpx 20rpx 0 0;
|
||||
margin-top: 20rpx;
|
||||
|
||||
&.vip-style {
|
||||
background: linear-gradient(90deg, #6429db 0%, #0075ed 100%);
|
||||
|
||||
.catalogue-item {
|
||||
background-color: rgba(0, 0, 0, 0.4);
|
||||
color: #fff;
|
||||
border-color: #fff;
|
||||
|
||||
&.active {
|
||||
background-color: #258feb;
|
||||
color: #fff;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.catalogue-item {
|
||||
flex: 1;
|
||||
text-align: center;
|
||||
padding: 16rpx 0;
|
||||
margin-right: 10rpx;
|
||||
border-radius: 20rpx 20rpx 0 0;
|
||||
border: 1px solid #fff;
|
||||
border-bottom: none;
|
||||
background-color: rgba(0, 0, 0, 0.4);
|
||||
color: #fff;
|
||||
transition: all 0.3s;
|
||||
|
||||
&:last-child {
|
||||
margin-right: 0;
|
||||
}
|
||||
|
||||
&.active {
|
||||
background-color: #258feb;
|
||||
padding: 20rpx 0;
|
||||
|
||||
.catalogue-title {
|
||||
font-size: 36rpx;
|
||||
font-weight: bold;
|
||||
}
|
||||
}
|
||||
|
||||
.catalogue-title {
|
||||
font-size: 30rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.chapter-list {
|
||||
padding: 20rpx;
|
||||
}
|
||||
|
||||
.catalogue-status {
|
||||
padding: 20rpx;
|
||||
margin-bottom: 20rpx;
|
||||
background-color: #fff;
|
||||
|
||||
.purchased-info {
|
||||
.info-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
font-size: 26rpx;
|
||||
line-height: 50rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.free-course {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.unpurchased-info {
|
||||
.tip-text {
|
||||
display: block;
|
||||
font-size: 26rpx;
|
||||
color: #666;
|
||||
margin-bottom: 20rpx;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.action-btns {
|
||||
display: flex;
|
||||
gap: 20rpx;
|
||||
justify-content: center;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.chapter-content {
|
||||
position: relative;
|
||||
padding: 20rpx;
|
||||
border: 4rpx solid #fffffc;
|
||||
background: linear-gradient(52deg, #e8f6ff 0%, #e3f2fe 50%);
|
||||
box-shadow: 0px 0px 10px 0px #89c8e9;
|
||||
border-top-right-radius: 40rpx;
|
||||
border-bottom-left-radius: 40rpx;
|
||||
|
||||
.vip-badge {
|
||||
display: inline-block;
|
||||
font-size: 24rpx;
|
||||
background: linear-gradient(90deg, #6429db 0%, #0075ed 100%);
|
||||
color: #fff;
|
||||
padding: 10rpx 20rpx;
|
||||
border-radius: 0 50rpx 50rpx 0;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.chapter-item {
|
||||
padding: 20rpx 0;
|
||||
border-bottom: 1px solid #fff;
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.chapter-content-wrapper {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
|
||||
.chapter-info {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10rpx;
|
||||
|
||||
&.locked {
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
.chapter-title {
|
||||
flex: 1;
|
||||
font-size: 28rpx;
|
||||
color: #1e2f3e;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.chapter-tag {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.lock-icon {
|
||||
margin-left: 20rpx;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.no-chapters {
|
||||
text-align: center;
|
||||
padding: 80rpx 0;
|
||||
color: #999;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
</style>
|
||||
187
pages/course/details/components/CourseInfo.vue
Normal file
187
pages/course/details/components/CourseInfo.vue
Normal file
@@ -0,0 +1,187 @@
|
||||
<template>
|
||||
<view class="course-info">
|
||||
<!-- 课程封面 -->
|
||||
<view class="course-cover">
|
||||
<image
|
||||
:src="course.image || '/static/nobg.jpg'"
|
||||
mode="widthFix"
|
||||
class="cover-image"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<!-- 课程标题 -->
|
||||
<view class="course-title">
|
||||
<text class="title-text">{{ course.title }}</text>
|
||||
</view>
|
||||
|
||||
<!-- 课程简介 -->
|
||||
<view v-if="course.content && course.content !== ''" class="course-content">
|
||||
<view class="content-wrapper">
|
||||
<view
|
||||
:class="['content-html', isCollapsed ? 'collapsed' : '']"
|
||||
v-html="parsedContent"
|
||||
/>
|
||||
|
||||
<!-- 图片列表 -->
|
||||
<view v-if="images.length > 0" class="content-images">
|
||||
<image
|
||||
v-for="(img, index) in images"
|
||||
:key="index"
|
||||
:src="img"
|
||||
mode="widthFix"
|
||||
class="content-image"
|
||||
@click="previewImage(img, index)"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<!-- 展开/收起按钮 -->
|
||||
<view class="toggle-btn" @click="toggleContent">
|
||||
<text>{{ isCollapsed ? '展开' : '收起' }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, watch } from 'vue'
|
||||
import type { ICourseDetail } from '@/types/course'
|
||||
|
||||
interface Props {
|
||||
course: ICourseDetail
|
||||
}
|
||||
|
||||
const props = defineProps<Props>()
|
||||
|
||||
const isCollapsed = ref(true)
|
||||
const parsedContent = ref('')
|
||||
const images = ref<string[]>([])
|
||||
|
||||
/**
|
||||
* 解析课程内容,分离文本和图片
|
||||
*/
|
||||
const parseContent = () => {
|
||||
if (!props.course.content) {
|
||||
parsedContent.value = ''
|
||||
images.value = []
|
||||
return
|
||||
}
|
||||
|
||||
// 提取图片URL
|
||||
const imgRegex = /<img[^>]+src="([^"]+)"[^>]*>/g
|
||||
const imgUrls: string[] = []
|
||||
let match
|
||||
|
||||
while ((match = imgRegex.exec(props.course.content)) !== null) {
|
||||
imgUrls.push(match[1])
|
||||
}
|
||||
|
||||
// 移除图片标签,保留文本内容
|
||||
const cleanText = props.course.content.replace(/<img[^>]*>/g, '')
|
||||
|
||||
parsedContent.value = cleanText
|
||||
images.value = imgUrls
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换展开/收起
|
||||
*/
|
||||
const toggleContent = () => {
|
||||
isCollapsed.value = !isCollapsed.value
|
||||
}
|
||||
|
||||
/**
|
||||
* 预览图片
|
||||
*/
|
||||
const previewImage = (current: string, index: number) => {
|
||||
uni.previewImage({
|
||||
current,
|
||||
urls: images.value,
|
||||
currentIndex: index
|
||||
})
|
||||
}
|
||||
|
||||
// 监听课程变化,重新解析内容
|
||||
watch(() => props.course, () => {
|
||||
parseContent()
|
||||
}, { immediate: true, deep: true })
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.course-info {
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
.course-cover {
|
||||
width: 100%;
|
||||
|
||||
.cover-image {
|
||||
width: 100%;
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
.course-title {
|
||||
padding: 30rpx 20rpx;
|
||||
|
||||
.title-text {
|
||||
font-size: 36rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
line-height: 1.4;
|
||||
}
|
||||
}
|
||||
|
||||
.course-content {
|
||||
padding: 0 20rpx 20rpx;
|
||||
|
||||
.content-wrapper {
|
||||
position: relative;
|
||||
|
||||
.content-html {
|
||||
font-size: 28rpx;
|
||||
line-height: 1.8;
|
||||
color: #666;
|
||||
text-align: justify;
|
||||
word-break: break-all;
|
||||
|
||||
&.collapsed {
|
||||
max-height: 200rpx;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
|
||||
&::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 60rpx;
|
||||
background: linear-gradient(to bottom, transparent, #fff);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.content-images {
|
||||
margin-top: 20rpx;
|
||||
|
||||
.content-image {
|
||||
width: 100%;
|
||||
display: block;
|
||||
margin-bottom: 20rpx;
|
||||
border-radius: 8rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.toggle-btn {
|
||||
text-align: right;
|
||||
padding: 20rpx 0 0;
|
||||
|
||||
text {
|
||||
color: #838588;
|
||||
font-size: 26rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user