瀏覽代碼

全局事件

he2802 3 年之前
父節點
當前提交
38d6a0f18b
共有 3 個文件被更改,包括 30 次插入29 次删除
  1. 3 3
      components/course/courseSection.vue
  2. 5 5
      pages2/class/detail.vue
  3. 22 21
      pages2/course/detail.vue

+ 3 - 3
components/course/courseSection.vue

@@ -96,13 +96,13 @@ export default {
 			if(this.playSectionId){
 				//切换视频
 				let oldSectionId = this.playSectionId
-				eventHub.$emit('changeSection', oldSectionId)
+				uni.$emit('changeSection', oldSectionId)
 			}
 			//设置播放的节ID
 			this.$store.commit('setPlaySectionId', {playSectionId  :this.newId});
 	//		return
-			eventHub.$emit('getSection', this.menuItem)
-			eventHub.$emit('levelId', this.levelId)
+			uni.$emit('getSection', this.menuItem)
+			uni.$emit('levelId', this.levelId)
 			
 		}
 	},

+ 5 - 5
pages2/class/detail.vue

@@ -147,7 +147,6 @@
 </template>
 
 <script>
-import eventHub from '@/common/eventHub.js';
 import courseModule from '@/components/course/courseModule.vue';
 import courseChapter from '@/components/course/courseChapter.vue';
 import courseSection from '@/components/course/courseSection.vue';
@@ -219,7 +218,6 @@ export default {
 			needSeek: false //第一次播放是否需要跳转
 		};
 	},
-	onUnload() {},
 	computed: { ...mapGetters(['userInfo', 'playSectionId']) },
 	onLoad(option) {
 		this.courseId = Number(option.id);
@@ -319,17 +317,19 @@ export default {
 			this.postStudyRecord();
 			//清除正在播放的节ID
 			this.$store.commit('setPlaySectionId', { playSectionId: 0 });
+			//移除所有的事件监听器
+			uni.$off();
 		}
 	},
 	mounted() {
-		eventHub.$on('changeSection', oldSectionId => {
+		uni.$on('changeSection', oldSectionId => {
 			this.ossAvatarUrl = '';
 			this.postStudyRecord(0, oldSectionId);
 		});
-		eventHub.$on('getSection', item => {
+		uni.$on('getSection', item => {
 			this.playVideo(item);
 		});
-		eventHub.$on('levelId', item => {
+		uni.$on('levelId', item => {
 			let arr = item.split('-');
 			//点击节获取的各层级ID
 			this.moduleId = arr[0];

+ 22 - 21
pages2/course/detail.vue

@@ -80,7 +80,6 @@
 </template>
 
 <script>
-import eventHub from '@/common/eventHub.js';
 import courseModule from '@/components/course/courseModule.vue';
 import courseChapter from '@/components/course/courseChapter.vue';
 import courseSection from '@/components/course/courseSection.vue';
@@ -116,9 +115,6 @@ export default {
 			timer:null,
 			startTime:0
 		};
-	},
-	onUnload() {
-		
 	},
 	computed: { ...mapGetters(['userInfo','goodsAuditionConfigIdList','playSectionId']) },
 	onLoad(option) {
@@ -126,38 +122,43 @@ export default {
 		this.getDetail()
 		this.goodsCourseList()
 	},
+	onUnload(option) {
+		this.$store.commit('setPlaySectionId', {playSectionId  :0});
+		//移除所有的事件监听器
+		uni.$off();
+	},
 	mounted() {
-		eventHub.$on('getSection', item => {
-			console.log('播放')
+		let self = this
+		uni.$on('getSection', item => {
 			//播放试听
-			this.listenSecond = 0
-			for (var itemChild of this.listenConfigList) {
-				if(itemChild.sectionId==this.playSectionId){
+			self.listenSecond = 0
+			for (var itemChild of self.listenConfigList) {
+				if(itemChild.sectionId==self.playSectionId){
 					if(itemChild.auditionMinute>0){
-						this.listenSecond = itemChild.auditionMinute *60 //试听秒数
+						self.listenSecond = itemChild.auditionMinute *60 //试听秒数
 					}
 				}
 			}
-			
-			if(this.listenSecond>0){
-				if(this.timer){
-					clearInterval(this.timer);
+			if(self.listenSecond>0){
+				if(self.timer){
+					clearInterval(self.timer);
 				}
-				 if(this.vid){
+				 if(self.vid){
 					 //切换视频
-					 var polyvPlayerContext = this.selectComponent('#playerVideo');
+					 var polyvPlayerContext = self.selectComponent('#playerVideo');
 					 polyvPlayerContext.changeVid(item.recordingUrl)
 				 }else{
-					 this.vid = item.recordingUrl
+					 self.vid = item.recordingUrl
 				 }
 				
-				this.startStatus = true
-				this.startTime = 0
+				self.startStatus = true
+				self.startTime = 0
 			}else{
-				this.$u.toast('试听配置错误');
+				
+				self.$u.toast('试听配置错误');
 			}
 			
-		});
+		})
 	},
 	methods: {
 		onStateChange(newstate, oldstate) {