From 700eb98db0151940cc91abcc5b3149ce23ec42de Mon Sep 17 00:00:00 2001
From: 马宇豪 <978517621@qq.com>
Date: Thu, 08 Aug 2024 08:55:49 +0800
Subject: [PATCH] 提交
---
pages/tabBar/current/detail.vue | 151 ++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 116 insertions(+), 35 deletions(-)
diff --git a/pages/tabBar/current/detail.vue b/pages/tabBar/current/detail.vue
index 9837974..3ffd3eb 100644
--- a/pages/tabBar/current/detail.vue
+++ b/pages/tabBar/current/detail.vue
@@ -16,8 +16,8 @@
</view>
</view>
<!-- <video-player ref="playerRef" @update-time="handleUpdateTime"></video-player>-->
- <view class="videoWrap" v-if="courseList && courseList.length>0">
- <video ref="videoRef" :key="moduleKey" id="myVideo" :poster="videoUrl+'?x-oss-process=video/snapshot,t_0,f_jpg'" style="width: 100%" :src="videoUrl" @timeupdate="handleTimeChange" :initial-time="initTime" :play-strategy="2" @play="handlePlay" @pause="handleUpdate" @ended="handleUpdate" controls></video>
+ <view class="videoWrap" v-if="courseList && courseList.length>0 && detail.resourceType == 1">
+ <video ref="videoRef" :key="moduleKey" id="myVideo" :poster="videoUrl+'?x-oss-process=video/snapshot,t_0,f_jpg'" style="width: 100%" :src="videoUrl" @timeupdate="handleTimeChange" :initial-time="initTime" :play-strategy="2" @play="handlePlay" @pause="handlePause" @ended="handlePause" controls></video>
<!-- <view class="videoBox">-->
<!-- <template v-if="!videoPause">-->
<!-- <view class="masterPic">-->
@@ -39,12 +39,12 @@
<view class="chapterItem" v-for="(item,index) in courseList" :key="index">
<view class="chapterName">{{item.chapterName }}</view>
<view class="courseList">
- <view class="courseItem" :class="{ selected: i.periodId === selectedPeriodId }" v-for="(i,idx) in item.studentStudyPeriodVOList" :key="idx" @click="getLesson(item.chapterId,item.courseId,i.periodId,i.resourceId)">
+ <view class="courseItem" :class="{ selected: i.periodId === selectedPeriodId }" v-for="(i,idx) in item.studentStudyPeriodVOList" :key="idx" @click="getLesson(item.chapterId,item.courseId,i.periodId,i.resourceId,true)">
<view class="c-i-l">
- <u-icon name="play-circle" :color="i.periodId == selectedPeriodId?'#fff':'#007aff'" size="24" style="margin-left: 0"></u-icon>
+ <u-icon :name="i.resourceType == 1 ?'play-circle':'order'" :color="i.periodId == selectedPeriodId?'#fff':'#007aff'" size="24" style="margin-left: 0"></u-icon>
<view>{{i.periodName}}</view>
</view>
- <view class="c-i-r">
+ <view class="c-i-r" v-if="i.resourceType == 1">
<u-line-progress style="width: 45px" height="10" :percentage="i.progress" activeColor="#19be6b"></u-line-progress>
<span>{{secondsToHms(i.period)}}</span>
</view>
@@ -67,16 +67,16 @@
import cover from '../../../static/defaultCover.jpg'
import {getClassList} from "../../../api";
import {getCourseDetail, getLessonDetail, postNewStudy, postUpdateStudy} from "../../../api/current";
-import videoPlayer from "./video";
export default {
components: {
- videoPlayer,
+
},
data() {
return {
- videoContext: null,
videoCover: cover,
showDetail: false,
+ bank: {},
+ id: null,
phaseId: null,
currentTime: null,
selectedChapterId: null,
@@ -100,21 +100,29 @@
y: 0,
},
statusBarHeight: 0,
- moduleKey: 0
+ moduleKey: 0,
+ updateInterval: null,
};
},
onReady(){
- this.videoContext = uni.createVideoContext('myVideo',this)
-
+ this.videoContext = uni.createVideoContext('myVideo')
},
onLoad(e) {
this.statusBarHeight = uni.getSystemInfoSync()['statusBarHeight'];
- this.phaseId = e.phase_id && JSON.parse(decodeURIComponent(e.phase_id));
-
+ this.bank = e.bank && JSON.parse(decodeURIComponent(e.bank));
+ this.phaseId = this.bank.phaseId
+ this.id = this.bank.id
+ this.updateInterval = null
},
onShow(){
},
+ onHide(){
+ this.clearUpdateInterval()
+ },
+ onUnload(){
+ this.clearUpdateInterval()
+ },
mounted() {
this.getData();
},
@@ -122,11 +130,11 @@
},
beforeUnmount() {
-
+ this.clearUpdateInterval()
},
beforeDestroy() {
-
+ this.clearUpdateInterval()
},
methods: {
@@ -140,6 +148,7 @@
this.currentTime = e.target.currentTime
},
handlePlay(){
+ // this.clearUpdateInterval()
const data = {
chapterId: this.selectedChapterId,
courseId: this.selectedCourseId,
@@ -150,33 +159,65 @@
postNewStudy(data).then(re=>{
if(re.code == 200){
this.studyId = re.data
- console.log('新建记录成功',this.studyId)
+ if (!this.updateInterval) { // 避免重复设置定时器
+ this.updateInterval = setInterval(() => {
+ this.handleUpdate(1);
+ }, 5000);
+ }
}else{
uni.$u.toast(res.message)
}
})
},
- handleUpdate(){
- const data = {
- id: this.studyId,
- periodId: this.selectedPeriodId,
- phaseId: this.phaseId,
- resourceId: this.selectedResourceId,
- chapterId: this.selectedChapterId,
- courseId: this.selectedCourseId,
- studentId: uni.getStorageSync('uid'),
- currentDuration: this.currentTime
+ handlePause(){
+ // this.handleUpdate().then(()=>{
+ this.clearUpdateInterval()
+ // })
+ },
+ handleUpdate(type){
+ let data = {}
+ if(type == 1){
+ data = {
+ id: this.studyId,
+ periodId: this.selectedPeriodId,
+ phaseId: this.phaseId,
+ resourceId: this.selectedResourceId,
+ chapterId: this.selectedChapterId,
+ courseId: this.selectedCourseId,
+ studentId: uni.getStorageSync('uid'),
+ currentDuration: this.currentTime
+ }
+ }else{
+ data = {
+ id: this.studyId,
+ periodId: this.selectedPeriodId,
+ phaseId: this.phaseId,
+ resourceId: this.selectedResourceId,
+ chapterId: this.selectedChapterId,
+ courseId: this.selectedCourseId,
+ studentId: uni.getStorageSync('uid'),
+ currentDuration: null
+ }
}
- postUpdateStudy(data).then(res=>{
+ return postUpdateStudy(data).then(res=>{
if(res.code == 200){
console.log('上报成功')
}else{
uni.$u.toast(res.message)
+ this.clearUpdateInterval()
}
})
},
+ clearUpdateInterval() {
+ if(this.updateInterval){
+ clearInterval(this.updateInterval)
+ this.updateInterval = null
+ console.log('清除计时')
+ }
+ console.log('无计时')
+ },
getData(){
- getCourseDetail({phaseStudentId: this.phaseId}).then(res => {
+ getCourseDetail({phaseStudentId: this.id}).then(res => {
if(res.code == 200) {
if(res.data && res.data.length > 0){
this.courseList = res.data
@@ -184,8 +225,8 @@
let courseId = this.courseList[0].courseId
let id = this.courseList[0].studentStudyPeriodVOList[0].periodId
let resourceId = this.courseList[0].studentStudyPeriodVOList[0].resourceId
- if(id){
- this.getLesson(chapterId,courseId,id,resourceId)
+ if(id && this.courseList[0].studentStudyPeriodVOList[0].resourceType == 1){
+ this.getLesson(chapterId,courseId,id,resourceId,false)
}
}else {
this.courseList = []
@@ -200,7 +241,8 @@
})
},
- getLesson(chapterId,courseId,id,resourceId){
+ getLesson(chapterId,courseId,id,resourceId,isClick){
+ this.clearUpdateInterval()
this.selectedChapterId = chapterId
this.selectedCourseId = courseId
this.selectedPeriodId = id;
@@ -210,10 +252,48 @@
if(res.data){
this.detail = res.data
this.showDetail = true
- this.$nextTick(() => {
- this.videoUrl = this.videoBaseUrl + this.detail.resourcePath
- this.moduleKey++
- });
+ if(this.detail.resourceType == 1){
+ this.$nextTick(() => {
+ // this.videoUrl = this.videoBaseUrl + this.detail.resourcePath
+ this.videoUrl = this.detail.resourcePath
+ this.moduleKey++
+ this.$nextTick(() => {
+ if(isClick == true){
+ uni.createVideoContext('myVideo', this).play();
+ }
+ })
+ })
+ }else{
+ const t = this
+ uni.downloadFile({
+ url: this.detail.resourcePath,
+ success: function (res) {
+ const data = {
+ chapterId: chapterId,
+ courseId: courseId,
+ periodId: id,
+ phaseId: t.phaseId,
+ studentId: uni.getStorageSync('uid')
+ }
+ postNewStudy(data).then(re=>{
+ if(re.code == 200){
+ this.studyId = re.data
+ this.handleUpdate(3)
+ }else{
+ uni.$u.toast(res.message)
+ }
+ })
+ var filePath = res.tempFilePath
+ uni.openDocument({
+ filePath: filePath,
+ showMenu: true,
+ success: function (res) {
+ console.log('打开文档成功');
+ }
+ })
+ }
+ })
+ }
}
}else{
uni.$u.toast(res.message)
@@ -226,6 +306,7 @@
// uni.navigateBack({
// delta: 1
// });
+ this.clearUpdateInterval()
uni.reLaunch({
url: uni.getStorageSync("prevPage") || '/pages/tabBar/firstPage/firstPage'
});
--
Gitblit v1.9.2