Explorar o código

学习-优化课程跳转时因多个请求loading会有闪烁和直播课程移除定时器

xuqiaoying %!s(int64=3) %!d(string=hai) anos
pai
achega
36c566e1f4
Modificáronse 3 ficheiros con 78 adicións e 32 borrados
  1. 5 1
      common/request.js
  2. 64 22
      pages/learn/index.vue
  3. 9 9
      pages3/live/detail.vue

+ 5 - 1
common/request.js

@@ -62,6 +62,9 @@ export const myRequest = (options) => {
 				// 	num++
 				// }
 				// doRequest(options)
+				if (!options.compleLoading) { // 请求的接口有带compleLoading 就不隐藏加载中
+					uni.hideLoading()
+				}
 				if (res.data.code == 401) {
 					if (num <= 2) {
 						if (!uni.getStorageSync('user_account')) {
@@ -91,6 +94,7 @@ export const myRequest = (options) => {
 				resolve(res)
 			},
 			fail: (err) => {
+				uni.hideLoading()
 				uni.showToast({
 					title: "请求接口失败",
 					icon: 'none'
@@ -98,7 +102,7 @@ export const myRequest = (options) => {
 				reject(JSON.stringify(err))
 			},
 			complete: () => {
-				uni.hideLoading()
+				// uni.hideLoading()
 				//		uni.hideToast()
 			}
 		})

+ 64 - 22
pages/learn/index.vue

@@ -687,7 +687,10 @@ export default {
 				})
 				return;
 			}
-
+			uni.showLoading({
+				title: '拼命加载中...',
+				mask:true,
+			})
 			var confirmDetail = true;
 			if (item.educationName == '继续教育') { 
 				if(item.officialName && item.businessName == '二级' && item.projectName == '建造师') { 
@@ -703,7 +706,7 @@ export default {
 			if (item.gradeStatus == 1 && item.status == 1 && (item.serviceEndTime > this.sysTime) && (item
 					.classEndTime && (item.classEndTime < this.sysTime)) && (item.periodStatus == 0 || item
 					.periodStatus == -1) && item.studyCount > 0) {
-				this.selectClass(item, index)
+				this.selectClass(item, index, 'loading')
 				return
 			}
 
@@ -711,6 +714,7 @@ export default {
 			let rebuildStatus = await this.courseGoodsRebuildStatus(item.goodsId, item.gradeId)
 
 			if (rebuildStatus == 0) {
+				uni.hideLoading()
 				this.$navTo.togo('/pages2/learn/details', {
 					gradeId: item.gradeId,
 					goodsId: item.goodsId,
@@ -734,13 +738,26 @@ export default {
 					} else if (res.data.code == 500) { //可以学习
 						// if (item.courseNum == 1) { // 课程数量
 							// /course/courseList查询商品下的课程列表
-							this.$api.courseCourseList({
-								pageNum: 1,
-								pageSize: 1,
-								goodsId: item.goodsId,
-								gradeId: item.gradeId,
-								orderGoodsId: item.orderGoodsId,
-							}).then(res => {
+							// this.$api.courseCourseList({
+							// 	pageNum: 1,
+							// 	pageSize: 1,
+							// 	goodsId: item.goodsId,
+							// 	gradeId: item.gradeId,
+							// 	orderGoodsId: item.orderGoodsId,
+							// })
+							this.$http({
+								url: '/course/courseList',
+								method: 'get',
+								data: {
+									pageNum: 1,
+									pageSize: 1,
+									goodsId: item.goodsId,
+									gradeId: item.gradeId,
+									orderGoodsId: item.orderGoodsId,
+								},
+								noLoading: true
+							})
+							.then(res => {
 								if (res.data.code == 200) {
 
 									if(res.data.total > 1) {
@@ -772,19 +789,37 @@ export default {
 		 */
 		courseGoodsRebuildStatus(goodsId, gradeId) {
 			return new Promise(resolve => {
-				this.$api.courseGoodsRebuildStatus({
-					goodsId: goodsId,
-					gradeId: gradeId
-				}).then(res => {
+				// this.$api.courseGoodsRebuildStatus({
+				// 	goodsId: goodsId,
+				// 	gradeId: gradeId
+				// })
+				this.$http({
+					url: '/course/goodsRebuildStatus',
+					method: 'get',
+					data: {
+						goodsId: goodsId,
+						gradeId: gradeId
+					},
+					noLoading: true,
+					compleLoading: true, // 请求成功是否还要继续显示加载中
+				})
+				.then(res => {
 					resolve(res.data.data)
 				})
 			})
 		},
 		userConfirmInfoDetail(){
 			return new Promise(resolve => {
-				this.$api.userConfirmInfoDetail({
-					orderGoodsId:this.activeItem.orderGoodsId,
-				}).then(res => {
+				// this.$api.userConfirmInfoDetail({
+				// 	orderGoodsId:this.activeItem.orderGoodsId,
+				// })
+				this.$http({
+					url: '/user/confirm/info/detail',
+					method: 'GET',
+					data: { orderGoodsId:this.activeItem.orderGoodsId },
+					noLoading:true,
+				})
+				.then(res => {
 					if(!res.data.data) {
 						clearInterval(this.confirmTimer);
 						this.confirmCount = 10;
@@ -813,16 +848,23 @@ export default {
 				})
 			})
 		},
-		selectClass(item, index) {
+		selectClass(item, index, load) {
 			this.itemIndex = index;
 			this.selectItem = item;
 			this.selectClassModal = true;
-			this.goodsGradeList(item.goodsId);
+			this.goodsGradeList(item.goodsId, load);
 		},
-		goodsGradeList(id) {
-			this.$api.goodsGradeList({
-				goodsId: id
-			}).then(res => {
+		goodsGradeList(id, load) {
+			// this.$api.goodsGradeList({
+			// 	goodsId: id
+			// })
+			this.$http({
+				url: '/grade/grade/list',
+				method: 'get',
+				data: { goodsId: id },
+				noLoading: load ? true : false,
+			})
+			.then(res => {
 				if (res.data.code == 200) {
 					this.gradeList = res.data.rows
 					if (this.gradeList.length == 0) {

+ 9 - 9
pages3/live/detail.vue

@@ -673,7 +673,7 @@ export default {
     this.$store.commit("setPlayChannelId", { playChannelId: 0 });
     this.$store.commit("setPlayVID", { playVID: null });
     this.closePlv();
-    console.log("onUnload");
+    // console.log("onUnload");
     //移除所有的事件监听器
     uni.$off();
     clearInterval(this.answerTimer);
@@ -681,14 +681,14 @@ export default {
       clearInterval(this.timer);
     }
     // console.log(this.lockTimer, "this.lockTimer");
-    // if (this.lockTimer) {
-    //   clearInterval(this.lockTimer);
-    //   this.$api
-    //     .lockDelLock({
-    //       action: "jxjy",
-    //     })
-    //     .then((res) => {});
-    // }
+    if (this.lockTimer) {
+      clearInterval(this.lockTimer);
+      this.$api
+        .lockDelLock({
+          action: "jxjy",
+        })
+        .then((res) => {});
+    }
     // websocket.sendMsg("delAction");
   },
   mounted() {