selectPage.vue 3.1 KB

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