en_set_question.js
14.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
var url="";
var temp_tag;
var temp_data;
var TEXTBOOK_ID="";
var question_box=[];
var question_num=0;
var pageNum=1;
var end=0;
var flag=0;
var paper_title = "" ;
var paper_time = "0" ;
$(document).ready(function(){
getPoint();
});
function getQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]); return null;
}
var subject_id=getQueryString("subject_id");
var class_id=getQueryString("class_id");
var user_id=getQueryString("user_id");
function getPoint(){ //获取知识点
$.ajax({
url:url+"/SunvoteEducation/api/v1/point",
async:false,
type:"post",
data:{depth:"",subject_id:subject_id,p_id:"",knowledge_from:101},
success:function(data){
var point_html="";
for(var i=0;i<data.data.length;i++){
point_html +='<li data-id="'+data.data[i].KNOWLEDGE_ID+'" data-img-click=0 data-span-click=0><img src="../static/images/add.png" class="add" /><span>'+(i+1)+data.data[i].NAME+'</span></li>';
}
if(data.data.length > 0){
paper_title = data.data[0].NAME;
}
$(".section").children("ul").html(point_html);
getQuestion($(".section li").eq(0));
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
// 错误信息
alert("Code State:"+XMLHttpRequest.status+"State:"+XMLHttpRequest.readyState+"Wrong message:"+textStatus+"");
window.top.loading.remove();
}
})
}
function getChapter(TEXTBOOK_ID){ //获取章节
$(".section").children("ul").html("");
$.ajax({
url:url+"/SunvoteEducation/api/v1/chapter",
async:false,
type:"post",
data:{TEXTBOOK_ID:TEXTBOOK_ID},
success:function(data){
for(var i=0;i<data.data.length;i++){
$(".section").children("ul").append('<li data-id="'+data.data[i].ID+'" data-img-click=0 data-span-click=0><img src="../static/images/add.png" class="add"/><span>'+data.data[i].NAME+'</span></li>');
if(data.data[i].CHILDREN.length>0){
$(".section").children("ul").children("li").eq(i).append("<ul></ul>");
for(var j=0;j<data.data[i].CHILDREN.length;j++){
$(".section").children("ul").children("li").eq(i).children("ul").append('<li data-id="'+data.data[i].CHILDREN[j].ID+'" onclick="getQuestion($(this))"><span>●</span><span>'+data.data[i].CHILDREN[j].NAME+'</span></li>');
}
}
}
getQuestion($(".section li").eq(0));
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
// 错误信息
alert("Code State"+XMLHttpRequest.status+"State"+XMLHttpRequest.readyState+"Wrong message:"+textStatus+"");
window.top.loading.remove();
}
})
}
function getMenu(id,obj){ //获取知识点下级内容
var _html="";
$.ajax({
url:url+"/SunvoteEducation/api/v1/point",
async:false,
type:"post",
data:{depth:"",subject_id:subject_id,p_id:id,knowledge_from:101},
success:function(data){
obj.append('<ul></ul>');
for(var i=0;i<data.data.length;i++){
console.log(typeof(data.data[i].CHILDREN));
if(data.data[i].CHILDREN===undefined)
_html +='<li data-id="'+data.data[i].KNOWLEDGE_ID+'" data-span-click=0 "><span>●</span><span>'+(i+1)+data.data[i].NAME+'</span></li>';
else
_html +='<li data-id="'+data.data[i].KNOWLEDGE_ID+'" data-img-click=0 data-span-click=0 ><img src="../static/images/add.png" class="add"/><span>'+(i+1)+data.data[i].NAME+'</span></li>';
}
obj.children('ul').html(_html);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
// 错误信息
alert("Code State"+XMLHttpRequest.status+"State"+XMLHttpRequest.readyState+"Wrong message:"+textStatus+"");
window.top.loading.remove();
}
})
}
function slide(obj){ //查看解析
obj.closest(".star_box").siblings(".resolve").slideToggle(function(){
if($(".resolve").css("display") == "none")
obj.text("View Analysis");
else
obj.text("Hide analysis");
});
}
function getQuestion(obj){ //获取题目
var knowledge_id="",chapter_id="";
if($(".tab .active").attr("data-index")==1){
knowledge_id=obj.attr("data-id");
}else{
chapter_id=obj.attr("data-id");
}
var _html="";
$.ajax({
url:url+"/SunvoteEducation/api/v1/questions",
async:true,
type:"post",
data:{chapter_id:chapter_id,teachingmaterial_id:"",knowledge_id:knowledge_id,question_from:101,user_id:"",problem_type:"",subject_id:subject_id,count:"5",pageNum:pageNum},
success:function(data){
window.top.loading.remove();
console.log(data);
if(data.data.length>0){
for(var i=0;i<data.data.length;i++){
_html += '<li data-id="'+data.data[i].QUESTION_ID+'" data-knowledge="' + knowledge_id + '"><div class="content"></div><div class="option"><ul></ul></div><div class="resolve"><div class="resolve_box"><p><span>【Answer】</span> '+data.data[i].ANSWER+'</p><p><span>【Analysis】</span>'+data.data[i].ANALYSIS+'</p></div></div><div class="star_box"><div class="col-md-6"><div class="star"><span style="float:left;">Difficulty Level </span></div><div class="resolve_click"><a onclick="slide($(this))">View Analysis</a><div class="check_box"></div></div></div><div class="clearfix"></div></div></li>';
}
$(".question_box").children("ul").append(_html);
console.log(5*(pageNum-1));
for(var j=5*(pageNum-1);j<(data.data.length+5*(pageNum-1));j++){
var option_html="";
data.data[j-5*(pageNum-1)].CONTENT = data.data[j-5*(pageNum-1)].CONTENT.replace('<fill></fill>','______');
$(".question_box li .content").eq(j).append('<span>'+(j+1)+'、</span>'+data.data[j-5*(pageNum-1)].CONTENT);
var arry_option=data.data[j-5*(pageNum-1)].OPTION_CONTENT;
if(question_box.indexOf(data.data[j-5*(pageNum-1)].QUESTION_ID)>=0){
$(".check_box").eq(j).addClass("checked");
}
for(var x=0;x<arry_option.length;x++){
option_html += '<li><span>'+String.fromCharCode(64 + parseInt(x+1))+'.</span>'+arry_option[x]+'</li>';
}
$(".option").eq(j).find("ul").html(option_html);
star(j,parseInt(data.data[j-5*(pageNum-1)].DIFFICULTY));
}
$(".view_more").css("display","block");
end=0;
}else{
$(".view_more").css("display","none");
// $(".question_box").children("ul").html("");
pageNum-=1;
if(pageNum<1)
pageNum=1;
end=1;
}
flag=0;
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
// 状态码
console.log(XMLHttpRequest.status);
// 状态
console.log(XMLHttpRequest.readyState);
// 错误信息
alert(textStatus);
flag=0;
pageNum-=1;
if(pageNum<1)
pageNum=1;
window.top.loading.remove();
}
})
}
function getTeachingMaterial(){ //获取教材版本
$.ajax({
url:url+"/SunvoteEducation/api/v1/teachingmaterial",
async:true,
type:"post",
data:{subject_id:subject_id},
success:function(data){
console.log(data);
if (data.data.length > 0) {
var teach_html = "";
for (var i = 0; i < data.data.length; i++) {
teach_html += '<li data-id="'
+ data.data[i].ID
+ '" class="li_name"><p class="name">'
+ data.data[i].NAME
+ '</p><img src="../static/images/arrow_right.png" /><div class="clearfix"></div></li>';
}
$(".book_box ul").html(teach_html);
var li_length = $(".book_box ul li").length;
for (var k = 0; k < li_length; k++) {
var books = [];
var book_html = "";
var book_id = $(".book_box ul").children("li")
.eq(k).attr("data-id");
if (textBook(book_id).length > 0) {
books = textBook($(".book_box ul li").eq(k)
.attr("data-id"));
$(".book_box ul li").eq(k).append('<div class="float_box"><ul><div class="clearfix"></div></ul></div>');
for (var j = 0; j < books.length; j++) {
console.log("j:" + j);
book_html += '<li data-id=' + books[j].id
+ '>' + books[j].name + '</li>';
}
$(".float_box").eq(k).children("ul").find(
".clearfix").before(book_html);
TEXTBOOK_ID = books[0].id;
}
}
getChapter(TEXTBOOK_ID);
$("#book_name").text(
$(".name").eq(0).text()
+ "/"
+ $(".float_box").eq(0).find('li')
.eq(0).text());
}else{
window.top.loading.remove();
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
// 错误信息
alert("Code State"+XMLHttpRequest.status+"State"+XMLHttpRequest.readyState+"Wrong message:"+textStatus+"");
window.top.loading.remove();
}
})
}
function textBook(id){ //获取教材
var textBookName=[];
$.ajax({
url:url+"/SunvoteEducation/api/v1/textbook",
async:false,
type:"post",
data:{teaching_material_id:id,subject_id:subject_id,grade_id:""},
success:function(data){
if(data.data.length>0){
for(var i=0;i<data.data.length;i++){
textBookName[i]={"name":data.data[i].NAME,"id":data.data[i].ID};
}
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
// 错误信息
alert("Code State"+XMLHttpRequest.status+"State"+XMLHttpRequest.readyState+"Wrong message:"+textStatus+"");
window.top.loading.remove();
}
})
return textBookName;
}
function getClassName(){ //获取中文班级名
$.ajax({
url:url+"/SunvoteEducation/api/v1/classname",
async:false,
type:"post",
data:{id:class_id},
success:function(data){
$(".classList li").html(data.data);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
// 错误信息
alert("Code State"+XMLHttpRequest.status+"State"+XMLHttpRequest.readyState+"Wrong message:"+textStatus+"");
window.top.loading.remove();
}
})
}
function star(index,num){ //难度星级
$(".star").eq(index).append('<ul></ul>');
var li_html="";
for(var i=1;i<=num;i++){
li_html +='<li class="on"></li>';
}
for(var j=num;j<5;j++){
li_html += '<li class="off"></li>';
}
$(".star").eq(index).find("ul").html(li_html);
}
$(".section").on("click",".add",function(event){ //展开菜单
event.stopPropagation();
var that=$(this).closest("li");
if($(".tab .active").attr("data-index")==1){
if(that.attr("data-img-click")==0){
getMenu(that.attr("data-id"),that);
}
that.attr("data-img-click",1);
}else{
that.attr("data-img-click",1);
}
if(that.children('ul').length>0)
that.children('ul').slideToggle(function(){
if(that.children('ul').css("display")=="block")
that.children('img').attr("src","../static/images/reduce.png");
else
that.children('img').attr("src","../static/images/add.png");
});
});
$(".section").on("click","span",function(event){ //点击菜单获取题目
window.top.loading.show();
event.stopPropagation();
pageNum=1;
$(".question_box ul").html("");
var that=$(this).closest("li");
if($(".tab .active").attr("data-index")==1){
paper_title = this.textContent;
getQuestion(that);
$(".menu_active").removeClass();
that.addClass("menu_active");
}else{
paper_title = this.textContent;
getQuestion(that);
$(".menu_active").removeClass();
that.addClass("menu_active");
}
});
$(".book_box").children("ul").on("mouseover","li",function(event){ //教材版本交互
event.stopPropagation();
$(this).children(".float_box").css("display","block");
});
$(".book_box").children("ul").on("mouseleave","li",function(event){ //教材版本交互
event.stopPropagation();
$(this).children(".float_box").css("display","none");
});
$(".float_box").on("mouseleave",function(event){ //教材版本交互
event.stopPropagation();
$(this).css("display","none");
});
$(document).on("click",".float_box li",function(event){ //教材版本交互
event.stopPropagation();
var id=$(this).attr("data-id");
$("#book_name").text($(this).closest(".li_name").children(".name").text()+"/"+$(this).text());
$(".float_box").css("display","none");
$(".book_box").slideToggle();
getChapter(id);
});
$(".book").click(function(){ //教材版本下拉框交互
$(".book_box").slideToggle();
})
$(document).on("click",".check_box",function(){ //选中题目
if($(this).hasClass("checked")){
var id=$(this).closest("li").attr("data-id");
var que_index= -1 ;
for(var tp = 0 ; tp < question_box.length; tp++){
if(question_box[tp].id == id){
que_index = tp;
}
}
$(this).removeClass("checked");
question_box.splice(que_index,1);
question_num--;
}else{
//question_box[question_num].id =$(this).closest("li").attr("data-id");
//question_box[question_num].knowledge_id =$(this).closest("li").attr("data-knowledge");
question_box[question_num] = {id:$(this).closest("li").attr("data-id"),knowledge_id:$(this).closest("li").attr("data-knowledge")};
question_num++;
$(this).addClass("checked");
}
$("#all_que_num").html(question_num);
});
$(".clear_que").click(function(){ //清空
question_num=0;
question_box=[];
$(".checked").removeClass("checked");
$("#all_que_num").html(question_num);
});
$(".tab li").click(function(){ //教材与知识点选择
window.top.loading.show();
pageNum=1;
$(this).siblings().removeClass("active");
$(this).addClass("active");
if($(this).index()==0){
getTeachingMaterial();
$(".choose_book").css("display","block");
//getChapter(TEXTBOOK_ID);
}else{
$(".choose_book").css("display","none");
getPoint();
}
});
$(".topic").click(function(){
if(parseInt($("#all_que_num").text())>0){
paper_time = parseInt($("#all_que_num").text()) > 75 ? "150" : (parseInt($("#all_que_num").text()) * 2);
$("#title").val(paper_title);
$("#time").val(paper_time);
$('#myModal').modal('show');
}else{
alert("Please select question first")
}
});
$(".view_more").click(function(){ //加载更多
flag++;
if(end>0){
$(".view_more p").html("No more");
return;
}
if(flag==1){
window.top.loading.show();
pageNum++;
getQuestion($(".menu_active"));
}
})
$("#submit").click(function(){
var question_arry=[];
for(var i=0;i<question_num;i++){
question_arry[i]={
score: "0",
part_score: "0",
question_id: question_box[i].id,
knowledge_id:question_box[i].knowledge_id,
rank: i.toString(),
no_name: i.toString()
};
}
var data={
title: $("#title").val(),
exam_time: $("#time").val(),
paper_type: "101",
subject_id: subject_id,
grade_id: "",
class_id: class_id,
user_id: user_id,
score: "",
questions: question_arry
};
sessionStorage.setItem("data",JSON.stringify(data));
location.href="paper_view.do?classID="+class_id+"&userid="+user_id;
})