selectPage.vue 3.4 KB

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