selectPage.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <template>
  2. <!-- 单词最多16个字母 选项最多两行 tx---不要删除 -->
  3. <view class="words-xuan-box">
  4. <!-- 显示区 -->
  5. <selectTypesVue activeSelect="4"></selectTypesVue>
  6. <view class="xuan-body-box">
  7. <!-- 单词区 -->
  8. <view class="show-words-box"> {{data.name}} </view>
  9. <!-- 音标区 -->
  10. <view class="yb-play-box">
  11. <text>{{activeWord.yinbiao}}</text>
  12. <!-- active -->
  13. <audioTwoVue @play-audio="handlePlay" :active-word="activeWord"></audioTwoVue>
  14. </view>
  15. </view>
  16. <!-- 选择区 -->
  17. <view class="select-change-box">
  18. <view class="select-item"
  19. :class="{active: data.answer == 'A', 'select-error': data.answer =='A' && !data.result, 'select-right':data.answer =='A' && data.result}"
  20. @click="handleSelect('A')"><text>{{data.opa}}</text></view>
  21. <view class="select-item"
  22. :class="{active: data.answer == 'B', 'select-error': data.answer =='B' && !data.result, 'select-right':data.answer =='B' && data.result}"
  23. @click="handleSelect('B')"><text>{{data.opb}}</text></view>
  24. <view class="select-item"
  25. :class="{active: data.answer == 'C', 'select-error': data.answer =='C' && !data.result, 'select-right':data.answer =='C' && data.result}"
  26. @click="handleSelect('C')"><text>{{data.opc}}</text></view>
  27. <view class="select-item"
  28. :class="{active: data.answer == 'D', 'select-error': data.answer =='D' && !data.result, 'select-right':data.answer =='D' && data.result}"
  29. @click="handleSelect('D')"><text>{{data.opd}}</text></view>
  30. </view>
  31. </view>
  32. </template>
  33. <script setup>
  34. import selectWordsVue from './selectWords.vue';
  35. import selectTypesVue from './selectTypes.vue';
  36. import audioTwoVue from './audioTwo.vue';
  37. import * as httpApi from "@/api/word.js"
  38. import {
  39. onLoad
  40. } from "@dcloudio/uni-app"
  41. import {
  42. reactive,
  43. computed,
  44. } from 'vue';
  45. import {
  46. getUserIdentity,
  47. } from "@/utils/common.js"
  48. const userCode = getUserIdentity();
  49. const emits = defineEmits(['play-audio'])
  50. const props = defineProps({
  51. activeWord: { // 单词数据
  52. type: Object,
  53. },
  54. activeWords: {
  55. type: Array
  56. },
  57. })
  58. const data = reactive({
  59. name: [],
  60. opa: null,
  61. opb: null,
  62. opc: null,
  63. opd: null,
  64. answer: null, // 已选项
  65. result: false, // 正确性
  66. })
  67. onLoad(() => {
  68. initItem()
  69. })
  70. function handlePlay(opt) {
  71. emits('play-audio', opt)
  72. }
  73. function initItem() {
  74. data.name = props.activeWord.name;
  75. data.opa = props.activeWord.opa;
  76. data.opb = props.activeWord.opb;
  77. data.opc = props.activeWord.opc;
  78. data.opd = props.activeWord.opd;
  79. }
  80. function handleSelect(d1) {
  81. data.answer = d1;
  82. checkIsRight();
  83. }
  84. function checkIsRight() {
  85. if (data.answer == props.activeWord.daan) {
  86. // 正确
  87. data.result = true;
  88. noticeBackDb()
  89. } else {
  90. data.result = false;
  91. }
  92. }
  93. function noticeBackDb() {
  94. if (userCode == 'Visitor') {
  95. // 游客不更新后台
  96. return;
  97. }
  98. httpApi.getWordZhangwo({
  99. type: 2,
  100. wordId: props.activeWord.id
  101. })
  102. }
  103. </script>