TextQuestionView.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <template>
  2. <div v-if="isSyncState" class="question-view">
  3. <question-body :questionBody="question.body" :examQuestion="examQuestion"></question-body>
  4. <div class="ops">
  5. <div class="score">({{examQuestion.questionScore}}分)</div>
  6. </div>
  7. <div class="option">
  8. <textarea v-model="studentAnswer" maxlength="5000" class="stu-answer" type="text" />
  9. </div>
  10. <div class="reset">
  11. <i-button type="warning" size="large" @click="studentAnswer=null">重置答案</i-button>
  12. </div>
  13. </div>
  14. </template>
  15. <script>
  16. import QuestionBody from "./QuestionBody";
  17. import { createNamespacedHelpers } from "vuex";
  18. const { mapMutations } = createNamespacedHelpers("examingHomeModule");
  19. export default {
  20. name: "TextQuestionView",
  21. data() {
  22. return {
  23. studentAnswer: this.examQuestion.studentAnswer
  24. };
  25. },
  26. props: {
  27. question: Object,
  28. examQuestion: Object
  29. },
  30. methods: {
  31. ...mapMutations(["updateExamQuestion"])
  32. },
  33. watch: {
  34. examQuestion() {
  35. // console.log(this.examQuestion.studentAnswer);
  36. this.studentAnswer = this.examQuestion.studentAnswer;
  37. },
  38. studentAnswer() {
  39. let realAnswer = null;
  40. if (this.studentAnswer) {
  41. // 如果有实际内容
  42. realAnswer = this.studentAnswer
  43. .replace(/<script/gi, "&lt;script")
  44. .replace(/script>/gi, "script&gt;");
  45. }
  46. if (realAnswer !== this.examQuestion.studentAnswer) {
  47. this.updateExamQuestion({
  48. order: this.examQuestion.order,
  49. studentAnswer: realAnswer
  50. });
  51. }
  52. }
  53. },
  54. computed: {
  55. isSyncState() {
  56. return this.examQuestion.order == this.$route.params.order;
  57. }
  58. },
  59. components: {
  60. QuestionBody
  61. }
  62. };
  63. </script>
  64. <style scoped>
  65. .question-view {
  66. display: grid;
  67. grid-row-gap: 10px;
  68. }
  69. .question-body {
  70. font-size: 18px;
  71. margin-bottom: 10px;
  72. }
  73. .ops {
  74. display: flex;
  75. align-items: flex-end;
  76. }
  77. .stu-answer {
  78. width: 500px;
  79. min-height: 300px;
  80. }
  81. .option {
  82. display: flex;
  83. }
  84. .question-options {
  85. text-align: left;
  86. }
  87. </style>