wordList.vue 4.0 KB

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