extend.html
15.5 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
<script>
var valid_result = false
{notempty name="row"}
var row = {:json_encode($row, 256)};
{else/}
var row = {};
{/notempty}
var app = new Vue({
el: '#app',
data: {
title: '',
kind: 'SINGLE',
// 填空题
fillOptions: [],
showTitleEditor: true,
showTitleFill: true,
// 简答题
shortOptions: [],
// 简答题分数设置
shortScoreDialogVisible: false,
shortScoreConfig: [],
shortScoreIndex: 0,
// 材料题
materialQuestions: [],
materialSummary: {
// 总分数及题数
total_score: 0,
total_quantity: 0,
// 各类题目的分数及题数
judge_quantity: 0,
judge_score: 0,
single_quantity: 0,
single_score: 0,
multi_quantity: 0,
multi_score: 0,
fill_quantity: 0,
fill_score: 0,
short_quantity: 0,
short_score: 0,
},
// 是否属于材料题的子题
isMaterialChild: 0,
},
created() {
// 编辑时初始化数据
if (row) {
this.title = row.title
this.kind = row.kind
this.isMaterialChild = row.is_material_child
this.hideMaterial()
// this.changeIsMaterialChild({target: {value: row.is_material_child}})
console.log('row.answer', row.answer)
switch (row.kind) {
// 填空题
case 'FILL':
this.fillOptions = JSON.parse(row.answer)
console.log('fillOptions', this.fillOptions)
break
// 简答题
case 'SHORT':
let shortAnswer = JSON.parse(row.answer)
this.shortOptions = shortAnswer.config
$('#c-short_answer').html(shortAnswer.answer)
console.log('shortOptions', this.shortOptions)
break
// 材料题
case 'MATERIAL':
let material_questions = row.material_questions ? row.material_questions : []
for (let i = 0; i < material_questions.length; i++) {
if (material_questions[i].question) {
material_questions[i].id = material_questions[i].question.id
material_questions[i].kind = material_questions[i].question.kind
material_questions[i].title = material_questions[i].question.title
material_questions[i].cates = material_questions[i].question.cates
}
}
this.materialQuestions = material_questions
this.statisticsMaterialSummary()
console.log('materialQuestions', this.materialQuestions)
break
default:
break
}
this.hideTitle(row.kind)
} else {
// $('#c-title2').hide()
this.showTitleFill = false
}
},
methods: {
// 修改是否属于材料题的子题
changeIsMaterialChild(e) {
console.log('changeKind', e.target.value)
this.isMaterialChild = e.target.value
this.hideMaterial()
},
// 修改题型
changeKind(e) {
console.log('changeKind', e.target.value)
this.kind = e.target.value
this.hideMaterial()
this.hideTitle(this.kind)
},
// 隐藏材料题子题相关的内容
hideMaterial() {
if (this.isMaterialChild == 1) {
$('label[for="row[kind]-MATERIAL"]').hide()
$('.is_material_child').show()
} else {
$('label[for="row[kind]-MATERIAL"]').show()
$('.is_material_child').hide()
}
if (this.kind == 'MATERIAL') {
$('#is_material_child').hide()
} else {
$('#is_material_child').show()
}
},
// 隐藏题目
hideTitle(kind) {
if (kind == 'FILL') {
this.showTitleEditor = false
this.showTitleFill = true
$('#c-title1').hide()
$('#c-title2').show()
} else {
this.showTitleEditor = true
this.showTitleFill = false
$('#c-title1').show()
$('#c-title2').hide()
}
console.log('hideTitle', kind, this.showTitleEditor, this.showTitleFill)
},
// 填空题 - 插入填空位
addFillOptions() {
this.fillOptions.push({
answers: [''],
})
this.title = this.title == undefined ? '' : this.title
this.title += '______'// 6个_
},
// 填空题 - 填空位添加答案
addFillAnswer(index) {
this.fillOptions[index].answers.push('')
},
// 填空题 - 填空位删除答案
deleteFillAnswer(index, key) {
if (this.fillOptions[index].answers.length === 1) {
this.fillOptions.splice(index, 1)
} else {
this.fillOptions[index].answers.splice(key, 1)
}
},
// 修改题目
changeTitle(e) {
console.log('changeTitle e', e, this.title)
},
// 简答题 - 插入答案
addShortOptions() {
this.shortOptions.push({
answer: '',
score: 1,
})
},
// 简答题 - 删除答案
deleteShortAnswer(index) {
this.shortOptions.splice(index, 1)
},
// 材料题 - 选择题目
selectMaterialQuestion() {
Fast.api.open('exam/question/select?kind=JUDGE,SINGLE,MULTI,FILL,SHORT', '选择题目', {
callback: (data) => {
console.log('selectMaterialQuestions', data)
for (let i = 0; i < data.length; i++) {
// 材料题不允许选择材料题
if (data[i].kind == 'MATERIAL') {
data.splice(i, 1)
continue;
}
data[i].score = 1
}
// 排除已经存在的试题
for (let i = 0; i < this.materialQuestions.length; i++) {
for (let j = 0; j < data.length; j++) {
if (this.materialQuestions[i].id == data[j].id) {
data.splice(j, 1)
}
}
}
// 合并数组
this.materialQuestions = this.materialQuestions.concat(data)
// 统计题目信息
this.statisticsMaterialSummary()
}
})
},
// 材料题 - 修改分数
scoreChange(index) {
console.log('scoreChange', index)
// 统计题目信息
this.statisticsMaterialSummary()
},
// 材料题 - 打开简答题关键词分数设置
openShortScoreDialog(row, index) {
let answer = row.answer
if (typeof answer == 'string') {
answer = JSON.parse(answer)
}
console.log('openShortScoreDialog', row, index, answer)
this.shortScoreConfig = [...answer.config]
this.shortScoreIndex = index
this.shortScoreDialogVisible = true
},
// 材料题 - 提交简答题关键词分数设置
shortScoreSubmit() {
console.log('shortScoreSubmit', this.shortScoreConfig, this.materialQuestions[this.shortScoreIndex])
let answer = this.materialQuestions[this.shortScoreIndex].answer
if (typeof answer == 'string') {
answer = JSON.parse(answer)
}
answer.config = this.shortScoreConfig
this.materialQuestions[this.shortScoreIndex].answer = answer
this.shortScoreConfig = null
this.shortScoreIndex = 0
this.shortScoreDialogVisible = false
// 统计题目信息
this.statisticsMaterialSummary()
},
// 材料题 - 删除试题
deleteQuestion(index) {
console.log('deleteQuestion', index)
this.materialQuestions.splice(index, 1)
// 统计题目信息
this.statisticsMaterialSummary()
},
// 材料题 - 统计材料题的分数及题数
statisticsMaterialSummary() {
let summary = {
// 总分数及题数
total_score: 0,
total_quantity: 0,
// 各类题目的分数及题数
judge_quantity: 0,
judge_score: 0,
single_quantity: 0,
single_score: 0,
multi_quantity: 0,
multi_score: 0,
fill_quantity: 0,
fill_score: 0,
short_quantity: 0,
short_score: 0,
}
for (let i = 0; i < this.materialQuestions.length; i++) {
let question = this.materialQuestions[i]
summary.total_score += question.score ? question.score : 1
summary.total_quantity += 1
switch (question.kind) {
case 'JUDGE':
summary.judge_quantity += 1
summary.judge_score += question.score ? question.score : 1
break
case 'SINGLE':
summary.single_quantity += 1
summary.single_score += question.score ? question.score : 1
break
case 'MULTI':
summary.multi_quantity += 1
summary.multi_score += question.score ? question.score : 1
break
case 'FILL':
summary.fill_quantity += 1
summary.fill_score += question.score ? question.score : 1
break
case 'SHORT':
summary.short_quantity += 1
summary.short_score += question.score ? question.score : 1
break
}
}
this.materialSummary = summary
},
// 验证
valid() {
console.log('trigger valid', this.kind)
switch (this.kind) {
case 'FILL':
console.log('this.fillOptions', this.fillOptions)
for (let i = 0; i < this.fillOptions.length; i++) {
let option = this.fillOptions[i]
for (let j = 0; j < option.answers.length; j++) {
let answer = option.answers[j]
console.log('answer', answer)
if (answer.length == 0) {
Fast.api.msg('填空位(' + (i + 1) + ')的第' + (j + 1) + '个答案不能为空')
console.log('填空位(' + (i + 1) + ')的第' + (j + 1) + '个答案不能为空')
valid_result = false
return false
}
}
}
// $('#options_extend').val(encodeURI(JSON.stringify(this.fillOptions)))
valid_result = true
return true
// 材料题
case 'MATERIAL':
console.log('this.materialQuestions', this.materialQuestions)
// if (this.materialQuestions.length == 0) {
// console.log('材料题的子题目不能为空')
// valid_result = false
// return false
// }
for (let i = 0; i < this.materialQuestions.length; i++) {
let question = this.materialQuestions[i]
if (question.kind == 'SHORT') {
let answer = question.answer
if (typeof answer == 'string') {
answer = JSON.parse(answer)
}
if (answer.config.length == 0) {
Fast.api.msg('简答题的关键词分数不能为空')
console.log('简答题的关键词分数不能为空')
valid_result = false
return false
}
}
}
// 将试题信息转换为JSON字符串
let questions = []
for (let i = 0; i < this.materialQuestions.length; i++) {
let question = this.materialQuestions[i]
questions.push({
id: question.id,
score: question.score,
answer: question.answer,
answer_config: question.answer_config ? question.answer_config : null,
})
}
$('#c-material_questions').val(JSON.stringify(questions))
valid_result = true
return true
default:
valid_result = true
return true
}
}
}
})
</script>
<style>
.sp_results {
min-width: 600px;
}
</style>