d5987f6a
阿宝
组件修改答案
|
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
|
<template>
<el-dialog :visible.sync="diaVisible" width="400" center>
<div slot="title">
<p>
<!-- 设置答案 <i class="fa fa-exchange" @click="editType = !editType"></i> -->
设置答案
</p>
</div>
<div v-show="editType">
<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>
</div>
</template>
</div>
</div>
<!-- <div v-show="!editType">
<p class="dia-tips">
请点击选项按钮设置答案,多选题题目之间用“,”隔开,若添加5道题:“AC,AD,BD,AC,CD”
</p>
<div class="dia-question-box">
<div v-for="(item, index) in FormQuestionList2" :key="index">
<template v-for="(items, indexs) in item.subQuestions">
<div class="set-questions" :key="indexs">
<div class="qs-num">
<p>{{ items.name }}</p>
<p>共{{ items.list.length }}题</p>
</div>
<div class="qs-options">
<p class="ipt">
<el-input
v-model="items.answerList"
@keydown.native="keydownAnswer($event)"
></el-input>
</p>
<p class="answer-box">
<template v-if="items.list[0].questionType == 4">
<span
class="answer-s active"
@click="
items.answerList.length < items.list.length
? (items.answerList += '✓')
: ''
"
>✓</span
>
<span
class="answer-s active"
@click="
items.answerList.length < items.list.length
? (items.answerList += '✗')
: ''
"
>✗</span
>
</template>
<template v-if="items.list[0].questionType == 3">
<span
class="answer-s active"
v-for="option in items.list[0].answerOptions"
:key="option"
@click="setAnswer(items,option)"
>{{ option }}</span
>
<span
class="answer-s active"
@click="
items.answerList.split(',').length < items.list.length
? (items.answerList += ',')
: ''
"
>,</span
>
</template>
<template
v-if="items.list[0].questionType == 2"
class="answer-box"
>
<span
class="answer-s active"
v-for="option in items.list[0].answerOptions"
:key="option"
@click="
items.answerList.length < items.list.length
? (items.answerList += option)
: ''
"
>{{ option }}</span
>
</template>
<span
class="answer-s delButton"
@click="items.answerList = items.answerList.slice(0, -1)"
>x</span
>
<span
class="answer-s ac"
@click="items.answerList = ''"
>AC</span
>
</p>
</div>
</div>
</template>
</div>
</div>
</div> -->
<div slot="footer">
<el-button class="dia-btn" type="primary" @click="saveAnswer"
>确 定</el-button
>
<el-button class="dia-btn" type="danger" @click="cancel">取 消</el-button>
</div>
</el-dialog>
</template>
<script>
import { deepClone } from "utils";
export default {
name: "SetAnswer",
props: {
diaVisible: false, //修改答案
paperId: "",
questionList: Array,
},
data() {
return {
editType: true, //修改答案模式
FormQuestionList: [],
};
},
watch: {
questionList: {
handler: function () {
this.FormQuestionList = deepClone(this.questionList);
console.log(this.questionList);
//组合每道大题中的相同题目
// let questionList = deepClone(item.questionList);
// for (let i = 0; i < questionList.length; i++) {
// let jsons = {};
// let answerOptions = [];
// 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;
// }
// });
// this.FormQuestionList2[i].subQuestions = Object.keys(jsons).map(
// (item) => {
// return {
// name: item,
// list: jsons[item],
// answerList: "",
// };
// }
// );
// }
},
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() {
const { data, status, message } = await this.$request.modifyPaper({
paperId: this.paperId,
questionList: questionList,
});
if (status == 0) {
this.$emit('saveSuccess')
} else {
this.$message.error(message);
}
},
cancel() {
this.$emit('cancel')
},
},
};
</script>
<style lang="scss" scoped>
.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;
}
}
}
</style>
|