danxuan.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <template>
  2. <view v-if="question" class="phone-danxuan-box">
  3. <view>{{question.onlyNum}}、</view>
  4. <!-- 题干区域 -->
  5. <rich-text :nodes="data.name" class="phone-shiti-question"></rich-text>
  6. <!-- 选项区域 -->
  7. <view v-for="(item,index) in data.contents" class="danxuan-option-box" :class="formatClass(index)" :key="index">
  8. <text class="option-change" @click="onSelect(index)">{{item.number}}</text>
  9. <rich-text :nodes="item.label" class="option-question"></rich-text>
  10. </view>
  11. </view>
  12. </template>
  13. <script setup>
  14. import {
  15. ref,
  16. reactive,
  17. watch
  18. } from 'vue';
  19. import {
  20. useQuestionTools
  21. } from "./useQuestionTools"
  22. const {
  23. getLetterByIndex
  24. } = useQuestionTools();
  25. const props = defineProps({
  26. question: {
  27. type: Object,
  28. },
  29. showError: {
  30. type: Boolean,
  31. default: false
  32. }
  33. })
  34. const data = reactive({
  35. name: '', //题干数据
  36. contents: [], // 选项数据
  37. })
  38. watch(() => props.question, (val) => formatData(val), {
  39. immediate: true
  40. })
  41. function formatClass(index) {
  42. if (props.showError) {
  43. return {
  44. active_right: props.question.result == index,
  45. showError: props.question.reply == index && props.question.result != index
  46. }
  47. } else {
  48. return {
  49. active: props.question.reply == index
  50. }
  51. }
  52. }
  53. function formatData(val) {
  54. if (val) {
  55. data.name = val.name;
  56. data.contents = val.content.map((item, index) => {
  57. return {
  58. label: item,
  59. number: getLetterByIndex(index)
  60. }
  61. })
  62. }
  63. }
  64. function onSelect(index) {
  65. if (props.showError) {
  66. return;
  67. }
  68. props.question.reply = index;
  69. }
  70. </script>
  71. <style lang="scss" scoped>
  72. .active {
  73. background-color: yellowgreen;
  74. }
  75. </style>