wordList.vue 7.4 KB

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