A 试卷倒计时

master
educoder_weapp 5 years ago
parent f62731e1a3
commit bfd7f13a58

@ -5,9 +5,10 @@ const developUrl = "https://test-newweb.educoder.net";
const trialUrl = "https://pre-newweb.educoder.net"; const trialUrl = "https://pre-newweb.educoder.net";
const releaseUrl = "https://www.educoder.net"; const releaseUrl = "https://www.educoder.net";
let _version = "0.15.1"; let _version = "0.15.2";
var eduUrl = releaseUrl; var eduUrl = releaseUrl;
/** /**
* A 试卷倒计时
*/ */
export function switchEnv(env) { export function switchEnv(env) {

@ -1,35 +1,6 @@
var throttle = function throttle(func, wait, options) { import {throttle} from "../../../js/utils";
var context = void 0;
var args = void 0;
var result = void 0;
var timeout = null;
var previous = 0;
if (!options) options = {};
var later = function later() {
previous = options.leading === false ? 0 : Date.now();
timeout = null;
result = func.apply(context, args);
if (!timeout) context = args = null;
};
return function () {
var now = Date.now();
if (!previous && options.leading === false) previous = now;
var remaining = wait - (now - previous);
context = this;
args = arguments;
if (remaining <= 0 || remaining > wait) {
clearTimeout(timeout);
timeout = null;
previous = now;
result = func.apply(context, args);
if (!timeout) context = args = null;
} else if (!timeout && options.trailing !== false) {
timeout = setTimeout(later, remaining);
}
return result;
};
};
Component({ Component({
options: { options: {
addGlobalClass: true, addGlobalClass: true,

@ -15,6 +15,7 @@ Component({
console.log(this.data); console.log(this.data);
let {course_identity,course_id,data:{mode, code, id:attendance_id}} = this.data; let {course_identity,course_id,data:{mode, code, id:attendance_id}} = this.data;
if(course_identity==5&&mode=="QUICK"){ if(course_identity==5&&mode=="QUICK"){
wx.reportAnalytics('tap_quick_attendance_button', {});
this.quickAttendance(); this.quickAttendance();
}else{ }else{
app.navigateTo({url:`{attendance_detail}?course_identity=${course_identity}&course_id=${course_id}&code=${code||''}&mode=${mode||''}&attendance_id=${attendance_id}`}); app.navigateTo({url:`{attendance_detail}?course_identity=${course_identity}&course_id=${course_id}&code=${code||''}&mode=${mode||''}&attendance_id=${attendance_id}`});

@ -1,10 +1,18 @@
import {throttle} from "../../../js/utils";
const app = getApp(); const app = getApp();
Page({ Page({
data: { data: {
exercise_questions: [], exercise_questions: [],
loading: true, loading: true,
exercise: {} exercise: {},
count_down:'试卷不限时'
},
scrollToAnswerSheet(){
wx.pageScrollTo({
selector:".exercise-status"
})
}, },
scrollToQues(e){ scrollToQues(e){
let {target: {dataset:{ques_id}}} = e; let {target: {dataset:{ques_id}}} = e;
@ -19,6 +27,71 @@ Page({
let {detail:{q_position,answered}} = e; let {detail:{q_position,answered}} = e;
let key = "question_status[" + (q_position - 1) +"].ques_status" let key = "question_status[" + (q_position - 1) +"].ques_status"
this.setData({[key]: answered}); this.setData({[key]: answered});
this.refreshAnsweredCount();
},
startCountDown({left_time}){
var left = left_time;
var setCountDown = (time)=>{
let s = time%60;
let m = parseInt(time/60)%60;
let h = parseInt(time/3600);
if(s<10)
s = '0' +s;
if(m<10)
m = '0' + m;
if(h<10)
h = '0' + h;
let count_down = h + ":" + m + ":" + s;
this.setData({count_down});
}
setCountDown(--left);
var id = setInterval(()=>{
if(left<=1){
return this.stopCountDown(id);
}
setCountDown(--left);
},1000);
},
stopCountDown(id){
clearInterval(id);
var showToast = throttle(wx.showToast, 800, {});//延时Toast
showToast({
title: '时间已到,系统自动为你提交中',icon:"none"
})
app.api("exercises.commit_exercise")({exercise_id:this.exercise_id, commit_method:2})
.then(res=>{
showToast({
title: "试卷提交成功!"
});
//this.pull_questions();
}).catch(e=>{
//app.showError(e);
var title = '提交失败';
//if(e.code==-2)
// title = '您未作答任何题';
showToast({
title,
icon:"none"
});
let db = wx.cloud.database();
db.collection("data").add({
data: {
name: "exercises.commit_exercise",
e,
createdAt: db.serverDate()
}
});
})
this.setData({count_down: '考试时间已截止'});
},
refreshAnsweredCount(){
if(!this.data.question_status)
return;
let answered_count = 0;
this.data.question_status.map(i=>{
answered_count += i.ques_status;
});
this.setData({answered_count});
}, },
pull_questions: function(){ pull_questions: function(){
app.api("exercises.start_answer")({exercise_id: this.exercise_id}) app.api("exercises.start_answer")({exercise_id: this.exercise_id})
@ -26,10 +99,14 @@ Page({
console.log("pull questions"); console.log("pull questions");
this.setData(res); this.setData(res);
this.setData({loading: false}); this.setData({loading: false});
}).catch(e => { if(this.data.question_status)
this.setData({status:e.code}); this.refreshAnsweredCount();
app.showError(e); if(res.exercise.left_time)
}); this.startCountDown({left_time: res.exercise.left_time});
}).catch(e => {
this.setData({status:e.code});
app.showError(e);
});
}, },
save_exercise: function({show_loading=true}={}){ save_exercise: function({show_loading=true}={}){
if(show_loading){ if(show_loading){
@ -51,44 +128,49 @@ Page({
}, },
commit_exercise: function(){ commit_exercise: function(){
let { question_status} = this.data; //wx.showLoading({title: '检查作答情况中'});
var answered = 1; app.api("exercises.begin_commit")({ exercise_id: this.exercise_id})
for(var ques of question_status){ .then(resp=>{
if (!ques.ques_status){ let {question_undo, shixun_undo} = resp;
answered = 0; if(question_undo==0)
break; var content = "交卷后无法更改作答,是否确认?"
} else {
} var content = "您还有"+question_undo+"题未作答";
var content = answered?'交卷后不能更改答案,确认交卷吗':'您还有题目未作答,交卷后无法更改,确认吗'; if(shixun_undo>0)
wx.showModal({ content += ",包含"+shixun_undo+"道实训题";
title: '确认', content +=",是否现在交卷呢?";
content, }
success: res=>{ //wx.hideLoading();
if(res.confirm){ wx.showModal({
app.api("exercises.begin_commit")({ exercise_id: this.exercise_id}) title:"提示",
.then( content,
()=>{ success:res=>{
if(res.confirm){
app.api("exercises.commit_exercise")({exercise_id: this.exercise_id}) app.api("exercises.commit_exercise")({exercise_id: this.exercise_id})
.then(res=>{ .then(res=>{
console.log("交卷"); console.log("交卷");
console.log(res); console.log(res);
app.showMsg(res); app.showMsg(res);
setTimeout(()=>{ setTimeout(()=>{
wx.navigateBack({ wx.navigateBack({
delta:1 delta:1
}) })
}, 800); }, 800);
}).catch(e=>{ })
app.showError(e); .catch(e=>{
console.error(e); app.showError(e);
}); console.error(e);
}).catch(e=>{ });
}
}
})
})
.catch(e=>{
app.showError(e); app.showError(e);
console.error(e); console.error(e);
}); });
}
}
})
}, },
onLoad: function (options) { onLoad: function (options) {
this.exercise_id = options.exercise_id; this.exercise_id = options.exercise_id;

@ -3,23 +3,38 @@
</page-meta> </page-meta>
<!--exercise-score wx:if="{{exercise.exercise_scores}}" data="{{exercise.exercise_scores}}"/--> <!--exercise-score wx:if="{{exercise.exercise_scores}}" data="{{exercise.exercise_scores}}"/-->
<block wx:if="{{question_status&&exercise.user_exercise_status!=1&&exercise.user_exercise_status!=4}}">
<view class="header">
<view class="left-time">倒计时:{{count_down}}</view>
<view class="count-down"></view>
<view bindtap="scrollToAnswerSheet" class="answer-count">
<view>答题卡</view>
<view class="answer-count-num">{{answered_count}}/{{question_status.length}}</view>
</view>
</view>
<view class="header-place-holder"></view>
</block>
<view class="exercise-score" wx:if="{{exercise_scores}}"> <view class="exercise-score" wx:if="{{exercise_scores}}">
<view class="user-score">总分 <view class="user-score">总分
<text class="color-main total-score">{{user_score}}</text>/{{exercise_types.q_scores}}</view> <text class="color-main total-score">{{user_score}}</text>/{{exercise_types.q_scores}}</view>
<view>客观题</view> <block wx:if="{{exercise_scores.objective_scores.length>0}}">
<view class="scores" bindtap="scrollToQues"> <view>客观题</view>
<view class="score-item" data-ques_id="{{item.ques_id}}" wx:for="{{exercise_scores.objective_scores}}"> <view class="scores" bindtap="scrollToQues">
{{item.ques_position}} <view class="score-item" data-ques_id="{{item.ques_id}}" wx:for="{{exercise_scores.objective_scores}}">
<view class="score {{item.answer_status==1?'right':'wrong'}}">{{item.user_score||'未评分'}}</view> {{item.ques_position}}
<view class="score {{item.answer_status==1?'right':'wrong'}}">{{item.user_score||'未评分'}}</view>
</view>
</view> </view>
</view> </block>
<view>主观题</view> <block wx:if="{{exercise_scores.subjective_scores.length>0}}">
<view class="scores" bindtap="scrollToQues"> <view>主观题</view>
<view class="score-item" data-ques_id="{{item.ques_id}}" wx:for="{{exercise_scores.subjective_scores}}"> <view class="scores" bindtap="scrollToQues">
{{item.ques_position}} <view class="score-item" data-ques_id="{{item.ques_id}}" wx:for="{{exercise_scores.subjective_scores}}">
<view class="score {{item.answer_status==1?'right':'wrong'}}">{{item.user_score||'未评分'}}</view> {{item.ques_position}}
<view class="score {{item.answer_status==1?'right':'wrong'}}">{{item.user_score||'未评分'}}</view>
</view>
</view> </view>
</view> </block>
</view> </view>
<view bindanswer="onAnswer"> <view bindanswer="onAnswer">
<view class="question-wrap" wx:for="{{exercise_questions}}" wx:key="question_id"> <view class="question-wrap" wx:for="{{exercise_questions}}" wx:key="question_id">

@ -1,6 +1,43 @@
page{ page{
overflow-x: hidden; overflow-x: hidden;
} }
.header{
position: fixed;
top: 0;
background: white;
display: flex;
align-items: center;
height: 40px;
width: 100%;
z-index: 1000;
justify-content: space-evenly;
font-size: 15px;
box-shadow: 2px 2px 2px #dddddd;
}
.left-time{
padding: 0 8px 0 12px;
}
.count-down{
flex:auto;
text-align: center;
}
.answer-count{
padding: 0 12px 0 8px;
font-size: 13px;
color: #0095f0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.answer-count-num{
font-size: 11px;
}
.header-place-holder{
height: 40px;
}
.user-score{ .user-score{
text-align: center; text-align: center;
font-size: 18px; font-size: 18px;

@ -236,3 +236,35 @@ export function navigateToUrl({url,open_type='navigateTo'}){
}else }else
return false; return false;
} }
export function throttle(func, wait, options) {
var context = void 0;
var args = void 0;
var result = void 0;
var timeout = null;
var previous = 0;
if (!options) options = {};
var later = function later() {
previous = options.leading === false ? 0 : Date.now();
timeout = null;
result = func.apply(context, args);
if (!timeout) context = args = null;
};
return function () {
var now = Date.now();
if (!previous && options.leading === false) previous = now;
var remaining = wait - (now - previous);
context = this;
args = arguments;
if (remaining <= 0 || remaining > wait) {
clearTimeout(timeout);
timeout = null;
previous = now;
result = func.apply(context, args);
if (!timeout) context = args = null;
} else if (!timeout && options.trailing !== false) {
timeout = setTimeout(later, remaining);
}
return result;
};
};

@ -7,7 +7,7 @@
<scroll-view class="challenge-body {{theme}}" scroll-y="1"> <scroll-view class="challenge-body {{theme}}" scroll-y="1">
<block wx:if="{{challenge}}"> <block wx:if="{{challenge}}">
<view class="subject {{theme}}">第{{challenge.position}}关:{{challenge.subject}}</view> <view class="subject {{theme}}">第{{challenge.position}}关:{{challenge.subject}}</view>
<view class="switch-wrap {{theme}}">黑暗模式(测试功能)<switch class="theme-switch" bindchange="switchTheme" color="dimgrey" checked="{{theme=='dark'}}"></switch></view> <view class="switch-wrap {{theme}}">黑暗模式<switch class="theme-switch" bindchange="switchTheme" color="dimgrey" checked="{{theme=='dark'}}"></switch></view>
</block> </block>
<rich-md nodes="{{challenge.task_pass}}" type="markdown" theme="{{theme}}"/> <rich-md nodes="{{challenge.task_pass}}" type="markdown" theme="{{theme}}"/>
</scroll-view> </scroll-view>

@ -109,7 +109,7 @@
"id": 6, "id": 6,
"name": "course/pages/course/course", "name": "course/pages/course/course",
"pathName": "course/pages/course/course", "pathName": "course/pages/course/course",
"query": "course_id=5141&module_type=teachers", "query": "course_id=5141&module_type=exercise",
"scene": null "scene": null
}, },
{ {

Loading…
Cancel
Save