wordList.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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"
  12. :key="item.jieId" @click="handleTitleClick(item)"
  13. :class="{active: listData.activeIndex == index}">Unit{{item.number}}</view>
  14. </scroll-view>
  15. <swiper class="word-view-swiper-box" :indicator-dots="false" :autoplay="false" :circular="false"
  16. @change="handleSwiperChange">
  17. <swiper-item v-for="citem in unitList" :key="citem.jieId">
  18. <view class="word-list-body" v-if="citem.wordList && citem.wordList.length > 0">
  19. <view class="word-num-box">
  20. <icon></icon><text>{{citem.studyCount || 0}}/{{citem.count || 0}}词</text>
  21. </view>
  22. <!-- 单词 -->
  23. <view class="word-list-item" v-for="(item,index) in item.wordList" :key="index"
  24. @click="toWord(item)" :class="{active: item.wcFlag == 1}">
  25. <view class="item-word">
  26. <view class="word-text">
  27. <text v-for="(word, wordIndex) in item.chaifen" :key="wordIndex"
  28. class="word-color">
  29. {{ word }}
  30. </text>
  31. </view>
  32. <view class="phonetic-alphabet">{{item.yinbiao || ''}}</view>
  33. </view>
  34. <view class="item-explain">
  35. <view class="item-explain-content">
  36. <view class="explain-text" v-for="(meaning, meaningIndex) in item.jianyi"
  37. :key="meaningIndex">{{meaning}}</view>
  38. </view>
  39. </view>
  40. <view class="item-arrow">
  41. <icon></icon>
  42. </view>
  43. </view>
  44. </view>
  45. </swiper-item>
  46. </swiper>
  47. </view>
  48. </view>
  49. <tip-big-dialog ref="youkeDialogRef" @confirm-btn="ykConfirm" :imgShow="true"></tip-big-dialog>
  50. </view>
  51. </template>
  52. <script setup>
  53. import {
  54. reactive,
  55. ref
  56. } from "vue";
  57. import {
  58. toast
  59. } from "@/utils/common";
  60. import {
  61. onLoad
  62. } from "@dcloudio/uni-app";
  63. import {
  64. getWordList,
  65. getWordListYk
  66. } from "@/api/word.js";
  67. import cacheManager from '@/utils/cacheManager.js';
  68. import tipBigDialog from '@/components/dialog/tipBigDialog.vue';
  69. const listData = reactive({
  70. jieNumberList: [], //节名称
  71. title: '', // 版本+年级+学期
  72. wordList: [], // 单词列表,默认值设为空数组
  73. activeIndex: 0,
  74. });
  75. let wordJieId = ref(null);
  76. let routerOpt = ref(false);
  77. let wordLeft = ref(0);
  78. const youkeDialogRef = ref(null);
  79. const currentIndex = ref(null)
  80. const unitList = ref([])
  81. const info= reactive({
  82. levelId: null,
  83. zhangId: null,
  84. })
  85. onLoad((options) => {
  86. routerOpt = options;
  87. info.levelId = routerOpt.levelId;
  88. info.zhangId = routerOpt.zhangId;
  89. if (!cacheManager.get('auth')) {
  90. // 游客
  91. const youkeData = JSON.parse(routerOpt.youkePageData)
  92. wordJieId = youkeData.jieId
  93. getWordListDataYk();
  94. } else {
  95. // 非游客
  96. wordJieId = routerOpt.jieId
  97. getWordListData();
  98. }
  99. });
  100. function handleSwiperChange(e) {
  101. currentIndex.value = e.detail.current + 1;
  102. }
  103. // 游客弹窗---确定
  104. function ykConfirm() {
  105. uni.redirectTo({
  106. url: '/pages/login/index'
  107. });
  108. }
  109. // 返回
  110. function goBack() {
  111. if (!cacheManager.get('auth')) {
  112. const youkeData = JSON.parse(routerOpt.youkePageData)
  113. // 游客
  114. uni.redirectTo({
  115. url: `/pages/study/index?levelId=${youkeData.levelId}&typeId=${youkeData.typeId}&subjectId=${youkeData.subjectId}&tipFlag=${youkeData.tipFlag}&youkeZhangId=${youkeData.youkeZhangId}&jieId=${youkeData.jieId}`
  116. })
  117. } else {
  118. // 非游客
  119. uni.redirectTo({
  120. url: `/pages/study/index`
  121. })
  122. }
  123. }
  124. // 修改缓存zid 用于定位岛
  125. function updataCache(data) {
  126. cacheManager.updateObject('zhangInfo', {
  127. curZid: data
  128. })
  129. }
  130. function handleTitleClick(item) {
  131. if (!cacheManager.get('auth')) {
  132. youkeDialogRef.value.handleShow();
  133. } else {
  134. // 非游客
  135. wordJieId = item.jieId;
  136. // 修改缓存zid 用于定位岛
  137. updataCache(item.zhangZid)
  138. getWordListData();
  139. }
  140. }
  141. function findIndexByJieId(list, jieId) {
  142. const findIndex = list.findIndex(item => item.jieId == jieId)
  143. wordLeft.value = findIndex * 40;
  144. return findIndex;
  145. }
  146. function getWordListData() {
  147. /*const opt = {
  148. jieId: wordJieId
  149. };
  150. getWordList(opt).then(res => {
  151. if (res.code === 0) {
  152. listData.count = res.data.count;
  153. listData.studyCount = res.data.studyCount;
  154. listData.jieNumberList = res.data.jieNumberList;
  155. listData.title = res.data.title;
  156. listData.wordList = res.data.wordList;
  157. listData.activeIndex = findIndexByJieId(listData.jieNumberList,wordJieId);
  158. }
  159. }).catch(err => {
  160. toast("获取单词列表数据失败");
  161. });*/
  162. const opt = {
  163. levelId: info.levelId,
  164. zhangId: info.zhangId,
  165. jieId: wordJieId
  166. };
  167. getWordList(opt).then(res => {
  168. if (res.code === 0) {
  169. unitList.value = res.data;
  170. unitList.value.forEach(item => {
  171. if (item.jieId == wordJieId.value) {
  172. listData.activeIndex = findIndexByJieId(listData.jieNumberList,wordJieId);
  173. }
  174. })
  175. }
  176. }).catch(err => {
  177. toast("获取单词列表数据失败");
  178. });
  179. }
  180. function getWordListDataYk() {
  181. const opt = {
  182. levelId: info.levelId,
  183. zhangId: info.zhangId,
  184. jieId: wordJieId
  185. };
  186. getWordListYk(opt).then(res => {
  187. if (res.code === 0) {
  188. /* listData.jieNumberList = res.data.jieNumberList;
  189. listData.title = res.data.title;
  190. listData.wordList = res.data.wordList;
  191. listData.activeIndex = findIndexByJieId(listData.jieNumberList, wordJieId); */
  192. unitList.value = res.data;
  193. unitList.value.forEach(item => {
  194. if (item.jieId == wordJieId.value) {
  195. listData.activeIndex = findIndexByJieId(listData.jieNumberList,wordJieId);
  196. }
  197. })
  198. }
  199. }).catch(err => {
  200. toast("获取单词列表数据失败");
  201. });
  202. }
  203. // 单词
  204. function toWord(data) {
  205. if (!cacheManager.get('auth')) {
  206. // 游客
  207. const youkeData = JSON.parse(routerOpt.youkePageData)
  208. uni.redirectTo({
  209. url: `/pages/newEnglish/index?jieId=${wordJieId}&wordId=${data.id}&levelId=${youkeData.levelId}&typeId=${youkeData.typeId}&subjectId=${youkeData.subjectId}&tipFlag=${youkeData.tipFlag}&youkeZhangId=${youkeData.youkeZhangId}`
  210. })
  211. } else {
  212. // 非游客
  213. uni.redirectTo({
  214. url: `/pages/newEnglish/index?jieId=${wordJieId}&wordId=${data.id}`
  215. })
  216. }
  217. }
  218. </script>