examtest/test_mini/pages/test/test.js

212 lines
4.8 KiB
JavaScript

// pages/lianxi/main.js
const api = require("../../utils/request.js");
var util = require('../../utils/util.js')
Page({
/**
* 页面的初始数据
*/
data: {
tms:[],
tmIndex: 0,
},
radioChange: function (e) {
var that = this
that.data.currentTm['userChecked'] = e.detail.value
that.data.tms[that.data.tmIndex] = that.data.currentTm
},
checkboxChange: function (e) {
var that = this
that.data.currentTm['userChecked'] = e.detail.value
that.data.tms[that.data.tmIndex] = that.data.currentTm
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function () {
var that = this
try {
var value = wx.getStorageSync('monitest')
if (value) {
that.data.monitest = value
that.data.tms = value.questions
that.setData({
tmtotal:value.questions.length
})
that.showTm(that.data.tmIndex)
}
} catch (e) { wx.navigateBack({}) }
try {
const res = wx.getSystemInfoSync()
that.setData({
scrollHeight: res.windowHeight - 70
})
} 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)
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
wx.hideHomeButton({})
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
clearInterval(getApp().globalData.timer)
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
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]
that.setData({
'tmIndex': index,
'currentTm': currentTm
})
that.showOptions()
},
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
},
next: function () {
var that = this
var tmIndex = that.data.tmIndex + 1
that.showTm(tmIndex)
},
previous: function () {
var that = this
var tmIndex = that.data.tmIndex - 1
that.showTm(tmIndex)
},
showOptions: function () {
let currentTm = this.data.currentTm
let options = []
for (let key in currentTm.options) {
let option = {}
option.key = key
option.value = key + ':' + currentTm.options[key]
if (currentTm.userChecked) {
if (key == currentTm.userChecked || currentTm.userChecked.indexOf(key) != -1) {
option.checked = true
}
} else {
option.checked = false
}
options.push(option)
}
this.setData({
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
})
}
})