index.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <template>
  2. <view class="ezy-xuexi-page">
  3. <view class="icon-title-navBar-box">
  4. <view @click="handleBack" class="nav-bar-icon"></view>
  5. <text class="nav-bar-title">学习</text>
  6. </view>
  7. <view class="ezy-page-body xuexi-page-body">
  8. <view class="change-dy-box">
  9. <view class="arrow-icon left-icon" :class="{ 'disabled': currentIndex == 0 }" @click="prev"> </view>
  10. <!-- 显示内容 -->
  11. <view class="change-dy-content">
  12. <view>{{ danyuanInfo.danyuanName }}</view>
  13. <view>{{ danyuanInfo.danyuanIntro }}</view>
  14. </view>
  15. <view class="arrow-icon right-icon" @click="next"
  16. :class="{ 'disabled': currentIndex == dagangList.length - 1 }"> </view>
  17. </view>
  18. <view class="xx-scroll-body">
  19. <view class="xx-jd-box">
  20. <view class="xx-progress-btn-box">
  21. <view class="xx-progress-box">
  22. <view>当前学习进度</view>
  23. <progress :percent="20" class="xx-progress" stroke-width="10" backgroundColor="#3c7dfd"
  24. activeColor="#ffd11c" />
  25. </view>
  26. <view class="jxxx-btn" @click="handlePlay(subjectDetail,'jixu')"></view>
  27. </view>
  28. <view class="jd-item-box">
  29. <view class="jd-item-btn">
  30. <icon class="dydg-icon"></icon>单元大纲
  31. </view>
  32. <view class="jd-item-btn">
  33. <icon class="dyml-icon"></icon>单元目录
  34. </view>
  35. </view>
  36. </view>
  37. <view class="xx-item-list">
  38. <view class="xx-item-box" v-for="section in dagangList" :key="section.jieId">
  39. <view class="xx-item-status"
  40. :class="section.wanchengFlag == 1 ? 'completed-status' : 'uncompleted-status'"> </view>
  41. <img :src="section.cover" />
  42. <view class="xx-text-box">
  43. <view>{{ section.jieName }}</view>
  44. <view>{{ section.jieIntro }}</view>
  45. </view>
  46. <view @click="handlePlay(section,'play')" class="xx-item-btn"></view>
  47. </view>
  48. </view>
  49. <!-- 底部占位 -->
  50. <view v-if="currentIndex != dagangList.length - 1" class="xx-next-btn" @click="next">
  51. 学习下一单元</view>
  52. <!-- <view class="xx-xw-text">课程已学完</view> -->
  53. </view>
  54. </view>
  55. <!-- <scroll-view scroll-y class="scroll-view" :scroll-top="scrollTop" @scroll="onScroll"> </scroll-view> -->
  56. <danyuanInfoVue ref="dyRef" v-if="isShow" @close="isShow= false"></danyuanInfoVue>
  57. <CustomTabBar :currentTabNumber="1"></CustomTabBar>
  58. </view>
  59. </template>
  60. <script>
  61. import CustomTabBar from '@/components/custom-tabbar/custom-tabbar.vue';
  62. import cacheManager from "@/utils/cacheManager.js";
  63. import {
  64. shuxueChanpinDanyuanInfo
  65. } from "@/api/chanpinneirong.js"
  66. import danyuanInfoVue from '@/pages/xinshuxue/components/danyuanInfo.vue';
  67. export default {
  68. data() {
  69. return {
  70. dagangList: [],
  71. currentUnitName: "",
  72. isShow: true,
  73. currentIndex: 0,
  74. danyuanInfo: {},
  75. banbenId: '',
  76. danyuanId: '',
  77. chanpinId: '',
  78. fontDanyuanId: '',
  79. nextDanyuanId: '',
  80. customType: '',
  81. cacheManagerLocal: null
  82. }
  83. },
  84. components: {
  85. CustomTabBar,
  86. danyuanInfoVue,
  87. },
  88. onShow() {
  89. console.log('学习页面显示,尝试恢复滚动位置')
  90. },
  91. onHide() {
  92. console.log('学习页面隐藏,保存滚动位置')
  93. },
  94. onLoad(options) {
  95. console.log('options', options);
  96. this.customType = options.customType
  97. if (this.customType) {
  98. this.chanpinId = options.chanpinId
  99. this.danyuanId = options.danyuanId
  100. this.banbenId = options.banbenId
  101. this.loadDataFromApi()
  102. } else {
  103. console.log('使用缓存');
  104. this.chanpinId = cacheManager.get('auth').chanpinId
  105. this.danyuanId = cacheManager.get('auth').danyuanId
  106. this.banbenId = cacheManager.get('auth').banbenId
  107. this.cacheManagerLocal = cacheManager.get('xuexi-' + this.chanpinId)
  108. // 使用缓存
  109. this.danyuanInfo = this.cacheManagerLocal
  110. this.fontDanyuanId = this.cacheManagerLocal.fontDanyuanId
  111. this.nextDanyuanId = this.cacheManagerLocal.nextDanyuanId
  112. this.dagangList = this.cacheManagerLocal.dagangList || []
  113. }
  114. },
  115. methods: {
  116. handleBack() {
  117. },
  118. loadDataFromApi() {
  119. const req = {
  120. banbenId: this.banbenId,
  121. danyuanId: this.danyuanId
  122. }
  123. shuxueChanpinDanyuanInfo(req).then(res => {
  124. this.danyuanInfo = res.data
  125. this.fontDanyuanId = res.data.fontDanyuanId
  126. this.nextDanyuanId = res.data.nextDanyuanId
  127. this.dagangList = res.data.dagangList || []
  128. cacheManager.set('xuexi-' + this.chanpinId, res.data)
  129. cacheManager.updateObject('auth', {
  130. chanpinId: this.chanpinId,
  131. banbenId: this.banbenId,
  132. danyuanId: this.danyuanId
  133. })
  134. // 初始化当前单元
  135. // if (this.danyuanList.length > 0) {
  136. // this.currentUnitName = this.danyuanList[0].danyuanName
  137. // }
  138. })
  139. },
  140. prev() {
  141. if (this.currentIndex > 0) {
  142. this.currentIndex--
  143. this.danyuanId = this.fontDanyuanId
  144. this.loadDataFromApi()
  145. }
  146. },
  147. next() {
  148. if (this.currentIndex < this.dagangList.length - 1) {
  149. this.currentIndex++
  150. this.danyuanId = this.nextDanyuanId
  151. this.loadDataFromApi()
  152. }
  153. },
  154. handlePlay(da, code) {
  155. let jieId = null;
  156. if (code == 'jixu') {
  157. jieId = da.curJieId;
  158. uni.navigateTo({
  159. url: `/pages/xinshuxue/lookShipin?jieId=${jieId}`
  160. })
  161. } else {
  162. jieId = da.jieId;
  163. if (da.type == 1) {
  164. uni.navigateTo({
  165. url: `/pages/xinshuxue/lookShipin?jieId=${jieId}`
  166. })
  167. } else {
  168. uni.navigateTo({
  169. url: `/pages/xinshuxue/unitTest?jieId=${jieId}`
  170. })
  171. }
  172. }
  173. },
  174. handleClickDanyuan(item) {
  175. console.log('item', item)
  176. this.isShow = true;
  177. setTimeout(() => {
  178. this.$refs.dyRef.handleShow(item.danyuanId)
  179. }, 100)
  180. },
  181. // 滚动事件处理
  182. onScroll(e) {
  183. const scrollTop = e.detail.scrollTop;
  184. // 更新滚动位置
  185. this.scrollTop = scrollTop;
  186. }
  187. }
  188. }
  189. </script>