wordList.vue 7.0 KB

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