index.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 v-if="userCode != 'Visitor'" @click="handleShouCang">收藏</view>
  17. <view @click="prevWord" v-if="!isFirst">上一词</view>
  18. <view @click="nextWord" v-if="!isLast">下一词</view>
  19. <view v-if="isLast" @click="handleComplete">返回</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. import {
  35. getUserIdentity,
  36. } from "@/utils/common.js"
  37. const userCode = getUserIdentity();
  38. function courseBjFun() {
  39. return 'static/images/course/couse-shuxue-bj.png'
  40. }
  41. function chunkArray(arr, chunkSize) {
  42. const result = [];
  43. for (let i = 0; i < arr.length; i += chunkSize) {
  44. result.push(arr.slice(i, i + chunkSize));
  45. }
  46. return result;
  47. }
  48. const data = reactive({
  49. jieId: null, // 节/单元ID
  50. activeId: null, // 当前单词
  51. wordList: [], // 单词列表
  52. arrayList: [], // 整合数据
  53. activeWord: null, // 单词详情数据
  54. collectFlag: 0, // 收藏状态
  55. subjectId: null, // 学科ID
  56. levelId: null, // 等级
  57. typeId: null, // 类型
  58. tipFlag: null, // 提示
  59. zhangId: null, // 章ID
  60. })
  61. onLoad(({
  62. jieId,
  63. wordId,
  64. subjectId,
  65. levelId,
  66. typeId,
  67. tipFlag,
  68. zhangId
  69. }) => {
  70. data.jieId = jieId;
  71. data.activeId = wordId;
  72. data.subjectId = subjectId;
  73. data.levelId = levelId;
  74. data.typeId = typeId;
  75. data.tipFlag = tipFlag;
  76. data.zhangId = zhangId;
  77. // 获取单词列表数据
  78. initWordInfo();
  79. })
  80. // 是否是最后一题
  81. const isLast = computed(() => {
  82. if (!data.wordList.length) {
  83. return false
  84. }
  85. return data.activeId == data.wordList[data.wordList.length - 1].id;
  86. })
  87. const isFirst = computed(() => {
  88. if (!data.wordList.length) {
  89. return false
  90. }
  91. return data.activeId == data.wordList[0].id;
  92. })
  93. const activeWords = computed(() => {
  94. if (!data.activeId) {
  95. return null
  96. }
  97. return data.arrayList.find(item => item.some(cit => cit.id == data.activeId))
  98. })
  99. function nextWord() {
  100. const index = data.wordList.findIndex(item => item.id == data.activeId);
  101. if (index < data.wordList.length - 1) {
  102. uni.redirectTo({
  103. url: `/pages/newEnglish/index?jieId=${data.jieId}&wordId=${data.wordList[index + 1].id }`
  104. })
  105. }
  106. }
  107. function prevWord() {
  108. const index = data.wordList.findIndex(item => item.id == data.activeId);
  109. if (index > 0) {
  110. uni.redirectTo({
  111. url: `/pages/newEnglish/index?jieId=${data.jieId}&wordId=${data.wordList[index - 1].id }`
  112. })
  113. }
  114. }
  115. function handleBack() {
  116. // 返回单词列表
  117. if (userCode !== 'Visitor') {
  118. uni.redirectTo({
  119. url: `/pages/wordList/wordList`
  120. })
  121. } else {
  122. const youkePageData = JSON.stringify({
  123. subjectId: data.subjectId,
  124. levelId: data.levelId,
  125. typeId: data.typeId,
  126. tipFlag: data.tipFlag,
  127. youkeZhangId: data.zhangId,
  128. jieId: data.jieId
  129. })
  130. uni.redirectTo({
  131. url: `/pages/wordList/wordList?youkePageData=${youkePageData}`
  132. })
  133. }
  134. }
  135. function handleComplete() {
  136. // 返回岛
  137. if (userCode !== 'Visitor') {
  138. uni.redirectTo({
  139. url: '/pages/study/index'
  140. })
  141. } else {
  142. uni.redirectTo({
  143. url: `/pages/study/index?levelId=${data.levelId}&typeId=${data.typeId}&subjectId=${data.subjectId}&tipFlag=${data.tipFlag}&youkeZhangId=${data.zhangId}&jieId=${data.jieId}`
  144. })
  145. }
  146. }
  147. function handleShouCang() {}
  148. function initWordInfo() {
  149. httpApi.getWordInfo({
  150. jieId: data.jieId,
  151. wordId: data.activeId
  152. }).then(res => {
  153. data.activeWord = res.data;
  154. data.wordList = res.data.danciList; // 单词组
  155. data.collectFlag = res.data.collectFlag; // 收藏状态
  156. if (data.wordList.length) {
  157. data.arrayList = chunkArray(data.wordList, 5); // 将1维单词数组转换为2维数组
  158. }
  159. })
  160. }
  161. </script>
  162. <style>
  163. </style>