wordList.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. // 获取缓存
  90. console.log(cacheManager.get('auth').levelId,'cacheManager.get');
  91. if (!cacheManager.get('auth')) {
  92. // 游客
  93. const youkeData = JSON.parse(routerOpt.youkePageData)
  94. wordJieId = youkeData.jieId
  95. getWordListDataYk();
  96. } else {
  97. // 非游客
  98. wordJieId = routerOpt.jieId
  99. getWordListData();
  100. }
  101. });
  102. function handleSwiperChange(e) {
  103. currentIndex.value = e.detail.current + 1;
  104. // unit滚动到指定位置
  105. findWordLeft(e.detail.current)
  106. // 修改缓存zid 用于定位岛
  107. // updataCache(item.zhangZid)
  108. }
  109. // 游客弹窗---确定
  110. function ykConfirm() {
  111. uni.redirectTo({
  112. url: '/pages/login/index'
  113. });
  114. }
  115. // 返回
  116. function goBack() {
  117. if (!cacheManager.get('auth')) {
  118. const youkeData = JSON.parse(routerOpt.youkePageData)
  119. // 游客
  120. uni.redirectTo({
  121. url: `/pages/study/index?levelId=${youkeData.levelId}&typeId=${youkeData.typeId}&subjectId=${youkeData.subjectId}&tipFlag=${youkeData.tipFlag}&youkeZhangId=${youkeData.youkeZhangId}&jieId=${youkeData.jieId}`
  122. })
  123. } else {
  124. // 非游客
  125. uni.redirectTo({
  126. url: `/pages/study/index`
  127. })
  128. }
  129. }
  130. // 修改缓存zid 用于定位岛
  131. function updataCache(data) {
  132. cacheManager.updateObject('zhangInfo', {
  133. curZid: data
  134. })
  135. }
  136. function handleTitleClick(item) {
  137. if (!cacheManager.get('auth')) {
  138. youkeDialogRef.value.handleShow();
  139. } else {
  140. // 非游客
  141. wordJieId = item.jieId;
  142. // 修改缓存zid 用于定位岛
  143. updataCache(item.zhangZid)
  144. getWordListData();
  145. }
  146. }
  147. function findIndexByJieId(list, jieId) {
  148. const findIndex = list.findIndex(item => item.jieId == jieId)
  149. // unit滚动到指定位置
  150. findWordLeft(findIndex)
  151. return findIndex;
  152. }
  153. // 获取滚动距离
  154. function findWordLeft(data){
  155. wordLeft.value = data * 40;
  156. return wordLeft.value;
  157. }
  158. function getWordListData() {
  159. /* const opt = {
  160. jieId: wordJieId
  161. };
  162. getWordList(opt).then(res => {
  163. if (res.code === 0) {
  164. listData.count = res.data.count;
  165. listData.studyCount = res.data.studyCount;
  166. listData.jieNumberList = res.data.jieNumberList;
  167. listData.title = res.data.title;
  168. listData.wordList = res.data.wordList;
  169. listData.activeIndex = findIndexByJieId(listData.jieNumberList,wordJieId);
  170. }
  171. }).catch(err => {
  172. toast("获取单词列表数据失败");
  173. }); */
  174. const opt = {
  175. levelId: info.levelId,
  176. zhangId: info.zhangId,
  177. jieId: wordJieId
  178. };
  179. getWordList(opt).then(res => {
  180. if (res.code === 0) {
  181. unitList.value = res.data;
  182. unitList.value.forEach(item => {
  183. if (item.jieId == wordJieId.value) {
  184. listData.activeIndex = findIndexByJieId(listData.jieNumberList,wordJieId);
  185. }
  186. })
  187. }
  188. }).catch(err => {
  189. toast("获取单词列表数据失败");
  190. });
  191. }
  192. function getWordListDataYk() {
  193. const opt = {
  194. levelId: info.levelId,
  195. zhangId: info.zhangId,
  196. jieId: wordJieId
  197. };
  198. getWordListYk(opt).then(res => {
  199. if (res.code === 0) {
  200. /* listData.jieNumberList = res.data.jieNumberList;
  201. listData.title = res.data.title;
  202. listData.wordList = res.data.wordList;
  203. listData.activeIndex = findIndexByJieId(listData.jieNumberList, wordJieId); */
  204. unitList.value = res.data;
  205. unitList.value.forEach(item => {
  206. if (item.jieId == wordJieId.value) {
  207. listData.activeIndex = findIndexByJieId(listData.jieNumberList,wordJieId);
  208. }
  209. })
  210. }
  211. }).catch(err => {
  212. toast("获取单词列表数据失败");
  213. });
  214. }
  215. // 单词
  216. function toWord(data) {
  217. if (!cacheManager.get('auth')) {
  218. // 游客
  219. const youkeData = JSON.parse(routerOpt.youkePageData)
  220. uni.redirectTo({
  221. url: `/pages/newEnglish/index?jieId=${wordJieId}&wordId=${data.id}&levelId=${youkeData.levelId}&typeId=${youkeData.typeId}&subjectId=${youkeData.subjectId}&tipFlag=${youkeData.tipFlag}&youkeZhangId=${youkeData.youkeZhangId}`
  222. })
  223. } else {
  224. // 非游客
  225. uni.redirectTo({
  226. url: `/pages/newEnglish/index?jieId=${wordJieId}&wordId=${data.id}`
  227. })
  228. }
  229. }
  230. </script>