beiPage.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. </template>
  93. </view>
  94. <view class="bei-confirm-btn-box">
  95. <!-- active -->
  96. <view class="big-btn" :class="{active: isDaxie}" @click="handleChangeDaxie">大写</view>
  97. <view class="bei-confirm-btn" @click="checkIsRight">确定</view>
  98. </view>
  99. </view>
  100. </view>
  101. </view>
  102. </template>
  103. <script setup>
  104. import selectWordsVue from './selectWords.vue';
  105. import selectTypesVue from './selectTypes.vue';
  106. import btnTxtVue from './btnTxt.vue';
  107. import audioOneVue from './audioOne.vue';
  108. import {
  109. reactive,
  110. computed,
  111. onUnmounted,
  112. nextTick,
  113. ref
  114. } from 'vue';
  115. import {
  116. getUserIdentity,
  117. } from "@/utils/common.js"
  118. import * as httpApi from "@/api/word.js"
  119. import {
  120. onLoad
  121. } from "@dcloudio/uni-app"
  122. import cacheManager from '@/utils/cacheManager';
  123. import {
  124. resultAudioPlayer
  125. } from "./useAudioRightWrong"
  126. const resultAudioPlayerD = new resultAudioPlayer();
  127. const userCode = getUserIdentity();
  128. const isDaxie = ref(false)
  129. const emits = defineEmits(['play-audio'])
  130. const props = defineProps({
  131. activeWord: { // 单词数据
  132. type: Object,
  133. },
  134. activeWords: {
  135. type: Array
  136. },
  137. pageData: {
  138. type: Object
  139. }
  140. })
  141. const data = reactive({
  142. answer: '',
  143. result: null, // 正确性
  144. isPlaying: false,
  145. code: null
  146. })
  147. function handleChangeDaxie() {
  148. isDaxie.value = true
  149. }
  150. function handlePlay(opt) {
  151. emits('play-audio', opt)
  152. }
  153. // 选择单词
  154. function checkIsRight() {
  155. let ans1 = props.activeWord.name;
  156. if (data.answer == ans1) {
  157. data.result = true;
  158. resultAudioPlayerD.play('right', 'bei')
  159. // noticeBackDb()
  160. } else {
  161. data.result = false;
  162. resultAudioPlayerD.play('wrong', 'bei')
  163. }
  164. noticeBackComplete()
  165. }
  166. function noticeBackComplete() {
  167. // 通知后台已学完当前单词
  168. if (userCode == 'Visitor') {
  169. // 游客不更新后台
  170. return;
  171. }
  172. if (props.pageData.jieId == 0) {
  173. // 已掌握不需要调用接口通知完成
  174. return;
  175. }
  176. httpApi.getWordWancheng({
  177. jieId: props.pageData.jieId,
  178. wordId: props.activeWord.id
  179. }).then((res) => {
  180. const {
  181. wanchengFlag
  182. } = res.data;
  183. if (wanchengFlag == 1) {
  184. // 更新当前岛小节完成状态
  185. cacheManager.updateUnitStatus('zhangInfo', props.pageData.jieId)
  186. }
  187. })
  188. }
  189. /* function noticeBackDb() {
  190. 当前功能已废弃,后台接口保留,前台代码注释
  191. // 通知后台已学完当前单词
  192. if (userCode == 'Visitor') {
  193. // 游客不更新后台
  194. return;
  195. }
  196. httpApi.getWordZhangwo({
  197. type: 3,
  198. wordId: props.activeWord.id
  199. }).then(res => {
  200. })
  201. }*/
  202. function handleReset(code) {
  203. if (code == 'all') {
  204. // 全部清空
  205. data.answer = '';
  206. } else {
  207. // 单个清空
  208. data.answer = data.answer ? data.answer.slice(0, -1) : '';
  209. }
  210. // 重置错误状态
  211. if (!data.answer.length) {
  212. nextTick(() => {
  213. data.result = null;
  214. })
  215. }
  216. }
  217. function handleSelect(word) {
  218. data.answer += word;
  219. isDaxie.value = false;
  220. }
  221. </script>
  222. <style>
  223. </style>