Bladeren bron

满意度调查问卷,提交到后台时,增加定时任务
这里可能存在一次提交不成功,所以加了定时任务,跑直到成功提交

hanchong 1 jaar geleden
bovenliggende
commit
2589d83a86
1 gewijzigde bestanden met toevoegingen van 39 en 37 verwijderingen
  1. 39 37
      subpages/sleepEvaluation/sleepEvaluation.js

+ 39 - 37
subpages/sleepEvaluation/sleepEvaluation.js

@@ -523,44 +523,46 @@ Page({
 
 		// 将surveyData发送到服务器  
 		console.log('提交的问卷数据:', surveyData);
-
-		//提交到数据库
-		wx.request({
-			url: `${homeApi}/system/sleepEvaluation`, //
-			method: 'POST',
-			header: {
-				'content-type': 'application/json', // 默认值
-				'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
-			},
-			data: surveyData,
-			success(res) {
-				console.log('res===' + JSON.stringify(res));
-				console.log('res.code===' + res.code);
-				if (res && res.data && res.data.code == 200) {
-					if (that.data.intervalId1) {
-						clearInterval(that.data.intervalId1);
-						that.data.intervalId1 = null;
-					}
-					wx.showToast({
-						title: '问卷提交成功',
-						icon: 'success',
-						duration: 2000,
-						success() {
-							setTimeout(() => {
-								wx.navigateBack()
-							}, 1500);
+		if (!that.data.intervalId1) {
+			that.data.intervalId1 = setInterval(() => {
+				//提交到数据库:这里可能存在一次提交不成功,所以加了定时任务,跑直到成功提交
+				wx.request({
+					url: `${homeApi}/system/sleepEvaluation`, //
+					method: 'POST',
+					header: {
+						'content-type': 'application/json', // 默认值
+						'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
+					},
+					data: surveyData,
+					success(res) {
+						console.log('res===' + JSON.stringify(res));
+						console.log('res.code===' + res.code);
+						if (res && res.data && res.data.code == 200) {
+							if (that.data.intervalId1) {
+								clearInterval(that.data.intervalId1);
+								that.data.intervalId1 = null;
+							}
+							wx.showToast({
+								title: '问卷提交成功',
+								icon: 'success',
+								duration: 2000,
+								success() {
+									setTimeout(() => {
+										wx.navigateBack()
+									}, 1500);
+								}
+							});
+				
 						}
-					});
-
-				}
-			},
-			fail: function (error) {
-				console.error('error', error);
-			},
-			complete: function (e) {
-			}
-		});
-
+					},
+					fail: function (error) {
+						console.error('error', error);
+					},
+					complete: function (e) {
+					}
+				});
+			}, 1000);
+		}
 
 		// wx.showToast({
 		// 	title: '问卷提交成功',