beiPage.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <!-- 单词区 && 音标区:最多15位,超过隐藏-->
  2. <!-- 单音节最长:swimming 多音节最长:transportation -->
  3. <template>
  4. <!-- 显示区 -->
  5. <selectTypesVue activeSelect="5"></selectTypesVue>
  6. <view class="ezy-border-body">
  7. <view class="words-bei-box">
  8. <!-- 输入区 -->
  9. <input class="words-answer-box" placeholder="请输入答案" v-model.trim="data.answer" readonly
  10. :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. </template>
  61. <script setup>
  62. import selectWordsVue from './selectWords.vue';
  63. import selectTypesVue from './selectTypes.vue';
  64. import btnTxtVue from './btnTxt.vue';
  65. import audioOneVue from './audioOne.vue';
  66. import {
  67. reactive,
  68. computed,
  69. onUnmounted,
  70. nextTick
  71. } from 'vue';
  72. import {
  73. getUserIdentity,
  74. } from "@/utils/common.js"
  75. import * as httpApi from "@/api/word.js"
  76. import {
  77. onLoad
  78. } from "@dcloudio/uni-app"
  79. import cacheManager from '@/utils/cacheManager';
  80. import {
  81. resultAudioPlayer
  82. } from "./useAudioRightWrong"
  83. const resultAudioPlayerD = new resultAudioPlayer();
  84. const userCode = getUserIdentity();
  85. const emits = defineEmits(['play-audio'])
  86. const props = defineProps({
  87. activeWord: { // 单词数据
  88. type: Object,
  89. },
  90. activeWords: {
  91. type: Array
  92. },
  93. pageData: {
  94. type: Object
  95. }
  96. })
  97. const data = reactive({
  98. answer: '',
  99. result: null, // 正确性
  100. isPlaying: false,
  101. code: null
  102. })
  103. function handlePlay(opt) {
  104. emits('play-audio', opt)
  105. }
  106. // 选择单词
  107. function checkIsRight() {
  108. if (data.answer == props.activeWord.name) {
  109. data.result = true;
  110. resultAudioPlayerD.play('right', 'bei')
  111. // noticeBackDb()
  112. } else {
  113. data.result = false;
  114. resultAudioPlayerD.play('wrong', 'bei')
  115. }
  116. noticeBackComplete()
  117. }
  118. function noticeBackComplete() {
  119. // 通知后台已学完当前单词
  120. if (userCode == 'Visitor') {
  121. // 游客不更新后台
  122. return;
  123. }
  124. if (props.pageData.jieId == 0) {
  125. // 已掌握不需要调用接口通知完成
  126. return;
  127. }
  128. httpApi.getWordWancheng({
  129. jieId: props.pageData.jieId,
  130. wordId: props.activeWord.id
  131. }).then((res) => {
  132. const {
  133. wanchengFlag
  134. } = res.data;
  135. if (wanchengFlag == 1) {
  136. // 更新当前岛小节完成状态
  137. cacheManager.updateUnitStatus('zhangInfo', props.pageData.jieId)
  138. }
  139. })
  140. }
  141. /* function noticeBackDb() {
  142. 当前功能已废弃,后台接口保留,前台代码注释
  143. // 通知后台已学完当前单词
  144. if (userCode == 'Visitor') {
  145. // 游客不更新后台
  146. return;
  147. }
  148. httpApi.getWordZhangwo({
  149. type: 3,
  150. wordId: props.activeWord.id
  151. }).then(res => {
  152. })
  153. }*/
  154. function handleReset(code) {
  155. if (code == 'all') {
  156. // 全部清空
  157. data.answer = '';
  158. } else {
  159. // 单个清空
  160. data.answer = data.answer ? data.answer.slice(0, -1) : '';
  161. }
  162. // 重置错误状态
  163. if (!data.answer.length) {
  164. nextTick(() => {
  165. data.result = null;
  166. })
  167. }
  168. }
  169. function handleSelect(word) {
  170. data.answer += word;
  171. }
  172. </script>
  173. <style>
  174. </style>