| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339 | 
							- <template>
 
- 	<view class="kecheng-study-page">
 
- 		<!-- <view class="icon-title-bjcolor-navBar-box">
 
- 			<view @click="goUpPage" class="nav-bar-icon"></view>
 
- 			<text class="nav-bar-title">{{name}}</text>
 
- 		</view> -->
 
- 		<!-- 播放器 -->
 
- 		<videoPlayVue v-if="showVideo" ref="videoRef" class="phone-video-box" @play-end="onPlayEnd" @play-play="onPlay"
 
- 			@play-pause="onPause" @play-timeupdate="onTimeupdate"></videoPlayVue>
 
- 			<!-- 视频背景图 -->
 
- 		<view v-else class="phone-video-box master-image">
 
- 				<!-- <view class="video-player-icon" @click="handlePlayFirst"></view> -->
 
- 		</view>
 
- 		<!-- 播放引导 -->
 
- 		<view class="yindao-shadow-image" v-if="!showVideo"> </view>
 
- 		<!-- 中间区域 -->
 
- 		<view class="kc-name-box">
 
- 			<icon @click="goUpPage"></icon>
 
- 			<view>{{name}}</view>
 
- 		</view>
 
- 		<view class="kc-info-box">
 
- 			<view>时长:{{period}}</view>
 
- 			<view>{{userCount}}人学习</view>
 
- 		</view>
 
- 		<!-- 大纲 -->
 
- 		<view class="phone-tab-box">
 
- 			<uni-segmented-control :current="current" :values="items" style-type="text" :active-color="activeColor"
 
- 				@clickItem="onClickItem" />
 
- 		</view>
 
- 		<view class="kecheng-content-box">
 
- 			<!-- 目录 -->
 
- 			<kechengMuluVue v-if="current === 0" :chapterArr="list" @play="handlePlay" :isHasProgress="true"
 
- 				:activeKjId="curPlayData&&curPlayData.kjId"></kechengMuluVue>
 
- 			<!-- 介绍 -->
 
- 			<rich-text :nodes="intro || '暂无内容'" v-if="current === 1 && intro" class="kecheng-jieshao-box"></rich-text>
 
- 		</view>
 
- 	</view>
 
- </template>
 
- <script>
 
- 	import * as kechengApi from "@/api/kecheng.js";
 
- 	import videoPlayVue from "@/components/videoPlay/videoPlay.vue";
 
- 	import kechengMuluVue from "@/components/kecheng-mulu/kecheng-mulu.vue";
 
- 	import {
 
- 		useUserCache
 
- 	} from "@/utils/userCache.js"
 
- 	import {
 
- 		formatSecondsToCnhms
 
- 	} from "@/utils/common.js"
 
- 	import {
 
- 		useKechengTools
 
- 	} from "./useKechengCache.js"
 
- 	const {
 
- 		getCurKjIndex,
 
- 		saveKechengData,
 
- 		getKechengDataFromHistory,
 
- 		saveKechengSectionPage,
 
- 		getKechengSectionPageFromHistory,
 
- 		mergeProgress,
 
- 		initCourseProgressAll,
 
- 		saveCourseProgress,
 
- 		updateSectionProgress,
 
- 	} = useKechengTools();
 
