index.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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"
  23. backgroundColor="#3c7dfd" 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="nextDanyuanId!=0" 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. import {
  69. toast
  70. } from '../../utils/common';
  71. export default {
  72. data() {
  73. return {
  74. dagangList: [],
  75. currentUnitName: "",
  76. isShow: true,
  77. currentIndex: 0,
  78. danyuanInfo: {},
  79. banbenId: '',
  80. danyuanId: '',
  81. chanpinId: '',
  82. fontDanyuanId: '',
  83. nextDanyuanId: '',
  84. dengjiId: '',
  85. customType: '',
  86. curProcess: '',
  87. cacheManagerLocal: null,
  88. curJieObject: null
  89. }
  90. },
  91. components: {
  92. CustomTabBar,
  93. danyuanInfoVue,
  94. danyuanMuluVue
  95. },
  96. onShow() {
  97. console.log('学习页面显示,尝试恢复滚动位置')
  98. },
  99. onHide() {
  100. console.log('学习页面隐藏,保存滚动位置')
  101. },
  102. onLoad(options) {
  103. console.log('options', options);
  104. if (!cacheManager.get('xuexi-shuxue')) {
  105. console.log('没有缓存');
  106. this.customType = options.customType
  107. this.chanpinId = options.chanpinId
  108. this.danyuanId = options.danyuanId
  109. this.banbenId = options.banbenId
  110. this.dengjiId = options.dengjiId
  111. this.loadDataFromApi()
  112. } else {
  113. console.log('使用缓存');
  114. this.chanpinId = cacheManager.get('auth').chanpinId
  115. this.danyuanId = cacheManager.get('auth').danyuanId
  116. this.banbenId = cacheManager.get('auth').banbenId
  117. //用于返回
  118. this.dengjiId = cacheManager.get('auth').dengjiId
  119. this.cacheManagerLocal = cacheManager.get('xuexi-shuxue') || {}
  120. // 使用缓存A@
  121. this.danyuanInfo = this.cacheManagerLocal
  122. this.curProcess = this.cacheManagerLocal.curProcess
  123. this.fontDanyuanId = this.cacheManagerLocal.fontDanyuanId
  124. this.nextDanyuanId = this.cacheManagerLocal.nextDanyuanId
  125. this.dagangList = this.cacheManagerLocal.dagangList || []
  126. const result = this.jisuanWanchengStatus(this.dagangList);
  127. if (result.allCompleted) {
  128. console.log('全部完成');
  129. } else {
  130. this.danyuanInfo.curJieId = result.firstUncompleted.jieId
  131. console.log('未完成项目:', result.firstUncompleted);
  132. console.log('未完成项目jieId:', result.firstUncompleted.jieId);
  133. }
  134. }
  135. },
  136. methods: {
  137. // 继续学习按钮是否可以点击
  138. jisuanWanchengStatus(dagangList) {
  139. // 查找第一个未完成的项目
  140. const firstUncompleted = dagangList.find(item => item.wanchengFlag == 0);
  141. if (firstUncompleted) {
  142. return {
  143. allCompleted: false,
  144. firstUncompleted: firstUncompleted
  145. };
  146. } else {
  147. return {
  148. allCompleted: true,
  149. firstUncompleted: null
  150. };
  151. }
  152. },
  153. handleSelectDanyuan(item) {
  154. console.log('切换单元', item)
  155. this.danyuanId = item.danyuanId
  156. this.loadDataFromApi()
  157. },
  158. handleClickMulu() {
  159. this.$refs.dyMlRef.showPopup(this.banbenId)
  160. },
  161. handleBack() {
  162. uni.navigateTo({
  163. url: `/pages/chanpinXuanze/banben?dengjiId=` + this.dengjiId
  164. })
  165. },
  166. loadDataFromApi() {
  167. const req = {
  168. banbenId: this.banbenId,
  169. danyuanId: this.danyuanId
  170. }
  171. shuxueChanpinDanyuanInfo(req).then(res => {
  172. this.danyuanInfo = res.data
  173. this.curProcess = res.data.curProcess
  174. this.fontDanyuanId = res.data.fontDanyuanId
  175. this.nextDanyuanId = res.data.nextDanyuanId
  176. this.dagangList = res.data.dagangList || []
  177. cacheManager.set('xuexi-shuxue', res.data)
  178. cacheManager.updateObject('auth', {
  179. chanpinId: this.chanpinId,
  180. banbenId: this.banbenId,
  181. danyuanId: this.danyuanId,
  182. dengjiId: this.dengjiId
  183. })
  184. })
  185. },
  186. prev() {
  187. if (this.fontDanyuanId != 0) {
  188. this.danyuanId = this.fontDanyuanId
  189. this.loadDataFromApi()
  190. }
  191. },
  192. next() {
  193. if (this.nextDanyuanId != 0) {
  194. this.danyuanId = this.nextDanyuanId
  195. this.loadDataFromApi()
  196. }
  197. },
  198. handlePlay(da, code) {
  199. let jieId = null;
  200. if (code == 'jixu') {
  201. if (da.curProcess >= 100) {
  202. toast("当前单元节内容全部学习完毕,请切换下一单元!")
  203. return
  204. }
  205. if (!da.jieId) {
  206. toast("无jieId");
  207. return;
  208. }
  209. jieId = da.jieId;
  210. if (da.type == 1) {
  211. uni.navigateTo({
  212. url: `/pages/xinshuxue/lookShipin?jieId=${jieId}`
  213. })
  214. } else {
  215. uni.navigateTo({
  216. url: `/pages/xinshuxue/unitTest?jieId=${jieId}`
  217. })
  218. }
  219. } else {
  220. jieId = da.jieId;
  221. if (da.type == 1) {
  222. uni.navigateTo({
  223. url: `/pages/xinshuxue/lookShipin?jieId=${jieId}`
  224. })
  225. } else {
  226. uni.navigateTo({
  227. url: `/pages/xinshuxue/unitTest?jieId=${jieId}`
  228. })
  229. }
  230. }
  231. },
  232. handleClickDanyuan() {
  233. this.isShow = true;
  234. setTimeout(() => {
  235. this.$refs.dyRef.handleShow(this.danyuanId)
  236. }, 100)
  237. },
  238. // 滚动事件处理
  239. onScroll(e) {
  240. const scrollTop = e.detail.scrollTop;
  241. // 更新滚动位置
  242. this.scrollTop = scrollTop;
  243. }
  244. }
  245. }
  246. </script>