index.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. <!-- 显示内容 -->
  10. <view class="change-dy-content">
  11. <view>{{ banbenInfo.chanpinName }}</view>
  12. <view>
  13. <text>等级</text>
  14. <text>{{banbenInfo.dengjiName}}</text>
  15. </view>
  16. <view>
  17. <text>版本</text>
  18. <text>{{banbenInfo.name}}</text>
  19. </view>
  20. <view>
  21. <text>单元</text>
  22. <text>{{banbenInfo.curDanyuanName}}</text>
  23. </view>
  24. <view>
  25. <text>课程</text>
  26. <text>{{banbenInfo.curKechengName}}</text>
  27. </view>
  28. <view>
  29. <view class="xx-progress-box">
  30. <view>当前学习进度</view>
  31. <progress :percent="curProcess" class="xx-progress" stroke-width="10"
  32. backgroundColor="#3c7dfd" activeColor="#ffd11c" />
  33. </view>
  34. <view class="jxxx-btn" @click="handlePlay(banbenInfo,'jixu')"></view>
  35. </view>
  36. </view>
  37. </view>
  38. <view class="xx-scroll-body">
  39. <view class="xx-item-list">
  40. <view v-for="danyuanItem in danyuanList" :key="danyuanItem.danyuanId">
  41. <view @click="handleClickDanyuan">
  42. <view>L{{danyuanItem.danyuanId}}</view>
  43. <view>{{danyuanItem.danyuanName}}</view>
  44. <view>{{danyuanItem.danyuanIntro}}</view>
  45. </view>
  46. <view class="xx-item-box" v-for="jieItem in danyuanItem.jieList" :key="jieItem.jieId" @click="handlePlay(jieItem,'play')" >
  47. <view class="xx-item-status"
  48. :class="jieItem.wanchengFlag == 1 ? 'completed-status' : 'uncompleted-status'"> </view>
  49. <img :src="jieItem.cover" />
  50. <view class="xx-text-box">
  51. <view>{{ jieItem.jieName }}</view>
  52. <view>{{ jieItem.jieIntro }}</view>
  53. </view>
  54. <view class="xx-item-btn"></view>
  55. </view>
  56. </view>
  57. </view>
  58. </view>
  59. </view>
  60. <danyuanInfoVue ref="dyRef" v-if="isShow" @close="isShow= false"></danyuanInfoVue>
  61. <CustomTabBar :currentTabNumber="1"></CustomTabBar>
  62. </view>
  63. </template>
  64. <script>
  65. import CustomTabBar from '@/components/custom-tabbar/custom-tabbar.vue';
  66. import cacheManager from "@/utils/cacheManager.js";
  67. import {
  68. shuxueChanpinBanbenInfo
  69. } from "@/api/chanpinneirong.js"
  70. import danyuanInfoVue from '@/pages/xinshuxue/components/danyuanInfo.vue';
  71. import {
  72. toast
  73. } from '../../utils/common';
  74. export default {
  75. data() {
  76. return {
  77. danyuanList: [],
  78. currentUnitName: "",
  79. isShow: true,
  80. currentIndex: 0,
  81. banbenInfo: {},
  82. banbenId: '',
  83. danyuanId: '',
  84. chanpinId: '',
  85. fontDanyuanId: '',
  86. nextDanyuanId: '',
  87. dengjiId: '',
  88. customType: '',
  89. curProcess: '',
  90. cacheManagerLocal: null,
  91. curJieObject: null
  92. }
  93. },
  94. components: {
  95. CustomTabBar,
  96. danyuanInfoVue
  97. },
  98. onShow() {
  99. console.log('学习页面显示,尝试恢复滚动位置')
  100. },
  101. onHide() {
  102. console.log('学习页面隐藏,保存滚动位置')
  103. },
  104. onLoad(options) {
  105. console.log('options', options);
  106. if (!cacheManager.get('xuexi-shuxue')) {
  107. console.log('没有缓存');
  108. this.customType = options.customType
  109. this.chanpinId = options.chanpinId
  110. this.danyuanId = options.danyuanId
  111. this.banbenId = options.banbenId
  112. this.dengjiId = options.dengjiId
  113. this.loadDataFromApi()
  114. } else {
  115. console.log('使用缓存');
  116. this.chanpinId = cacheManager.get('auth').chanpinId
  117. this.danyuanId = cacheManager.get('auth').danyuanId
  118. this.banbenId = cacheManager.get('auth').banbenId
  119. //用于返回
  120. this.dengjiId = cacheManager.get('auth').dengjiId
  121. this.cacheManagerLocal = cacheManager.get('xuexi-shuxue') || {}
  122. // 使用缓存
  123. this.banbenInfo = this.cacheManagerLocal
  124. this.curProcess = this.cacheManagerLocal.curProcess
  125. this.fontDanyuanId = this.cacheManagerLocal.fontDanyuanId
  126. this.nextDanyuanId = this.cacheManagerLocal.nextDanyuanId
  127. this.danyuanList = this.cacheManagerLocal.danyuanList || []
  128. const result = this.jisuanWanchengStatus(this.danyuanList);
  129. if (result.allCompleted) {
  130. console.log('全部完成');
  131. } else {
  132. this.banbenInfo.curJieId = result.firstUncompleted.jieId
  133. console.log('未完成项目:', result.firstUncompleted);
  134. console.log('未完成项目jieId:', result.firstUncompleted.jieId);
  135. }
  136. }
  137. },
  138. methods: {
  139. // 继续学习按钮是否可以点击
  140. jisuanWanchengStatus(dagangList) {
  141. // 查找第一个未完成的项目
  142. const firstUncompleted = danyuanList.find(item => item.wanchengFlag == 0);
  143. if (firstUncompleted) {
  144. return {
  145. allCompleted: false,
  146. firstUncompleted: firstUncompleted
  147. };
  148. } else {
  149. return {
  150. allCompleted: true,
  151. firstUncompleted: null
  152. };
  153. }
  154. },
  155. handleSelectDanyuan(item) {
  156. console.log('切换单元', item)
  157. this.danyuanId = item.danyuanId
  158. this.loadDataFromApi()
  159. },
  160. handleBack() {
  161. uni.navigateTo({
  162. url: `/pages/chanpinXuanze/banben?dengjiId=` + this.dengjiId
  163. })
  164. },
  165. loadDataFromApi() {
  166. const req = {
  167. banbenId: this.banbenId
  168. }
  169. shuxueChanpinBanbenInfo(req).then(res => {
  170. this.banbenInfo = res.data
  171. this.curProcess = res.data.curProcess
  172. this.fontDanyuanId = res.data.fontDanyuanId
  173. this.nextDanyuanId = res.data.nextDanyuanId
  174. this.danyuanList = res.data.danyuanList || []
  175. cacheManager.set('xuexi-shuxue', res.data)
  176. cacheManager.updateObject('auth', {
  177. chanpinId: this.chanpinId,
  178. banbenId: this.banbenId,
  179. danyuanId: this.danyuanId,
  180. dengjiId: this.dengjiId
  181. })
  182. })
  183. },
  184. handlePlay(da, code) {
  185. let jieId = null;
  186. if (code == 'jixu') {
  187. if (!da.curJieId) {
  188. toast("无jieId");
  189. return;
  190. }
  191. jieId = da.curJieId;
  192. if (da.type == 1) {
  193. uni.navigateTo({
  194. url: `/pages/xinshuxue/lookShipin?jieId=${jieId}`
  195. })
  196. } else {
  197. uni.navigateTo({
  198. url: `/pages/xinshuxue/unitTest?jieId=${jieId}`
  199. })
  200. }
  201. } else {
  202. jieId = da.jieId;
  203. if (da.type == 1) {
  204. uni.navigateTo({
  205. url: `/pages/xinshuxue/lookShipin?jieId=${jieId}`
  206. })
  207. } else {
  208. uni.navigateTo({
  209. url: `/pages/xinshuxue/unitTest?jieId=${jieId}`
  210. })
  211. }
  212. }
  213. },
  214. handleClickDanyuan() {
  215. this.isShow = true;
  216. setTimeout(() => {
  217. this.$refs.dyRef.handleShow(this.danyuanId)
  218. }, 100)
  219. },
  220. // 滚动事件处理
  221. onScroll(e) {
  222. const scrollTop = e.detail.scrollTop;
  223. // 更新滚动位置
  224. this.scrollTop = scrollTop;
  225. }
  226. }
  227. }
  228. </script>