wordList.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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)">
  14. <view class="item-word">
  15. <view class="word-text">
  16. <text v-for="(word, wordIndex) in item.chaifen[0].split(',')"
  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. // 游客
  64. uni.redirectTo({
  65. url: `/pages/study/index?levelId=${routerOpt.levelId}&typeId=${routerOpt.typeId}&subjectId=${routerOpt.subjectId}&tipFlag=${routerOpt.tipFlag}&youkeZhangId=${routerOpt.youkeZhangId}&jieId=${routerOpt.jieId}`
  66. })
  67. } else {
  68. // 非游客
  69. uni.redirectTo({
  70. url: `/pages/study/index`
  71. })
  72. }
  73. }
  74. function getWordListData() {
  75. const opt = {
  76. jieId: routerOpt.jieId
  77. };
  78. getWordList(opt).then(res => {
  79. if (res.code === 0) {
  80. listData.count = res.data.count;
  81. listData.studyCount = res.data.studyCount;
  82. listData.jieName = res.data.jieName;
  83. listData.title = res.data.title;
  84. listData.wordList = res.data.wordList;
  85. }
  86. }).catch(err => {
  87. toast("获取单词列表数据失败");
  88. });
  89. }
  90. function getWordListDataYk() {
  91. const opt = {
  92. jieId: routerOpt.jieId
  93. };
  94. getWordListYk(opt).then(res => {
  95. if (res.code === 0) {
  96. listData.count = res.data.count;
  97. listData.studyCount = res.data.studyCount;
  98. listData.jieName = res.data.jieName;
  99. listData.title = res.data.title;
  100. listData.wordList = res.data.wordList;
  101. }
  102. }).catch(err => {
  103. toast("获取单词列表数据失败");
  104. });
  105. }
  106. // 单词
  107. function toWord(data){
  108. if (!cacheManager.get('auth')) {
  109. // 游客
  110. uni.redirectTo({
  111. url: `/pages/newEnglish/index?jieId=${routerOpt.jieId}&wordId=${data.id}&levelId=${routerOpt.levelId}&typeId=${routerOpt.typeId}&subjectId=${routerOpt.subjectId}&tipFlag=${routerOpt.tipFlag}&youkeZhangId=${routerOpt.youkeZhangId}&jieId=${routerOpt.jieId}`
  112. })
  113. } else {
  114. // 非游客
  115. uni.redirectTo({
  116. url: `/pages/newEnglish/index?jieId=${routerOpt.jieId}&wordId=${data.id}`
  117. })
  118. }
  119. }
  120. </script>