beiPage.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <!-- 单词区 && 音标区:最多15位,超过隐藏-->
  2. <!-- 单音节最长:swimming 多音节最长:transportation -->
  3. <template>
  4. <view class="ezy-tab-border">
  5. <!-- 显示区 -->
  6. <selectTypesVue activeSelect="5"></selectTypesVue>
  7. <view class="ezy-border-body">
  8. <view class="words-bei-box">
  9. <!-- 输入区 -->
  10. <input class="words-answer-box" placeholder="请输入答案" v-model.trim="data.answer" readonly :class="{'words-answer-right-box': data.result&&data.result!=null, 'words-answer-error-box': !data.result&&data.result!=null}" />
  11. <!-- 清空按钮 -->
  12. <view class="clean-btn" @click="handleReset('all')" v-if="data.answer.length"></view>
  13. <view class="bei-body-box">
  14. <!-- 解释区 -->
  15. <view class="pin-words-explain-box">
  16. <view class="words-explain-item" v-for="item in activeWord.jianyi" :key="item">{{item}}</view>
  17. </view>
  18. <!-- 播放和待播 -->
  19. <audioOneVue :active-word="activeWord" @play-audio="handlePlay"></audioOneVue>
  20. </view>
  21. <!-- 浮层输入区 -->
  22. <view class="words-keyboard-box">
  23. <view class="keyboard-row">
  24. <btnTxtVue @text-select="handleSelect('a')">a</btnTxtVue>
  25. <btnTxtVue @text-select="handleSelect('b')">b</btnTxtVue>
  26. <btnTxtVue @text-select="handleSelect('c')">c</btnTxtVue>
  27. <btnTxtVue @text-select="handleSelect('d')">d</btnTxtVue>
  28. <btnTxtVue @text-select="handleSelect('e')">e</btnTxtVue>
  29. <btnTxtVue @text-select="handleSelect('f')">f</btnTxtVue>
  30. <btnTxtVue @text-select="handleSelect('g')">g</btnTxtVue>
  31. <btnTxtVue @text-select="handleSelect('h')">h</btnTxtVue>
  32. <btnTxtVue @text-select="handleSelect('i')">i</btnTxtVue>
  33. </view>
  34. <view class="keyboard-row">
  35. <btnTxtVue @text-select="handleSelect('j')">j</btnTxtVue>
  36. <btnTxtVue @text-select="handleSelect('k')">k</btnTxtVue>
  37. <btnTxtVue @text-select="handleSelect('l')">l</btnTxtVue>
  38. <btnTxtVue @text-select="handleSelect('m')">m</btnTxtVue>
  39. <btnTxtVue @text-select="handleSelect('n')">n</btnTxtVue>
  40. <btnTxtVue @text-select="handleSelect('o')">o</btnTxtVue>
  41. <btnTxtVue @text-select="handleSelect('p')">p</btnTxtVue>
  42. <btnTxtVue @text-select="handleSelect('q')">q</btnTxtVue>
  43. <btnTxtVue @text-select="handleSelect('r')">r</btnTxtVue>
  44. </view>
  45. <view class="keyboard-row">
  46. <btnTxtVue @text-select="handleSelect('s')">s</btnTxtVue>
  47. <btnTxtVue @text-select="handleSelect('t')">t</btnTxtVue>
  48. <btnTxtVue @text-select="handleSelect('u')">u</btnTxtVue>
  49. <btnTxtVue @text-select="handleSelect('v')">v</btnTxtVue>
  50. <btnTxtVue @text-select="handleSelect('w')">w</btnTxtVue>
  51. <btnTxtVue @text-select="handleSelect('x')">x</btnTxtVue>
  52. <btnTxtVue @text-select="handleSelect('y')">y</btnTxtVue>
  53. <btnTxtVue @text-select="handleSelect('z')">z</btnTxtVue>
  54. <btnTxtVue @text-select="handleReset" class="del-btn"></btnTxtVue>
  55. </view>
  56. <view class="bei-confirm-btn" @click="checkIsRight"></view>
  57. </view>
  58. </view>
  59. </view>
  60. </view>
  61. </template>
  62. <script setup>
  63. import selectWordsVue from './selectWords.vue';
  64. import selectTypesVue from './selectTypes.vue';
  65. import btnTxtVue from './btnTxt.vue';
  66. import audioOneVue from './audioOne.vue';
  67. import {
  68. reactive,
  69. computed,
  70. onUnmounted,
  71. nextTick
  72. } from 'vue';
  73. import {
  74. getUserIdentity,
  75. } from "@/utils/common.js"
  76. import * as httpApi from "@/api/word.js"
  77. import {
  78. onLoad
  79. } from "@dcloudio/uni-app"
  80. import cacheManager from '@/utils/cacheManager';
  81. import {resultAudioPlayer} from "./useAudioRightWrong"
  82. const resultAudioPlayerD = new resultAudioPlayer();
  83. const userCode = getUserIdentity();
  84. const emits = defineEmits(['play-audio'])
  85. const props = defineProps({
  86. activeWord: { // 单词数据
  87. type: Object,
  88. },
  89. activeWords: {
  90. type: Array
  91. },
  92. pageData: {
  93. type:Object
  94. }
  95. })
  96. const data = reactive({
  97. answer: '',
  98. result: null, // 正确性
  99. isPlaying: false,
  100. code: null
  101. })
  102. function handlePlay(opt) {
  103. emits('play-audio', opt)
  104. }
  105. // 选择单词
  106. function checkIsRight() {
  107. if (data.answer == props.activeWord.name) {
  108. data.result = true;
  109. resultAudioPlayerD.play('right','bei')
  110. noticeBackDb()
  111. } else {
  112. data.result = false;
  113. resultAudioPlayerD.play('wrong','bei')
  114. }
  115. noticeBackComplete()
  116. }
  117. function noticeBackComplete() {
  118. // 通知后台已学完当前单词
  119. if (userCode == 'Visitor') {
  120. // 游客不更新后台
  121. return;
  122. }
  123. if (props.pageData.jieId == 0) {
  124. // 已掌握不需要调用接口通知完成
  125. return;
  126. }
  127. httpApi.getWordWancheng({
  128. jieId: props.pageData.jieId,
  129. wordId: props.activeWord.id
  130. })
  131. }
  132. function noticeBackDb() {
  133. // 通知后台已学完当前单词
  134. if (userCode == 'Visitor') {
  135. // 游客不更新后台
  136. return;
  137. }
  138. httpApi.getWordZhangwo({
  139. type: 3,
  140. wordId: props.activeWord.id
  141. }).then(res => {
  142. const { wanchangflag } = res.data;
  143. if (wanchangflag == 1) {
  144. // 通知岛重新调用接口
  145. cacheManager.remove('zhangInfo')
  146. }
  147. })
  148. }
  149. function handleReset(code) {
  150. if (code == 'all') {
  151. // 全部清空
  152. data.answer = '';
  153. } else {
  154. // 单个清空
  155. data.answer = data.answer ? data.answer.slice(0, -1) : '';
  156. }
  157. // 重置错误状态
  158. if (!data.answer.length) {
  159. nextTick(() => {
  160. data.result = null;
  161. })
  162. }
  163. }
  164. function handleSelect(word) {
  165. data.answer += word;
  166. }
  167. </script>
  168. <style>
  169. </style>