wordList.vue 7.7 KB

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