- 	export default {
 
- 		components: {
 
- 			videoPlayVue,
 
- 			kechengMuluVue
 
- 		},
 
- 		data() {
 
- 			return {
 
- 				showVideo: false,
 
- 				items: ['目录', '介绍'],
 
- 				colors: ['#007aff', '#4cd964', '#dd524d'],
 
- 				activeColor: '#3fd2a1',
 
- 				current: 0, // 激活的选项卡
 
- 				operId: '', // 课程
 
- 				name: '',
 
- 				period: 0, // 时长
 
- 				userCount: 0, // 学习人数
 
- 				list: [],
 
- 				intro: '',
 
- 				curPlayData: null,
 
- 				timer1: null,
 
- 				kcId: null,
 
- 				from: '',
 
- 				jzId: null,
 
- 			}
 
- 		},
 
- 		onLoad(options) {
 
- 			this.kcId = options.kcId;
 
- 			this.from = options.from;
 
- 			this.jzId = options.jzId;
 
- 			this.init();
 
- 		},
 
- 		methods: {
 
- 			handlePlayFirst() {
 
- 				let sectionPage = getKechengSectionPageFromHistory(this.operId)
 
- 				if (sectionPage) {
 
- 					const {
 
- 						zhangIndex,
 
- 						jieIndex
 
- 					} = getCurKjIndex(sectionPage.kjId,this.operId)
 
- 					sectionPage.iChapter = zhangIndex;
 
- 					sectionPage.iSection = jieIndex;
 
- 					sectionPage.kjId = sectionPage.kjId;
 
- 					sectionPage.operId = this.operId;
 
- 					
 
- 					// 设置默认展开项
 
- 					this.list[zhangIndex].open = true;
 
- 					this.list[zhangIndex].jieList[jieIndex].open = true;
 
- 					
 
- 					const kejian = this.list[0].jieList && this.list[zhangIndex].jieList[jieIndex].kejianList.find(item => item.kjId ==sectionPage.kjId )
 
- 					this.handlePlay(kejian)
 
- 				} else {
 
- 					if (this.list && this.list[0].jieList && this.list[0].jieList[0].kejianList) {
 
- 						// 设置默认展开项
 
- 						this.list[0].open = true;
 
- 						this.list[0].jieList[0].open = true;
 
- 						// 设置播放可见
 
- 						const kejian = this.list[0].jieList[0].kejianList[0];
 
- 						this.handlePlay(kejian)
 
- 						// 更新缓存
 
- 						sectionPage = {
 
- 							kjId: kejian.kjId,
 
- 							iChapter: 0,
 
- 							iSection: 0,
 
- 							operId: this.operId
 
- 						}
 
- 					}
 
- 				}
 
- 						
 
- 				saveKechengSectionPage(this.operId, sectionPage)
 
- 			},
 
- 			onPause() {
 
- 				clearInterval(this.timer1);
 
- 				this.timer1 = null;
 
- 			},
 
- 			onPlay() {
 
- 				clearInterval(this.timer1);
 
- 				this.timer1 = null;
 
- 				this.timer = setInterval(() => {
 
- 					updateSectionProgress(this.operId);
 
- 				}, 1000 * 1 * 60) // 自动保存进度 1分钟已保存
 
- 			
 
- 			},
 
- 			sectionPlayerProgress(progress) {
 
- 				let sectionPage = getKechengSectionPageFromHistory(this.operId);
 
- 				let maxProcess = this.list[sectionPage.iChapter].jieList[sectionPage.iSection].kejianList.find(it1=>it1.kjId == sectionPage.kjId).maxProcess;
 
- 				// 更新缓存进度
 
- 				this.list[sectionPage.iChapter].jieList[sectionPage.iSection].kejianList.find(it1=>it1.kjId == sectionPage.kjId).curProcess = progress;
 
- 				if (progress < 100) {
 
- 					// 播放进度小于100
 
- 					if (progress < maxProcess) {
 
- 						this.list[sectionPage.iChapter].jieList[sectionPage.iSection].kejianList.find(it1=>it1.kjId == sectionPage.kjId).maxProcess = maxProcess
 
- 					} else {
 
- 						this.list[sectionPage.iChapter].jieList[sectionPage.iSection].kejianList.find(it1=>it1.kjId == sectionPage.kjId).maxProcess = progress
 
- 					}
 
- 				} else {
 
- 					// 播放进度大于100
 
- 					this.list[sectionPage.iChapter].jieList[sectionPage.iSection].kejianList.find(it1=>it1.kjId == sectionPage.kjId).maxProcess = 100
 
- 				}
 
- 			},
 
- 			onTimeupdate(time) {
 
- 				const progress = parseInt(time / this.curPlayData.duration * 100);
 
- 				this.curPlayData.curProgress = parseInt(progress >= 100 ? '99' : progress);
 
- 				// 保存进度
 
- 				saveCourseProgress(time, this.curPlayData.duration, this.operId)
 
- 				// 更新进度
 
- 				this.sectionPlayerProgress(progress)
 
- 			},
 
- 			onPlayEnd() {
 
- 				clearInterval(this.timer1);
 
- 				this.timer1 = null;
 
- 				saveCourseProgress(this.curPlayData.duration, this.curPlayData.duration, this.operId, 'end');
 
- 				updateSectionProgress(this.operId, 'end', 'video', () => {
 
- 					this.curPlayData.maxProcess = 99;
 
- 					this.curPlayData.curProcess = 99;
 
- 				});
 
- 				console.log('end')
 
- 			},
 
- 			goUpPage() {
 
- 				const pages = getCurrentPages();
 
- 				if (pages.length>1) {
 
- 					uni.navigateBack()
 
- 				} else {
 
- 					/* if (this.from == 'kechengList') {
 
- 						uni.redirectTo({
 
- 							url: '/pages/client/Kecheng/list'
 
- 						})
 
- 					} else if (this.from == 'shouye') {
 
- 						uni.redirectTo({
 
- 							url: '/pages/client/ShouYe/shouye'
 
- 						})
 
- 					} else {
 
- 						uni.redirectTo({
 
- 							url: '/pages/client/ShouYe/shouye'
 
- 						})
 
- 					} */
 
- 					 history.back();
 
- 				}
 
- 				
 
- 			},
 
- 			onClickItem(e) {
 
- 				if (this.current !== e.currentIndex) {
 
- 					this.current = e.currentIndex
 
- 				}
 
- 			},
 
- 			formatData(data) {
 
- 				data.forEach(zhang => {
 
- 					zhang.open = false;
 
- 					zhang.jieList.forEach(jie => {
 
- 						jie.open = false;
 
- 					})
 
- 				})
 
- 				return data;
 
- 			},
 
- 			handlePlay(data) {
 
- 				this.showVideo = true;
 
- 				if (this.curPlayData && this.curPlayData.url == data.url) {
 
- 					return;
 
- 				}
 
- 				this.curPlayData = data;
 
- 				const {
 
- 					zhangIndex,
 
- 					jieIndex
 
- 				} = getCurKjIndex(data.kjId,this.operId)
 
- 				const sectionPage = {};
 
- 				sectionPage.iChapter = zhangIndex;
 
- 				sectionPage.iSection = jieIndex;
 
- 				sectionPage.kjId = data.kjId;
 
- 				sectionPage.operId = this.operId;
 
- 				saveKechengSectionPage(this.operId, sectionPage)
 
- 				kechengApi.getVideoAuth({
 
- 					videoId: data.url
 
- 				}).then(res => {
 
- 					const progress = data.curProcess || 0;
 
- 					this.$refs.videoRef.init({
 
- 						videoId: data.url,
 
- 						playAuth: res.data,
 
- 						seekTime: data.duration * progress / 100,
 
- 						isPlay: false
 
- 					})
 
- 				})
 
- 			},
 
- 			initFirstVideo() {
 
- 				let sectionPage = getKechengSectionPageFromHistory(this.operId)
 
- 				if (sectionPage) {
 
- 					const {
 
- 						zhangIndex,
 
- 						jieIndex
 
- 					} = getCurKjIndex(sectionPage.kjId,this.operId)
 
- 					sectionPage.iChapter = zhangIndex;
 
- 					sectionPage.iSection = jieIndex;
 
- 					sectionPage.kjId = sectionPage.kjId;
 
- 					sectionPage.operId = this.operId;
 
- 					
 
- 					// 设置默认展开项
 
- 					this.list[zhangIndex].open = true;
 
- 					this.list[zhangIndex].jieList[jieIndex].open = true;
 
- 					
 
- 					const kejian = this.list[0].jieList && this.list[zhangIndex].jieList[jieIndex].kejianList.find(item => item.kjId ==sectionPage.kjId )
 
- 					// this.handlePlay(kejian)
 
- 				} else {
 
- 					if (this.list && this.list[0].jieList && this.list[0].jieList[0].kejianList) {
 
- 						// 设置默认展开项
 
- 						this.list[0].open = true;
 
- 						this.list[0].jieList[0].open = true;
 
- 						// 设置播放可见
 
- 						const kejian = this.list[0].jieList[0].kejianList[0];
 
- 						// this.handlePlay(kejian)
 
- 						// 更新缓存
 
- 						sectionPage = {
 
- 							kjId: kejian.kjId,
 
- 							iChapter: 0,
 
- 							iSection: 0,
 
- 							operId: this.operId
 
- 						}
 
- 					}
 
- 				}
 
- 		
 
- 				saveKechengSectionPage(this.operId, sectionPage)
 
- 			},
 
- 			init() {
 
- 				kechengApi.getClientKechengStart({
 
- 					kcId: this.kcId,
 
- 					jzId:this.jzId
 
- 				}).then(res => {
 
- 					const {
 
- 						userCount,
 
- 						period,
 
- 						name,
 
- 						kejianUserVo,
 
- 						intro,
 
- 						operId,
 
- 					} = res.data;
 
- 					this.userCount = userCount;
 
- 					this.period = formatSecondsToCnhms(period,true);
 
- 					this.name = name;
 
- 					this.formatData(kejianUserVo.zhangList)
 
- 					this.list = kejianUserVo.zhangList;
 
- 					this.intro = intro;
 
- 					this.operId = operId;
 
- 					// 获取课程缓存 && 课件缓存(课件缓存点击后产生)
 
- 					let historyArrKecheng = getKechengDataFromHistory(this.operId)
 
- 					let sectionPageHistory = getKechengSectionPageFromHistory(this.operId)
 
- 					// 判断是否有前台缓存
 
- 					if (historyArrKecheng && sectionPageHistory) {
 
- 						// 有缓存---- 把start接口中,返回数据进度100%,更新到前台缓存
 
- 						const arrKecheng = mergeProgress(kejianUserVo && kejianUserVo.zhangList,
 
- 							historyArrKecheng);
 
- 						// 后台数据 同步前台缓存
 
- 						saveKechengData(this.operId, arrKecheng)
 
- 					} else {
 
- 						// 无缓存----把start接口中,返回的所有数据,更新到前台缓存
 
- 						saveKechengData(this.operId, kejianUserVo && kejianUserVo.zhangList)
 
- 					}
 
- 					// 初始化页面 常规数据
 
- 					initCourseProgressAll(this.operId)
 
- 					console.log('初始化播放首次')
 
- 					// 设置播放视频
 
- 					this.initFirstVideo();
 
- 				}).catch(err => {
 
- 					this.goUpPage();
 
- 				})
 
- 			}
 
- 		}
 
- 	}
 
- </script>
 
- <style>
 
- </style>
 
 
  |