selectPage.vue 3.4 KB

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