selectPage.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <view>
  3. <!-- 单词区 -->
  4. <selectWordsVue :active-words="activeWords" :activeWord="activeWord"></selectWordsVue>
  5. <!-- 显示区 -->
  6. <selectTypesVue activeSelect="4"></selectTypesVue>
  7. <!-- 拼读区 -->
  8. <view>
  9. {{data.name}}
  10. </view>
  11. <!-- 音标区 -->
  12. <view>
  13. {{activeWord.yinbiao}}
  14. </view>
  15. <!-- 图片区 -->
  16. <view>
  17. {{ data.result ?'正确':'错误' }}
  18. </view>
  19. <!-- 选择区 -->
  20. <view>
  21. <view :class="{active: data.answer == 'A'}" @click="handleSelect('A')">{{data.opa}}</view>
  22. <view :class="{active: data.answer == 'B'}" @click="handleSelect('B')">{{data.opb}}</view>
  23. <view :class="{active: data.answer == 'C'}" @click="handleSelect('C')">{{data.opc}}</view>
  24. <view :class="{active: data.answer == 'D'}" @click="handleSelect('D')">{{data.opd}}</view>
  25. </view>
  26. </view>
  27. </template>
  28. <script setup>
  29. import selectWordsVue from './selectWords.vue';
  30. import selectTypesVue from './selectTypes.vue';
  31. import * as httpApi from "@/api/word.js"
  32. import {
  33. onLoad
  34. } from "@dcloudio/uni-app"
  35. import {
  36. reactive,
  37. computed
  38. } from 'vue';
  39. import {
  40. getUserIdentity,
  41. } from "@/utils/common.js"
  42. const userCode = getUserIdentity();
  43. const props = defineProps({
  44. activeWord: { // 单词数据
  45. type: Object,
  46. },
  47. activeWords: {
  48. type: Array
  49. },
  50. })
  51. const data = reactive({
  52. name: [],
  53. opa: null,
  54. opb: null,
  55. opc: null,
  56. opd: null,
  57. answer: null, // 已选项
  58. result: false, // 正确性
  59. })
  60. onLoad(() => {
  61. initItem()
  62. })
  63. function initItem() {
  64. data.name = props.activeWord.name;
  65. data.opa = props.activeWord.opa;
  66. data.opb = props.activeWord.opb;
  67. data.opc = props.activeWord.opc;
  68. data.opd = props.activeWord.opd;
  69. }
  70. function handleSelect(d1) {
  71. data.answer = d1;
  72. checkIsRight();
  73. }
  74. function checkIsRight() {
  75. if (data.answer == props.activeWord.daan) {
  76. // 正确
  77. data.result = true;
  78. noticeBackDb()
  79. } else {
  80. data.result = false;
  81. }
  82. }
  83. function noticeBackDb() {
  84. if (userCode == 'Visitor') {
  85. // 游客不更新后台
  86. return;
  87. }
  88. httpApi.getWordZhangwo({
  89. type: 2,
  90. wordId: props.activeWord.id
  91. })
  92. }
  93. </script>
  94. <style lang="scss" scoped>
  95. .active {
  96. color: red;
  97. }
  98. </style>