beiPage.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. <template v-if="!isDaxie">
  25. <btnTxtVue @text-select="handleSelect('a')">a</btnTxtVue>
  26. <btnTxtVue @text-select="handleSelect('b')">b</btnTxtVue>
  27. <btnTxtVue @text-select="handleSelect('c')">c</btnTxtVue>
  28. <btnTxtVue @text-select="handleSelect('d')">d</btnTxtVue>
  29. <btnTxtVue @text-select="handleSelect('e')">e</btnTxtVue>
  30. <btnTxtVue @text-select="handleSelect('f')">f</btnTxtVue>
  31. <btnTxtVue @text-select="handleSelect('g')">g</btnTxtVue>
  32. <btnTxtVue @text-select="handleSelect('h')">h</btnTxtVue>
  33. <btnTxtVue @text-select="handleSelect('i')">i</btnTxtVue>
  34. </template>
  35. <template v-else>
  36. <btnTxtVue @text-select="handleSelect('A')">A</btnTxtVue>
  37. <btnTxtVue @text-select="handleSelect('B')">B</btnTxtVue>
  38. <btnTxtVue @text-select="handleSelect('C')">C</btnTxtVue>
  39. <btnTxtVue @text-select="handleSelect('D')">D</btnTxtVue>
  40. <btnTxtVue @text-select="handleSelect('E')">E</btnTxtVue>
  41. <btnTxtVue @text-select="handleSelect('F')">F</btnTxtVue>
  42. <btnTxtVue @text-select="handleSelect('G')">G</btnTxtVue>
  43. <btnTxtVue @text-select="handleSelect('H')">H</btnTxtVue>
  44. <btnTxtVue @text-select="handleSelect('I')">I</btnTxtVue>
  45. </template>
  46. </view>
  47. <view class="keyboard-row">
  48. <template v-if="!isDaxie">
  49. <btnTxtVue @text-select="handleSelect('j')">j</btnTxtVue>
  50. <btnTxtVue @text-select="handleSelect('k')">k</btnTxtVue>
  51. <btnTxtVue @text-select="handleSelect('l')">l</btnTxtVue>
  52. <btnTxtVue @text-select="handleSelect('m')">m</btnTxtVue>
  53. <btnTxtVue @text-select="handleSelect('n')">n</btnTxtVue>
  54. <btnTxtVue @text-select="handleSelect('o')">o</btnTxtVue>
  55. <btnTxtVue @text-select="handleSelect('p')">p</btnTxtVue>
  56. <btnTxtVue @text-select="handleSelect('q')">q</btnTxtVue>
  57. <btnTxtVue @text-select="handleSelect('r')">r</btnTxtVue>
  58. </template>
  59. <template v-else>
  60. <btnTxtVue @text-select="handleSelect('J')">J</btnTxtVue>
  61. <btnTxtVue @text-select="handleSelect('K')">K</btnTxtVue>
  62. <btnTxtVue @text-select="handleSelect('L')">L</btnTxtVue>
  63. <btnTxtVue @text-select="handleSelect('M')">M</btnTxtVue>
  64. <btnTxtVue @text-select="handleSelect('N')">N</btnTxtVue>
  65. <btnTxtVue @text-select="handleSelect('O')">O</btnTxtVue>
  66. <btnTxtVue @text-select="handleSelect('P')">P</btnTxtVue>
  67. <btnTxtVue @text-select="handleSelect('Q')">Q</btnTxtVue>
  68. <btnTxtVue @text-select="handleSelect('R')">R</btnTxtVue>
  69. </template>
  70. </view>
  71. <view class="keyboard-row">
  72. <template v-if="!isDaxie">
  73. <btnTxtVue @text-select="handleSelect('s')">s</btnTxtVue>
  74. <btnTxtVue @text-select="handleSelect('t')">t</btnTxtVue>
  75. <btnTxtVue @text-select="handleSelect('u')">u</btnTxtVue>
  76. <btnTxtVue @text-select="handleSelect('v')">v</btnTxtVue>
  77. <btnTxtVue @text-select="handleSelect('w')">w</btnTxtVue>
  78. <btnTxtVue @text-select="handleSelect('x')">x</btnTxtVue>
  79. <btnTxtVue @text-select="handleSelect('y')">y</btnTxtVue>
  80. <btnTxtVue @text-select="handleSelect('z')">z</btnTxtVue>
  81. <btnTxtVue @text-select="handleReset" class="del-btn"></btnTxtVue>
  82. </template>
  83. <template v-else>
  84. <btnTxtVue @text-select="handleSelect('S')">S</btnTxtVue>
  85. <btnTxtVue @text-select="handleSelect('T')">T</btnTxtVue>
  86. <btnTxtVue @text-select="handleSelect('U')">U</btnTxtVue>
  87. <btnTxtVue @text-select="handleSelect('V')">V</btnTxtVue>
  88. <btnTxtVue @text-select="handleSelect('W')">W</btnTxtVue>
  89. <btnTxtVue @text-select="handleSelect('X')">X</btnTxtVue>
  90. <btnTxtVue @text-select="handleSelect('Y')">Y</btnTxtVue>
  91. <btnTxtVue @text-select="handleSelect('Z')">Z</btnTxtVue>
  92. <btnTxtVue @text-select="handleReset" class="del-btn"></btnTxtVue>
  93. </template>
  94. </view>
  95. <view class="bei-confirm-btn-box">
  96. <!-- active -->
  97. <view class="big-btn" :class="{active: isDaxie}" @click="handleChangeDaxie">大写</view>
  98. <view class="bei-confirm-btn" @click="checkIsRight">确定</view>
  99. </view>
  100. </view>
  101. </view>
  102. </view>
  103. </template>
  104. <script setup>
  105. import selectWordsVue from './selectWords.vue';
  106. import selectTypesVue from './selectTypes.vue';
  107. import btnTxtVue from './btnTxt.vue';
  108. import audioOneVue from './audioOne.vue';
  109. import {
  110. reactive,
  111. nextTick,
  112. ref
  113. } from 'vue';
  114. import * as httpApi from "@/api/chaojidanci.js"
  115. import cacheManager from '@/utils/cacheManager';
  116. import {
  117. resultAudioPlayer
  118. } from "./useAudioRightWrong"
  119. const resultAudioPlayerD = new resultAudioPlayer();
  120. const isDaxie = ref(false)
  121. const emits = defineEmits(['play-audio'])
  122. const props = defineProps({
  123. activeWord: { // 单词数据
  124. type: Object,
  125. },
  126. activeWords: {
  127. type: Array
  128. },
  129. pageData: {
  130. type: Object
  131. }
  132. })
  133. const data = reactive({
  134. answer: '',
  135. result: null, // 正确性
  136. isPlaying: false,
  137. code: null
  138. })
  139. function handleChangeDaxie() {
  140. isDaxie.value = !isDaxie.value;
  141. }
  142. function handlePlay(opt) {
  143. emits('play-audio', opt)
  144. }
  145. // 选择单词
  146. function checkIsRight() {
  147. let ans1 = props.activeWord.name;
  148. if (data.answer == ans1) {
  149. data.result = true;
  150. resultAudioPlayerD.play('right', 'bei')
  151. // noticeBackDb()
  152. } else {
  153. data.result = false;
  154. resultAudioPlayerD.play('wrong', 'bei')
  155. }
  156. noticeBackComplete()
  157. }
  158. function noticeBackComplete() {
  159. if (props.pageData.danyuanId == 0) {
  160. // 已掌握不需要调用接口通知完成
  161. return;
  162. }
  163. httpApi.getWordWancheng({
  164. danyuanId: props.pageData.danyuanId,
  165. wordId: props.activeWord.id
  166. }).then((res) => {
  167. const {
  168. wanchengFlag
  169. } = res.data;
  170. if (wanchengFlag == 1) {
  171. // 更新当前岛小节完成状态
  172. cacheManager.updateUnitStatus('zhangInfo', props.pageData.danyuanId)
  173. }
  174. })
  175. }
  176. function handleReset(code) {
  177. if (code == 'all') {
  178. // 全部清空
  179. data.answer = '';
  180. } else {
  181. // 单个清空
  182. data.answer = data.answer ? data.answer.slice(0, -1) : '';
  183. }
  184. // 重置错误状态
  185. if (!data.answer.length) {
  186. nextTick(() => {
  187. data.result = null;
  188. })
  189. }
  190. }
  191. function handleSelect(word) {
  192. data.answer += word;
  193. isDaxie.value = false;
  194. }
  195. </script>
  196. <style>
  197. </style>