index.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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="data.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. title: '', // 版本+年级+学期
  52. studyCount: 0, // 已学习总数
  53. wordList: [], // 单词列表
  54. arrayList: [], // 整合数据
  55. activeWord: null, // 单词详情数据
  56. collectFlag: 0, // 收藏状态
  57. })
  58. onLoad(({
  59. jieId,
  60. wordId
  61. }) => {
  62. data.jieId = jieId;
  63. data.activeId = wordId;
  64. // 获取单词列表数据
  65. initWordInfo();
  66. })
  67. // 是否是最后一题
  68. const isLast = computed(() => {
  69. if (!data.wordList.length) {
  70. return false
  71. }
  72. return data.activeId == data.wordList[data.wordList.length - 1].id;
  73. })
  74. const isFirst = computed(() => {
  75. if (!data.wordList.length) {
  76. return false
  77. }
  78. return data.activeId == data.wordList[0].id;
  79. })
  80. const activeWords = computed(() => {
  81. if (!data.activeId) {
  82. return null
  83. }
  84. return data.arrayList.find(item => item.some(cit => cit.id == data.activeId))
  85. })
  86. function nextWord() {
  87. const index = data.wordList.findIndex(item => item.id == data.activeId);
  88. if (index < data.wordList.length - 1) {
  89. uni.redirectTo({
  90. url: `/pages/newEnglish/index?jieId=${data.jieId}&wordId=${data.wordList[index + 1].id }`
  91. })
  92. }
  93. }
  94. function prevWord() {
  95. const index = data.wordList.findIndex(item => item.id == data.activeId);
  96. if (index > 0) {
  97. uni.redirectTo({
  98. url: `/pages/newEnglish/index?jieId=${data.jieId}&wordId=${data.wordList[index - 1].id }`
  99. })
  100. }
  101. }
  102. function initWordInfo() {
  103. httpApi.getWordInfo({
  104. jieId: data.jieId,
  105. wordId: data.activeId
  106. }).then(res => {
  107. data.activeWord = res.data;
  108. data.wordList = res.data.danciList; // 单词组
  109. data.collectFlag = res.data.collectFlag; // 收藏状态
  110. if (data.wordList.length) {
  111. data.arrayList = chunkArray(data.wordList, 5); // 将1维单词数组转换为2维数组
  112. }
  113. })
  114. }
  115. </script>
  116. <style>
  117. </style>