wordList.vue 7.0 KB

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