beiPage.vue 4.5 KB

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