index.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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': fontDanyuanId == 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" :class="{ 'disabled': nextDanyuanId == 0 }"> </view>
  16. </view>
  17. <view class="xx-scroll-body">
  18. <view class="xx-jd-box">
  19. <view class="xx-progress-btn-box">
  20. <view class="xx-progress-box">
  21. <view>当前学习进度</view>
  22. <progress :percent="20" class="xx-progress" stroke-width="10" backgroundColor="#3c7dfd"
  23. activeColor="#ffd11c" />
  24. </view>
  25. <view class="jxxx-btn" @click="handlePlay(danyuanInfo,'jixu')"></view>
  26. </view>
  27. <view class="jd-item-box">
  28. <view class="jd-item-btn" @click="handleClickDanyuan">
  29. <icon class="dydg-icon"></icon>单元大纲
  30. </view>
  31. <view class="jd-item-btn" @click="handleClickMulu">
  32. <icon class="dyml-icon"></icon>单元目录
  33. </view>
  34. </view>
  35. </view>
  36. <view class="xx-item-list">
  37. <view class="xx-item-box" v-for="section in dagangList" :key="section.jieId">
  38. <view class="xx-item-status"
  39. :class="section.wanchengFlag == 1 ? 'completed-status' : 'uncompleted-status'"> </view>
  40. <img :src="section.cover" />
  41. <view class="xx-text-box">
  42. <view>{{ section.jieName }}</view>
  43. <view>{{ section.jieIntro }}</view>
  44. </view>
  45. <view @click="handlePlay(section,'play')" class="xx-item-btn"></view>
  46. </view>
  47. </view>
  48. <!-- 底部占位 -->
  49. <view v-if="currentIndex != dagangList.length - 1" class="xx-next-btn" @click="next">
  50. 学习下一单元</view>
  51. <!-- <view class="xx-xw-text">课程已学完</view> -->
  52. </view>
  53. </view>
  54. <!-- <scroll-view scroll-y class="scroll-view" :scroll-top="scrollTop" @scroll="onScroll"> </scroll-view> -->
  55. <danyuanInfoVue ref="dyRef" v-if="isShow" @close="isShow= false"></danyuanInfoVue>
  56. <danyuanMuluVue ref="dyMlRef" @select="handleSelectDanyuan"></danyuanMuluVue>
  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. import danyuanMuluVue from '@/pages/xinshuxue/components/danyuanMulu.vue';
  68. export default {
  69. data() {
  70. return {
  71. dagangList: [],
  72. currentUnitName: "",
  73. isShow: true,
  74. currentIndex: 0,
  75. danyuanInfo: {},
  76. banbenId: '',
  77. danyuanId: '',
  78. chanpinId: '',
  79. fontDanyuanId: '',
  80. nextDanyuanId: '',
  81. dengjiId: '',
  82. customType: '',
  83. cacheManagerLocal: null
  84. }
  85. },
  86. components: {
  87. CustomTabBar,
  88. danyuanInfoVue,
  89. danyuanMuluVue
  90. },
  91. onShow() {
  92. console.log('学习页面显示,尝试恢复滚动位置')
  93. },
  94. onHide() {
  95. console.log('学习页面隐藏,保存滚动位置')
  96. },
  97. onLoad(options) {
  98. console.log('options', options);
  99. this.customType = options.customType
  100. if (this.customType) {
  101. this.chanpinId = options.chanpinId
  102. this.danyuanId = options.danyuanId
  103. this.banbenId = options.banbenId
  104. this.dengjiId = options.dengjiId
  105. this.loadDataFromApi()
  106. } else {
  107. console.log('使用缓存');
  108. this.chanpinId = cacheManager.get('auth').chanpinId
  109. this.danyuanId = cacheManager.get('auth').danyuanId
  110. this.banbenId = cacheManager.get('auth').banbenId
  111. //用于返回
  112. this.dengjiId = cacheManager.get('auth').dengjiId
  113. this.cacheManagerLocal = cacheManager.get('xuexi-' + this.chanpinId)
  114. // 使用缓存
  115. this.danyuanInfo = this.cacheManagerLocal
  116. this.fontDanyuanId = this.cacheManagerLocal.fontDanyuanId
  117. this.nextDanyuanId = this.cacheManagerLocal.nextDanyuanId
  118. this.dagangList = this.cacheManagerLocal.dagangList || []
  119. }
  120. },
  121. methods: {
  122. handleSelectDanyuan(item) {
  123. console.log('切换单元', item)
  124. this.danyuanId =item.danyuanId
  125. this.loadDataFromApi()
  126. },
  127. handleClickMulu() {
  128. this.$refs.dyMlRef.showPopup(this.banbenId)
  129. },
  130. handleBack() {
  131. uni.navigateTo({
  132. url: `/pages/chanpinXuanze/banben?dengjiId=` + this.dengjiId
  133. })
  134. },
  135. loadDataFromApi() {
  136. const req = {
  137. banbenId: this.banbenId,
  138. danyuanId: this.danyuanId
  139. }
  140. shuxueChanpinDanyuanInfo(req).then(res => {
  141. this.danyuanInfo = res.data
  142. this.fontDanyuanId = res.data.fontDanyuanId
  143. this.nextDanyuanId = res.data.nextDanyuanId
  144. this.dagangList = res.data.dagangList || []
  145. cacheManager.set('xuexi-' + this.chanpinId, res.data)
  146. cacheManager.updateObject('auth', {
  147. chanpinId: this.chanpinId,
  148. banbenId: this.banbenId,
  149. danyuanId: this.danyuanId,
  150. dengjiId: this.dengjiId
  151. })
  152. })
  153. },
  154. prev() {
  155. if (this.fontDanyuanId != 0) {
  156. this.danyuanId = this.fontDanyuanId
  157. this.loadDataFromApi()
  158. }
  159. },
  160. next() {
  161. if (this.nextDanyuanId != 0) {
  162. this.danyuanId = this.nextDanyuanId
  163. this.loadDataFromApi()
  164. }
  165. },
  166. handlePlay(da, code) {
  167. console.log('da', da)
  168. let jieId = null;
  169. if (code == 'jixu') {
  170. // 判断学习状态
  171. /* if (已学完) {
  172. return;
  173. } */
  174. jieId = da.curJieId;
  175. uni.navigateTo({
  176. url: `/pages/xinshuxue/lookShipin?jieId=${jieId}`
  177. })
  178. } else {
  179. jieId = da.jieId;
  180. if (da.type == 1) {
  181. uni.navigateTo({
  182. url: `/pages/xinshuxue/lookShipin?jieId=${jieId}`
  183. })
  184. } else {
  185. uni.navigateTo({
  186. url: `/pages/xinshuxue/unitTest?jieId=${jieId}`
  187. })
  188. }
  189. }
  190. },
  191. handleClickDanyuan() {
  192. this.isShow = true;
  193. setTimeout(() => {
  194. this.$refs.dyRef.handleShow(this.danyuanId)
  195. }, 100)
  196. },
  197. // 滚动事件处理
  198. onScroll(e) {
  199. const scrollTop = e.detail.scrollTop;
  200. // 更新滚动位置
  201. this.scrollTop = scrollTop;
  202. }
  203. }
  204. }
  205. </script>