wordList.vue 8.2 KB

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