beiPage.vue 7.7 KB

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