etms/asset/js/cetc54/exam/question.js
liyuchen c24bea2687 Initial commit: JCDP 教育培训管理系统 v54
- 系统管理模块(用户/角色/组织/权限/日志)
- 教育培训计划管理模块
- 教育培训实施模块
- 考试管理模块
- 调研问卷管理模块
- 外派培训管理模块
- 年度培训总结模块
- 学习资源管理模块
- 任职资格管理模块
- 即时通讯模块
- APP 版本管理
- 统计分析模块(FineReport)
- 代码审查标准和报告(CODE_REVIEW_GUIDE.md, CODE_REVIEW_REPORT.md)
- 项目开发指南(PROJECT_GUIDE.md)
2026-04-16 16:41:34 +08:00

648 lines
22 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

var webroot = $("#hdWebroot").val();
var rootUrl = webroot + '/exam/question/';
var deleteUrl = rootUrl + 'delete';//删除地址
var isNotLoginerURL = rootUrl + 'isNotLoginer';//判断当前登录用户是否有编辑权限
$(function () {
//------------------------属性-------------------------------------
var listUrl = rootUrl + 'list';//分页数据地址
var saveUrl = rootUrl + 'save';//保存添加数据地址
var importQuesPage = rootUrl + 'importQuesPage';//保存添加数据地址
var dialogSize = {width: 900, height: '90%'};//弹出窗口大小
var dialog = $('#dialog');
var grid_form = $('#grid_form');
var grid = $('#grid');
var questionImportUrl = rootUrl + 'questionImport';//批量导入试题
//-----------------------初始化--------------------------------------
initQuestionsGrid();
initQuestionsForm();
// addFilter();
addEvents();
//-------------------------------------方法--------------------------------------------------------
function initQuestionsGrid() {
//初始化搜索框
$('#searchbox').uiSearchbox({
width: 240,
prompt: '题目类型|题目|试卷类别',
searcher: function (v) {
grid.uiGrid('loadData', {queryParams: {key: $.trim(v)}, pageIndex: 1});
}
});
//初始化grid
grid.uiGrid({
url: listUrl,
// localData:{rows:[
// {id: '1', type: '1',subject:'单选题的第一道题目',category:'项目管理',categoryid:'1',description:'第一道单选题解析',answer:'A',edittime:'2019-01-01 11:15:10',optionA:'选项A',optionB:'选项B',optionC:'选项C',optionD:'选项D',optionE:'',optionF:''},
// {id: '2', type: '2',subject:'多选题的第一道题目',category:'项目管理',categoryid:'1',description:'第一道多选题解析',answer:'ACD',edittime:'2019-01-03 11:15:10',optionA:'选项A',optionB:'选项B',optionC:'选项C',optionD:'选项D',optionE:'选项E',optionF:'选项F'},
// {id: '3', type: '1',subject:'单选题的第二道题目',category:'质量管理',categoryid:'2',description:'第二道单选题解析',answer:'B',edittime:'2019-01-05 11:15:10',optionA:'选项A',optionB:'选项B',optionC:'选项C',optionD:'选项D',optionE:'',optionF:''},
// {id: '4', type: '3',subject:'判断题的第一道题目',category:'项目管理',categoryid:'1',description:'第一道判断题解析',answer:'对',edittime:'2019-01-14 11:15:10',optionA:'',optionB:'',optionC:'',optionD:'',optionE:'',optionF:''},
// {id: '5', type: '4',subject:'问答题的第一道题目',category:'项目管理',categoryid:'1',description:'第一道问答题解析',answer:'这是第一道问答题的答案',edittime:'2019-01-19 11:15:10',optionA:'a',optionB:'b',optionC:'c',optionD:'d',optionE:'e',optionF:'f'}]},
defaultSortField: 'edittime'
});
}
function initQuestionsForm() {
dialog.uiDialog({
title: '新建',//新增题目
width: dialogSize.width,
onOpen: function () {
var dialogP = $('#dialog').uiDialog('getUserParam');
op = dialogP.action;
var id = dialogP.id;
switch (op) {
case 'view':
case 'edit':
grid_form.uiForm('load', grid.uiGrid('selectedData')[0]);
break;
case 'add':
var roleType = 0;
grid_form.uiForm('load', {});
break;
default :
break;
}
},
buttons: [
{
id: 'btnOK',
label: '保存',
style: 'button_submit',
icons: {left: 'icon_submit'},
disabled: false,
onClick: function () {
$('#grid_form').uiForm('submit', {
url: saveUrl,
onSubmit: function (param) {
//这个位置要增加编辑提示,后台检测有题目被历史试卷引用时,需要提醒。
// $('#txtcategory').uiCombo('getText')
param.id = $('#hdID').val();
var isValid = $('#grid_form').uiForm('validate');
return isValid; // 返回false终止表单提交
},
success: function (result) {
if (result.success) {
dialog.uiDialog('close');//保存成功后关闭对话框
grid.uiGrid('loadData');//保存成功后刷新界面调用了后台的list方法
}
showResult(result.success, result.message);
}
});
return false;
}
},
{
id: 'btnCancel',
label: '关闭',
icons: {left: 'icon_cancel'},
disabled: false,
style: 'button_cancel',
onClick: function () {
dialog.uiDialog('close');
}
}
]
});
grid_form.uiForm({
template: 'grid_form_temp',
onLoadSuccess: function (data) {
initUI();
var me = $(this);
switch (op) {
case 'view':
me.uiForm('setReadonly', true);
break;
case 'edit':
break;
case 'add':
break;
default :
break;
}
//初始化——设为空格
$('#btn_space').uiButton({
style: 'button_submit',
icons: {left: 'icon_edit'},
onClick:function () {
var t = $('#txtsubject')[0];
//var t = $('#txtsubject').get(0);//等同于$('#txtsubject')[0]
//var t = document.getElementById('txtsubject');//js写法等同于$('#txtsubject')[0]和$('#txtsubject').get(0)
// if (window.getSelection) {//IE8不支持谷歌等支持的写法
if (document.selection) {//IE8支持谷歌等不支持的写法
// if (t.selectionStart != undefined && t.selectionEnd != undefined && t.selectionStart != t.selectionEnd) {//IE8不支持谷歌等支持的写法
if (document.selection.createRange().text != '' && document.selection.createRange().text != $('#txtsubject').val()) {//IE8支持谷歌等不支持的写法
var previous_answer = $('#txtanswer').val();
// var answer = t.value.substring(t.selectionStart, t.selectionEnd);//IE8不支持谷歌等支持的写法
var answer = document.selection.createRange().text;//IE8支持谷歌等不支持的写法
if(previous_answer != "")
{
answer = previous_answer + "," + answer;
}
setAnswer(answer);
// var a = t.value.substring(t.selectionStart, t.selectionEnd);//IE8不支持谷歌等支持的写法
var a = document.selection.createRange().text;//IE8支持谷歌等不支持的写法
var b = t.value;
//t.val(b.replace(a,"__"));//错误
$('#txtsubject').val(b.replace(a,"____"));
} else {
return;
}
} else {
return;
}
}
});
//写到这里有效
// $('#btn_space').bind('click',function(){
//
// });
}
});
}
//初始化表单
var formimportInit2 = function () {
// $('#btnUpload').uiButton();
$('#fileform').uiForm({
template: 'grid_form_temp2',
onLoadSuccess: function (data) {
$('#btnUpload').bind('click', function () {
$('#fileform').uiForm('submit', {
url: questionImportUrl,
dataType: "application/json",
onSubmit: function (params) {
},
success: function (result) {
if (result.success) {
$('#importques_dialog').uiDialog('close');//保存成功后关闭对话框
grid.uiGrid('loadData');
}
showResult(result.success, result.message);
}
});
});
}
});
};
//初始化试题批量导入弹出窗口
var importques_dialog = $('#importques_dialog').uiDialog({
title: '导入',
icon: 'list',
width:"80%",
height:"60%",
mask: true,
showBtnBar: true,
updateOnOpen: true,
lazyLoad: true,
url: importQuesPage,
onLoadComplete: formimportInit2,
onOpen: function () {
var dialogP = $('#importques_dialog').uiDialog('getUserParam');
op = dialogP.action;
var id = dialogP.id;
switch (op) {
case 'view':
case 'edit':
$('#fileform').uiForm('load', grid.uiGrid('selectedData')[0]);
break;
case 'add':
$('#fileform').uiForm('load', {});
break;
default :
break;
}
// $('#fileform').uiForm('load');//为组件加载数据
}
});
function addEvents() {
//新建
$('#btn1').bind('click', function () {
dialog.uiDialog('setUserParam', {action: 'add', id: 0});
dialog.uiDialog('button', 'btnOK').show();
dialog.uiDialog('open');
dialog.uiDialog('title').html('新增题目');//与初始化中的title重复设置
hideAndShow_add();
});
//删除
$('#btn2').bind('click', function () {
var ids = grid.uiGrid('selectedData', 'id');
if (ids.length == 0) {
showResult(false, '请选择要删除的行!', 'alert');
} else {
deleteRow(ids);
}
});
//批量导入试题
$('#btn3').bind('click', function () {
importques_dialog.uiDialog('setUserParam', {action: 'add', id: 0});
importques_dialog.uiDialog('button', 'btnOK').show();
importques_dialog.uiDialog('open');
importques_dialog.uiDialog('title').html('导入');
});
//不可实现,因为此方法(设为空格的点击事件)需要写到初始化的方法内才有效
// $('#btn_space').bind('click',function(){
//
// });
}
});
//查看
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();
var value = $('#txttype').val();
hideAndShow(value);
$('#cbA').attr("disabled","disabled");
$('#cbB').attr("disabled","disabled");
$('#cbC').attr("disabled","disabled");
$('#cbD').attr("disabled","disabled");
$('#cbE').attr("disabled","disabled");
$('#cbF').attr("disabled","disabled");
}
//编辑
function editRow(id) {
$.ajax({
type: 'post',
url: isNotLoginerURL,
data: {id:id},
dataType: "json",
success: function (result) {
if(result.success){
var dialog = $('#dialog');
dialog.uiDialog('setUserParam', {action: 'edit', id: id});
dialog.uiDialog('open');
dialog.uiDialog('title').html('编辑');
dialog.uiDialog('button', 'btnOK').show();
var value = $('#txttype').val();
hideAndShow(value);
}else{
$('#dialog').uiDialog('close');
alert("您没有权限编辑其他人添加的试题");
}
},
error:function() {
alert("判断当前登录用户是否有编辑权限失败");
}
});
// $('#grid_form').scrollTop(0);
}
// 删除
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);
}
});
}
}
});
}
function initUI()
{
$('#txttype').dictCombobox({
onSelect: function () {
var value = $('#txttype').dictCombobox('getValue');
switch(value){
case '1':
clear();
$('#rowA').show();
$('#rowB').show();
$('#rowC').show();
$('#rowD').show();
$('#rowE').hide();
$('#rowF').hide();
$('#tap').hide();
$('#cho').show();
$('#blank_space').hide();
break;
case '2':
clear();
$('#rowA').show();
$('#rowB').show();
$('#rowC').show();
$('#rowD').show();
$('#rowE').show();
$('#rowF').show();
$('#tap').hide();
$('#cho').show();
$('#blank_space').hide();
break;
case '3':
clear();
$('#rowA').hide();
$('#rowB').hide();
$('#rowC').hide();
$('#rowD').hide();
$('#rowE').hide();
$('#rowF').hide();
$('#tap').show();
$('#cho').hide();
$('#txtanswer').prop("disabled",false);
$('#txtanswer').innerText = '对';
$('#blank_space').hide();
break;
case '4':
clear();
$('#rowA').hide();
$('#rowB').hide();
$('#rowC').hide();
$('#rowD').hide();
$('#rowE').hide();
$('#rowF').hide();
$('#tap').hide();
$('#cho').hide();
$('#txtanswer').prop("disabled",false);
$('#blank_space').show();
break;
case '5':
clear();
$('#rowA').hide();
$('#rowB').hide();
$('#rowC').hide();
$('#rowD').hide();
$('#rowE').hide();
$('#rowF').hide();
$('#tap').hide();
$('#cho').hide();
$('#txtanswer').prop("disabled",false);
$('#blank_space').hide();
break;
}
}
});//.dictCombobox('select','1');
$('#txtcategory').dictCombobox();
$('#cbA').bind('click',function () {
if('1' == $('#txttype').dictCombobox('getValue'))
{
if($('#cbA').prop('checked'))
{
$('#cbB').prop('checked',false);
$('#cbC').prop('checked',false);
$('#cbD').prop('checked',false);
setAnswer('A');
}else
{
setAnswer(' ');
}
}else
{
setAnswer();
}
});
$('#cbB').bind('click',function () {
if('1' == $('#txttype').dictCombobox('getValue'))
{
if($('#cbB').prop('checked'))
{
$('#cbA').prop('checked',false);
$('#cbC').prop('checked',false);
$('#cbD').prop('checked',false);
setAnswer('B');
}else
{
setAnswer(' ');
}
}else
{
setAnswer();
}
});
$('#cbC').bind('click',function () {
if('1' == $('#txttype').dictCombobox('getValue'))
{
if($('#cbC').prop('checked'))
{
$('#cbA').prop('checked',false);
$('#cbB').prop('checked',false);
$('#cbD').prop('checked',false);
setAnswer('C');
}else
{
setAnswer(' ');
}
}else
{
setAnswer();
}
});
$('#cbD').bind('click',function () {
if('1' == $('#txttype').dictCombobox('getValue'))
{
if($('#cbD').prop('checked'))
{
$('#cbA').prop('checked',false);
$('#cbB').prop('checked',false);
$('#cbC').prop('checked',false);
setAnswer('D');
}else
{
setAnswer(' ');
}
}else
{
setAnswer();
}
});
$('#cbE').bind('click',function () {
setAnswer();
});
$('#cbF').bind('click',function () {
setAnswer();
});
}
function clear() {
$('#cbA').prop('checked',false);
$('#cbB').prop('checked',false);
$('#cbC').prop('checked',false);
$('#cbD').prop('checked',false);
$('#cbE').prop('checked',false);
$('#cbF').prop('checked',false);
$('#txtanswer').val('');
}
function setAnswer(ans)
{
// $('#txtanswer').prop("disabled",true);
if(null != ans)
{
$('#txtanswer').val(ans);
return;
}
var answer = '';
if($('#cbA').prop('checked'))
{
answer += 'A';
}
if($('#cbB').prop('checked'))
{
answer += 'B';
}
if($('#cbC').prop('checked'))
{
answer += 'C';
}
if($('#cbD').prop('checked'))
{
answer += 'D';
}
if($('#cbE').prop('checked'))
{
answer += 'E';
}
if($('#cbF').prop('checked'))
{
answer += 'F';
}
$('#txtanswer').val(answer);
}
function hideAndShow(value) {
switch(value){
case '1':
//clear();
$('#rowA').show();
$('#rowB').show();
$('#rowC').show();
$('#rowD').show();
$('#rowE').hide();
$('#rowF').hide();
$('#tap').hide();
$('#cho').show();
$('#blank_space').hide();
break;
case '2':
//clear();
$('#rowA').show();
$('#rowB').show();
$('#rowC').show();
$('#rowD').show();
$('#rowE').show();
$('#rowF').show();
$('#tap').hide();
$('#cho').show();
$('#blank_space').hide();
break;
case '3':
//clear();
$('#rowA').hide();
$('#rowB').hide();
$('#rowC').hide();
$('#rowD').hide();
$('#rowE').hide();
$('#rowF').hide();
$('#tap').show();
$('#cho').hide();
$('#txtanswer').prop("disabled",false);
$('#txtanswer').innerText = '对';
$('#blank_space').hide();
break;
case '4':
//clear();
$('#rowA').hide();
$('#rowB').hide();
$('#rowC').hide();
$('#rowD').hide();
$('#rowE').hide();
$('#rowF').hide();
$('#tap').hide();
$('#cho').hide();
$('#txtanswer').prop("disabled",false);
$('#blank_space').show();
break;
case '5':
//clear();
$('#rowA').hide();
$('#rowB').hide();
$('#rowC').hide();
$('#rowD').hide();
$('#rowE').hide();
$('#rowF').hide();
$('#tap').hide();
$('#cho').hide();
$('#txtanswer').prop("disabled",false);
$('#blank_space').hide();
break;
}
}
//添加题目时仅显示共有部分,隐藏其他部分
function hideAndShow_add() {
$('#cho').hide();
$('#rowA').hide();
$('#rowB').hide();
$('#rowC').hide();
$('#rowD').hide();
$('#rowE').hide();
$('#rowF').hide();
$('#blank_space').hide();
$('#tap').hide();
}
//设为空格
// function setSpace() {
//
// //不可实现需要写到初始化的方法内才有效如果想要写成一个方法写到这里可以参考exampaper_editexampaper.js中的setSpace()写法
// // $('#btn_space').uiButton({
// // onClick: function () {
//
// // }
// // });
// }
function checkSize(ele){
var size_m = (ele.files[0].size / 1024);
if(size_m >= 1024*1024*5){
$('#hidFile').val(1);
return false;
}
$('#hidFile').val(0);
return true;
}