index.vue 4.8 KB

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