selectPage.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. import {resultAudioPlayer} from "./useAudioRightWrong"
  52. const resultAudioPlayerD = new resultAudioPlayer();
  53. const userCode = getUserIdentity();
  54. const emits = defineEmits(['play-audio'])
  55. const props = defineProps({
  56. activeWord: { // 单词数据
  57. type: Object,
  58. },
  59. activeWords: {
  60. type: Array
  61. },
  62. })
  63. const data = reactive({
  64. name: [],
  65. opa: null,
  66. opb: null,
  67. opc: null,
  68. opd: null,
  69. answer: null, // 已选项
  70. result: false, // 正确性
  71. })
  72. onLoad(() => {
  73. initItem()
  74. })
  75. function handlePlay(opt) {
  76. emits('play-audio', opt)
  77. }
  78. function initItem() {
  79. data.name = props.activeWord.name;
  80. data.opa = props.activeWord.opa;
  81. data.opb = props.activeWord.opb;
  82. data.opc = props.activeWord.opc;
  83. data.opd = props.activeWord.opd;
  84. }
  85. function handleSelect(d1) {
  86. data.answer = d1;
  87. checkIsRight();
  88. }
  89. function checkIsRight() {
  90. if (data.answer == props.activeWord.daan) {
  91. // 正确
  92. data.result = true;
  93. resultAudioPlayerD.play('right','select')
  94. noticeBackDb()
  95. } else {
  96. data.result = false;
  97. resultAudioPlayerD.play('wrong','select')
  98. }
  99. }
  100. function noticeBackDb() {
  101. if (userCode == 'Visitor') {
  102. // 游客不更新后台
  103. return;
  104. }
  105. httpApi.getWordZhangwo({
  106. type: 2,
  107. wordId: props.activeWord.id
  108. })
  109. }
  110. </script>