index.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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(danyuanInfo,'jixu')"></view>
  27. </view>
  28. <view class="jd-item-box">
  29. <view class="jd-item-btn" @click="handleClickDanyuan">
  30. <icon class="dydg-icon"></icon>单元大纲
  31. </view>
  32. <view class="jd-item-btn" @click="handleClickMulu">
  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. <danyuanMuluVue ref="dyMlRef" @select="handleSelectDanyuan"></danyuanMuluVue>
  58. <CustomTabBar :currentTabNumber="1"></CustomTabBar>
  59. </view>
  60. </template>
  61. <script>
  62. import CustomTabBar from '@/components/custom-tabbar/custom-tabbar.vue';
  63. import cacheManager from "@/utils/cacheManager.js";
  64. import {
  65. shuxueChanpinDanyuanInfo
  66. } from "@/api/chanpinneirong.js"
  67. import danyuanInfoVue from '@/pages/xinshuxue/components/danyuanInfo.vue';
  68. import danyuanMuluVue from '@/pages/xinshuxue/components/danyuanMulu.vue';
  69. export default {
  70. data() {
  71. return {
  72. dagangList: [],
  73. currentUnitName: "",
  74. isShow: true,
  75. currentIndex: 0,
  76. danyuanInfo: {},
  77. banbenId: '',
  78. danyuanId: '',
  79. chanpinTypeId: '',
  80. chanpinId: '',
  81. fontDanyuanId: '',
  82. nextDanyuanId: '',
  83. dengjiId: '',
  84. customType: '',
  85. cacheManagerLocal: null
  86. }
  87. },
  88. components: {
  89. CustomTabBar,
  90. danyuanInfoVue,
  91. danyuanMuluVue
  92. },
  93. onShow() {
  94. console.log('学习页面显示,尝试恢复滚动位置')
  95. },
  96. onHide() {
  97. console.log('学习页面隐藏,保存滚动位置')
  98. },
  99. onLoad(options) {
  100. console.log('options', options);
  101. this.customType = options.customType
  102. if (this.customType) {
  103. this.chanpinId = options.chanpinId
  104. this.danyuanId = options.danyuanId
  105. this.banbenId = options.banbenId
  106. this.dengjiId = options.dengjiId
  107. this.chanpinTypeId = options.chanpinTypeId
  108. this.loadDataFromApi()
  109. } else {
  110. console.log('使用缓存');
  111. this.chanpinId = cacheManager.get('auth').chanpinId
  112. this.danyuanId = cacheManager.get('auth').danyuanId
  113. this.banbenId = cacheManager.get('auth').banbenId
  114. this.chanpinTypeId = cacheManager.get('auth').chanpinTypeId
  115. //用于返回
  116. this.dengjiId = cacheManager.get('auth').dengjiId
  117. this.cacheManagerLocal = cacheManager.get('xuexi-' + this.chanpinId)
  118. // 使用缓存
  119. this.danyuanInfo = this.cacheManagerLocal
  120. this.fontDanyuanId = this.cacheManagerLocal.fontDanyuanId
  121. this.nextDanyuanId = this.cacheManagerLocal.nextDanyuanId
  122. this.dagangList = this.cacheManagerLocal.dagangList || []
  123. }
  124. },
  125. methods: {
  126. handleSelectDanyuan(item) {
  127. console.log('切换单元', item)
  128. },
  129. handleClickMulu() {
  130. this.$refs.dyMlRef.showPopup(this.banbenId)
  131. },
  132. handleBack() {
  133. uni.navigateTo({
  134. url: `/pages/chanpinXuanze/banben?dengjiId=`+this.dengjiId
  135. })
  136. },
  137. loadDataFromApi() {
  138. const req = {
  139. banbenId: this.banbenId,
  140. danyuanId: this.danyuanId
  141. }
  142. shuxueChanpinDanyuanInfo(req).then(res => {
  143. this.danyuanInfo = res.data
  144. this.fontDanyuanId = res.data.fontDanyuanId
  145. this.nextDanyuanId = res.data.nextDanyuanId
  146. this.dagangList = res.data.dagangList || []
  147. cacheManager.set('xuexi-' + this.chanpinId, res.data)
  148. cacheManager.updateObject('auth', {
  149. chanpinId: this.chanpinId,
  150. chanpinTypeId: this.chanpinTypeId,
  151. banbenId: this.banbenId,
  152. danyuanId: this.danyuanId,
  153. dengjiId: this.dengjiId
  154. })
  155. // 初始化当前单元
  156. // if (this.danyuanList.length > 0) {
  157. // this.currentUnitName = this.danyuanList[0].danyuanName
  158. // }
  159. })
  160. },
  161. prev() {
  162. if (this.currentIndex > 0) {
  163. this.currentIndex--
  164. this.danyuanId = this.fontDanyuanId
  165. this.loadDataFromApi()
  166. }
  167. },
  168. next() {
  169. if (this.currentIndex < this.dagangList.length - 1) {
  170. this.currentIndex++
  171. this.danyuanId = this.nextDanyuanId
  172. this.loadDataFromApi()
  173. }
  174. },
  175. handlePlay(da, code) {
  176. console.log('da', da)
  177. let jieId = null;
  178. if (code == 'jixu') {
  179. // 判断学习状态
  180. /* if (已学完) {
  181. return;
  182. } */
  183. jieId = da.curJieId;
  184. uni.navigateTo({
  185. url: `/pages/xinshuxue/lookShipin?jieId=${jieId}`
  186. })
  187. } else {
  188. jieId = da.jieId;
  189. if (da.type == 1) {
  190. uni.navigateTo({
  191. url: `/pages/xinshuxue/lookShipin?jieId=${jieId}`
  192. })
  193. } else {
  194. uni.navigateTo({
  195. url: `/pages/xinshuxue/unitTest?jieId=${jieId}`
  196. })
  197. }
  198. }
  199. },
  200. handleClickDanyuan() {
  201. this.isShow = true;
  202. setTimeout(() => {
  203. this.$refs.dyRef.handleShow(this.danyuanId)
  204. }, 100)
  205. },
  206. // 滚动事件处理
  207. onScroll(e) {
  208. const scrollTop = e.detail.scrollTop;
  209. // 更新滚动位置
  210. this.scrollTop = scrollTop;
  211. }
  212. }
  213. }
  214. </script>