This commit is contained in:
@fawn-nine
2024-06-12 16:34:44 +08:00
parent 43a7fd802e
commit f8e165f758
3 changed files with 589 additions and 59 deletions

204
pages/course/learn.vue Normal file
View File

@@ -0,0 +1,204 @@
<template>
<view>
<!-- 公共组件-每个页面必须引入 -->
<public-module></public-module>
<z-nav-bar :title="chapter.detail.id ? chapter.detail.title : '课程详情'"></z-nav-bar>
<view class="box">
<view class="topImg" v-if="chapter.detail.imgUrl != ''">
<image :src="chapter.detail.imgUrl" mode="widthFix"></image>
</view>
<view class="sourcesList" v-if="chapter.videos.length > 0">
<scroll-view class="scroll-view_H" scroll-x="true" scroll-left="120">
<view class="scroll-view-item_H item" v-for="(item, index) in chapter.videos" :key="index">
<!-- .mp3 -->
<view class="" v-if="item.type == 2">
<audio style="text-align: left" :src="current.src" :poster="current.poster" :name="current.name" :author="current.author" :action="audioAction" controls></audio>
</view>
<view class="" v-if="item.type == 1">
<video id="myVideo" src="https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/2minute-demo.mp4"
enable-danmu danmu-btn controls></video>
</view>
</view>
</scroll-view>
</view>
</view>
<u-tabs :class="['tabList']" @click="" :current="curTagId"
:activeStyle="activeStyle" :scrollable="scrollable" :list="tabList"
itemStyle="padding-left: 15px; background-color:#fff; padding-right: 15px; height: 50px;"></u-tabs>
<view class="box">
<rich-text v-if="chapter.detail.content" class="content"
:nodes="formatRichText(chapter.detail.content)"></rich-text>
</view>
<u-back-top :scroll-top="scrollTop" bottom="150" :customStyle='bgiStyle' :iconStyle="iconStyle"></u-back-top>
<!-- <music-play :playData="playData"></music-play> -->
<z-navigation></z-navigation>
</view>
</template>
<script>
// import musicPlay from '@/components/music.vue'
import $http from '@/config/requestConfig.js';
var clear;
import {
mapState
} from 'vuex';
export default {
data() {
return {
playData: {},
scrollable:false,
current: {
poster: 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/music-a.png',
name: '致爱丽丝',
author: '暂无',
src: 'https://web-ext-storage.dcloud.net.cn/uni-app/ForElise.mp3',
},
audioAction: {
method: 'pause'
},
activeStyle: {
color: '#333',
fontWeight: 'bold',
transform: 'scale(1.2)',
// backgroundColor: '#258feb'
},
chapter: {
detail: {}, // type:0. 不加密 //1. mp4 2. mp3
videos: []
},
bgiStyle: {
background: '#fff'
},
curTagId:1,
iconStyle: {
fontSize: '40rpx',
fontWeight: 'bold',
color: '#258feb',
},
tabList:[
{id:1, name:"章节介绍"},{id:2, name:"评论"},
],
scrollTop: 0,
courseId: null,
catalogueId: null,
chapterId: null,
};
},
//第一次加载
onLoad(e) {
// 隐藏原生的tabbar
uni.hideTabBar();
// this.newsId = e.newsId
this.courseId = e.courseId
this.catalogueId = e.catalogueId
this.chapterId = e.chapterId
console.log(e, '------')
},
computed: {
...mapState(['userInfo'])
},
//页面显示
onShow() {
// 隐藏原生的tabbar
uni.hideTabBar();
this.getData();
},
onPullDownRefresh() {
uni.stopPullDownRefresh()
},
components: {
// musicPlay
},
//方法
methods: {
onPageScroll(e) {
this.scrollTop = e.scrollTop;
},
getData() {
$http.request({
url: `sociology/course/getCourseCatalogueChapterDetail`,
method: "POST", // POST、GET、PUT、DELETE具体说明查看官方文档
data: {
id: this.chapterId
},
header: { //默认 无 说明:请求头
'Content-Type': 'application/json'
},
}).then(res => {
if (res.code == 0) {
this.chapter = res.data
}
}).catch(e => {
console.log(e, '获取新闻详情报错')
});
},
formatRichText(html) { //控制图片大小
let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {
match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
return match;
});
newContent = newContent.replace(/style="[^"]+"/gi, function(match, capture) {
match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi,
'max-width:100%;');
return match;
});
// newContent = newContent.replace(/<img[^>]*>/gi, function(match, capture) {
// match = match.replace(/<img[^>]*>/gi, "@click='1111'").replace(/<img[^>]*>/gi, "@click='1111'");
// return match;
// });
newContent = newContent.replace(/<br[^>]*\/>/gi, '');
newContent = newContent.replace(/\<img/gi,
'<img style="max-width:100%;height:auto;display:inline-block;margin:10rpx auto;"');
return newContent;
},
},
};
</script>
<style lang="scss" scoped>
@import '@/style/mixin.scss';
.scroll-view_H {
white-space: nowrap;
width: 100%;
}
.scroll-view-item_H {
display: inline-block;
// width: 100%;
// height: 300rpx;
line-height: 300rpx;
text-align: center;
font-size: 36rpx;
}
.box {
background-color: #fff;
@include pleft_right(10px);
min-height: calc(100vh - 270rpx);
}
.title {
font-size: 32rpx;
font-weight: bold;
display: block;
text-align: center;
}
.content {
font-size: 26rpx;
line-height: 48rpx;
margin-top: 10rpx;
}
</style>