d5987f6a
阿宝
组件修改答案
|
1
|
<template>
|
45504a95
阿宝
即时测页面,以及小题修改答案
|
2
3
4
5
6
7
8
|
<div
class="el-dialog-wrapper"
v-show="diaVisible"
width="400"
center
@click.self="cancel"
>
|
dd5150c5
阿宝
数据同步
|
9
10
|
<div class="el-dialog-content">
<p class="title">
|
45504a95
阿宝
即时测页面,以及小题修改答案
|
11
12
|
设置答案 <i class="fa fa-exchange" @click="editType = !editType"></i>
<!-- 设置答案 -->
|
dd5150c5
阿宝
数据同步
|
13
|
<i class="el-icon-close" @click="cancel"></i>
|
d5987f6a
阿宝
组件修改答案
|
14
|
</p>
|
45504a95
阿宝
即时测页面,以及小题修改答案
|
15
|
<div v-if="editType">
|
dd5150c5
阿宝
数据同步
|
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
|
<div v-for="(item, index) in FormQuestionList" :key="index">
<template v-for="(subQuestions, indexs) in item.subQuestions">
<div
class="sub-questions"
:key="indexs"
v-if="subQuestions.correctAnswer"
>
<div class="qs-num">题{{ subQuestions.questionIndex }}</div>
<div class="qs-options qs-options2">
<p v-if="subQuestions.questionType == 4" class="answer-box">
<span
class="answer-s"
:class="subQuestions.correctAnswer == 1 ? 'active' : ''"
@click="subQuestions.correctAnswer = 1"
>✓</span
>
<span
class="answer-s"
:class="subQuestions.correctAnswer == 2 ? 'active' : ''"
@click="subQuestions.correctAnswer = 2"
>✗</span
>
</p>
<p v-if="subQuestions.questionType == 3" class="answer-box">
<span
class="answer-s"
v-for="option in subQuestions.answerOptions"
:class="
subQuestions.correctAnswer.includes(option)
? 'active'
: ''
"
:key="option"
@click="changAnswer(subQuestions, option)"
>{{ option }}</span
>
</p>
<p v-if="subQuestions.questionType == 2" class="answer-box">
<span
class="answer-s"
v-for="option in subQuestions.answerOptions"
:class="
subQuestions.correctAnswer == option ? 'active' : ''
"
:key="option"
@click="subQuestions.correctAnswer = option"
>{{ option }}</span
>
</p>
</div>
|
d5987f6a
阿宝
组件修改答案
|
66
|
</div>
|
dd5150c5
阿宝
数据同步
|
67
68
|
</template>
</div>
|
d5987f6a
阿宝
组件修改答案
|
69
|
</div>
|
45504a95
阿宝
即时测页面,以及小题修改答案
|
70
|
<div v-else>
|
d5987f6a
阿宝
组件修改答案
|
71
|
<p class="dia-tips">
|
45504a95
阿宝
即时测页面,以及小题修改答案
|
72
73
|
请点击选项按钮设置答案,多选题题目之间用“,”隔开,若添加5道题:“AC,AD,BD,AC,CD”
</p>
|
d5987f6a
阿宝
组件修改答案
|
74
75
|
<div class="dia-question-box">
<div v-for="(item, index) in FormQuestionList2" :key="index">
|
45504a95
阿宝
即时测页面,以及小题修改答案
|
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
|
<div class="set-questions">
<div class="qs-num">
<p class="txt">{{ item.name }}</p>
<p class="num">共{{ item.list.length }}题</p>
</div>
<div class="qs-options">
<p class="ipt">
<el-input
v-model="item.answerList"
@keydown.native="keydownAnswer($event)"
></el-input>
</p>
<p class="answer-box">
<template v-if="item.list[0].questionType == 4">
<span
class="answer-s active"
@click="
item.answerList.length < item.list.length
? (item.answerList += '✓')
: ''
"
>✓</span
>
<span
class="answer-s active"
@click="
item.answerList.length < item.list.length
? (item.answerList += '✗')
: ''
"
>✗</span
|
d5987f6a
阿宝
组件修改答案
|
107
|
>
|
45504a95
阿宝
即时测页面,以及小题修改答案
|
108
109
|
</template>
<template v-if="item.list[0].questionType == 3">
|
d5987f6a
阿宝
组件修改答案
|
110
|
<span
|
45504a95
阿宝
即时测页面,以及小题修改答案
|
111
112
113
114
115
|
class="answer-s active"
v-for="option in item.list[0].answerOptions"
:key="option"
@click="setAnswer(item, option)"
>{{ option }}</span
|
d5987f6a
阿宝
组件修改答案
|
116
117
|
>
<span
|
45504a95
阿宝
即时测页面,以及小题修改答案
|
118
119
120
121
122
123
124
|
class="answer-s active"
@click="
item.answerList.split(',').length < item.list.length
? (item.answerList += ',')
: ''
"
>,</span
|
d5987f6a
阿宝
组件修改答案
|
125
|
>
|
45504a95
阿宝
即时测页面,以及小题修改答案
|
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
</template>
<template
v-if="item.list[0].questionType == 2"
class="answer-box"
>
<span
class="answer-s active"
v-for="option in item.list[0].answerOptions"
:key="option"
@click="
item.answerList.length < item.list.length
? (item.answerList += option)
: ''
"
>{{ option }}</span
>
</template>
<span
class="answer-s delButton"
@click="item.answerList = item.answerList.slice(0, -1)"
>x</span
>
</p>
|
d5987f6a
阿宝
组件修改答案
|
149
|
</div>
|
45504a95
阿宝
即时测页面,以及小题修改答案
|
150
|
</div>
|
d5987f6a
阿宝
组件修改答案
|
151
152
|
</div>
</div>
|
45504a95
阿宝
即时测页面,以及小题修改答案
|
153
|
</div>
|
dd5150c5
阿宝
数据同步
|
154
155
156
157
158
159
160
161
|
<div class="footer-box">
<el-button class="dia-btn" type="primary" @click="saveAnswer"
>确 定</el-button
>
<el-button class="dia-btn" type="danger" @click="cancel"
>取 消</el-button
>
</div>
|
d5987f6a
阿宝
组件修改答案
|
162
|
</div>
|
dd5150c5
阿宝
数据同步
|
163
|
</div>
|
d5987f6a
阿宝
组件修改答案
|
164
165
166
|
</template>
<script>
|
45504a95
阿宝
即时测页面,以及小题修改答案
|
167
|
import { deepClone, checkAnswer } from "utils";
|
d5987f6a
阿宝
组件修改答案
|
168
169
170
171
172
173
174
175
176
177
178
|
export default {
name: "SetAnswer",
props: {
diaVisible: false, //修改答案
paperId: "",
questionList: Array,
},
data() {
return {
editType: true, //修改答案模式
FormQuestionList: [],
|
45504a95
阿宝
即时测页面,以及小题修改答案
|
179
|
FormQuestionList2: [],
|
d5987f6a
阿宝
组件修改答案
|
180
181
182
183
184
185
|
};
},
watch: {
questionList: {
handler: function () {
this.FormQuestionList = deepClone(this.questionList);
|
45504a95
阿宝
即时测页面,以及小题修改答案
|
186
|
this.FormQuestionList2 = [];
|
d5987f6a
阿宝
组件修改答案
|
187
|
console.log(this.questionList);
|
45504a95
阿宝
即时测页面,以及小题修改答案
|
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
|
// 组合每道大题中的相同题目
let questionList = deepClone(this.questionList);
let jsons = {};
let answerOptions = [];
for (let i = 0; i < questionList.length; i++) {
questionList[i].subQuestions.map((items) => {
let txt = this.setSubPro(items.questionType);
if (jsons[txt]) {
jsons[txt].push(items);
} else {
jsons[txt] = [items];
}
if (items.questionType == 2 || items.questionType == 3) {
if (items.answerOptions.length > answerOptions.length) {
answerOptions = items.answerOptions;
}
jsons[txt][0].answerOptions = answerOptions;
}
});
console.log(jsons);
}
this.FormQuestionList2 = Object.keys(jsons).map((item) => {
let answerList = "";
jsons[item].map((items, index) => {
if (items.questionType == 2) {
answerList += items.correctAnswer;
} else if (items.questionType == 3) {
answerList +=
items.correctAnswer +
(jsons[item].length - 1 != index ? "," : "");
} else if (items.questionType == 4) {
answerList += items.correctAnswer == 1 ? "✓" : "✗";
}
});
return {
name: item,
list: jsons[item],
answerList: answerList,
};
});
|
d5987f6a
阿宝
组件修改答案
|
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
|
},
deep: true,
},
},
methods: {
setSubPro(type) {
let tit;
switch (type) {
case 2:
tit = "单选题";
break;
case 3:
tit = "多选题";
break;
case 4:
tit = "判断题";
break;
case 5:
tit = "主观题";
break;
}
return tit;
},
keydownAnswer(event) {
//快速答案设置禁止输入
if (
event.key == "Meta" ||
event.key == "CapsLock" ||
event.key == "Shift" ||
event.key == "Enter" ||
event.key == "Alt" ||
event.key == "Backspace" ||
event.key == "Delete" ||
event.key == "ArrowUp" ||
event.key == "ArrowDown" ||
event.key == "ArrowLeft" ||
event.key == "v" ||
event.key == "V" ||
event.key == "ArrowRight"
) {
return;
} else {
event.returnValue = "";
}
},
setAnswer(obj, answer) {
//多选答案设置
obj.answerList += answer;
let str = obj.answerList;
let str2 = checkAnswer(
str,
3,
obj.list[0].answerOptions,
obj.list.length
);
obj.answerList = str2;
},
changAnswer(sub, option) {
//设置多选答案
let str = new RegExp(option, "g");
if (sub.correctAnswer?.includes(option)) {
sub.correctAnswer = sub.correctAnswer.replace(str, "");
} else {
let arrs = (sub.correctAnswer && sub.correctAnswer.split("")) || [];
arrs.push(option);
sub.correctAnswer = arrs.sort().join("");
}
},
async saveAnswer() {
|
45504a95
阿宝
即时测页面,以及小题修改答案
|
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
|
let questionList = [],
questionList2 = [];
if (this.editType) {
questionList = [...this.FormQuestionList];
} else {
this.FormQuestionList2.map((item) => {
item.list.map((items, index) => {
if (items.questionType == 2 ) {
items.correctAnswer = item.answerList.split("")[index];
} else if (items.questionType == 3) {
items.correctAnswer = item.answerList.split(",")[index];
}else if (items.questionType == 4) {
items.correctAnswer = item.answerList[index] == "✓" ? 1 : 2;
}
questionList2.push(items);
});
});
questionList = this.FormQuestionList.map((item) => {
let subQuestions = item.subQuestions.map((items) => {
items.correctAnswer = questionList2.find((question) => {
return question.questionIndex == items.questionIndex;
})?.correctAnswer;
return items;
});
return {
...item,
subQuestions: [...subQuestions],
};
});
}
console.log(questionList);
|
d5987f6a
阿宝
组件修改答案
|
328
329
330
331
332
|
const { data, status, message } = await this.$request.modifyPaper({
paperId: this.paperId,
questionList: questionList,
});
if (status == 0) {
|
dd5150c5
阿宝
数据同步
|
333
|
this.$emit("saveSuccess");
|
d5987f6a
阿宝
组件修改答案
|
334
335
336
337
338
|
} else {
this.$message.error(message);
}
},
cancel() {
|
dd5150c5
阿宝
数据同步
|
339
|
this.$emit("cancel");
|
d5987f6a
阿宝
组件修改答案
|
340
341
342
343
344
345
|
},
},
};
</script>
<style lang="scss" scoped>
|
dd5150c5
阿宝
数据同步
|
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
|
.el-dialog-wrapper {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
overflow: auto;
margin: 0;
background: rgba(0, 0, 0, 0.5);
display: flex;
justify-content: center;
align-items: center;
z-index: 2022;
.el-dialog-content {
width: 600px;
|
45504a95
阿宝
即时测页面,以及小题修改答案
|
361
|
background: #fff;
|
dd5150c5
阿宝
数据同步
|
362
|
border-radius: 10px;
|
45504a95
阿宝
即时测页面,以及小题修改答案
|
363
|
padding: 16px 20px 20px;
|
dd5150c5
阿宝
数据同步
|
364
|
}
|
45504a95
阿宝
即时测页面,以及小题修改答案
|
365
|
.title {
|
dd5150c5
阿宝
数据同步
|
366
367
|
font-size: 18px;
position: relative;
|
45504a95
阿宝
即时测页面,以及小题修改答案
|
368
369
|
margin-bottom: 20px;
.el-icon-close {
|
dd5150c5
阿宝
数据同步
|
370
|
position: absolute;
|
45504a95
阿宝
即时测页面,以及小题修改答案
|
371
372
373
|
top: 0;
right: 12px;
padding: 2px;
|
dd5150c5
阿宝
数据同步
|
374
375
|
font-size: 16px;
cursor: pointer;
|
45504a95
阿宝
即时测页面,以及小题修改答案
|
376
377
378
379
380
381
382
383
|
&:hover {
color: #667ffa;
}
}
.fa-exchange {
color: #999;
cursor: pointer;
&:hover {
|
dd5150c5
阿宝
数据同步
|
384
385
386
387
388
389
390
|
color: #667ffa;
}
}
}
}
.footer-box {
text-align: center;
|
45504a95
阿宝
即时测页面,以及小题修改答案
|
391
|
padding-top: 20px;
|
dd5150c5
阿宝
数据同步
|
392
|
}
|
d5987f6a
阿宝
组件修改答案
|
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
|
.sub-questions {
width: 100%;
display: flex;
&:hover {
background: #f8f8f8;
}
& > div {
min-height: 40px;
padding: 5px;
flex-shrink: 0;
display: flex;
justify-content: center;
align-items: center;
}
.qs-num {
width: 80px;
font-size: 16px;
color: #333;
font-weight: 500;
}
.qs-options {
flex: 1;
}
.qs-options2 {
text-align: left;
justify-content: flex-start;
padding-left: 20px;
.answer-s {
cursor: pointer;
border-color: #667ffd;
color: #667ffd;
margin: 0 15px;
&.active {
color: #fff;
}
}
}
:deep(.el-select) {
.el-input__inner {
border-radius: 20px;
border-color: #667ffd;
width: 150px;
height: 32px;
line-height: 32px;
background: rgba($color: #667ffd, $alpha: 0.05);
}
.el-input__icon {
line-height: 32px;
}
}
}
|
45504a95
阿宝
即时测页面,以及小题修改答案
|
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
|
.dia-tips {
line-height: 18px;
padding-bottom: 10px;
}
.set-questions {
display: flex;
padding-right: 20px;
margin-bottom: 20px;
.qs-num {
width: 80px;
padding-top: 6px;
.txt {
font-size: 16px;
line-height: 18px;
margin-bottom: 6px;
}
}
.qs-options {
flex: 1;
.ipt {
margin-bottom: 5px;
}
.answer-box {
.answer-s {
cursor: pointer;
user-select: none;
&:first-of-type {
margin-left: 0;
}
}
}
}
.delButton {
border-color: #ff6868;
background: #ff6868 url("../assets/images/arrow.png") no-repeat center;
background-size: 19px;
color: transparent;
}
.ac {
border-color: #ff6868;
background: #ff6868;
color: #fff;
}
}
|
d5987f6a
阿宝
组件修改答案
|
488
|
</style>
|