wordList.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <view class="word-list-page">
  3. <view class="icon-title-navBar-box">
  4. <view @click="goBack" class="nav-bar-icon"></view>
  5. <text class="nav-bar-title">{{listData.title || ''}}</text>
  6. </view>
  7. <view class="ezy-tab-border">
  8. <view class="ezy-border-body">
  9. <scroll-view scroll-x="true" :scroll-left='wordLeft' class="word-title-box"
  10. v-if="listData.jieNumberList && listData.jieNumberList.length >0">
  11. <view :id="'item-' + item.jieId" class="title-item" v-for="(item,index) in listData.jieNumberList" :key="item.jieId"
  12. @click="handleTitleClick(item)" :class="{active: listData.activeIndex == index}">Unit{{item.number}}</view>
  13. </scroll-view>
  14. <view class="word-num-box"><icon></icon><text>{{listData.studyCount || 0}}/{{listData.count || 0}}词</text></view>
  15. <view class="word-list-body" v-if="listData.wordList && listData.wordList.length > 0">
  16. <!-- 单词 -->
  17. <view class="word-list-item" v-for="(item,index) in listData.wordList" :key="index" @click="toWord(item)" :class="{active: item.wcFlag == 1}">
  18. <view class="item-word">
  19. <view class="word-text">
  20. <text v-for="(word, wordIndex) in item.chaifen"
  21. :key="wordIndex" class="word-color">
  22. {{ word }}
  23. </text>
  24. </view>
  25. <view class="phonetic-alphabet">{{item.yinbiao || ''}}</view>
  26. </view>
  27. <view class="item-explain">
  28. <view class="item-explain-content">
  29. <view class="explain-text" v-for="(meaning, meaningIndex) in item.jianyi" :key="meaningIndex">{{meaning}}</view>
  30. </view>
  31. </view>
  32. <view class="item-arrow"><icon></icon></view>
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. </template>
  39. <script setup>
  40. import {reactive,ref} from "vue";
  41. import {toast} from "@/utils/common";
  42. import {onLoad} from "@dcloudio/uni-app";
  43. import {getWordList,getWordListYk} from "@/api/word.js";
  44. import cacheManager from '@/utils/cacheManager.js';
  45. const listData = reactive({
  46. count: 0, // 总数,默认值设为 0
  47. studyCount: 0, // 已学总数,默认值设为 0
  48. jieNumberList: [],//节名称
  49. title: '', // 版本+年级+学期
  50. wordList: [], // 单词列表,默认值设为空数组
  51. activeIndex: 0,
  52. });
  53. let wordJieId = ref(null);
  54. let routerOpt = ref(false);
  55. let wordLeft = ref(0);
  56. onLoad((options) => {
  57. routerOpt = options;
  58. if (!cacheManager.get('auth')) {
  59. // 游客
  60. const youkeData = JSON.parse(routerOpt.youkePageData)
  61. wordJieId = youkeData.jieId
  62. getWordListDataYk();
  63. } else {
  64. // 非游客
  65. wordJieId = routerOpt.jieId
  66. getWordListData();
  67. }
  68. });
  69. // 返回
  70. function goBack(){
  71. if (!cacheManager.get('auth')) {
  72. const youkeData = JSON.parse(routerOpt.youkePageData)
  73. // 游客
  74. uni.redirectTo({
  75. url: `/pages/study/index?levelId=${youkeData.levelId}&typeId=${youkeData.typeId}&subjectId=${youkeData.subjectId}&tipFlag=${youkeData.tipFlag}&youkeZhangId=${youkeData.youkeZhangId}&jieId=${youkeData.jieId}`
  76. })
  77. } else {
  78. // 非游客
  79. uni.redirectTo({
  80. url: `/pages/study/index`
  81. })
  82. }
  83. }
  84. function handleTitleClick(item){
  85. wordJieId = item.jieId;
  86. if (!cacheManager.get('auth')) {
  87. getWordListDataYk();
  88. }else {
  89. // 非游客
  90. getWordListData();
  91. }
  92. }
  93. function findIndexByJieId(list, jieId){
  94. const findIndex=list.findIndex(item => item.jieId == jieId)
  95. wordLeft.value = findIndex*40;
  96. return findIndex;
  97. }
  98. function getWordListData() {
  99. const opt = {
  100. jieId: wordJieId
  101. };
  102. getWordList(opt).then(res => {
  103. if (res.code === 0) {
  104. listData.count = res.data.count;
  105. listData.studyCount = res.data.studyCount;
  106. listData.jieNumberList = res.data.jieNumberList;
  107. listData.title = res.data.title;
  108. listData.wordList = res.data.wordList;
  109. listData.activeIndex = findIndexByJieId(listData.jieNumberList,wordJieId);
  110. }
  111. }).catch(err => {
  112. toast("获取单词列表数据失败");
  113. });
  114. }
  115. function getWordListDataYk() {
  116. const opt = {
  117. jieId: wordJieId
  118. };
  119. getWordListYk(opt).then(res => {
  120. if (res.code === 0) {
  121. listData.count = res.data.count;
  122. listData.studyCount = res.data.studyCount;
  123. listData.jieNumberList = res.data.jieNumberList;
  124. listData.title = res.data.title;
  125. listData.wordList = res.data.wordList;
  126. listData.activeIndex = findIndexByJieId(listData.jieNumberList,wordJieId);
  127. }
  128. }).catch(err => {
  129. toast("获取单词列表数据失败");
  130. });
  131. }
  132. // 单词
  133. function toWord(data){
  134. if (!cacheManager.get('auth')) {
  135. // 游客
  136. const youkeData = JSON.parse(routerOpt.youkePageData)
  137. uni.redirectTo({
  138. url: `/pages/newEnglish/index?jieId=${youkeData.jieId}&wordId=${data.id}&levelId=${youkeData.levelId}&typeId=${youkeData.typeId}&subjectId=${youkeData.subjectId}&tipFlag=${youkeData.tipFlag}&youkeZhangId=${youkeData.youkeZhangId}`
  139. })
  140. } else {
  141. // 非游客
  142. uni.redirectTo({
  143. url: `/pages/newEnglish/index?jieId=${routerOpt.jieId}&wordId=${data.id}`
  144. })
  145. }
  146. }
  147. </script>