From 8d68e1cf927d116df7f194f89d5c7d80fd0264a2 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Wed, 18 Mar 2020 22:58:46 +0800 Subject: [PATCH] test part2 --- test_mini/pages/test/test.js | 101 +++++++++++++++++++++++++-------- test_mini/pages/test/test.wxml | 8 ++- test_mini/pages/test/test.wxss | 4 +- test_mini/utils/util.js | 23 +++++++- 4 files changed, 109 insertions(+), 27 deletions(-) diff --git a/test_mini/pages/test/test.js b/test_mini/pages/test/test.js index f384bc9..06a7e95 100644 --- a/test_mini/pages/test/test.js +++ b/test_mini/pages/test/test.js @@ -35,7 +35,7 @@ Page({ }) that.showTm(that.data.tmIndex) } - } catch (e) { } + } catch (e) { wx.navigateBack({}) } try { const res = wx.getSystemInfoSync() that.setData({ @@ -43,6 +43,14 @@ Page({ }) } catch (e) { } + let mil = that.data.monitest.limit * 60 * 1000 + let starttimes = (new Date()).getTime() //时间戳 + let endtimes = starttimes + mil + that.data.starttimes = starttimes + that.data.endtimes = endtimes + getApp().globalData.timer = setInterval(function () { + that.startpass() + }, 1000) }, /** * 生命周期函数--监听页面初次渲染完成 @@ -69,6 +77,7 @@ Page({ * 生命周期函数--监听页面卸载 */ onUnload: function () { + clearInterval(getApp().globalData.timer) }, /** @@ -91,7 +100,18 @@ Page({ onShareAppMessage: function () { }, + startpass: function () { + var mil = this.data.endtimes - (new Date()).getTime() + if (mil < 2000) { + clearInterval(getApp().globalData.timer) + this.handtest() + }; + var temp = util.formatmil(mil); + this.setData({ + countdown: temp, + }); + }, showTm: function (index) { var that = this var currentTm = that.data.tms[index] @@ -101,29 +121,27 @@ Page({ }) that.showOptions() }, - // panTi: function () { - // var that = this - // let currentTm = that.data.currentTm - // let isright = false - // if (currentTm.type == 2) { - // if (currentTm.userChecked) { - // if (currentTm.userChecked.sort().toString() == currentTm.right.sort().toString()) { - // isright = true - // } - // } + panTi: function (currentTm) { + let isright = false + if (currentTm.type == 2) { + if (currentTm.userChecked) { + if (currentTm.userChecked.sort().toString() == currentTm.right.sort().toString()) { + isright = true + } + } - // } else { - // isright = currentTm.right == currentTm.userChecked - // } - // if (isright == false && currentTm.userChecked != undefined) { - // currentTm.dtime = util.formatTime(new Date()) - // that.data.ctms.unshift(currentTm) - // if (that.data.ctms.length > 40) { - // that.data.ctms.length = 40 - // } - // } - // return isright - // }, + } else { + isright = currentTm.right == currentTm.userChecked + } + if (isright == false && currentTm.userChecked != undefined) { + currentTm.dtime = util.formatTime(new Date()) + that.data.ctms.unshift(currentTm) + if (that.data.ctms.length > 40) { + that.data.ctms.length = 40 + } + } + return isright + }, next: function () { var that = this var tmIndex = that.data.tmIndex + 1 @@ -154,4 +172,41 @@ Page({ options: options }) }, + hand: function () { + var that = this + for (i = 0, len = that.data.tms.length; i < len; i++) { + let tm = that.data.tms[i] + if (tm.userChecked == undefined || tm.length == 0){ + wx.showModal({ + title: '警告', + content: '答卷未完成,可点击答题卡复查!', + confirmText: "仍旧提交", + cancelText: "取消", + success: function (res) { + if (res.confirm) { + that.handtest() + } + } + }) + return + } + } + wx.showModal({ + content: '确定提交?', + confirmText: "确定", + cancelText: "取消", + success: function (res) { + if (res.confirm) { + that.handtest() + } + } + }) + }, + handtest: function (){ + wx.showLoading({ + title: '正在判卷中...', + mask:true + }) + + } }) \ No newline at end of file diff --git a/test_mini/pages/test/test.wxml b/test_mini/pages/test/test.wxml index c623c4c..7aeb0c2 100644 --- a/test_mini/pages/test/test.wxml +++ b/test_mini/pages/test/test.wxml @@ -1,5 +1,11 @@ - 题量: {{tmIndex+1}}/{{tmtotal}} + + 倒计时 {{countdown}} + + + 题量:{{tmIndex+1}}/{{tmtotal}} + + diff --git a/test_mini/pages/test/test.wxss b/test_mini/pages/test/test.wxss index 0ee5e6b..662adc2 100644 --- a/test_mini/pages/test/test.wxss +++ b/test_mini/pages/test/test.wxss @@ -3,7 +3,9 @@ height:30px; color:#fff; background-color: cornflowerblue; - text-align: center; + text-align: left; + display:flex; + flex-direction: row; } .btns{ height:40px; diff --git a/test_mini/utils/util.js b/test_mini/utils/util.js index dbadbb8..3cc2ba3 100644 --- a/test_mini/utils/util.js +++ b/test_mini/utils/util.js @@ -14,6 +14,25 @@ const formatNumber = n => { return n[1] ? n : '0' + n } -module.exports = { - formatTime: formatTime +function formatmil(mil) { + var allSecond = Math.floor(mil / 1000); + var h = Math.floor(allSecond / 3600); + var m = Math.floor((allSecond - h * 3600) / 60); + var s = Math.floor(allSecond - h * 3600 - m * 60); + h = toTow(h); + m = toTow(m); + s = toTow(s); + return h + ":" + m + ":" + s; +} +function toTow(num) { + if (num < 10) { + return "0" + num; + } else { + return num; + } +} + +module.exports = { + formatTime: formatTime, + formatmil: formatmil }