wordList.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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"
  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. getDataFromStr
  60. } from "@/utils/common";
  61. import {
  62. onLoad
  63. } from "@dcloudio/uni-app";
  64. import {
  65. getWordList,
  66. getWordListYk
  67. } from "@/api/word.js";
  68. import cacheManager from '@/utils/cacheManager.js';
  69. import tipBigDialog from '@/components/dialog/tipBigDialog.vue';
  70. const listData = reactive({
  71. jieNumberList: [], //节名称
  72. title: '', // 版本+年级+学期
  73. wordList: [], // 单词列表,默认值设为空数组
  74. activeIndex: 0,
  75. });
  76. let wordJieId = ref(null);
  77. let routerOpt = ref(false);
  78. let wordLeft = ref(0);
  79. const youkeDialogRef = ref(null);
  80. const unitList = ref([])
  81. const info = reactive({
  82. levelId: null,
  83. zhangId: null,
  84. })
  85. onLoad((options) => {
  86. routerOpt = options;
  87. if (!cacheManager.get('auth')) {
  88. info.levelId = routerOpt.levelId;
  89. info.zhangId = routerOpt.zhangId;
  90. // 游客
  91. const youkeData = JSON.parse(routerOpt.youkePageData)
  92. wordJieId = youkeData.jieId
  93. getWordListDataYk();
  94. } else {
  95. // 获取缓存
  96. [info.levelId, info.zhangId ] = getDataFromStr(cacheManager.get('auth').levelId)
  97. // 非游客
  98. wordJieId = routerOpt.jieId
  99. getWordListData();
  100. }
  101. });
  102. function handleSwiperChange(e) {
  103. listData.activeIndex = e.detail.current;
  104. // unit滚动到指定位置
  105. findWordLeft(listData.activeIndex)
  106. handleTitleClick(listData.jieNumberList[listData.activeIndex])
  107. }
  108. // 游客弹窗---确定
  109. function ykConfirm() {
  110. uni.redirectTo({
  111. url: '/pages/login/index'
  112. });
  113. }
  114. // 返回
  115. function goBack() {
  116. if (!cacheManager.get('auth')) {
  117. const youkeData = JSON.parse(routerOpt.youkePageData)
  118. // 游客
  119. uni.redirectTo({
  120. url: `/pages/study/index?levelId=${youkeData.levelId}&typeId=${youkeData.typeId}&subjectId=${youkeData.subjectId}&tipFlag=${youkeData.tipFlag}&youkeZhangId=${youkeData.youkeZhangId}&jieId=${youkeData.jieId}`
  121. })
  122. } else {
  123. // 非游客
  124. uni.redirectTo({
  125. url: `/pages/study/index`
  126. })
  127. }
  128. }
  129. // 修改缓存zid 用于定位岛
  130. function updataCache(data) {
  131. cacheManager.updateObject('zhangInfo', {
  132. curZid: data
  133. })
  134. }
  135. function handleTitleClick(item) {
  136. if (!cacheManager.get('auth')) {
  137. youkeDialogRef.value.handleShow();
  138. } else {
  139. // 非游客
  140. wordJieId = item.jieId;
  141. // 修改缓存zid 用于定位岛
  142. updataCache(item.zhangZid)
  143. getWordListData();
  144. }
  145. }
  146. function findIndexByJieId(list, jieId) {
  147. const findIndex = list.findIndex(item => item.jieId == jieId)
  148. // unit滚动到指定位置
  149. findWordLeft(findIndex)
  150. return findIndex;
  151. }
  152. // 获取滚动距离
  153. function findWordLeft(data) {
  154. wordLeft.value = data * 40;
  155. return wordLeft.value;
  156. }
  157. function getWordListData() {
  158. /* const opt = {
  159. jieId: wordJieId
  160. };
  161. getWordList(opt).then(res => {
  162. if (res.code === 0) {
  163. listData.count = res.data.count;
  164. listData.studyCount = res.data.studyCount;
  165. listData.jieNumberList = res.data.jieNumberList;
  166. listData.title = res.data.title;
  167. listData.wordList = res.data.wordList;
  168. listData.activeIndex = findIndexByJieId(listData.jieNumberList,wordJieId);
  169. }
  170. }).catch(err => {
  171. toast("获取单词列表数据失败");
  172. }); */
  173. const opt = {
  174. levelId: info.levelId,
  175. zhangId: info.zhangId,
  176. jieId: wordJieId
  177. };
  178. getWordList(opt).then(res => {
  179. if (res.code === 0) {
  180. unitList.value = res.data;
  181. unitList.value.forEach(item => {
  182. if (item.jieId == wordJieId.value) {
  183. listData.activeIndex = findIndexByJieId(listData.jieNumberList, wordJieId);
  184. }
  185. })
  186. }
  187. }).catch(err => {
  188. toast("获取单词列表数据失败");
  189. });
  190. }
  191. function getWordListDataYk() {
  192. const opt = {
  193. levelId: info.levelId,
  194. zhangId: info.zhangId,
  195. jieId: wordJieId
  196. };
  197. getWordListYk(opt).then(res => {
  198. if (res.code === 0) {
  199. /* listData.jieNumberList = res.data.jieNumberList;
  200. listData.title = res.data.title;
  201. listData.wordList = res.data.wordList;
  202. listData.activeIndex = findIndexByJieId(listData.jieNumberList, wordJieId); */
  203. unitList.value = res.data;
  204. unitList.value.forEach(item => {
  205. if (item.jieId == wordJieId.value) {
  206. listData.activeIndex = findIndexByJieId(listData.jieNumberList, wordJieId);
  207. }
  208. })
  209. }
  210. }).catch(err => {
  211. toast("获取单词列表数据失败");
  212. });
  213. }
  214. // 单词
  215. function toWord(data) {
  216. if (!cacheManager.get('auth')) {
  217. // 游客
  218. const youkeData = JSON.parse(routerOpt.youkePageData)
  219. uni.redirectTo({
  220. url: `/pages/newEnglish/index?jieId=${wordJieId}&wordId=${data.id}&levelId=${youkeData.levelId}&typeId=${youkeData.typeId}&subjectId=${youkeData.subjectId}&tipFlag=${youkeData.tipFlag}&youkeZhangId=${youkeData.youkeZhangId}`
  221. })
  222. } else {
  223. // 非游客
  224. uni.redirectTo({
  225. url: `/pages/newEnglish/index?jieId=${wordJieId}&wordId=${data.id}`
  226. })
  227. }
  228. }
  229. </script>