wordList.vue 7.7 KB

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