wordList.vue 8.2 KB

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