BooleanQuestion.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <div class="boolean-question">
  3. <el-form
  4. ref="modalFormComp"
  5. :model="modalForm"
  6. :rules="rules"
  7. label-width="100px"
  8. >
  9. <el-form-item prop="quesBody" label="题干">
  10. <v-editor
  11. v-model="modalForm.quesBody"
  12. @change="quesBodyChange"
  13. ></v-editor>
  14. </el-form-item>
  15. <el-form-item prop="quesAnswer" label="答案">
  16. <el-radio-group v-model="modalForm.quesAnswer" @change="answerChange">
  17. <el-radio
  18. v-for="option in answerOptions"
  19. :key="option.value"
  20. :label="option.value"
  21. >
  22. {{ option.label }}
  23. </el-radio>
  24. </el-radio-group>
  25. </el-form-item>
  26. <el-form-item label="答案解析">
  27. <v-editor v-model="modalForm.comment"></v-editor>
  28. </el-form-item>
  29. </el-form>
  30. <question-info-edit
  31. ref="QuestionInfoEdit"
  32. :question="modalForm"
  33. @change="questionInfoChange"
  34. ></question-info-edit>
  35. </div>
  36. </template>
  37. <script>
  38. import { isAnEmptyRichText } from "@/utils/utils";
  39. import { getInitQuestionModel } from "../model/questionModel";
  40. import QuestionInfoEdit from "../QuestionInfoEdit.vue";
  41. export default {
  42. name: "BooleanQuestion",
  43. components: { QuestionInfoEdit },
  44. props: {
  45. question: {
  46. type: Object,
  47. default() {
  48. return {};
  49. },
  50. },
  51. },
  52. data() {
  53. return {
  54. modalForm: {},
  55. answerOptions: [
  56. {
  57. value: "false",
  58. label: "错误",
  59. },
  60. {
  61. value: "true",
  62. label: "正确",
  63. },
  64. ],
  65. rules: {
  66. quesBody: [
  67. {
  68. validator: (rule, value, callback) => {
  69. if (!value || isAnEmptyRichText(value)) {
  70. return callback(new Error(`请输入题干`));
  71. }
  72. callback();
  73. },
  74. trigger: "change",
  75. },
  76. ],
  77. quesAnswer: [
  78. {
  79. required: true,
  80. message: "请设置答案",
  81. trigger: "change",
  82. },
  83. ],
  84. },
  85. };
  86. },
  87. created() {
  88. this.initData();
  89. },
  90. methods: {
  91. initData() {
  92. this.modalForm = this.$objAssign(
  93. getInitQuestionModel("BOOL_ANSWER_QUESTION"),
  94. this.question
  95. );
  96. },
  97. quesBodyChange() {
  98. this.$refs.modalFormComp.validateField(`quesBody`, () => {});
  99. },
  100. answerChange() {
  101. this.$refs.modalFormComp.validateField(`quesAnswer`, () => {});
  102. },
  103. questionInfoChange(questionInfo) {
  104. this.modalForm = Object.assign({}, this.modalForm, questionInfo);
  105. },
  106. validate() {
  107. return this.$refs.modalFormComp.validate();
  108. },
  109. getData() {
  110. let data = { ...this.modalForm };
  111. return data;
  112. },
  113. },
  114. };
  115. </script>