Commit def690b2e067cdebe8d4515ad30109cb2da7924a
1 parent
f5729396
批量设置答案
Showing
4 changed files
with
22 additions
and
34 deletions
src/components/setAnswer.vue
... | ... | @@ -133,11 +133,7 @@ |
133 | 133 | > |
134 | 134 | <span |
135 | 135 | class="answer-s active" |
136 | - @click=" | |
137 | - formAns.answerList.split(',').length < formAns.subNum | |
138 | - ? (formAns.answerList += ',') | |
139 | - : '' | |
140 | - " | |
136 | + @click="setMultiple(formAns, ',')" | |
141 | 137 | >,</span |
142 | 138 | > |
143 | 139 | </template> | ... | ... |
src/views/examinationPaper/add.vue
... | ... | @@ -500,6 +500,7 @@ |
500 | 500 | questionForm.questionType == 3 || |
501 | 501 | questionForm.questionType == 6 |
502 | 502 | " |
503 | + ref="formAnsIpt2" | |
503 | 504 | v-model="questionForm.answerList" |
504 | 505 | @keydown.native=" |
505 | 506 | keydownAnswer($event, questionForm.questionType, 1) |
... | ... | @@ -541,18 +542,13 @@ |
541 | 542 | v-if="opIdx < questionForm.selectNum" |
542 | 543 | class="answer-s active" |
543 | 544 | :key="option" |
544 | - @click="setMultiple(questionForm, option)" | |
545 | + @click="setMultiple(questionForm, option, 1)" | |
545 | 546 | >{{ option }}</span |
546 | 547 | > |
547 | 548 | </template> |
548 | 549 | <span |
549 | 550 | class="answer-s active" |
550 | - @click=" | |
551 | - questionForm.answerList.split(',').length < | |
552 | - questionForm.number | |
553 | - ? (questionForm.answerList += ',') | |
554 | - : '' | |
555 | - " | |
551 | + @click="setMultiple(questionForm, ',', 1)" | |
556 | 552 | >,</span |
557 | 553 | > |
558 | 554 | </template> |
... | ... | @@ -774,16 +770,12 @@ |
774 | 770 | class="answer-s active" |
775 | 771 | v-for="option in formAns.answerOptions.split(',')" |
776 | 772 | :key="option" |
777 | - @click="setMultiple(formAns, option)" | |
773 | + @click="setMultiple(formAns, option, 2)" | |
778 | 774 | >{{ option }}</span |
779 | 775 | > |
780 | 776 | <span |
781 | 777 | class="answer-s active" |
782 | - @click=" | |
783 | - formAns.answerList.split(',').length < formAns.subNum | |
784 | - ? (formAns.answerList += ',') | |
785 | - : '' | |
786 | - " | |
778 | + @click="setMultiple(formAns, ',', 2)" | |
787 | 779 | >,</span |
788 | 780 | > |
789 | 781 | </template> |
... | ... | @@ -1087,8 +1079,7 @@ export default { |
1087 | 1079 | |
1088 | 1080 | this.diaSetAns = true; |
1089 | 1081 | }, |
1090 | - insertTxtAndSetcursor(answerList, str) { | |
1091 | - let element = this.$refs.formAnsIpt.$el.children[0]; // 获取到指定标签 | |
1082 | + insertTxtAndSetcursor(element, answerList, str) { | |
1092 | 1083 | let startPos = element.selectionStart; // 获取光标开始的位置 |
1093 | 1084 | if (startPos === undefined) { |
1094 | 1085 | // 如果没有光标位置 不操作 |
... | ... | @@ -1103,10 +1094,19 @@ export default { |
1103 | 1094 | }; |
1104 | 1095 | } |
1105 | 1096 | }, |
1106 | - setMultiple(obj, answer) { | |
1097 | + setMultiple(obj, answer, type) { | |
1107 | 1098 | //多选答案设置 |
1108 | - let resault = this.insertTxtAndSetcursor(obj.answerList || "", answer); | |
1099 | + let elements = | |
1100 | + type == 1 | |
1101 | + ? this.$refs["formAnsIpt2"].$el.children[0] | |
1102 | + : this.$refs["formAnsIpt"].$el.children[0]; | |
1103 | + let resault = this.insertTxtAndSetcursor( | |
1104 | + elements, | |
1105 | + obj.answerList || "", | |
1106 | + answer | |
1107 | + ); | |
1109 | 1108 | obj.answerList = resault.text; |
1109 | + console.log(resault.startPos); | |
1110 | 1110 | let str = obj.answerList; |
1111 | 1111 | let str2; |
1112 | 1112 | if (!!obj.answerOptions) { |
... | ... | @@ -1120,8 +1120,8 @@ export default { |
1120 | 1120 | str2 = checkAnswer(str, 3, obj.selectNum, obj.answerList.length); |
1121 | 1121 | } |
1122 | 1122 | obj.answerList = str2; |
1123 | - this.$refs.formAnsIpt.$el.children[0].focus(); | |
1124 | - this.$refs.formAnsIpt.$el.children[0].selectionStart = resault.startPos; | |
1123 | + elements.focus(); | |
1124 | + elements.selectionStart = resault.startPos; | |
1125 | 1125 | }, |
1126 | 1126 | saveFormAns() { |
1127 | 1127 | //批量修改答案 | ... | ... |
src/views/examinationPaper/edit.vue
... | ... | @@ -297,11 +297,7 @@ |
297 | 297 | > |
298 | 298 | <span |
299 | 299 | class="answer-s active" |
300 | - @click=" | |
301 | - formAns.answerList.split(',').length < formAns.subNum | |
302 | - ? (formAns.answerList += ',') | |
303 | - : '' | |
304 | - " | |
300 | + @click="setMultiple(formAns, ',')" | |
305 | 301 | >,</span |
306 | 302 | > |
307 | 303 | </template> | ... | ... |
src/views/test/editAnswer.vue
... | ... | @@ -281,11 +281,7 @@ |
281 | 281 | > |
282 | 282 | <span |
283 | 283 | class="answer-s active" |
284 | - @click=" | |
285 | - formAns.answerList.split(',').length < formAns.subNum | |
286 | - ? (formAns.answerList += ',') | |
287 | - : '' | |
288 | - " | |
284 | + @click="setMultiple(formAns, ',')" | |
289 | 285 | >,</span |
290 | 286 | > |
291 | 287 | </template> | ... | ... |