Blame view

WebRoot/static/js/control-604.js 23.5 KB
83b5ddeb   孙向锦   模板添加
1
2
3
4
5
6
7
8
9
10
  var questionNUm = 0;
  /*数字转汉字数字*/
  var chnNumChar = [ "零", "一", "二", "三", "四", "五", "六", "七", "八", "九" ];
  var chnUnitSection = [ "", "万", "亿", "万亿", "亿亿" ];
  var chnUnitChar = [ "", "十", "百", "千" ];
  /* 快速创建答案列表 */
  var score = 0;
  var total_score = 0;
  var answerLen = 0;
  
eca4feb5   孙向锦   管理员功能完善
11
  
83b5ddeb   孙向锦   模板添加
12
13
14
15
16
17
18
19
20
21
22
23
24
25
  $(function() {
  	
  
  	function creat(str_ans, a_num, fraction) {
  		// $(".section").remove();
  		answer_index_b = $(".section").length + 1;
  		/*
  		 * $(".content").append('<div class="section section-1 single"
  		 * data-fraction="'+fraction+'" data-score=""> <div class="title"> <h3><span
  		 * class="que_num">一、</span><span class="que_name">单选</span></h3>
  		 * <input type="button" class="btn btn-danger pull-right remove"
  		 * name="remove" value="删除" /> </div> <div class="question_list"></div></div>')
  		 */
  		var str = str_ans.split('');
5d2c2033   孙向锦   自定义出题
26
  		console.log(str);
83b5ddeb   孙向锦   模板添加
27
28
29
30
  		for (i = 0; i < str.length; i++) {
  			if (str[i] == " ") {
  				str.splice(i, 1);
  				i = i - 1;
5d2c2033   孙向锦   自定义出题
31
32
  			}
  		}
83b5ddeb   孙向锦   模板添加
33
34
  		q_num = str.length;
  		$(".content").append('<div class="section section-'	+ answer_index_b+ ' single" data-fraction="'+ fraction+ '" data-score="'
ffa525ff   孙向锦   修改出卷页面
35
  								+ (q_num * fraction) + '" style="margin-top:80px;"><div class="title"><h3>第'	+ answer_index_b+ '大题(单选)总分: '
83b5ddeb   孙向锦   模板添加
36
37
38
39
40
41
42
  								+ q_num	+ ' X '	+ fraction	+ ' = '	+ (q_num * fraction)
  								+ ' 分<!--<span>请在试题选项上点击,亮色为该试题的正确答案&nbsp; </span> --></h3> </div><div class="question_list"></div></div>');
  		for (var i = 0; i < q_num; i++) {
  			str_temp = str[i];
  			str_temp = str_temp.toUpperCase()
  			code = str_temp.charCodeAt();
  			on_index = code - 65;
10146a46   孙向锦   创建试卷
43
  			questionNUm++;
83b5ddeb   孙向锦   模板添加
44
  			if (code < (65 + a_num)) {
5d2c2033   孙向锦   自定义出题
45
  				console.log(str_temp);
83b5ddeb   孙向锦   模板添加
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
  				$(".section-" + answer_index_b + " .question_list").append(
  						'<div class="question question' + (questionNUm)
  								+ '"><span>' + (questionNUm)
  								+ '、</span><ul></ul></div>');
  				for (var j = 0; j < a_num; j++) {
  					option = String.fromCharCode(0x41 + j);
  					if (on_index == j) {
  						console.log(on_index + "---" + j);
  						$(".question" + (questionNUm) + ' ul').append(
  								'<li class="btn btn-default on">' + option
  										+ '</li>');
  					} else
  						$(".question" + (questionNUm) + ' ul').append(
  								'<li class="btn btn-default">' + option
  										+ '</li>');
  				}
  			} else {
  				alert("题目" + (i + 1) + ":" + String.fromCharCode(code)
  						+ "答案错误,超出选项数");
  				// return;
5d2c2033   孙向锦   自定义出题
66
67
  			}
  		}
83b5ddeb   孙向锦   模板添加
68
  		$(".section-" + answer_index_b).attr("data-score",
ffa525ff   孙向锦   修改出卷页面
69
  				q_num * fraction);
10146a46   孙向锦   创建试卷
70
71
  		total_score += q_num * fraction;
  		$("#score_all").text(total_score);
5d2c2033   孙向锦   自定义出题
72
73
  	}
  
83b5ddeb   孙向锦   模板添加
74
  	/***************************************************************************
bf10975d   jack   1.修改新建试卷不显示年级bug
75
  	 * 1、单选题 2、完形填空 3、阅读理解 4、判断题 5、多选题 6、填空题
83b5ddeb   孙向锦   模板添加
76
  	 **************************************************************************/
5d2c2033   孙向锦   自定义出题
77
  
83b5ddeb   孙向锦   模板添加
78
  	function addQuestion(type, a_num, index_s_2, index_e_2, fraction2) {
5d2c2033   孙向锦   自定义出题
79
  		console.log(type);
83b5ddeb   孙向锦   模板添加
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
  		answer_index_b = $(".section").length + 1;
  		var question_num = SectionToChinese($(".section").length + 1);
  		switch (type) {
  		case 1: // 单选题
  			// alert(typeof(index_s_2));
  			$(".content")
  					.append(
  							'<div class="section section-'
  									+ answer_index_b
  									+ ' single" data-fraction="'
  									+ fraction2
  									+ '" data-score=""> <div class="title"> <h3><span class="que_num">'
  									+ question_num
  									+ '、</span>'
  									+ '<span class="que_name">单选</span></h3> <input type="button" class="btn btn-danger pull-right remove" name="remove" value="删除" /> </div> <div class="question_list"></div></div>');
  			for (i = index_s_2; i <= index_e_2; i++) {
  				$(".section-" + answer_index_b + " .question_list").append(
  						'<div class="question question' + i + '"><span>' + i
  								+ '、</span><ul></ul></div>');
  				for (var j = 0; j < a_num; j++) {
  					option = String.fromCharCode(0x41 + j);
  					$(".section-" + answer_index_b + " .question" + i + ' ul')
  							.append(
  									'<li class="btn btn-default">' + option
  											+ '</li>');
5d2c2033   孙向锦   自定义出题
105
  				}
83b5ddeb   孙向锦   模板添加
106
  			}
5d2c2033   孙向锦   自定义出题
107
  			break;
83b5ddeb   孙向锦   模板添加
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
  		case 2: // 完形填空
  			$(".content")
  					.append(
  							'<div class="section section-'
  									+ answer_index_b
  									+ ' single" data-fraction="'
  									+ fraction2
  									+ '" data-score=""> <div class="title"> <h3><span class="que_num">'
  									+ question_num
  									+ '、</span><span class="que_name">完形填空</span></h3> <input type="button" class="btn btn-danger pull-right remove" name="remove" value="删除" /> </div> <div class="question_list"></div></div>');
  			for (var i = index_s_2; i <= index_e_2; i++) {
  				$(".section-" + answer_index_b + " .question_list").append(
  						'<div class="question question' + i + '"><span>' + i
  								+ '、</span><ul></ul></div>');
  				for (var j = 0; j < a_num; j++) {
  					option = String.fromCharCode(0x41 + j);
  					$(".section-" + answer_index_b + " .question" + i + ' ul')
  							.append(
  									'<li class="btn btn-default">' + option
  											+ '</li>');
5d2c2033   孙向锦   自定义出题
128
  				}
83b5ddeb   孙向锦   模板添加
129
  			}
5d2c2033   孙向锦   自定义出题
130
  			break;
83b5ddeb   孙向锦   模板添加
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
  		case 3: // 阅读理解
  			$(".content")
  					.append(
  							'<div class="section section-'
  									+ answer_index_b
  									+ ' single" data-fraction="'
  									+ fraction2
  									+ '" data-score=""> <div class="title"> <h3><span class="que_num">'
  									+ question_num
  									+ '、</span><span class="que_name">阅读理解</span></h3> <input type="button" class="btn btn-danger pull-right remove" name="remove" value="删除" /> </div> <div class="question_list"></div></div>');
  			for (var i = index_s_2; i <= index_e_2; i++) {
  				$(".section-" + answer_index_b + " .question_list").append(
  						'<div class="question question' + i + '"><span>' + i
  								+ '、</span><ul></ul></div>');
  				for (var j = 0; j < a_num; j++) {
  					option = String.fromCharCode(0x41 + j);
  					$(".section-" + answer_index_b + " .question" + i + ' ul')
  							.append(
  									'<li class="btn btn-default">' + option
  											+ '</li>');
5d2c2033   孙向锦   自定义出题
151
  				}
83b5ddeb   孙向锦   模板添加
152
  			}
5d2c2033   孙向锦   自定义出题
153
  			break;
83b5ddeb   孙向锦   模板添加
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
  		case 4: // 判断题
  			$(".content")
  					.append(
  							'<div class="section section-'
  									+ answer_index_b
  									+ ' single" data-fraction="'
  									+ fraction2
  									+ '" data-score=""> <div class="title"> <h3><span class="que_num">'
  									+ question_num
  									+ '、</span><span class="que_name">判断题</span></h3> <input type="button" class="btn btn-danger pull-right remove" name="remove" value="删除" /> </div> <div class="question_list"></div></div>');
  			for (var i = index_s_2; i <= index_e_2; i++) {
  				$(".section-" + answer_index_b + " .question_list").append(
  						'<div class="question question' + i + '"><span>' + i
  								+ '、</span><ul></ul></div>');
  				for (var j = 0; j < a_num; j++) {
  					if (j % 2 == 0)
  						option = "√";
  					else
  						option = "×";
  					$(".section-" + answer_index_b + " .question" + i + ' ul')
  							.append(
  									'<li class="btn btn-default">' + option
  											+ '</li>');
5d2c2033   孙向锦   自定义出题
177
  				}
83b5ddeb   孙向锦   模板添加
178
  			}
5d2c2033   孙向锦   自定义出题
179
  			break;
83b5ddeb   孙向锦   模板添加
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
  		/*
  		 * case 5: //多选题 $(".content").append('<div class="section
  		 * section-'+answer_index_b+' check" data-fraction="'+fraction2+'"
  		 * data-score=""> <div class="title"> <h3><span
  		 * class="que_num">'+question_num+'</span><span class="que_name">多选题</span></h3>
  		 * <input type="button" class="btn btn-danger pull-right remove"
  		 * name="remove" value="删除" /> </div> <div class="question_list"></div></div>');
  		 * for(var i=index_s_2;i<=index_e_2;i++){
  		 * $(".section-"+answer_index_b+" .question_list").append('<div
  		 * class="question question'+i+'"><span>'+i+'</span><ul></ul></div>');
  		 * for(var j=0;j<a_num;j++){ option=String.fromCharCode(0x41+j);
  		 * $(".section-"+answer_index_b+" .question"+i+' ul').append('<li class="btn btn-default">'+option+'</li>'); } }
  		 */
  		case 5: // 多选题
  		// $(".content").html("");
  			$(".content")
  					.append(
  							'<div class="section section-'
  									+ answer_index_b
  									+ ' check" data-fraction="'
  									+ fraction2
  									+ '" data-score="'
  									+ ((index_e_2 - index_s_2 + 1) * fraction2)
  									+ '"> <div class="title"><h3>第'
  									+ answer_index_b
  									+ '大题(多选)总分: '
  									+ (index_e_2 - index_s_2 + 1)
  									+ ' X '
  									+ fraction2
  									+ ' = '
  									+ ((index_e_2 - index_s_2 + 1) * fraction2)
  									+ ' 分<!--<span>请在试题选项上点击,亮色为该试题的正确答案&nbsp; </span>--></h3> </div> <div class="question_list"></div></div>');
  			for (var i = index_s_2; i <= index_e_2; i++) {
  				questionNUm++;
  				$(".section-" + answer_index_b + " .question_list").append(
  						'<div class="question question' + questionNUm
  								+ '"><span>' + questionNUm
  								+ '、</span><ul></ul></div>');
  				for (var j = 0; j < a_num; j++) {
  					option = String.fromCharCode(0x41 + j);
  					$(
  							".section-" + answer_index_b + " .question"
  									+ questionNUm + ' ul').append(
  							'<li class="btn btn-default">' + option + '</li>');
5d2c2033   孙向锦   自定义出题
224
  				}
83b5ddeb   孙向锦   模板添加
225
226
227
  			}
  			total_score += ((index_e_2 - index_s_2 + 1) * fraction2);
  			$("#score_all").text(total_score);
5d2c2033   孙向锦   自定义出题
228
229
  			break;
  		}
83b5ddeb   孙向锦   模板添加
230
231
232
  		// $(".section-"+answer_index_b).attr("data-score",$(".section-"+answer_index_b).find(".question").length*fraction2);
  		$(".section0").attr("data-score",
  				$(".section0").find(".question").length * fraction2);
5d2c2033   孙向锦   自定义出题
233
234
  	}
  
83b5ddeb   孙向锦   模板添加
235
  	$(document).on('click', '.remove', function() { // 删除按钮
5d2c2033   孙向锦   自定义出题
236
237
  		$(this).parent().parent(".section").remove();
  	})
83b5ddeb   孙向锦   模板添加
238
239
240
241
242
243
244
  
  	$("#fast_submit").click(function() { // 点击确定,创建答案列表
  	// $("#addQuestion").attr("disabled","disabled");
  		var answer = $("#answer").val();
  		var num_ans = $("#num_ans").val();
  		var fraction = $("#fraction").val();
  		if (answer == '') {
ee61a3f0   孙向锦   增强判断
245
  			alert("请输入题目答案");
5d2c2033   孙向锦   自定义出题
246
  			return;
83b5ddeb   孙向锦   模板添加
247
  		} else if (fraction == '') {
5d2c2033   孙向锦   自定义出题
248
249
250
  			alert("请输入题目分数");
  			return;
  		}
10146a46   孙向锦   创建试卷
251
  		var frac = parseFloat(fraction);
83b5ddeb   孙向锦   模板添加
252
253
254
  		if (frac > 0) {
  			// score += parseInt(fraction)*answer.split(",").length;
  			creat(answer, num_ans, fraction);
67dfaf5c   孙向锦   提交代码
255
  			$('.fast').modal('hide');
83b5ddeb   孙向锦   模板添加
256
  		} else {
67dfaf5c   孙向锦   提交代码
257
258
259
  			alert("请输入正确分数");
  			return;
  		}
83b5ddeb   孙向锦   模板添加
260
  	})
5d2c2033   孙向锦   自定义出题
261
  
83b5ddeb   孙向锦   模板添加
262
263
264
265
266
267
268
269
270
271
  	/* 添加试题的确定按钮 */
  	$("#addQuestion_submit").click(function() {
  		// $("#fast").attr("disabled","disabled");
  		var type_2 = 5;// parseInt($("#type").val())
  		var index_s_2 = 1;// parseInt($("#index_s_2").val())
  		var index_e_2 = parseInt($("#index_s_2").val());
  		// var answer_2=$("#answer_2").val();
  		var num_ans_2 = $("#num_ans_2").val();
  		var fraction2 = parseFloat($("#fraction2").val());
  		if (isNaN(index_s_2)) {
5d2c2033   孙向锦   自定义出题
272
273
  			alert("请输入题目开始序号");
  			return;
83b5ddeb   孙向锦   模板添加
274
275
  		} else if (isNaN(index_e_2)) {
  			alert("请输入题目个数");// alert("请输入题目结束序号");
5d2c2033   孙向锦   自定义出题
276
  			return;
83b5ddeb   孙向锦   模板添加
277
  		} else if (isNaN(fraction2)) {
ee61a3f0   孙向锦   增强判断
278
279
  			alert("请输入题目分数");
  			return;
5d2c2033   孙向锦   自定义出题
280
  		}
67dfaf5c   孙向锦   提交代码
281
  		var iindex_e_2 = parseInt(index_e_2);
83b5ddeb   孙向锦   模板添加
282
  		if (iindex_e_2 < 1 || iindex_e_2 > 100) {
67dfaf5c   孙向锦   提交代码
283
284
285
  			alert("题目个数不合法");
  			return;
  		}
83b5ddeb   孙向锦   模板添加
286
287
  		// console.log(typeof(type_2));
  		addQuestion(type_2, num_ans_2, index_s_2, index_e_2, fraction2);
5d2c2033   孙向锦   自定义出题
288
289
  		$('.addQuestion').modal('hide');
  	})
83b5ddeb   孙向锦   模板添加
290
291
  	$("#type").change(function() {
  		if ($("#type").val() == 4) {
5d2c2033   孙向锦   自定义出题
292
  			$("#num_ans_2").val(2);
83b5ddeb   孙向锦   模板添加
293
294
  			$("#num_ans_2").attr("disabled", "disabled");
  		} else {
5d2c2033   孙向锦   自定义出题
295
296
  			$("#num_ans_2").removeAttr("disabled");
  			$("#num_ans_2").val(4);
83b5ddeb   孙向锦   模板添加
297
  
5d2c2033   孙向锦   自定义出题
298
299
  		}
  	})
83b5ddeb   孙向锦   模板添加
300
301
302
303
  	/* 更改考试时长 */
  	$("#time_submit").click(function() {
  		var test_time = $("#enter_time").val();
  		if (test_time == '') {
5d2c2033   孙向锦   自定义出题
304
305
306
307
308
309
  			alert("请输入考试时间");
  			return;
  		}
  		$("#time").html(test_time);
  		$('.test_time').modal('hide');
  	})
83b5ddeb   孙向锦   模板添加
310
311
  	/* 更改单选答案 */
  	$(document).on('click', '.single li', function() {
5d2c2033   孙向锦   自定义出题
312
313
314
  		$(this).siblings().removeClass("on");
  		$(this).addClass("on");
  	})
83b5ddeb   孙向锦   模板添加
315
316
317
318
  	/* 更改多选答案 */
  	$(document).on('click', '.check li', function() {
  		// $(this).siblings().removeClass("on");
  		if ($(this).hasClass('on')) {
67dfaf5c   孙向锦   提交代码
319
  			$(this).removeClass("on");
83b5ddeb   孙向锦   模板添加
320
  		} else {
67dfaf5c   孙向锦   提交代码
321
322
  			$(this).addClass("on");
  		}
5d2c2033   孙向锦   自定义出题
323
  	})
83b5ddeb   孙向锦   模板添加
324
325
326
  	/* 提交保存数据 */
  	$("#save").click(function() {
  						var url = URL;
5d2c2033   孙向锦   自定义出题
327
  
83b5ddeb   孙向锦   模板添加
328
329
330
331
332
333
334
335
336
337
338
  						var data = {
  							title : $(".header_box h1").text(),
  							exam_time : parseInt($("#time").text()),
  							paper_type : testData.paper_type,
  							subject_id : testData.subject_id,
  							grade_id : testData.grade_id,
  							user_id : testData.user_id,
  							school_id : testData.school_id,
  							score : total_score,
  							questions : []
  						}
5d2c2033   孙向锦   自定义出题
339
  
83b5ddeb   孙向锦   模板添加
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
  						if ($(".section").length > 0) {
  							var rank = 0
  							for (i = 0; i < $(".section").length; i++) {
  								// rank++;
  								data.questions[i] = {
  									chapter_id : "0",
  									problem_type_id : "0",
  									knowledge_id : "0",
  									// content:
  									// $(".section").eq(i).find(".que_name").text(),
  									option_num : "",
  									option_content : "",
  									answer : "",
  									difficulty : "",
  									analysis : "",
  									question_from : "",
  									score : parseFloat($(".section").eq(i)
  											.attr("data-score")),
  									part_score : "",
  									remark : "",
  									rank : rank,
  									no_name : $(".section").eq(i).find(
  											".que_num").text(),
  									questions : []
  								}
  								for (j = 0; j < $(".section").eq(i).find(
  										".question_list").children(".question").length; j++) {
  									rank++;
  									var on_num = $(".section").eq(i).find(
  											".question").eq(j).find(".on").length;
  									var answer = "";
  									for (k = 0; k < on_num; k++) {
  										answer += $(".section").eq(i).find(
  												".question").eq(j).find(".on")
  												.eq(k).text();
  										// console.log(answer);
  									}
  									if (answer == '') {
  										alert("还有试题未编辑答案。");
  										return;
  									}
  									data.questions[i].questions[j] = {
  										chapter_id : "0",
  										problem_type_id : "0",
  										knowledge_id : "0",
  										content : "",
  										option_num : $(".section").eq(i).find(
  												".question").eq(j).find("li").length,
  										option_content : "",
  										answer : answer,
  										difficulty : "0",
  										analysis : "",
  										question_from : "1",
  										score : parseFloat($(".section").eq(i)
  												.attr("data-fraction")),
  										part_score : "0",
  										remark : "",
  										rank : rank,
  										no_name : rank,
  									}
  								}
  							}
  						}
  
  						if (data.questions.length > 0) {
  							data = JSON.stringify(data);
  							dataJson = {
  								"json" : data
  							};
  							console.log(data);
  							ajax_submit(url, dataJson);
  						} else
  							alert("请添加试题");
  					});
5d2c2033   孙向锦   自定义出题
414
  
83b5ddeb   孙向锦   模板添加
415
416
417
418
419
420
421
422
423
424
425
426
  	/* ajax封装函数 */
  	function ajax_submit(url, data) {
  		$(".loading").css("display", "block");
  		console.log(data);
  		$.ajax({
  			url : url,
  			type : "POST",
  			data : data,
  			dataType : "json",
  			contentType : "application/x-www-form-urlencoded; charset=utf-8",
  			success : function(data) {
  				$(".loading").css("display", "none");
4b347a15   孙向锦   修改编辑试题后,添加的返回路径
427
428
429
430
431
  				if(testData.paper_type == '1'){
  					window.location.href = JUMP_URL + "?a=1&defaulturl=../paper/list2.do";
  				}else{
  					window.location.href = JUMP_URL + "?a=1&defaulturl=../paper/list4.do?school_id=" + testData.school_id ;
  				}
83b5ddeb   孙向锦   模板添加
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
  			}
  		})
  	}
  	function fastSort(array, head, tail) {
  		// 考虑到给每个分区操作的时候都是在原有的数组中进行操作的,所以这里head,tail来确定分片的位置
  		/* 生成随机项 */
  		var randomnum = parseInt((head + tail) / 2);
  		var random = array[randomnum];
  		/* 将小于random的项放置在其左边 策略就是通过一个临时的数组来储存分好区的结果,再到原数组中替换 */
  		var arrayTemp = [];
  		var unshiftHead = 0;
  		for (var i = head; i <= tail; i++) {
  			if (parseInt(array[i].rank) < parseInt(random.rank)) {
  				arrayTemp.unshift(array[i]);
  				unshiftHead++;
  			} else if (parseInt(array[i].rank) > parseInt(random.rank)) {
  				arrayTemp.push(array[i]);
  			}
  			/* 当它等于的时候放哪,这里我想选择放到队列的前面,也就是从unshift后的第一个位置放置 */
  			if (parseInt(array[i].rank) === parseInt(random.rank)) {
  				arrayTemp.splice(unshiftHead, 0, array[i]);
  			}
5d2c2033   孙向锦   自定义出题
454
  		}
83b5ddeb   孙向锦   模板添加
455
456
457
458
459
460
  		/* 将对应项覆盖原来的记录 */
  		for (var j = head, u = 0; j <= tail; j++, u++) {
  			array.splice(j, 1, arrayTemp[u]);
  		}
  		/* 寻找中间项所在的index */
  		var nowIndex = array.indexOf(random);
5d2c2033   孙向锦   自定义出题
461
  
83b5ddeb   孙向锦   模板添加
462
463
464
  		/* 设置出口,当要放进去的片段只有2项的时候就可以收工了 */
  		if (arrayTemp.length <= 2) {
  			return;
5d2c2033   孙向锦   自定义出题
465
  		}
83b5ddeb   孙向锦   模板添加
466
467
468
  		/* 递归,同时应用其左右两个区域 */
  		fastSort(array, head, nowIndex);
  		fastSort(array, nowIndex + 1, tail);
5d2c2033   孙向锦   自定义出题
469
  	}
83b5ddeb   孙向锦   模板添加
470
  	function creatHtml(data) {
5d2c2033   孙向锦   自定义出题
471
  		console.log(data);
83b5ddeb   孙向锦   模板添加
472
  		$(".header_box h1").html(data.title);
5d2c2033   孙向锦   自定义出题
473
  		$("#time").html(data.exam_time);
83b5ddeb   孙向锦   模板添加
474
475
476
477
478
  		if(data.score != null && data.score > 0 && data.score != ''){
  			$("#score_all").html(data.score);
  		}
  
  		if (data.questions.length > 0) {
0b46638a   孙向锦   标准答案
479
480
481
482
  			$(".time").removeAttr("data-target");
  			$(".remove").remove();
  			$(".btn_box").remove();
  		}
9687df59   jack   1.轻松考(中性)-增加题目根据r...
483
484
485
486
487
488
489
490
491
492
493
494
495
  		
  		data.questions.sort(function (a, b) {
  //			if (a.rank < b.rank) {
  //				return -1;
  //			} else if (a.rank == b.rank) {
  //				return 0;
  //			} else {
  //				return 1;
  //			}
  			var rankA = isNaN(parseInt(a.rank))?0:parseInt(a.rank);
  			var rankB = isNaN(parseInt(b.rank))?0:parseInt(b.rank);
  			return rankA-rankB;
  		})
83b5ddeb   孙向锦   模板添加
496
497
498
  
  		for (var i = 0; i < data.questions.length; i++) {
  			if (data.questions[i].questions) {
9687df59   jack   1.轻松考(中性)-增加题目根据r...
499
500
501
502
503
504
505
506
507
508
509
510
511
  				var sortTemp = data.questions[i].questions.sort(function (a, b) {
  //					if (parseInt(a.rank) < parseInt(b.rank)) {
  //						return -1;
  //					} else if (a.rank == b.rank) {
  //						return 0;
  //					} else {
  //						return 1;
  //					}
  					var rankA = isNaN(parseInt(a.rank))?0:parseInt(a.rank);
  					var rankB = isNaN(parseInt(b.rank))?0:parseInt(b.rank);
  					return rankA-rankB;
  				})
  				console.log(sortTemp)
83b5ddeb   孙向锦   模板添加
512
513
514
515
516
517
  				$(".content")
  						.append(
  								'<div class="section section-'
  										+ i
  										+ '" data-fraction="'
  										+ data.questions[i].score
ffa525ff   孙向锦   修改出卷页面
518
  										+ '" style="margin-top:80px;"> <h3><span class="que_num">'
83b5ddeb   孙向锦   模板添加
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
  										+ '第'
  										+ (i + 1)
  										+ '大题总分:'
  										+ data.questions[i].questions.length
  										+ " X "
  										+ (parseFloat(data.questions[i].sug_score) / data.questions[i].questions.length)
  										+ " = "
  										+ data.questions[i].sug_score
  										+ '</span>'
  										+ '<span class="que_name">'
  										+ data.questions[i].content
  										+ '</span></h3><!-- <input type="button" class="btn btn-danger pull-right remove" name="remove" value="删除" /> --> <div class="question_list"></div></div>');
  			} else {
  				if (i == 0) {
  					$(".content")
  							.append(
ffa525ff   孙向锦   修改出卷页面
535
  									'<div class="section section0"> <div class="question_list" style="margin-top:80px"></div></div>');
0b46638a   孙向锦   标准答案
536
  				}
83b5ddeb   孙向锦   模板添加
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
  				$(".section0").find(".question_list").append(
  						'<div class="question question' + (i + 1) + '"><span>'
  								+ (++questionNUm) + '、</span><ul></ul></div>');
  				for (var k = 0; k < parseInt(data.questions[i].option_num); k++) {
  					str_temp = data.questions[i].answer;
  					$(".section0").find(".question" + (i + 1) + ' ul').append(
  							'<li class="btn btn-default">'
  									+ String.fromCharCode(0x41 + k) + '</li>');
  					for (var l = 0; l < str_temp.length; l++) {
  						str_temp_arry = str_temp.split('');
  						code = str_temp_arry[l].charCodeAt();
  						on_index = code - 65;
  						if (on_index == k) {
  							$(".section0").find(
  									".question" + (i + 1) + ' ul li').eq(
  									on_index).attr("class",
  									"btn btn-default on");
  						}
0b46638a   孙向锦   标准答案
555
556
  					}
  				}
5d2c2033   孙向锦   自定义出题
557
  			}
83b5ddeb   孙向锦   模板添加
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
  
  			if (data.questions[i].questions) {
  				for (var j = 0; j < data.questions[i].questions.length; j++) {
  					$(".section-" + i).find(".question_list").append(
  							'<div class="question question' + (j + 1)
  									+ '"><span>' + (++questionNUm)
  									+ '、</span><ul></ul></div>');
  					if ($(".section-" + i).find(".que_name").text() == "判断题") {
  						for (var k = 0; k < parseInt(data.questions[i].questions[j].option_num); k++) {
  							str_temp = data.questions[i].questions[j].answer;
  							if (k % 2 == 0) {
  								$(".section-" + i).find(
  										".question" + (j + 1) + ' ul').append(
  										'<li class="btn btn-default">√</li>');
  							} else if (k % 2 == 1) {
  								$(".section-" + i).find(
  										".question" + (j + 1) + ' ul').append(
  										'<li class="btn btn-default">×</li>');
0b46638a   孙向锦   标准答案
576
  							}
83b5ddeb   孙向锦   模板添加
577
578
579
580
581
  
  							if (str_temp == "√")
  								$(".section-" + i).find(
  										".question" + (j + 1) + ' ul li').eq(0)
  										.attr("class", "btn btn-default on");
0b46638a   孙向锦   标准答案
582
  							else
83b5ddeb   孙向锦   模板添加
583
584
585
  								$(".section-" + i).find(
  										".question" + (j + 1) + ' ul li').eq(1)
  										.attr("class", "btn btn-default on");
5d2c2033   孙向锦   自定义出题
586
  						}
83b5ddeb   孙向锦   模板添加
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
  					} else {
  						for (var k = 0; k < parseInt(data.questions[i].questions[j].option_num); k++) {
  							str_temp = data.questions[i].questions[j].answer;
  							$(".section-" + i).find(
  									".question" + (j + 1) + ' ul').append(
  									'<li class="btn btn-default">'
  											+ String.fromCharCode(0x41 + k)
  											+ '</li>');
  							for (var l = 0; l < str_temp.length; l++) {
  								str_temp_arry = str_temp.split('');
  								code = str_temp_arry[l].charCodeAt();
  								on_index = code - 65;
  								if (on_index == k) {
  									$(".section-" + i).find(
  											".question" + (j + 1) + ' ul li')
  											.eq(on_index).attr("class",
  													"btn btn-default on");
  								}
0b46638a   孙向锦   标准答案
605
  							}
5d2c2033   孙向锦   自定义出题
606
607
608
609
610
611
  						}
  					}
  				}
  			}
  		}
  	}
7242423d   孙向锦   添加固件管理
612
  
83b5ddeb   孙向锦   模板添加
613
614
615
616
617
618
619
620
621
622
623
624
625
  	
  	/*快速建题中,每输入五个答案就加一个空格*/
  	$("#answer").on("input propertychange", function(event) {
  		var answerStr = "";
  		answerStr = $("#answer").val();
  		var result = "";
  		if (answerStr.length > 5) {
  			answerStr = answerStr.replace(new RegExp(" ", "gm"), "");
  			for (var i = 0; i < answerStr.length; i++) {
  				result += answerStr[i];
  				if (i % 5 == 4 && i != answerStr.length - 1) {
  					result += " ";
  				}
0b46638a   孙向锦   标准答案
626
  			}
83b5ddeb   孙向锦   模板添加
627
628
  		} else {
  			result = answerStr;
7242423d   孙向锦   添加固件管理
629
  		}
83b5ddeb   孙向锦   模板添加
630
631
632
633
634
635
636
  		$("#answer").val(result);
  		if (answerStr.length > 0) {
  			$(".tips").text("共" + answerStr.length + "题");
  		} else {
  			$(".tips").text("");
  		}
  	})
5d2c2033   孙向锦   自定义出题
637
  
83b5ddeb   孙向锦   模板添加
638
  	
5d2c2033   孙向锦   自定义出题
639
  
83b5ddeb   孙向锦   模板添加
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
  	function SectionToChinese(section) {
  		var strIns = '', chnStr = '';
  		var unitPos = 0;
  		var zero = true;
  		while (section > 0) {
  			var v = section % 10;
  			if (v === 0) {
  				if (!zero) {
  					zero = true;
  					chnStr = chnNumChar[v] + chnStr;
  				}
  			} else {
  				zero = false;
  				strIns = chnNumChar[v];
  				strIns += chnUnitChar[unitPos];
  				chnStr = strIns + chnStr;
  			}
  			unitPos++;
  			section = Math.floor(section / 10);
  		}
  		return chnStr;
  	}
5d2c2033   孙向锦   自定义出题
662
  
83b5ddeb   孙向锦   模板添加
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
  	
  	if (template != null && template.length > 0) {
  		
  			$("#addQuestion").attr("disabled", "disabled");
  			$("#fast").attr("disabled", "disabled");
  			for (var i = 0; i < template.length; i++) {
  				if (template[i].type == 1) {
  					var answer = "";
  					for (var j = 0; j < template[i].questionNum; j++) {
  						answer += "1";
  					}
  					creat(answer, template[i].optionNum, template[i].score);
  				}
  				if (template[i].type == 2) {
  					addQuestion(5, template[i].optionNum, 1,
  							template[i].questionNum, template[i].score);
  				}
  			}
eef2f078   孙向锦   修改域名问题
681
682
683
684
685
686
687
  			if(testData != null){
  				$(".header_box h1").html(testData.title);
  				$("#time").html(testData.exam_time);
  				if(testData.score != null && testData.score > 0 && testData.score != ''){
  					$("#score_all").html(testData.score);
  				}
  			}
83b5ddeb   孙向锦   模板添加
688
689
690
691
692
  		
  	}else if (testData != null && testData.questions != null
  			&& testData.questions.length > 0) {
  		fastSort(testData.questions, 0, testData.questions.length - 1);
  		for (var i = 0; i < testData.questions.length; i++) {
5d2c2033   孙向锦   自定义出题
693
  
83b5ddeb   孙向锦   模板添加
694
695
696
697
698
699
700
  			if (testData.questions[0].questions
  					&& testData.questions[0].questions.length > 1) {
  				fastSort(testData.questions[i].questions, 0,
  						testData.questions[i].questions.length - 1);
  			}
  		}
  		creatHtml(testData);
ffa525ff   孙向锦   修改出卷页面
701
702
703
704
  	}else{
  		if(testData != null){
  			$(".header_box h1").html(testData.title);
  			$("#time").html(testData.exam_time);
eef2f078   孙向锦   修改域名问题
705
  			if(testData.score != null && testData.score > 0 && testData.score != ''){
ffa525ff   孙向锦   修改出卷页面
706
707
708
  				$("#score_all").html(testData.score);
  			}
  		}
83b5ddeb   孙向锦   模板添加
709
710
  	}
  })