index.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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="curProcess" 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. curProcess: '',
  84. cacheManagerLocal: null
  85. }
  86. },
  87. components: {
  88. CustomTabBar,
  89. danyuanInfoVue,
  90. danyuanMuluVue
  91. },
  92. onShow() {
  93. console.log('学习页面显示,尝试恢复滚动位置')
  94. },
  95. onHide() {
  96. console.log('学习页面隐藏,保存滚动位置')
  97. },
  98. onLoad(options) {
  99. console.log('options', options);
  100. this.customType = options.customType
  101. if (this.customType) {
  102. this.chanpinId = options.chanpinId
  103. this.danyuanId = options.danyuanId
  104. this.banbenId = options.banbenId
  105. this.dengjiId = options.dengjiId
  106. this.loadDataFromApi()
  107. } else {
  108. console.log('使用缓存');
  109. this.chanpinId = cacheManager.get('auth').chanpinId
  110. this.danyuanId = cacheManager.get('auth').danyuanId
  111. this.banbenId = cacheManager.get('auth').banbenId
  112. //用于返回
  113. this.dengjiId = cacheManager.get('auth').dengjiId
  114. this.cacheManagerLocal = cacheManager.get('xuexi-' + this.chanpinId)
  115. // 使用缓存
  116. this.danyuanInfo = this.cacheManagerLocal
  117. this.curProcess = this.cacheManagerLocal.curProcess
  118. this.fontDanyuanId = this.cacheManagerLocal.fontDanyuanId
  119. this.nextDanyuanId = this.cacheManagerLocal.nextDanyuanId
  120. this.dagangList = this.cacheManagerLocal.dagangList || []
  121. }
  122. },
  123. methods: {
  124. handleSelectDanyuan(item) {
  125. console.log('切换单元', item)
  126. this.danyuanId =item.danyuanId
  127. this.loadDataFromApi()
  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.curProcess = res.data.curProcess
  145. this.fontDanyuanId = res.data.fontDanyuanId
  146. this.nextDanyuanId = res.data.nextDanyuanId
  147. this.dagangList = res.data.dagangList || []
  148. cacheManager.set('xuexi-' + this.chanpinId, res.data)
  149. cacheManager.updateObject('auth', {
  150. chanpinId: this.chanpinId,
  151. banbenId: this.banbenId,
  152. danyuanId: this.danyuanId,
  153. dengjiId: this.dengjiId
  154. })
  155. })
  156. },
  157. prev() {
  158. if (this.fontDanyuanId != 0) {
  159. this.danyuanId = this.fontDanyuanId
  160. this.loadDataFromApi()
  161. }
  162. },
  163. next() {
  164. if (this.nextDanyuanId != 0) {
  165. this.danyuanId = this.nextDanyuanId
  166. this.loadDataFromApi()
  167. }
  168. },
  169. handlePlay(da, code) {
  170. console.log('da', da)
  171. let jieId = null;
  172. if (code == 'jixu') {
  173. // 判断学习状态
  174. /* if (已学完) {
  175. return;
  176. } */
  177. jieId = da.curJieId;
  178. uni.navigateTo({
  179. url: `/pages/xinshuxue/lookShipin?jieId=${jieId}`
  180. })
  181. } else {
  182. jieId = da.jieId;
  183. if (da.type == 1) {
  184. uni.navigateTo({
  185. url: `/pages/xinshuxue/lookShipin?jieId=${jieId}`
  186. })
  187. } else {
  188. uni.navigateTo({
  189. url: `/pages/xinshuxue/unitTest?jieId=${jieId}`
  190. })
  191. }
  192. }
  193. },
  194. handleClickDanyuan() {
  195. this.isShow = true;
  196. setTimeout(() => {
  197. this.$refs.dyRef.handleShow(this.danyuanId)
  198. }, 100)
  199. },
  200. // 滚动事件处理
  201. onScroll(e) {
  202. const scrollTop = e.detail.scrollTop;
  203. // 更新滚动位置
  204. this.scrollTop = scrollTop;
  205. }
  206. }
  207. }
  208. </script>