wordList.vue 8.0 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. <view class="word-title-box" style="display: flex;overflow-x: auto;" v-if="listData.jieNumberList && listData.jieNumberList.length >0">
  10. <view :id="'item-' + item.jieId" class="title-item" v-for="(item,index) in listData.jieNumberList" @click="handleTitleClick(item)"
  11. :key="item.jieId" :class="{active: listData.activeIndex == index}">Unit{{item.number}}</view>
  12. </view>
  13. <swiper class="word-list-swiper-box" :indicator-dots="false" :autoplay="false" :circular="false" :current="listData.activeIndex"
  14. @change="handleSwiperChange" :disable-touch="!swiperData.isAllowed">
  15. <swiper-item class="word-list-swiper-item" v-for="citem in unitList" :key="citem.jieId" @touchstart="handleTouchStart"
  16. @touchend="handleTouchEnd">
  17. <view class="word-list-body" v-if="citem.wordList && citem.wordList.length > 0">
  18. <!-- num -->
  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. <!-- 没有单词 -->
  46. <view class="no-word-box" v-else>
  47. 暂无单词
  48. </view>
  49. </swiper-item>
  50. </swiper>
  51. </view>
  52. </view>
  53. <tip-big-dialog ref="youkeDialogRef" @confirm-btn="ykConfirm" :imgShow="true"></tip-big-dialog>
  54. <tip-small-dialog ref="goPayDialogRef" @confirm-btn="goPayPage" :content="tipContent"></tip-small-dialog>
  55. </view>
  56. </template>
  57. <script setup>
  58. import {reactive,ref,nextTick} from "vue";
  59. import {toast,getDataFromStr,useActiveDomIntoView} from "@/utils/common";
  60. import {onLoad} from "@dcloudio/uni-app";
  61. import {getWordZhangList,getWordZhangListYK,} from "@/api/word.js";
  62. import cacheManager from '@/utils/cacheManager.js';
  63. import tipBigDialog from '@/components/dialog/tipBigDialog.vue';
  64. import {useSwiper} from "@/utils/useSwiper";
  65. import tipSmallDialog from '@/components/dialog/tipSmallDialog.vue'
  66. const goPayDialogRef = ref(null);
  67. const listData = reactive({
  68. jieNumberList: [], //节名称
  69. title: '', // 版本+年级+学期
  70. wordList: [], // 单词列表,默认值设为空数组
  71. activeIndex: 0,
  72. });
  73. let wordJieId = ref(null);
  74. let routerOpt = ref(false);
  75. let wordLeft = ref(0);
  76. const youkeDialogRef = ref(null);
  77. const unitList = ref([])
  78. const info = reactive({
  79. levelId: null,
  80. zhangId: null,
  81. })
  82. const tipContent = '是否前往开通付费?';
  83. const {
  84. swiperData,
  85. handleTouchStart,
  86. handleTouchEnd,
  87. userCode
  88. } = useSwiper(listData, (userCode) => {
  89. // 非VIP
  90. if (userCode == 'Not-Vip') {
  91. goPayDialogRef.value.handleShow();
  92. }else if(userCode == 'Visitor'){
  93. // 游客
  94. youkeDialogRef.value.handleShow();
  95. }
  96. });
  97. onLoad((options) => {
  98. routerOpt = options;
  99. if (!cacheManager.get('auth')) {
  100. // 游客
  101. const youkeData = JSON.parse(routerOpt.youkePageData)
  102. info.levelId = youkeData.levelId;
  103. info.zhangId = youkeData.youkeZhangId;
  104. wordJieId = youkeData.jieId
  105. getWordListDataYk();
  106. } else {
  107. // 获取缓存
  108. [info.levelId, info.zhangId] = getDataFromStr(cacheManager.get('auth').levelId)
  109. // 非游客
  110. wordJieId = routerOpt.jieId
  111. getWordListData();
  112. }
  113. });
  114. // Swiper 切换
  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. updataShuju(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. //tab click
  157. function handleTitleClick(item) {
  158. if (!cacheManager.get('auth')) {
  159. youkeDialogRef.value.handleShow();
  160. } else {
  161. updataShuju(item)
  162. }
  163. }
  164. // 修改数据 &&定位岛
  165. function updataShuju(data){
  166. // 非游客
  167. wordJieId = data.jieId;
  168. // 修改缓存zid 用于定位岛
  169. updataCache(data.zhangZid)
  170. getWordListData();
  171. }
  172. // 返回节index
  173. function findIndexByJieId(list, jieId) {
  174. const findIndex = list.findIndex(item => item.jieId == jieId)
  175. // unit滚动到指定位置
  176. findWordLeft(findIndex)
  177. return findIndex;
  178. }
  179. // 获取滚动距离
  180. function findWordLeft(data) {
  181. useActiveDomIntoView('.word-title-box','.title-item.active')
  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>