123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425 |
- <template>
- <view class="">
- <view class="navbar">
- <view class="back">
- <text class="iconfont icon-fanhui " @click="backLast()"></text>
- </view>
- <text>视频学习</text>
- </view>
- <view class="msg" style="border-radius:0 0 10px 10px ;">
- <!-- <video src="" style="width: 100%;"></video> -->
- <video id="myVideo" :src="videoUrl" :initial-time="initialTime" @error="videoErrorCallback"
- @timeupdate="timeupdate" @play="videoPlay" @pause="videoPause" :title="videoTitle" :autoplay="true"
- show-loading @ended="videoEnd" controls style="width: 100%;"></video>
- <view class="title"><text style="margin-right: 7px;">{{msg.title}}</text> <text class="tag"
- v-for="item1 in msg.labels" :key="item1">{{item1}}</text></view>
- <view class="view1">
- <text style="color: darkgrey;">视频数量: <text
- style="color: coral;font-weight:550">{{msg.video_nums}}</text></text>
- <text style="color: darkgrey;" v-if="msg.user_count>0"> <text
- style="color: coral;font-weight:550">{{msg.user_count}}</text>人已学习</text>
- <text style="color: darkgrey;" v-else>暂无学习</text>
- </view>
- </view>
- <view class="msg content">
- <view class="tab">
- <view class="tab-item" :class="currentTab==0 ? 'active-item' :''" @click="changeTab(0)">
- 介绍
- <view class="line" v-if="currentTab==0">
- </view>
- </view>
- <view class="tab-item" :class="currentTab==1 ? 'active-item' :''" @click="changeTab(1)">
- 目录
- <view class="line" v-if="currentTab==1">
- </view>
- </view>
- </view>
- <view class="desc" v-if="currentTab==0">
- <div v-html="msg.description"></div>
- </view>
- <view class="directory" v-if="currentTab==1">
- <view class="chapt" v-for="(item,index) in directoryList" :key="index">
- <view class="chapt-title">
- {{item.title}}
- </view>
- <view class="dirc-list" v-for="(video,index1) in item.children " :key="index1"
- :class="video.id==videoId ? 'active-video' :''" @click="changeNextVideo(video,index1)">
- <view class="icon"></view>
- <view class="right">
- <view class="title">
- {{video.title}}
- </view>
- <view class="minte">
- <view>{{video.duration_text}}</view>
- <view class="progress">进度:<text
- style="color: #fd6308;font-weight: 550;">{{video.progress}} % </text></view>
- </view>
- </view>
- </view>
- </view>
- </view>
- </view>
- </view>
- </template>
- <script>
- var app = getApp()
- import navBar from '../../components/navBar/navbar.vue';
- import configData from '../../config.js'
- export default {
- data() {
- return {
- msg: '',
- currentTab: 1,
- directoryList: [],
- videoUrl: '', //当前视频列表
- videoId: '', //当前视频id
- currentVideo: '', //当前视频的序号
- videoList: [], //视频列表
- videoTitle: '', //当前视频的标题
- videoDuration: 0,
- currentMint: 0, //当前播放秒数防止重复发送,观看时长记录
- sendTime: 0, //视频观看进度发送间隔
- initialTime: 0, //当前视频播放秒数
- }
- },
- components: {
- navBar
- },
- onShow() {
- this.getSettings()
- },
- onLoad(options) {
- app.request('/course/show-detail?slug=' + options.slug, 'get').then(res => {
- console.log(res)
- this.msg = res.data.data.course
- this.directoryList = res.data.data.directory
- let file = res.data.data.directory
- let arr = file.filter(item => {
- return item.children.length > 0
- })
- if (arr.length == 0) {
- uni.showModal({
- title: '提示',
- content: '当前暂无可播放视频',
- showCancel: false,
- })
- } else {
- console.log(arr, '-----', arr1)
- let arr1 = []
- this.currentVideo = 0
- let indexProgress = [] //进度不为0 的下表
- arr.map(item => {
- item.children.map((item1, index) => {
- arr1.push(item1)
- })
- })
- arr1.map((item, index) => {
- if (item.progress == 0) {
- console.log(item, '---', index)
- indexProgress.push(index)
- }
- })
- console.log(indexProgress, 'indexProgressindexProgressindexProgress', arr1)
- if (indexProgress.length > 0) {
- this.currentVideo = indexProgress[0]
- } else {
- this.currentVideo = 0
- }
- this.videoList = arr1
- this.videoUrl = this.videoList[this.currentVideo].url_resource.url
- this.videoId = this.videoList[this.currentVideo].id
- this.videoTitle = this.videoList[this.currentVideo].title
- this.videoDuration = this.videoList[this.currentVideo].duration
- if (this.videoList[this.currentVideo].progress !== 100) {
- this.initialTime = this.videoDuration * this.videoList[this.currentVideo].progress
- }
- }
- })
- // app.request('/course/video?id=' + options.id, 'get').then(res => {
- // console.log(res)
- // })
- // app.request('/course/chapter?id=' + options.id, 'get').then(res => {
- // console.log(res)
- // })
- },
- methods: {
- getSettings() {
- app.request('/setting/keys', {
- keys: ['SENG_VIDEO_MSG'],
- }, 'post').then(res => {
- let data = res.data.data
- this.sendTime = data.SENG_VIDEO_MSG
- })
- },
- backLast: function() {
- uni.navigateBack()
- },
- //tab切换视频底部标签
- changeTab(e) {
- this.currentTab = e
- },
- //播放进度发生变化时
- timeupdate(event) {
- let currentTime = event.detail.currentTime
- if (currentTime) {
- let min = currentTime.toFixed(0)
- let yu = min % Number(this.sendTime)
- if (yu == 0 && min > 1 && this.currentMint !== min) {
- console.log(min, '-----', this.currentMint)
- this.currentMint = min
- this.postProgress(min)
- }
- }
- },
- //发送观看进度
- postProgress(currentTime) {
- let data = {
- course_id: this.msg.id,
- video_id: this.videoId,
- watch_seconds: currentTime
- }
- app.request('/course/video/look-record', data, 'post').then(res => {
- console.log(res, '观看进度')
- })
- },
- //点击切换视频
- changeNextVideo(item) {
- console.log(item, 'ppppp')
- let id = item.id
- this.videoId = item.id
- this.videoUrl = item.url_resource.url
- this.videoTitle = item.title
- this.videoDuration = item.duration
- if (item.progress !== 100) {
- this.initialTime = item.duration * item.progress
- }
- this.videoList.map((item1, index) => {
- if (item1.id == id) {
- this.currentVideo = index
- }
- })
- },
- //视频播放时触发
- videoPlay() {},
- //视频暂停播放
- videoPause() {},
- //视频播放结束
- videoEnd() {
- this.postProgress(this.videoDuration)
- setTimeout(() => {
- //播放结束自动播放下一节
- if (this.currentVideo == this.videoList.length - 1) {
- return
- } else {
- this.currentVideo++
- this.videoUrl = this.videoList[this.currentVideo].url_resource.url
- this.videoId = this.videoList[this.currentVideo].id
- this.videoTitle = this.videoList[this.currentVideo].title
- this.videoDuration = this.videoList[this.currentVideo].duration
- }
- }, 500)
- },
- //加载失败
- videoErrorCallback() {}
- }
- }
- </script>
- <style lang="scss">
- page {
- background-color: #EFF1F6;
- }
- .navbar {
- font-size: 32upx;
- height: 100upx;
- line-height: 100upx;
- color: #888888;
- position: relative;
- position: fixed;
- top: 0;
- z-index: 9999999;
- width: 100%;
- background-color: #FFFFFF;
- text-align: center;
- border-bottom: solid 2upx #EFF1F6;
- .back {
- height: 100upx;
- width: 100upx;
- text-align: center;
- position: absolute;
- float: left;
- left: 0upx;
- font-size: 32upx;
- }
- }
- .msg {
- margin-top: 100upx;
- background: white;
- padding-bottom: 10upx;
- .title {
- padding: 8px 0;
- font-weight: 550;
- color: #3e3e3e;
- font-size: 16px;
- padding: 0 30upx;
- }
- .tag {
- display: inline-block;
- border-radius: 3px;
- border: solid 1px #1c85f1;
- color: #1c85f1;
- font-size: 12px;
- padding: 0px 3px;
- margin-right: 5px;
- font-weight: normal;
- }
- .view1 {
- display: flex;
- align-items: center;
- justify-content: space-between;
- padding: 0 30upx;
- padding-top: 15upx;
- padding-bottom: 10px;
- font-size: 26upx;
- color: #888888;
- }
- .text1 {
- padding-left: 30upx;
- padding-top: 10upx;
- font-size: 32upx;
- color: black;
- font-weight: bold;
- }
- }
- .content {
- margin-top: 30upx;
- border-radius: 10px 10px 0 0;
- min-height: 30vh;
- .desc {
- padding: 5px 10px 10px;
- font-size: 14px;
- color: #3e3e3e;
- }
- }
- .tab {
- display: flex;
- width: 50vw;
- margin: 0 auto;
- padding: 10px 0;
- .tab-item {
- flex: 1;
- color: #6b6b6b;
- text-align: center;
- position: relative;
- .line {
- height: 3px;
- background-color: #1c85f1;
- border-radius: 8px;
- // position: absolute;
- left: 10px;
- width: 25px;
- bottom: 0;
- margin: 0 auto;
- margin-top: 8px;
- }
- }
- .active-item {
- color: #000;
- }
- }
- .directory {
- padding: 0 30upx;
- .chapt-title {
- // background-color: #eff2fc;
- border-left: 4px solid #1c85f1;
- font-size: 26upx;
- font-weight: 500;
- padding: 5px;
- color: #484848;
- border-radius: 2px;
- margin-bottom: 5px;
- }
- .chapt {
- padding-bottom: 10px;
- }
- .dirc-list {
- display: flex;
- padding-left: 10px;
- .right {
- flex: 1;
- padding: 10px;
- border-bottom: solid 1px #EFF1F6;
- font-size: 13px;
- .title {
- padding: 0;
- font-size: 13px;
- font-weight: 400 !important;
- margin-bottom: 5px;
- }
- }
- .minte {
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
- .progress {}
- }
- .active-video {
- .right {
- flex: 1;
- padding: 10px;
- border-bottom: solid 1px #EFF1F6;
- font-size: 13px;
- color: #1c85f1;
- .title {
- padding: 0;
- font-size: 13px;
- font-weight: 400 !important;
- margin-bottom: 5px;
- color: #1c85f1;
- }
- }
- }
- }
- </style>
|