beiPage.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. const userCode = getUserIdentity();
  78. const emits = defineEmits(['play-audio'])
  79. const props = defineProps({
  80. activeWord: { // 单词数据
  81. type: Object,
  82. },
  83. activeWords: {
  84. type: Array
  85. },
  86. pageData: {
  87. type:Object
  88. }
  89. })
  90. const data = reactive({
  91. answer: '',
  92. result: null, // 正确性
  93. isPlaying: false,
  94. code: null
  95. })
  96. function handlePlay(opt) {
  97. emits('play-audio', opt)
  98. }
  99. // 选择单词
  100. function checkIsRight() {
  101. if (data.answer == props.activeWord.name) {
  102. data.result = true;
  103. noticeBackDb()
  104. } else {
  105. data.result = false;
  106. }
  107. noticeBackComplete()
  108. }
  109. function noticeBackComplete() {
  110. // 通知后台已学完当前单词
  111. if (userCode == 'Visitor') {
  112. // 游客不更新后台
  113. return;
  114. }
  115. if (props.pageData.jieId == 0) {
  116. // 已掌握不需要调用接口通知完成
  117. return;
  118. }
  119. httpApi.getWordWancheng({
  120. jieId: props.pageData.jieId,
  121. wordId: props.activeWord.id
  122. })
  123. }
  124. function noticeBackDb() {
  125. // 通知后台已学完当前单词
  126. if (userCode == 'Visitor') {
  127. // 游客不更新后台
  128. return;
  129. }
  130. httpApi.getWordZhangwo({
  131. type: 3,
  132. wordId: props.activeWord.id
  133. }).then(res => {
  134. const { wanchangflag } = res.data;
  135. if (wanchangflag == 1) {
  136. // 通知岛重新调用接口
  137. cacheManager.remove('daoPageCache')
  138. }
  139. })
  140. }
  141. function handleReset(code) {
  142. if (code == 'all') {
  143. // 全部清空
  144. data.answer = '';
  145. } else {
  146. // 单个清空
  147. data.answer = data.answer ? data.answer.slice(0, -1) : '';
  148. }
  149. // 重置错误状态
  150. if (!data.answer.length) {
  151. nextTick(() => {
  152. data.result = null;
  153. })
  154. }
  155. }
  156. function handleSelect(word) {
  157. data.answer += word;
  158. }
  159. </script>
  160. <style>
  161. </style>