diff --git a/app.js b/app.js index f4b4f64..2b79967 100644 --- a/app.js +++ b/app.js @@ -95,11 +95,11 @@ App({ openid:null }, serverUrl: 'https://safeyun.ctcshe.com/', - //serverUrl: 'http://127.0.0.1:8001/', + //serverUrl: 'http://127.0.0.1:8000/', //serverUrl: 'http://10.21.28.148:8000/', - //serverUrl: 'http://192.168.0.107:8000/', + //serverUrl: 'http://192.168.0.103:8000/', //serverUrl:'http://10.0.11.195:8000/', - timepass:null //定时器 + timer:null //定时器 }, }) \ No newline at end of file diff --git a/pages/examtest/main.js b/pages/examtest/main.js index 9137bf9..aa63f9f 100644 --- a/pages/examtest/main.js +++ b/pages/examtest/main.js @@ -8,7 +8,9 @@ Page({ data: { tmIndex: 0, answerChoices:[], - ydtm:0 + ydtm:0, + took:0, + handdisable:false }, tmdata: { @@ -63,8 +65,9 @@ Page({ * 生命周期函数--监听页面加载 */ onLoad: function (options) { + var that = this if(options.id){ - this.setData({ + that.setData({ testid:options.id }) wx.showLoading({}) @@ -79,13 +82,20 @@ Page({ console.log(res.data) let tms = res.data - this.tmdata = tms + that.tmdata = tms console.log(tms.duration) let mil = tms.duration * 60 * 1000 - console.log(mil) - this.begin(mil) - this.showTm(0) - this.setData({ + let starttimes = (new Date()).getTime() //时间戳 + let endtimes = starttimes + mil + // console.log(new Date(endtime)) + // console.log(mil) + that.data.starttimes = starttimes + that.data.endtimes = endtimes + getApp().globalData.timer = setInterval(function(){ + that.startpass() + }, 1000) + that.showTm(0) + that.setData({ tmtotal: tms.tms.length, starttime: tms.starttime }) wx.hideLoading() @@ -133,6 +143,7 @@ Page({ // } // } // }) + clearInterval(getApp().globalData.timer) }, /** @@ -155,26 +166,25 @@ Page({ onShareAppMessage: function () { }, - begin: function (mil) { + startpass:function(){ + var mil = this.data.endtimes - (new Date()).getTime() + console.log('定时器在走!') + if (mil < 2000) { + clearInterval(getApp().globalData.timer) + wx.showLoading({ + title: '时间到,正在交卷..', + }); + if( this.data.handdisable == false){ + this.handtest() + } + + return + }; var temp = formatmil(mil); this.setData({ countdown: temp, }); - - if (mil < 1000) { - wx.showLoading({ - title: '时间到,正在交卷..', - }); - this.handtest() - return - }; - - getApp().globalData.timepass=setTimeout( - () => { - mil -= 1000; - this.begin(mil); - }, 1000 - ); + }, showTm: function (index) { var that = this @@ -262,33 +272,42 @@ Page({ } }, handtest:function(){ - var data={ - 'testid': this.data.testid, - 'starttime':this.data.starttime, - 'endtime': util.formatTime(new Date()), - 'sheet':this.tmdata.tms - } - wx.showLoading({ - title: '自动判卷中..', - }) - wx.request({ - url: getApp().globalData.serverUrl + 'api/examtestdetail?a=handtest&id=' + this.data.testid, - header: { - 'content-type': 'application/json', // 默认值 - 'Cookie': wx.getStorageSync("sessionid"), - }, - method: 'POST', - data: data, - success: res => { - if (res.statusCode === 200) { - wx.hideLoading() - wx.redirectTo({ - url: 'result?' + parseParams(res.data.data), - }) - clearTimeout(getApp().globalData.timepass) - } + clearInterval(getApp().globalData.timer) + if(this.data.handdisable == false){ + this.setData({ + handdisable: true + }) + var data = { + 'testid': this.data.testid, + 'starttime': this.data.starttime, //服务器时间 + 'endtime': util.formatTime(new Date()), + 'sheet': this.tmdata.tms, + 'took': Math.floor(((new Date()).getTime() - this.data.starttimes) / 1000) } - }); + wx.showLoading({ + title: '自动判卷中..', + mask: true + }) + wx.request({ + url: getApp().globalData.serverUrl + 'api/examtestdetail?a=handtest&id=' + this.data.testid, + header: { + 'content-type': 'application/json', // 默认值 + 'Cookie': wx.getStorageSync("sessionid"), + }, + method: 'POST', + data: data, + success: res => { + if (res.statusCode === 200) { + clearInterval(getApp().globalData.timer) + wx.hideLoading() + wx.redirectTo({ + url: 'result?' + parseParams(res.data.data), + }) + } + } + }); + } + } }) function formatmil(mil) { diff --git a/pages/examtest/main.wxml b/pages/examtest/main.wxml index 923bc9b..fd8e39b 100644 --- a/pages/examtest/main.wxml +++ b/pages/examtest/main.wxml @@ -45,6 +45,6 @@ - + \ No newline at end of file diff --git a/pages/examtest/note.js b/pages/examtest/note.js index 1f37994..fad3380 100644 --- a/pages/examtest/note.js +++ b/pages/examtest/note.js @@ -33,6 +33,7 @@ Page({ } wx.showLoading({ title: '加载中', + mask:true }) wx.request({ url: getApp().globalData.serverUrl + 'api/examtest?a=detail&id='+examtestid, diff --git a/pages/examtest/note2.js b/pages/examtest/note2.js index a90a667..ddd11f0 100644 --- a/pages/examtest/note2.js +++ b/pages/examtest/note2.js @@ -25,6 +25,7 @@ Page({ }) wx.showLoading({ title: '加载中', + mask: true }) wx.request({ url: getApp().globalData.serverUrl + 'api/examtest?a=detail&id=' + examtestid, diff --git a/pages/totalrate/index.wxml b/pages/totalrate/index.wxml index f13d3db..a0f8f50 100644 --- a/pages/totalrate/index.wxml +++ b/pages/totalrate/index.wxml @@ -5,7 +5,7 @@ 人参与 更新时间:{{updatetime}} - +