From 117da08d652db513d8889924ea12b13aed68fba2 Mon Sep 17 00:00:00 2001
From: 马宇豪 <978517621@qq.com>
Date: 星期二, 16 七月 2024 14:59:09 +0800
Subject: [PATCH] 提交

---
 pages/tabBar/current/detail.vue |  421 +++++++++++++++++++++++++---------------------------
 1 files changed, 200 insertions(+), 221 deletions(-)

diff --git a/pages/tabBar/current/detail.vue b/pages/tabBar/current/detail.vue
index 1fd7dc8..0229f55 100644
--- a/pages/tabBar/current/detail.vue
+++ b/pages/tabBar/current/detail.vue
@@ -1,13 +1,24 @@
 <template>
-	<view class="wrap">
-    <view class="top_head pr">
-      <view class="t-head-l"></view>
-      <view style="text-align: center">课程</view>
-      <view class="t-head-r" @click="goBack">返回</view>
+  <view style="display: flex;flex-direction: column;height: 100%;">
+    <!-- 自定义导航栏 -->
+    <view class="navBarBox">
+      <!-- 状态栏占位 -->
+      <view class="statusBar" :style="{ paddingTop: statusBarHeight + 'px' }"></view>
+      <!-- 真正的导航栏内容 -->
+      <view style="display: flex; flex-direction: column;">
+        <view class="navBar">
+          <u-icon name="arrow-left" color="black" size="17" style="margin-left: 8px;" @click="goBack" />
+          <view class="barText">信息详情</view>
+          <!-- 					<view >
+                      <u-button type="text" @click="loginOut" style="color: blue;margin-right: 5px;">退出</u-button>
+                    </view> -->
+        </view>
+      </view>
     </view>
-
-		<view class="videoWrap">
-			<view class="videoBox">
+<!--		 <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="videoBox">-->
 <!--				<template v-if="!videoPause">-->
 <!--					<view class="masterPic">-->
 <!--						<image class="img" :src="videoCover" mode="scaleToFill"></image>-->
@@ -15,53 +26,69 @@
 <!--					<image class="startIcon" src="/static/image/bofang.png" mode="scaleToFill"  @click="startFirstVideo"></image>-->
 <!--				</template>-->
 <!--				<template v-else>-->
-              <view class="video-js" ref="video" style="width: 100%;height: 100%;"></view>
+<!--              <view class="video-js" ref="video" style="width: 100%;height: 100%;"></view>-->
 <!--				</template>-->
-			</view>
+<!--			</view>-->
       <view class="viden-info" v-if="showDetail">
         <view class="viden-info-t">{{detail.name}}</view>
         <view class="viden-info-i">创建时间:{{detail.createTime}}</view>
       </view>
 		</view>
-    <view class="d-e-c p-0-20">
+    <view class="m-p-15" v-if="courseList && courseList.length>0">
       <view class="chapterList">
         <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="getCourseDetail(i.periodId)">
-              <view>
-                <up-icon name="play-circle" :color="i.periodId == selectedPeriodId?'#fff':'#007aff'" size="24" style="margin-left: 0"></up-icon>
+            <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="c-i-l">
+                <u-icon name="play-circle" :color="i.periodId == selectedPeriodId?'#fff':'#007aff'" size="24" style="margin-left: 0"></u-icon>
                 <view>{{i.periodName}}</view>
               </view>
-              <span>{{secondsToHms(i.period)}}</span>
+              <view class="c-i-r">
+                <u-line-progress style="width: 45px" height="10" :percentage="i.progress" activeColor="#19be6b"></u-line-progress>
+                <span>{{secondsToHms(i.period)}}</span>
+              </view>
             </view>
           </view>
         </view>
       </view>
     </view>
+    <view v-else>
+      <u-empty
+          mode="list"
+          icon="http://cdn.uviewui.com/uview/empty/list.png"
+      >
+      </u-empty>
+    </view>
 	</view>
 </template>
 
 <script>
-import utils from '@/common/utils.js';
-import Videojs from 'video.js'
-import 'video.js/dist/video-js.min.css'
-import cover from '../../../static/image/index/swiperPic.png'
+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,
-			section_id: null,
-			course_id: null,
       phaseId: null,
+      currentTime: null,
+      selectedChapterId: null,
+      selectedCourseId: null,
       selectedPeriodId: null,
