wordList.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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" @click="handleTitleClick(item)"
  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. // Swiper 切换
  116. function handleSwiperChange(e) {
  117. listData.activeIndex = e.detail.current;
  118. if (!swiperData.isAllowed) {
  119. // 不满足条件时回退到原索引
  120. nextTick(() => {
  121. listData.activeIndex = 0; // 强制回退
  122. });
  123. swiperData.isAllowed = false; // 重置状态
  124. }
  125. if (userCode == 'VIP') {
  126. findWordLeft(listData.activeIndex)
  127. updataShuju(listData.jieNumberList[listData.activeIndex])
  128. }
  129. }
  130. // 游客弹窗---确定
  131. function ykConfirm() {
  132. uni.redirectTo({
  133. url: '/pages/login/index'
  134. });
  135. }
  136. // 返回
  137. function goBack() {
  138. if (!cacheManager.get('auth')) {
  139. const youkeData = JSON.parse(routerOpt.youkePageData)
  140. // 游客
  141. uni.redirectTo({
  142. url: `/pages/study/index?levelId=${youkeData.levelId}&typeId=${youkeData.typeId}&subjectId=${youkeData.subjectId}&tipFlag=${youkeData.tipFlag}&youkeZhangId=${youkeData.youkeZhangId}&jieId=${youkeData.jieId}`
  143. })
  144. } else {
  145. // 非游客
  146. uni.redirectTo({
  147. url: `/pages/study/index`
  148. })
  149. }
  150. }
  151. // 修改缓存zid 用于定位岛
  152. function updataCache(data) {
  153. cacheManager.updateObject('zhangInfo', {
  154. curZid: data
  155. })
  156. }
  157. //tab click
  158. function handleTitleClick(item) {
  159. if (!cacheManager.get('auth')) {
  160. youkeDialogRef.value.handleShow();
  161. } else {
  162. updataShuju(item)
  163. }
  164. }
  165. // 修改数据 &&定位岛
  166. function updataShuju(data){
  167. // 非游客
  168. wordJieId = data.jieId;
  169. // 修改缓存zid 用于定位岛
  170. updataCache(data.zhangZid)
  171. getWordListData();
  172. }
  173. // 返回节index
  174. function findIndexByJieId(list, jieId) {
  175. const findIndex = list.findIndex(item => item.jieId == jieId)
  176. // unit滚动到指定位置
  177. findWordLeft(findIndex)
  178. return findIndex;
  179. }
  180. // 获取滚动距离
  181. function findWordLeft(data) {
  182. wordLeft.value = data * 80;
  183. return wordLeft.value;
  184. }
  185. // 非游客接口数据
  186. function getWordListData() {
  187. const opt = {
  188. levelId: info.levelId,
  189. zhangId: info.zhangId,
  190. jieId: wordJieId
  191. };
  192. getWordZhangList(opt).then(res => {
  193. if (res.code === 0) {
  194. listData.title = res.data.title;
  195. unitList.value = res.data.jieWordsList;
  196. listData.jieNumberList = res.data.jieNumberList;
  197. unitList.value.forEach(item => {
  198. if (item.jieId == wordJieId) {
  199. listData.activeIndex = findIndexByJieId(listData.jieNumberList, wordJieId);
  200. }
  201. })
  202. }
  203. }).catch(err => {
  204. toast("获取单词列表数据失败");
  205. });
  206. }
  207. // 游客接口数据
  208. function getWordListDataYk() {
  209. const opt = {
  210. levelId: info.levelId,
  211. zhangId: info.zhangId,
  212. jieId: wordJieId
  213. };
  214. getWordZhangListYK(opt).then(res => {
  215. if (res.code === 0) {
  216. listData.title = res.data.title;
  217. unitList.value = res.data.jieWordsList;
  218. listData.jieNumberList = res.data.jieNumberList;
  219. unitList.value.forEach(item => {
  220. if (item.jieId == wordJieId.value) {
  221. listData.activeIndex = findIndexByJieId(listData.jieNumberList, wordJieId);
  222. }
  223. })
  224. }
  225. }).catch(err => {
  226. toast("获取单词列表数据失败");
  227. });
  228. }
  229. // 单词
  230. function toWord(data) {
  231. if (!cacheManager.get('auth')) {
  232. // 游客
  233. const youkeData = JSON.parse(routerOpt.youkePageData)
  234. uni.redirectTo({
  235. url: `/pages/newEnglish/index?jieId=${wordJieId}&wordId=${data.id}&levelId=${youkeData.levelId}&typeId=${youkeData.typeId}&subjectId=${youkeData.subjectId}&tipFlag=${youkeData.tipFlag}&youkeZhangId=${youkeData.youkeZhangId}`
  236. })
  237. } else {
  238. // 非游客
  239. uni.redirectTo({
  240. url: `/pages/newEnglish/index?jieId=${wordJieId}&wordId=${data.id}`
  241. })
  242. }
  243. }
  244. // 去支付
  245. function goPayPage() {
  246. let zhangInfoLocal = cacheManager.get('zhangInfo')
  247. if (!zhangInfoLocal.cardId) {
  248. toast("cardId 丢失请重新选择学科LevelId");
  249. return false
  250. }
  251. uni.redirectTo({
  252. url: '/pages/mall/mallPage?cardId=' + zhangInfoLocal.cardId + '&from=daoPage' + '&subjectId=' +
  253. zhangInfoLocal.subjectId
  254. })
  255. }
  256. </script>