tiankong.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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>正确答案:
  17. <view class="green-color" v-for="(item,index) in data.result">{{`填空${index+1}`}} :{{item}}</view>
  18. </view>
  19. <view>您的答案:
  20. <view class="orange-color" v-for="(item,index) in data.reply"> {{`填空${index+1}`}}:{{item}}</view>
  21. </view>
  22. <view class="btdf-row">本题得分:<text>{{data.score}}</text>分</view>
  23. <view class="dajx-row">答案解析:
  24. <rich-text :nodes="data.answer"></rich-text>
  25. </view>
  26. </view>
  27. </view>
  28. </template>
  29. <script setup>
  30. import {
  31. ref,
  32. reactive,
  33. watch
  34. } from 'vue';
  35. const data = reactive({
  36. name: '', //题干数据
  37. score: '',
  38. result: '',
  39. reply: '',
  40. answer: '',
  41. contents: [], // 选项数据
  42. })
  43. const props = defineProps({
  44. question: {
  45. type: Object,
  46. },
  47. showError: {
  48. type: Boolean,
  49. default: false
  50. }
  51. })
  52. watch(() => props.question, (val) => formatData(val), {
  53. immediate: true
  54. })
  55. function formatData(val) {
  56. data.reply = val.reply || [];
  57. data.result = val.result || [];
  58. data.answer = val.answer;
  59. }
  60. function formatClass(index) {
  61. if (props.showError) {
  62. return {
  63. active_right: props.question.result[index].some(item => item == props.question.reply[index] ? props
  64. .question.reply[index].trim() : ''),
  65. showError: !props.question.result[index].some(item => item == props.question.reply[index] ? props.question
  66. .reply[index].trim() : '')
  67. }
  68. }
  69. }
  70. </script>