wordList.vue 4.6 KB

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