+      selectedResourceId: null,
+      initTime: 0,
       courseList: [],
 			course: {},
 			detail: {},
       videoBaseUrl: 'http://192.168.2.16:9000/trainexam/',
+      videoUrl: '',
 			status: false,
 			beforeAudio: true,
 			duration: 0,
@@ -71,181 +98,148 @@
 			removeArea:{
 				x: 0,
 				y: 0,
-			}
+			},
+      statusBarHeight: 0,
+      moduleKey: 0
 		};
 	},
   onReady(){
+    this.videoContext = uni.createVideoContext('myVideo',this)
 
   },
 	onLoad(e) {
-    this.phaseId = e.phase_id
-		this.getSystemInfo();
+    this.statusBarHeight = uni.getSystemInfoSync()['statusBarHeight'];
+    this.phaseId = e.phase_id && JSON.parse(decodeURIComponent(e.phase_id));
 
 	},
 	onShow(){
 
 	},
 	mounted() {
-    // this.getData();
+    this.getData();
 	},
   computed: {
 
   },
 	beforeUnmount() {
-    if (this.player) {
-      this.player.dispose()
-    }
+
   },
 
   beforeDestroy() {
-    if (this.player) {
-      this.player.dispose()
-    }
+
   },
 
   methods: {
-		getSystemInfo(){
-			let self = this;
-			uni.getSystemInfo({
-				success(res) {
-					self.removeArea.x = res.windowWidth - 70;
-					self.removeArea.y = res.windowHeight - 120;
-				}
-			});
-		},
-
-    /*获取数据*/
-    getData() {
-      let self = this;
-      uni.showLoading({
-        title: '加载中'
-      });
-      self._get(
-          '/api/app/phase-student/getPhaseStudentById', {
-            phaseStudentId: self.phaseId,
-          },
-          function (res) {
-            self.courseList = res.data
-            let id = self.courseList[0].studentStudyPeriodVOList[0].periodId
+    videoErrorCallback: function(e) {
+      uni.showModal({
+        content: e.target.errMsg,
+        showCancel: false
+      })
+    },
+    handleTimeChange(e){
+      this.currentTime = e.target.currentTime
+    },
+    handlePlay(){
+      const data = {
+        chapterId: this.selectedChapterId,
+        courseId: this.selectedCourseId,
+        periodId: this.selectedPeriodId,
+        phaseId: this.phaseId,
+        studentId: uni.getStorageSync('uid')
+      }
+      postNewStudy(data).then(re=>{
+        if(re.code == 200){
+          this.studyId = re.data
+          console.log('新建记录成功',this.studyId)
+        }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
+      }
+      postUpdateStudy(data).then(res=>{
+        if(res.code == 200){
+          console.log('上报成功')
+        }else{
+          uni.$u.toast(res.message)
+        }
+      })
+    },
+    getData(){
+      getCourseDetail({phaseStudentId: this.phaseId}).then(res => {
+        if(res.code == 200) {
+          if(res.data && res.data.length > 0){
+            this.courseList = res.data
+            let chapterId = this.courseList[0].chapterId
+            let courseId = this.courseList[0].courseId
+            let id = this.courseList[0].studentStudyPeriodVOList[0].periodId
+            let resourceId = this.courseList[0].studentStudyPeriodVOList[0].resourceId
             if(id){
-              self.getCourseDetail(id)
+              this.getLesson(chapterId,courseId,id,resourceId)
             }
-            uni.hideLoading();
-          },
-          function (err) {
-
+          }else {
+            this.courseList = []
+            uni.showToast({
+              title: '本课程暂无可学习内容',
+              duration: 1000
+            });
           }
-      );
+        }else{
+          uni.$u.toast(res.message)
+        }
+      })
     },
 
-    getCourseDetail(id){
-      let self = this;
-      self.selectedPeriodId = id;
-      self.showDetail = true
-      uni.showLoading({
-        title: '加载中'
-      });
-      self._get(
-          '/api/app/resource/getResourceByPeriod', {
-            periodId: id,
-          },
-          function (res) {
-            self.detail = res.data
-            let videoElement = document.getElementById('video');
-            if (videoElement) {
-              videoElement.parentNode.removeChild(videoElement);
-            }
-            self.initVideo(self.videoBaseUrl + self.detail.resourcePath)
-            // self.startVideo(self.videoBaseUrl + self.detail.resourcePath)
-            uni.hideLoading();
-          },
-          function (err) {
-
+    getLesson(chapterId,courseId,id,resourceId){
+      // if(this.videoContext.src){
+      //   this.videoContext.stop()
+      //   this.videoContext.src = ''
+      // }
+      console.log(this.videoContext,666)
+      this.selectedChapterId = chapterId
+      this.selectedCourseId = courseId
+      this.selectedPeriodId = id;
+      this.selectedResourceId = resourceId
+      getLessonDetail({periodId: id}).then(res => {
+        if(res.code == 200) {
+          if(res.data){
+            this.detail = res.data
+            this.showDetail = true
+            this.$nextTick(() => {
+              this.videoUrl = this.videoBaseUrl + this.detail.resourcePath
+              this.moduleKey++
+            });
           }
-      );
+        }else{
+          uni.$u.toast(res.message)
+        }
+      })
+
     },
 
     goBack(){
-      uni.navigateBack({
-        delta: 1
+      // uni.navigateBack({
+      //   delta: 1
+      // });
+      uni.reLaunch({
+        url: uni.getStorageSync("prevPage") || '/pages/tabBar/firstPage/firstPage'
       });
     },
 
-    initVideo(path){
-      let video = document.createElement('video');
-      video.id = 'video';
-      video.style = 'width: 100%; height: 100%;';
-      video.controls = true;
-      video.preload="auto"
-      video.setAttribute('playsinline', true) //IOS微信浏览器支持小窗内播放
-      video.setAttribute('webkit-playsinline', true) //这个bai属性是ios 10中设置可以让视频在小du窗内播放,也就是不是全zhi屏播放的video标签的一个属性
-      video.setAttribute('x5-video-player-type', 'h5') //安卓 声明启用同层H5播放器 可以在video上面加东西
-      let source = document.createElement('source');
-      source.src = path
-      // source.type = 'application/x-mpegURL';
-      video.appendChild(source);
-      this.$refs.video.$el.appendChild(video);
-      let that = this;
-      that.player = Videojs('video', {
-        poster: '', // 视频封面图地址
-        title:'4564564',
-        playbackRates: [0.7, 1.0, 1.5, 2.0], //播放速度
-        autoDisable: true,
-        preload: 'none', //auto - 当页面加载后载入整个视频 meta - 当页面加载后只载入元数据 none - 当页面加载后不载入视频
-        language: 'zh-CN',
-        fluid: true, // 自适应宽高
-        muted: false, //  是否静音
-        aspectRatio: '16:9', // 将播放器置于流畅模式,并在计算播放器的动态大小时使用该值。值应该代表一个比例 - 用冒号分隔的两个数字(例如"16:9"或"4:3")
-        controls: true, //是否拥有控制条 【默认true】,如果设为false ,那么只能通过api进行控制了。也就是说界面上不会出现任何控制按钮
-        autoplay: "muted", //如果true,浏览器准备好时开始回放。 autoplay: "muted", // //自动播放属性,muted:静音播放
-        loop: true, // 导致视频一结束就重新开始。 视频播放结束后,是否循环播放
-        screenshot:true,
-        controlBar: {
-          volumePanel: { //声音样式
-            inline: false // 不使用水平方式
-          },
-          timeDivider: true, // 时间分割线
-          durationDisplay: true, // 总时间
-          progressControl: true, // 进度条
-          remainingTimeDisplay: true, //当前以播放时间
-          fullscreenToggle: true, //全屏按钮
-          pictureInPictureToggle: true, //画中画
-        }
-      }, function() {
-        this.on('error', function(err) { //请求数据时遇到错误
-          console.log("请求数据时遇到错误",err)
-        });
-        this.on('stalled', function(stalled) { //网速失速
-          console.log("网速失速",stalled)
-        });
-        this.on('play', function() { //开始播放
-          console.log("开始播放")
-        });
-        this.on('pause', function() { //暂停
-          console.log("暂停")
-        });
-        this.on('timeupdate', function(timeupdate) {
-          // console.log(timeupdate)
-        })
-      });
-    },
+    handleUpdateTime(time) {
+      console.log("当前播放时间:", time);
 
-		startVideo(videoPath){
-      console.log(videoPath,'path')
-      this.player.src({
-        src: videoPath,
-        type: 'application/x-mpegURL'
-      })
-      // this.player.load()
-		},
-
-    startFirstVideo(){
-      let id = this.courseList[0].studentStudyPeriodVOList[0].periodId
-      if(id){
-        this.getCourseDetail(id)
-      }else{
-        uni.$u.toast('暂无可播放视频内容')
-      }
+      // 你可以在这里处理传递过来的播放时间
     },
 
     secondsToHms(seconds) {
@@ -276,30 +270,30 @@
 </script>
 
 <style lang="scss" scoped>
-.top_head {
-  height: 40px;
-  line-height: 40px;
-  position: sticky;
-  top: 0;
-  left: 0;
-  z-index: 100;
-  background: #fff;
+.navBarBox .navBar {
+  background-color:#fff;
+  height: 50px;
   display: flex;
+  flex-direction: row;
+  justify-content: space-around;
   align-items: center;
-  justify-content: space-between;
-  .t-head-l{
-    width: 100px;
-  }
-  .t-head-r{
-    width: 100px;
-    text-align: center;
-    height: 40px;
-    line-height: 40px;
-    color: #666;
-    margin: 0;
-  }
+  box-shadow: 0 3px 12px rgba(0,0,0,0.05);
 }
-
+.barText{
+  margin-left: -20px;
+  flex: 1;
+  /* margin-left: 20px; */
+  text-align: center;
+  width: 85%;
+  font-size: 16px;
+  /* text-align: center; */
+  font-weight: 600;
+}
+.navBarBox .navBar .logo {
+  width: 82rpx;
+  height: 82rpx;
+  margin-right: 10rpx;
+}
 .videoWrap {
 	background: #fff;
 
@@ -307,40 +301,6 @@
 		width: 100%;
     height: 260px;
 		position: relative;
-
-		.masterPic {
-      width: 100%;
-			height: 100%;
-
-			&::before {
-				content: "";
-				position: absolute;
-				top: 0;
-				left: 0;
-				background: rgb(0, 0, 0, 0.45);
-				width: 100%;
-				height: 100%;
-				z-index: 1;
-			}
-
-			.img {
-				width: 100%;
-				height: 100%;
-			}
-		}
-
-		.startIcon {
-			position: absolute;
-			left: 50%;
-			top: 50%;
-			transform: translate(-50%, -50%);
-			width: 92rpx;
-			height: 92rpx;
-			z-index: 10;
-		}
-    .videoPlayer-dimensions.vjs-fluid:not(.vjs-audio-only-mode){
-      padding: 0;
-    }
 	}
 
   .viden-info{
@@ -348,7 +308,7 @@
     box-sizing: border-box;
 
     .viden-info-t{
-      font-size: 28rpx;
+      font-size: 32rpx;
       font-weight: bold;
       color: #007aff;
       margin-bottom: 10px;
@@ -359,20 +319,26 @@
     }
   }
 }
-
+.m-p-15{
+  width: 100%;
+  padding: 0 15px;
+  box-sizing: border-box;
+}
 .chapterList{
   width: 100%;
   background: #fff;
-  border-radius: 8px;
+  border-radius: 16px;
   margin: 20px 0;
   padding: 15px;
   box-sizing: border-box;
+  box-shadow: 0 5px 10px rgba(150,150,150,.05);
 
   .chapterItem{
     padding-bottom: 15px;
     margin-bottom: 15px;
     border-bottom: 1px solid #f0f0f0;
     box-sizing: border-box;
+
     &:last-of-type{
       margin-bottom: 0;
       padding-bottom: 0;
@@ -391,13 +357,14 @@
         height: 44rpx;
         padding: 10px;
         background: #f5f5f5;
-        border-radius: 4rpx;
+        border-radius: 4px;
         margin-bottom: 10px;
         display: flex;
         align-items: center;
         justify-content: space-between;
+        transition: .6s;
 
-        &>view{
+        .c-i-l{
           display: flex;
           align-items: center;
           view{
@@ -406,11 +373,23 @@
             margin-left: 10px;
           }
         }
-
+        .c-i-r{
+          height: 100%;
+          display: flex;
+          justify-content: right;
+          align-items: center;
+          span{
+            font-size: 13px;
+            margin-left: 10px;
+          }
+        }
       }
       .selected{
         background: #007aff;
         color: #fff;
+        border-radius: 99rpx !important;
+        box-shadow: 3px 3px 12px rgba(51,133,217,.3), -2px -2px 6px #fff,inset 3px 3px 9px rgba(0,0,0,.1);
+        border: 1px solid #fff;
       }
     }
   }

--
Gitblit v1.9.2