index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <template>
  2. <view class="word-view-page" :style="{backgroundImage: 'url(' + courseBjFun() + ')'}">
  3. <view class="icon-title-navBar-box">
  4. <view @click="handleBack" class="nav-bar-icon"></view>
  5. <text class="nav-bar-title">学习</text>
  6. </view>
  7. <view class="ezy-tab-border">
  8. <view class="ezy-border-body">
  9. <template v-for="item in data.wordList">
  10. <mainCardVue :active-word="data.activeWord" :active-words="activeWords" v-if="item.id == data.activeId"
  11. :key="item.id">
  12. </mainCardVue>
  13. </template>
  14. </view>
  15. </view>
  16. <view class="word-view-bottom">
  17. <view v-if="userCode != 'Visitor'" @click="handleShouCang">收藏</view>
  18. <view class="bottom-btn-box">
  19. <view class="word-view-btn" @click="prevWord" v-if="!isFirst">上一词</view>
  20. <view class="word-view-btn" @click="nextWord" v-if="!isLast">下一词</view>
  21. <view v-if="isLast" @click="handleComplete">完成</view>
  22. </view>
  23. </view>
  24. </view>
  25. </template>
  26. <script setup>
  27. import mainCardVue from "./components/mainCard.vue";
  28. import {
  29. ref,
  30. reactive,
  31. computed
  32. } from "vue";
  33. import {
  34. onLoad
  35. } from "@dcloudio/uni-app";
  36. import * as httpApi from "@/api/word.js"
  37. import {
  38. getUserIdentity,
  39. } from "@/utils/common.js"
  40. const userCode = getUserIdentity();
  41. function courseBjFun() {
  42. return 'static/images/course/course-cjdc-bj.png'
  43. }
  44. function chunkArray(arr, chunkSize) {
  45. const result = [];
  46. for (let i = 0; i < arr.length; i += chunkSize) {
  47. result.push(arr.slice(i, i + chunkSize));
  48. }
  49. return result;
  50. }
  51. const data = reactive({
  52. jieId: null, // 节/单元ID
  53. activeId: null, // 当前单词
  54. wordList: [], // 单词列表
  55. arrayList: [], // 整合数据
  56. activeWord: null, // 单词详情数据
  57. collectFlag: 0, // 收藏状态
  58. subjectId: null, // 学科ID
  59. levelId: null, // 等级
  60. typeId: null, // 类型
  61. tipFlag: null, // 提示
  62. zhangId: null, // 章ID
  63. })
  64. onLoad(({
  65. jieId,
  66. wordId,
  67. subjectId,
  68. levelId,
  69. typeId,
  70. tipFlag,
  71. zhangId
  72. }) => {
  73. data.jieId = jieId;
  74. data.activeId = wordId;
  75. data.subjectId = subjectId;
  76. data.levelId = levelId;
  77. data.typeId = typeId;
  78. data.tipFlag = tipFlag;
  79. data.zhangId = zhangId;
  80. // 获取单词列表数据
  81. initWordInfo();
  82. })
  83. // 是否是最后一题
  84. const isLast = computed(() => {
  85. if (!data.wordList.length) {
  86. return false
  87. }
  88. return data.activeId == data.wordList[data.wordList.length - 1].id;
  89. })
  90. const isFirst = computed(() => {
  91. if (!data.wordList.length) {
  92. return false
  93. }
  94. return data.activeId == data.wordList[0].id;
  95. })
  96. const activeWords = computed(() => {
  97. if (!data.activeId) {
  98. return null
  99. }
  100. return data.arrayList.find(item => item.some(cit => cit.id == data.activeId))
  101. })
  102. function nextWord() {
  103. const index = data.wordList.findIndex(item => item.id == data.activeId);
  104. if (index < data.wordList.length - 1) {
  105. uni.redirectTo({
  106. url: `/pages/newEnglish/index?jieId=${data.jieId}&wordId=${data.wordList[index + 1].id }`
  107. })
  108. }
  109. }
  110. function prevWord() {
  111. const index = data.wordList.findIndex(item => item.id == data.activeId);
  112. if (index > 0) {
  113. uni.redirectTo({
  114. url: `/pages/newEnglish/index?jieId=${data.jieId}&wordId=${data.wordList[index - 1].id }`
  115. })
  116. }
  117. }
  118. function handleBack() {
  119. // 返回单词列表
  120. if (userCode !== 'Visitor') {
  121. uni.redirectTo({
  122. url: `/pages/wordList/wordList?jieId=${data.jieId}`
  123. })
  124. } else {
  125. const youkePageData = JSON.stringify({
  126. subjectId: data.subjectId,
  127. levelId: data.levelId,
  128. typeId: data.typeId,
  129. tipFlag: data.tipFlag,
  130. youkeZhangId: data.zhangId,
  131. jieId: data.jieId
  132. })
  133. uni.redirectTo({
  134. url: `/pages/wordList/wordList?youkePageData=${youkePageData}`
  135. })
  136. }
  137. }
  138. function handleComplete() {
  139. // 返回岛
  140. if (userCode !== 'Visitor') {
  141. uni.redirectTo({
  142. url: `/pages/study/index`
  143. })
  144. } else {
  145. uni.redirectTo({
  146. url: `/pages/study/index?levelId=${data.levelId}&typeId=${data.typeId}&subjectId=${data.subjectId}&tipFlag=${data.tipFlag}&youkeZhangId=${data.zhangId}&jieId=${data.jieId}`
  147. })
  148. }
  149. }
  150. function handleShouCang() {}
  151. function initWordInfo() {
  152. httpApi.getWordInfo({
  153. jieId: data.jieId,
  154. wordId: data.activeId
  155. }).then(res => {
  156. data.activeWord = res.data;
  157. data.wordList = res.data.danciList; // 单词组
  158. data.collectFlag = res.data.collectFlag; // 收藏状态
  159. if (data.wordList.length) {
  160. data.arrayList = chunkArray(data.wordList, 5); // 将1维单词数组转换为2维数组
  161. }
  162. })
  163. }
  164. </script>
  165. <style>
  166. </style>