- 系统管理模块(用户/角色/组织/权限/日志) - 教育培训计划管理模块 - 教育培训实施模块 - 考试管理模块 - 调研问卷管理模块 - 外派培训管理模块 - 年度培训总结模块 - 学习资源管理模块 - 任职资格管理模块 - 即时通讯模块 - APP 版本管理 - 统计分析模块(FineReport) - 代码审查标准和报告(CODE_REVIEW_GUIDE.md, CODE_REVIEW_REPORT.md) - 项目开发指南(PROJECT_GUIDE.md)
621 lines
20 KiB
JavaScript
621 lines
20 KiB
JavaScript
//用户答题界面
|
||
var webroot = $("#hdWebroot").val();
|
||
var rootUrl = webroot + '/exam/exam/';
|
||
var deleteUrl = rootUrl + 'delete';//删除地址
|
||
var editexamPage =rootUrl + 'editexampaperPage';//编辑页面地址
|
||
var saveUrl = rootUrl + 'save';//保存添加数据地址
|
||
var isNotSubmitUrl = rootUrl + 'isNotSubmit';//判断是否已提交试卷是否已答题
|
||
|
||
var titlename;//试卷名称
|
||
var UserEdit_id;//试卷id
|
||
var sc;//考试时长
|
||
var counttime;//总秒钟
|
||
var submit_flag = 0;//未提交试卷0,已提交试卷1
|
||
var vartt;
|
||
|
||
$(function () {
|
||
//------------------------属性-------------------------------------
|
||
var listUrl = rootUrl + 'list';//分页数据地址
|
||
|
||
var userTestUrl = rootUrl + 'userTestList';//用户答题-答题-查询
|
||
|
||
var dialogSize = {width: 800, height: '80%'};//弹出窗口大小
|
||
var dialog = $('#dialog');
|
||
var grid_form = $('#grid_form');
|
||
var grid = $('#grid');
|
||
|
||
var pg = "";//控制考试与调研页面交替,1考试2调研
|
||
pg = $('#pg').val();
|
||
|
||
//-----------------------初始化--------------------------------------
|
||
initexamsGrid();
|
||
// addFilter();
|
||
addEvents();
|
||
|
||
//-------------------------------------方法--------------------------------------------------------
|
||
function initexamsGrid() {
|
||
//初始化搜索框
|
||
$('#searchbox').uiSearchbox({
|
||
width: 240,
|
||
prompt: '试卷名称|试卷类别',
|
||
searcher: function (v) {
|
||
grid.uiGrid('loadData', {queryParams: {key: $.trim(v)}, pageIndex: 1});
|
||
}
|
||
});
|
||
//初始化grid
|
||
grid.uiGrid({
|
||
url: listUrl,
|
||
queryParams:{pg: pg},
|
||
defaultSortField: 'edittime'
|
||
});
|
||
}
|
||
|
||
//初始化表单 用户答题——答题
|
||
var formeditexamInit = function () {
|
||
|
||
var eqlist2 = $('#eqlist2');
|
||
|
||
eqlist2.uiGrid({
|
||
autoFit: true,
|
||
border: false,
|
||
colFit: true,
|
||
gridTitleFix: false,
|
||
width: "100%",
|
||
height: "80%",
|
||
showHeader: false,
|
||
icon: 'list',
|
||
pageSize: 50,
|
||
url:userTestUrl,
|
||
queryParams: {UserEdit_id: grid.uiGrid('selectedData', 'id')[0]},//从前端获取,向后台传递参数
|
||
|
||
defaultSortField: 'num'
|
||
});
|
||
|
||
// daojishi();
|
||
|
||
};
|
||
|
||
//初始化弹出窗口 用户答题——答题
|
||
var editexam_dialog = $('#editexam_dialog').uiDialog({
|
||
title: '新建',
|
||
icon: 'list',
|
||
width:"95%",
|
||
height:"95%",
|
||
mask: true,
|
||
showBtnBar: true,
|
||
updateOnOpen: true,
|
||
lazyLoad: true,
|
||
url: editexamPage,
|
||
queryParams:{pg: pg},
|
||
onLoadComplete: formeditexamInit,
|
||
onOpen: function () {
|
||
var dialogP = $('#editexam_dialog').uiDialog('getUserParam');
|
||
var id = dialogP.id;
|
||
|
||
setTimeout( function(){
|
||
setStatistic();
|
||
},100);
|
||
},
|
||
onClose:function(){
|
||
window.clearTimeout(vartt);//停止倒计时
|
||
},
|
||
onPanelResize: function () {
|
||
// setStatistic();//将计算题数和总分的方法放在了组件改变大小时触发,不合理,考虑用SQL语句初始化出来
|
||
},
|
||
buttons: [
|
||
// {
|
||
// id: 'btnOK',
|
||
// label: '保存',
|
||
// style: 'button_submit',
|
||
// icons: {left: 'icon_submit'},
|
||
// disabled: false,
|
||
// onClick: function () {
|
||
// $.uiMessagebox.confirm({
|
||
// title: '确认操作',
|
||
// content: "保存成功!请在考试时间内及时点击提交!",
|
||
// onClose: function (value) {
|
||
// if (value){
|
||
// submitExam();
|
||
// }
|
||
// }
|
||
// });
|
||
// }
|
||
// },
|
||
{
|
||
id: 'btnOK',
|
||
label: '提交',
|
||
style: 'button_submit',
|
||
icons: {left: 'icon_submit'},
|
||
disabled: false,
|
||
onClick: function () {
|
||
var content = "";
|
||
if(pg == "2"){
|
||
content = "确定提交问卷吗?提交后将关闭此次调研!";
|
||
}else{
|
||
content = "确定提交试卷吗?提交后将关闭考试!";
|
||
}
|
||
var TorF = isMust();
|
||
if(TorF){
|
||
$.uiMessagebox.confirm({
|
||
title: '确认操作',
|
||
content: content,
|
||
onClose: function (value) {
|
||
if (value){
|
||
$.uiLoading.show({text: '数据正在加载……',width: 140,container:$('#editexam_dialog')});//窗口加遮罩
|
||
submitExam();//提交考试
|
||
window.clearTimeout(vartt);//停止倒计时
|
||
}
|
||
}
|
||
});
|
||
}
|
||
|
||
}
|
||
},
|
||
{
|
||
id: 'btnCancel',
|
||
label: '关闭',
|
||
icons: {left: 'icon_cancel'},
|
||
disabled: false,
|
||
style: 'button_cancel',
|
||
onClick: function () {
|
||
var content = "";
|
||
if(pg == "2"){
|
||
content = "确定关闭问卷吗?关闭问卷后将清空已作答部分!";
|
||
}else{
|
||
content = "确定关闭考试吗?关闭考试后将清空答案!";
|
||
}
|
||
$.uiMessagebox.confirm({
|
||
title: '确认操作',
|
||
content: content,
|
||
onClose: function (value) {
|
||
if (value) {
|
||
editexam_dialog.uiDialog('close');
|
||
window.clearTimeout(vartt);//停止倒计时
|
||
}
|
||
}
|
||
});
|
||
}
|
||
},
|
||
{
|
||
id: 'btnStop',
|
||
label: '暂停',
|
||
icons: {left: 'icon_cancel'},
|
||
disabled: false,
|
||
style: 'button_cancel',
|
||
onClick: function () {
|
||
window.clearTimeout(vartt);//停止倒计时
|
||
alert("考试暂停!点击确定继续答题!");
|
||
window.setTimeout("daojishi()",1000);//开始倒计时
|
||
}
|
||
}
|
||
// {
|
||
// id: 'btnContinue',
|
||
// label: '继续答题',
|
||
// icons: {left: 'icon_submit'},
|
||
// disabled: false,
|
||
// style: 'button_submit',
|
||
// onClick: function () {
|
||
// window.setTimeout("daojishi()",1000);//开始倒计时
|
||
// }
|
||
// }
|
||
]
|
||
});
|
||
|
||
|
||
function addEvents() {
|
||
|
||
//答题
|
||
$('#btn1').bind('click', function () {
|
||
var ids = grid.uiGrid('selectedData', 'id');
|
||
UserEdit_id = ids[0];
|
||
//console.log(AndEdit_id);
|
||
if(ids.length == 0){
|
||
showResult(false,'请选择要考试的试卷!','alert');
|
||
}
|
||
else if(ids.length > 1){
|
||
showResult(false,'请选择要考试的一张试卷,不支持同时选择多张试卷!','alert');
|
||
}
|
||
else{
|
||
$.ajax({
|
||
type: 'post',
|
||
url: isNotSubmitUrl,
|
||
data:{'exam_id':UserEdit_id},
|
||
dataType: "json",
|
||
success: function (result) { //result是接收后台return的结果
|
||
if (result.data.rows.length > 0){
|
||
alert("试卷已提交,不可继续答题!");
|
||
}
|
||
else{
|
||
editexam_dialog.uiDialog('setUserParam', {action: 'add', id: 0});
|
||
editexam_dialog.uiDialog('button', 'btnOK').show();
|
||
editexam_dialog.uiDialog('open');
|
||
if(pg == "2"){
|
||
editexam_dialog.uiDialog('title').html('调研');
|
||
}else {
|
||
editexam_dialog.uiDialog('title').html('考试');
|
||
}
|
||
|
||
|
||
$.ajax({
|
||
type: 'post',
|
||
url: userTestUrl,
|
||
data:{'UserEdit_id':UserEdit_id},
|
||
dataType: "json",
|
||
success: function (result) { //result是接收后台return的结果
|
||
//showResult(result.success, result.message);
|
||
|
||
setTimeout( function(){
|
||
if(result.data.rows.length > 0){
|
||
var data=result.data.rows[0];
|
||
titlename=data.name;
|
||
sc=data.sc;
|
||
$('#title_name').html(data.name);//将后台return的结果显示在前端
|
||
$('#title_description').html(data.description);
|
||
|
||
counttime=Number(sc)*3600;//总秒钟
|
||
// counttime=parseFloat(sc)*3600;
|
||
daojishi();
|
||
}
|
||
},100);
|
||
|
||
// $('#eqlist2').uiGrid('loadData');
|
||
},
|
||
error:function() {
|
||
alert("获取数据失败");
|
||
}
|
||
});
|
||
}
|
||
},
|
||
error:function() {
|
||
alert("查询是否已答题失败");
|
||
}
|
||
});
|
||
}
|
||
});
|
||
|
||
}
|
||
//arttemplate语法
|
||
template.helper('judge', function (data, format) {
|
||
if (data!=undefined && data.indexOf(format)!=-1){
|
||
return true;
|
||
}else {
|
||
return false;}
|
||
});
|
||
|
||
});
|
||
//查看
|
||
function viewRow(id, title) {
|
||
var dialog = $('#dialog');
|
||
dialog.uiDialog('setUserParam', {action: 'view', id: id});
|
||
dialog.uiDialog('open');
|
||
title = '-' + title || '';
|
||
dialog.uiDialog('title').html('查看' + title);
|
||
dialog.uiDialog('button', 'btnOK').hide();
|
||
|
||
}
|
||
|
||
//编辑
|
||
function editRow(id) {
|
||
var dialog = $('#dialog');
|
||
dialog.uiDialog('setUserParam', {action: 'edit', id: id});
|
||
dialog.uiDialog('open');
|
||
dialog.uiDialog('title').html('编辑');
|
||
dialog.uiDialog('button', 'btnOK').show();
|
||
}
|
||
|
||
// 删除
|
||
function deleteRow(id) {
|
||
deleteData("此操作将删除试卷,可能会导致以往考试找不到试卷,确定删除吗?", deleteUrl, {ids: id}, function (result) {
|
||
if (result.success) {
|
||
$('#grid').uiGrid('loadData');
|
||
}
|
||
});
|
||
}
|
||
|
||
//删除
|
||
function deleteData(confirmText, url, data, callback) {
|
||
$.uiMessagebox.confirm({
|
||
title: '确认操作',
|
||
content: confirmText,
|
||
onClose: function (value) {
|
||
if (value) {
|
||
$.ajax({
|
||
type: 'post',
|
||
url: url,
|
||
data: data,
|
||
dataType: "json",
|
||
success: function (result) {
|
||
callback && callback.call(this, result);
|
||
}
|
||
});
|
||
}
|
||
}
|
||
});
|
||
}
|
||
|
||
|
||
// var counttime=90*60;//总秒钟
|
||
|
||
function daojishi(){
|
||
if(isNaN(counttime)){
|
||
return;
|
||
}
|
||
|
||
if(counttime>=0){
|
||
var ms = counttime%60;//余数 89%60==29秒
|
||
var mis = Math.floor(counttime/60);//分钟
|
||
if(mis>=60){
|
||
var hour=Math.floor(mis/60);
|
||
|
||
mis=Math.floor((counttime-hour*60*60)/60);
|
||
$("#kssj").html(hour+"小时"+mis+"分"+ms+"秒");
|
||
}else if(mis>=1){
|
||
$("#kssj").html(mis+"分"+ms+"秒");
|
||
}else{
|
||
$("#kssj").html(ms+"秒");
|
||
}
|
||
|
||
counttime--;
|
||
window.clearTimeout(vartt);//先销毁再重新开始计时
|
||
vartt = window.setTimeout("daojishi()",1000);
|
||
}else{
|
||
window.clearTimeout(vartt);
|
||
submitExam();
|
||
window.confirm("考试时间到,试卷已自动提交!");
|
||
|
||
}
|
||
|
||
}
|
||
|
||
//单项选择ABCD
|
||
function checkBox(e) {
|
||
var parent = $(e).parents().filter('tr:eq(0)');
|
||
parent.find('#cbA').bind('click',function (){
|
||
if(parent.find('#cbA').prop('checked'))
|
||
{
|
||
parent.find('#cbB').prop('checked',false);
|
||
parent.find('#cbC').prop('checked',false);
|
||
parent.find('#cbD').prop('checked',false);
|
||
}
|
||
});
|
||
parent.find('#cbB').bind('click',function (){
|
||
if(parent.find('#cbB').prop('checked'))
|
||
{
|
||
parent.find('#cbA').prop('checked',false);
|
||
parent.find('#cbC').prop('checked',false);
|
||
parent.find('#cbD').prop('checked',false);
|
||
}
|
||
});
|
||
parent.find('#cbC').bind('click',function (){
|
||
if(parent.find('#cbC').prop('checked'))
|
||
{
|
||
parent.find('#cbB').prop('checked',false);
|
||
parent.find('#cbA').prop('checked',false);
|
||
parent.find('#cbD').prop('checked',false);
|
||
}
|
||
});
|
||
parent.find('#cbD').bind('click',function (){
|
||
if(parent.find('#cbD').prop('checked'))
|
||
{
|
||
parent.find('#cbB').prop('checked',false);
|
||
parent.find('#cbC').prop('checked',false);
|
||
parent.find('#cbA').prop('checked',false);
|
||
}
|
||
});
|
||
}
|
||
|
||
//判断题
|
||
function checkYesNo(e) {
|
||
var parent = $(e).parents().filter('tr:eq(0)');
|
||
parent.find('#yes').bind('click',function (){
|
||
if(parent.find('#yes').prop('checked'))
|
||
{
|
||
parent.find('#no').prop('checked',false);
|
||
}
|
||
});
|
||
parent.find('#no').bind('click',function (){
|
||
if(parent.find('#no').prop('checked'))
|
||
{
|
||
parent.find('#yes').prop('checked',false);
|
||
}
|
||
});
|
||
}
|
||
|
||
//提交考试
|
||
function submitExam() {
|
||
|
||
// var examInfo = [];
|
||
var examInfo = {id:'',question_id:'',exam_id:'',name:'',num:'',subject:'',type:'',ismust:'',score:'',
|
||
isParagraph:'',answer:'',user_answer:''};//定义对象
|
||
var examArray = [];//定义数组
|
||
|
||
for (var i=1; i<$('#eqlist2').find('tr').length; i++){
|
||
var parent="";
|
||
var id="";
|
||
var question_id="";
|
||
var exam_id="";
|
||
var name="";
|
||
var num="";
|
||
var subject="";
|
||
var type="";
|
||
var ismust="";
|
||
var score="";
|
||
var isParagraph = "";
|
||
var answer="";
|
||
var user_answer="";
|
||
|
||
parent=$('#eqlist2').find('tr:eq('+i+')');
|
||
|
||
// id=parent.find(".qid").html();
|
||
// question_id=parent.find(".ques_id").html();
|
||
question_id=parent.find(".qid").html();
|
||
|
||
exam_id=UserEdit_id;
|
||
name=titlename;
|
||
num=parent.find(".qxh").html();
|
||
subject=parent.find(".qtm").html();
|
||
type=parent.find(".qtype").html();
|
||
ismust=parent.find(".qbd").html();
|
||
score=parent.find(".score").html();
|
||
isParagraph = 0;
|
||
// answer=parent.find(".subject_answer").html();
|
||
|
||
if(type == "单选题" || type == "多选题"){
|
||
if(parent.find("#cbA").prop('checked')){
|
||
user_answer += "A";
|
||
}
|
||
if (parent.find("#cbB").prop('checked')){
|
||
user_answer += "B";
|
||
}
|
||
if (parent.find("#cbC").prop('checked')){
|
||
user_answer += "C";
|
||
}
|
||
if (parent.find("#cbD").prop('checked')){
|
||
user_answer += "D";
|
||
}
|
||
if (parent.find("#cbE").prop('checked')){
|
||
user_answer += "E";
|
||
}
|
||
if (parent.find("#cbF").prop('checked')){
|
||
user_answer += "F";
|
||
}
|
||
}
|
||
if(type == "判断题"){
|
||
if(parent.find("#yes").prop('checked')){
|
||
user_answer = "对";
|
||
}
|
||
if (parent.find("#no").prop('checked')){
|
||
user_answer = "错";
|
||
}
|
||
}
|
||
if(type == "填空题")
|
||
{
|
||
user_answer = parent.find(".blank").val();
|
||
}
|
||
if(type == "问答题")
|
||
{
|
||
user_answer = parent.find(".answer").val();//该方法可以获取最近的class为answer的标签的内容
|
||
}
|
||
|
||
if(user_answer.length > 2000){
|
||
alert("答案限制2000个字符,请修改后保存!");
|
||
return;
|
||
}
|
||
|
||
examInfo.id=id;
|
||
examInfo.question_id= question_id;
|
||
examInfo.exam_id=exam_id;
|
||
examInfo.name=name;
|
||
examInfo.num=num;
|
||
examInfo.subject=subject;
|
||
examInfo.type=type;
|
||
examInfo.ismust=ismust;
|
||
examInfo.score=score;
|
||
examInfo.isParagraph=isParagraph;
|
||
examInfo.answer=answer;
|
||
examInfo.user_answer=user_answer;
|
||
|
||
examArray.push(examInfo);
|
||
examInfo = {id:'',question_id:'',exam_id:'',name:'',num:'',subject:'',type:'',ismust:'',score:'',
|
||
isParagraph:'',answer:'',user_answer:''};//清空对象
|
||
}
|
||
|
||
$.ajax({
|
||
type: 'post',
|
||
url: saveUrl,
|
||
// data: {'id':id,'question_id':question_id, 'exam_id':exam_id,'name':name,'num':num,'subject':subject,'type':type,
|
||
// 'ismust':ismust,'score':score,'isParagraph':isParagraph,'answer':answer,'user_answer':user_answer},
|
||
data: {'examArray':JSON.stringify(examArray)},
|
||
dataType: "json",
|
||
success: function (result) {
|
||
// if (result.success) {
|
||
// $('#eqlist2').uiGrid('loadData');
|
||
// }
|
||
if (result.success) {
|
||
$.uiLoading.remove({container: $('#editexam_dialog')});//窗口移除遮罩
|
||
$('#editexam_dialog').uiDialog('close');
|
||
$('#grid').uiGrid('loadData');
|
||
}
|
||
showResult(result.success, result.message);
|
||
},
|
||
error:function() {
|
||
alert("提交考试失败");
|
||
$.uiLoading.remove({container: $('#editexam_dialog')});//窗口移除遮罩
|
||
}
|
||
});
|
||
|
||
}
|
||
|
||
//计算题数和总分
|
||
function setStatistic() {
|
||
var totalQuestion="";
|
||
var totalScore=0;
|
||
var score="";
|
||
for (var i=1; i<$('#eqlist2').find('tr').length; i++){
|
||
var parent="";
|
||
parent=$('#eqlist2').find('tr:eq('+i+')');
|
||
score=parent.find(".score").html();
|
||
totalScore +=Number(score);
|
||
}
|
||
totalQuestion = $('#eqlist2').find('tr').length - 1;
|
||
$('#sum').val(totalQuestion);
|
||
$('#sum_score').val(totalScore);
|
||
}
|
||
|
||
//必答题必填 选答题选填
|
||
function isMust() {
|
||
for (var i=1; i<$('#eqlist2').find('tr').length; i++){
|
||
var parent="";
|
||
var ismust="";
|
||
var user_answer="";
|
||
var type = "";
|
||
|
||
parent=$('#eqlist2').find('tr:eq('+i+')');
|
||
ismust=parent.find(".qbd").html();
|
||
type=parent.find(".qtype").html();
|
||
if(type == "单选题" || type == "多选题"){
|
||
if(parent.find("#cbA").prop('checked')){
|
||
user_answer += "A";
|
||
}
|
||
if (parent.find("#cbB").prop('checked')){
|
||
user_answer += "B";
|
||
}
|
||
if (parent.find("#cbC").prop('checked')){
|
||
user_answer += "C";
|
||
}
|
||
if (parent.find("#cbD").prop('checked')){
|
||
user_answer += "D";
|
||
}
|
||
if (parent.find("#cbE").prop('checked')){
|
||
user_answer += "E";
|
||
}
|
||
if (parent.find("#cbF").prop('checked')){
|
||
user_answer += "F";
|
||
}
|
||
}
|
||
if(type == "判断题"){
|
||
if(parent.find("#yes").prop('checked')){
|
||
user_answer = "对";
|
||
}
|
||
if (parent.find("#no").prop('checked')){
|
||
user_answer = "错";
|
||
}
|
||
}
|
||
if(type == "填空题")
|
||
{
|
||
user_answer = parent.find(".blank").val();
|
||
}
|
||
if(type == "问答题")
|
||
{
|
||
user_answer = parent.find(".answer").val();//该方法可以获取最近的class为answer的标签的内容
|
||
}
|
||
|
||
if(ismust == 1 && user_answer == ""){
|
||
alert("请完成第"+i+"题必答题再提交!");
|
||
return false;
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|