123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- <template>
- <div class="fill-blank-question">
- <el-form
- ref="modalFormComp"
- :model="modalForm"
- :rules="rules"
- label-width="100px"
- >
- <el-form-item prop="quesBody" label="题干">
- <v-editor
- v-model="modalForm.quesBody"
- enable-answer-point
- @answer-point-changed="answerPointsChange"
- @change="quesBodyChange"
- ></v-editor>
- </el-form-item>
- <el-form-item label="答案"></el-form-item>
- <el-form-item
- v-for="(answer, oindex) in modalForm.quesAnswer"
- :key="oindex"
- :prop="`quesAnswer.${oindex}.body`"
- :rules="answerRule"
- >
- <div class="question-edit-option">
- <div class="option-check">({{ oindex + 1 }})</div>
- <div class="option-body">
- <v-editor v-model="answer.body"></v-editor>
- </div>
- </div>
- </el-form-item>
- <el-form-item label="答案解析">
- <v-editor v-model="modalForm.comment"></v-editor>
- </el-form-item>
- </el-form>
- <question-info-edit
- ref="QuestionInfoEdit"
- :question="modalForm"
- @change="questionInfoChange"
- ></question-info-edit>
- </div>
- </template>
- <script>
- import { isAnEmptyRichText } from "@/utils/utils";
- import { getInitQuestionModel } from "../model/questionModel";
- import QuestionInfoEdit from "../QuestionInfoEdit.vue";
- export default {
- name: "FillBlankQuestion",
- components: { QuestionInfoEdit },
- props: {
- question: {
- type: Object,
- default() {
- return {};
- },
- },
- },
- data() {
- return {
- modalForm: {},
- rules: {
- quesBody: [
- {
- validator: (rule, value, callback) => {
- if (!value || isAnEmptyRichText(value)) {
- return callback(new Error(`请输入题干`));
- }
- callback();
- },
- trigger: "change",
- },
- ],
- },
- answerRule: {
- validator: (rule, value, callback) => {
- if (!value || !value.length) {
- return callback(new Error(`请输入答案内容`));
- }
- callback();
- },
- trigger: "change",
- },
- };
- },
- created() {
- this.initData();
- },
- methods: {
- initData() {
- this.modalForm = this.$objAssign(
- getInitQuestionModel("FILL_BLANK_QUESTION"),
- this.question
- );
- this.modalForm.quesAnswer = this.modalForm.quesAnswer.map((item) => {
- return {
- body: item,
- };
- });
- },
- answerPointsChange(answerPointsCount) {
- console.log(answerPointsCount);
- let curAnswerPointsCount = this.modalForm.quesAnswer.length;
- if (curAnswerPointsCount === answerPointsCount) return;
- if (curAnswerPointsCount > answerPointsCount) {
- this.modalForm.quesAnswer = this.modalForm.quesAnswer.slice(
- 0,
- answerPointsCount
- );
- } else {
- for (let i = curAnswerPointsCount; i < answerPointsCount; i++) {
- this.modalForm.quesAnswer.push({
- body: null,
- });
- }
- }
- },
- quesBodyChange() {
- this.$refs.modalFormComp.validateField(`quesBody`, () => {});
- },
- questionInfoChange(questionInfo) {
- this.modalForm = Object.assign({}, this.modalForm, questionInfo);
- },
- validate() {
- return this.$refs.modalFormComp.validate();
- },
- getData() {
- let data = { ...this.modalForm };
- data.quesAnswer = this.modalForm.quesAnswer.map((item, index) => {
- return {
- ...item.body,
- index,
- };
- });
- return data;
- },
- },
- };
- </script>
|