|
@@ -523,44 +523,46 @@ Page({
|
|
|
|
|
|
|
|
// 将surveyData发送到服务器
|
|
// 将surveyData发送到服务器
|
|
|
console.log('提交的问卷数据:', 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({
|
|
// wx.showToast({
|
|
|
// title: '问卷提交成功',
|
|
// title: '问卷提交成功',
|