tiankong.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <template>
  2. <view v-if="question" class="phone-tiankong-box">
  3. <view class="phone-shiti-question">
  4. <view class="question-num">{{question.onlyNum}}、</view>
  5. <!-- 题干区域 -->
  6. <rich-text :nodes="question.name"></rich-text>
  7. </view>
  8. <!-- 选项区域 -->
  9. <view v-for="(item,index) in question.reply" class="tiankong-option-box" :key="index"
  10. :class="formatClass(index)">
  11. <text class="option-question">填空{{index+1}}:</text>
  12. <input type="text" v-model="question.reply[index]" class="option-question-text"
  13. :placeholder="`请输入填空${index+1}答案`">
  14. </view>
  15. <view class="phone-question-answer-box">
  16. <view class="phone-line-title">答案解析</view>
  17. <view class="btdf-row">本题得分:<text>{{data.score}}</text>分</view>
  18. <view class="zqda-row">正确答案:
  19. <view v-for="(item,index) in data.result">{{`填空${index+1}`}} : {{item}}</view>
  20. </view>
  21. <view class="ndda-row">您的答案:
  22. <view v-for="(item,index) in data.reply"> {{`填空${index+1}`}}: {{item}}</view>
  23. </view>
  24. <view class="dajx-row">答案解析:
  25. <rich-text :nodes="data.answer"></rich-text>
  26. </view>
  27. </view>
  28. </view>
  29. </template>
  30. <script setup>
  31. import {
  32. ref,
  33. reactive,
  34. watch
  35. } from 'vue';
  36. const data = reactive({
  37. name: '', //题干数据
  38. score: '',
  39. result: '',
  40. reply: '',
  41. answer: '',
  42. contents: [], // 选项数据
  43. })
  44. const props = defineProps({
  45. question: {
  46. type: Object,
  47. },
  48. showError: {
  49. type: Boolean,
  50. default: false
  51. }
  52. })
  53. watch(() => props.question, (val) => formatData(val), {
  54. immediate: true
  55. })
  56. function formatData(val) {
  57. data.reply = val.reply || [];
  58. data.result = val.result || [];
  59. data.answer = val.answer;
  60. }
  61. function formatClass(index) {
  62. if (props.showError) {
  63. return {
  64. active_right: props.question.result[index].some(item => item == props.question.reply[index] ? props
  65. .question.reply[index].trim() : ''),
  66. showError: !props.question.result[index].some(item => item == props.question.reply[index] ? props.question
  67. .reply[index].trim() : '')
  68. }
  69. }
  70. }
  71. </script>