beiPage.vue 5.2 KB

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