wordList.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. <tip-big-dialog ref="youkeDialogRef" @confirm-btn="ykConfirm" :imgShow="true"></tip-big-dialog>
  38. </view>
  39. </template>
  40. <script setup>
  41. import {reactive,ref} from "vue";
  42. import {toast} from "@/utils/common";
  43. import {onLoad} from "@dcloudio/uni-app";
  44. import {getWordList,getWordListYk} from "@/api/word.js";
  45. import cacheManager from '@/utils/cacheManager.js';
  46. import tipBigDialog from '@/components/dialog/tipBigDialog.vue';
  47. const listData = reactive({
  48. count: 0, // 总数,默认值设为 0
  49. studyCount: 0, // 已学总数,默认值设为 0
  50. jieNumberList: [],//节名称
  51. title: '', // 版本+年级+学期
  52. wordList: [], // 单词列表,默认值设为空数组
  53. activeIndex: 0,
  54. });
  55. let wordJieId = ref(null);
  56. let routerOpt = ref(false);
  57. let wordLeft = ref(0);
  58. const youkeDialogRef = ref(null);
  59. onLoad((options) => {
  60. routerOpt = options;
  61. if (!cacheManager.get('auth')) {
  62. // 游客
  63. const youkeData = JSON.parse(routerOpt.youkePageData)
  64. wordJieId = youkeData.jieId
  65. getWordListDataYk();
  66. } else {
  67. // 非游客
  68. wordJieId = routerOpt.jieId
  69. getWordListData();
  70. }
  71. });
  72. // 游客弹窗---确定
  73. function ykConfirm() {
  74. uni.redirectTo({
  75. url: '/pages/login/index'
  76. });
  77. }
  78. // 返回
  79. function goBack(){
  80. if (!cacheManager.get('auth')) {
  81. const youkeData = JSON.parse(routerOpt.youkePageData)
  82. // 游客
  83. uni.redirectTo({
  84. url: `/pages/study/index?levelId=${youkeData.levelId}&typeId=${youkeData.typeId}&subjectId=${youkeData.subjectId}&tipFlag=${youkeData.tipFlag}&youkeZhangId=${youkeData.youkeZhangId}&jieId=${youkeData.jieId}`
  85. })
  86. } else {
  87. // 非游客
  88. uni.redirectTo({
  89. url: `/pages/study/index`
  90. })
  91. }
  92. }
  93. // 修改缓存zid 用于定位岛
  94. function updataCache(data){
  95. cacheManager.updateObject('zhangInfo', {
  96. curZid: data
  97. })
  98. }
  99. function handleTitleClick(item){
  100. if (!cacheManager.get('auth')) {
  101. youkeDialogRef.value.handleShow();
  102. }else {
  103. // 非游客
  104. wordJieId = item.jieId;
  105. // 修改缓存zid 用于定位岛
  106. updataCache(item.zhangZid)
  107. getWordListData();
  108. }
  109. }
  110. function findIndexByJieId(list, jieId){
  111. const findIndex=list.findIndex(item => item.jieId == jieId)
  112. wordLeft.value = findIndex*40;
  113. return findIndex;
  114. }
  115. function getWordListData() {
  116. const opt = {
  117. jieId: wordJieId
  118. };
  119. getWordList(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. function getWordListDataYk() {
  133. const opt = {
  134. jieId: wordJieId
  135. };
  136. getWordListYk(opt).then(res => {
  137. if (res.code === 0) {
  138. listData.count = res.data.count;
  139. listData.studyCount = res.data.studyCount;
  140. listData.jieNumberList = res.data.jieNumberList;
  141. listData.title = res.data.title;
  142. listData.wordList = res.data.wordList;
  143. listData.activeIndex = findIndexByJieId(listData.jieNumberList,wordJieId);
  144. }
  145. }).catch(err => {
  146. toast("获取单词列表数据失败");
  147. });
  148. }
  149. // 单词
  150. function toWord(data){
  151. if (!cacheManager.get('auth')) {
  152. // 游客
  153. const youkeData = JSON.parse(routerOpt.youkePageData)
  154. uni.redirectTo({
  155. url: `/pages/newEnglish/index?jieId=${wordJieId}&wordId=${data.id}&levelId=${youkeData.levelId}&typeId=${youkeData.typeId}&subjectId=${youkeData.subjectId}&tipFlag=${youkeData.tipFlag}&youkeZhangId=${youkeData.youkeZhangId}`
  156. })
  157. } else {
  158. // 非游客
  159. uni.redirectTo({
  160. url: `/pages/newEnglish/index?jieId=${wordJieId}&wordId=${data.id}`
  161. })
  162. }
  163. }
  164. </script>