index.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <template>
  2. <view class="ezy-exam-page" :style="{backgroundImage: 'url(' + courseBjFun() + ')'}">
  3. <view class="ezy-navBar-box">
  4. <view @click="handleBack" class="nav-bar-icon"></view>
  5. <text class="nav-bar-title">学习</text>
  6. </view>
  7. <view>
  8. <template v-for="item in data.wordList">
  9. <mainCardVue :active-word="activeWord" :active-words="activeWords" v-if="item.id == data.activeId"
  10. :key="item.id">
  11. </mainCardVue>
  12. </template>
  13. </view>
  14. <view>
  15. 底部
  16. <view>收藏</view>
  17. <view @click="prevWord" v-if="!isFirst">上一词</view>
  18. <view @click="nextWord" v-if="!isLast">下一词</view>
  19. <view v-if="isLast">完成</view>
  20. </view>
  21. </view>
  22. </template>
  23. <script setup>
  24. import mainCardVue from "./components/mainCard.vue";
  25. import {
  26. ref,
  27. reactive,
  28. computed
  29. } from "vue";
  30. import {
  31. onLoad
  32. } from "@dcloudio/uni-app";
  33. import * as httpApi from "@/api/word.js"
  34. function courseBjFun() {
  35. return 'static/images/course/couse-shuxue-bj.png'
  36. }
  37. function chunkArray(arr, chunkSize) {
  38. const result = [];
  39. for (let i = 0; i < arr.length; i += chunkSize) {
  40. result.push(arr.slice(i, i + chunkSize));
  41. }
  42. return result;
  43. }
  44. function handleBack() {}
  45. const data = reactive({
  46. jieId: null, // 节/单元ID
  47. activeId: null, // 当前单词
  48. subjectId: null, // 学科ID
  49. levelId: null, // 等级
  50. jieName: '', // 节/单元名称
  51. count: 0, // 单词总数
  52. title: '', // 版本+年级+学期
  53. studyCount: 0, // 已学习总数
  54. wordList: [], // 单词列表
  55. arrayList: [], // 整合数据
  56. wordInfo: null, // 单词详情数据
  57. })
  58. onLoad(({
  59. jieId,wordId
  60. }) => {
  61. data.jieId = jieId;
  62. data.activeId = wordId;
  63. // 获取单词列表数据
  64. initWordInfo();
  65. })
  66. // 当前单词
  67. const activeWord = computed(() => {
  68. if (!data.activeId) {
  69. return null
  70. }
  71. return data.wordList.find(item => item.id == data.activeId)
  72. })
  73. // 是否是最后一题
  74. const isLast = computed(() => {
  75. if (!data.wordList.length) {
  76. return false
  77. }
  78. return data.activeId == data.wordList[data.count - 1].id;
  79. })
  80. const isFirst = computed(() => {
  81. if (!data.wordList.length) {
  82. return false
  83. }
  84. return data.activeId == data.wordList[0].id;
  85. })
  86. const activeWords = computed(() => {
  87. if (!data.activeId) {
  88. return null
  89. }
  90. return data.arrayList.find(item => item.some(cit => cit.id == data.activeId))
  91. })
  92. function nextWord() {
  93. const index = data.wordList.findIndex(item => item.id == data.activeId);
  94. if (index < data.count - 1) {
  95. data.activeId = data.wordList[index + 1].id;
  96. }
  97. }
  98. function prevWord() {
  99. const index = data.wordList.findIndex(item => item.id == data.activeId);
  100. if (index > 0) {
  101. data.activeId = data.wordList[index - 1].id;
  102. }
  103. }
  104. function initWordInfo() {
  105. /*httpApi.getWordInfo({
  106. jieId: data.jieId,
  107. wordId: data.activeId
  108. }).then(res => {
  109. // data.count = res.data.count;
  110. data.wordInfo = res.data;
  111. data.count = res.data.wordList.length; // 数据异常暂时用length 替代
  112. data.jieName = res.data.jieName;
  113. data.levelId = res.data.levelId;
  114. data.studyCount = res.data.studyCount;
  115. data.subjectId = res.data.subjectId;
  116. data.title = res.data.title;
  117. data.wordList = res.data.wordList;
  118. if (data.wordList.length) {
  119. data.arrayList = chunkArray(data.wordList, 2); // 将1维单词数组转换为2维数组
  120. }
  121. })*/
  122. }
  123. </script>
  124. <style>
  125. </style>