index.vue 4.3 KB

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