index.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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"
  47. @click="handlePlay(jieItem,'play')">
  48. <view class="xx-item-status"
  49. :class="jieItem.wanchengFlag == 1 ? 'completed-status' : 'uncompleted-status'"> </view>
  50. <img :src="jieItem.cover" />
  51. <view class="xx-text-box">
  52. <view>{{ jieItem.jieName }}</view>
  53. <view>{{ jieItem.jieIntro }}</view>
  54. </view>
  55. <view class="xx-item-btn"></view>
  56. </view>
  57. </view>
  58. </view>
  59. </view>
  60. </view>
  61. <danyuanInfoVue ref="dyRef" v-if="isShow" @close="isShow= false"></danyuanInfoVue>
  62. <CustomTabBar :currentTabNumber="1"></CustomTabBar>
  63. </view>
  64. </template>
  65. <script>
  66. import CustomTabBar from '@/components/custom-tabbar/custom-tabbar.vue';
  67. import cacheManager from "@/utils/cacheManager.js";
  68. import {
  69. shuxueChanpinBanbenInfo
  70. } from "@/api/chanpinneirong.js"
  71. import danyuanInfoVue from '@/pages/xinshuxue/components/danyuanInfo.vue';
  72. import {
  73. toast
  74. } from '../../utils/common';
  75. export default {
  76. data() {
  77. return {
  78. danyuanList: [],
  79. currentUnitName: "",
  80. isShow: true,
  81. banbenInfo: {},
  82. banbenId: '',
  83. danyuanId: '',
  84. chanpinId: '',
  85. dengjiId: '',
  86. curProcess: '',
  87. cacheManagerLocal: null,
  88. isFirstFlag: false
  89. }
  90. },
  91. components: {
  92. CustomTabBar,
  93. danyuanInfoVue
  94. },
  95. onShow() {
  96. console.log('学习页面显示,尝试恢复滚动位置')
  97. console.log('this.isFirstFlag', this.isFirstFlag);
  98. if (!this.isFirstFlag) {
  99. return false
  100. }
  101. this.chanpinId = cacheManager.get('auth').chanpinId
  102. this.danyuanId = cacheManager.get('auth').danyuanId
  103. this.banbenId = cacheManager.get('auth').banbenId
  104. //用于返回
  105. this.dengjiId = cacheManager.get('auth').dengjiId
  106. this.cacheManagerLocal = cacheManager.get('xuexi-shuxue') || {}
  107. // 使用缓存
  108. this.banbenInfo = this.cacheManagerLocal
  109. this.curProcess = this.cacheManagerLocal.curProcess
  110. this.danyuanList = this.cacheManagerLocal.danyuanList || []
  111. },
  112. onHide() {
  113. console.log('学习页面隐藏,保存滚动位置')
  114. this.isFirstFlag = true
  115. },
  116. onLoad(options) {
  117. if (this.isFirstFlag) {
  118. return false
  119. }
  120. console.log('options', options);
  121. if (!cacheManager.get('xuexi-shuxue')) {
  122. console.log('没有缓存');
  123. this.chanpinId = options.chanpinId
  124. this.danyuanId = options.danyuanId
  125. this.banbenId = options.banbenId
  126. this.dengjiId = options.dengjiId
  127. this.loadDataFromApi()
  128. } else {
  129. toast("使用xuexi-shuxue缓存,并且this.isFirstFlag 为false")
  130. return false
  131. }
  132. },
  133. methods: {
  134. // 继续学习按钮是否可以点击
  135. jisuanWanchengStatus(dagangList) {
  136. // 查找第一个未完成的项目
  137. const firstUncompleted = danyuanList.find(item => item.wanchengFlag == 0);
  138. if (firstUncompleted) {
  139. return {
  140. allCompleted: false,
  141. firstUncompleted: firstUncompleted
  142. };
  143. } else {
  144. return {
  145. allCompleted: true,
  146. firstUncompleted: null
  147. };
  148. }
  149. },
  150. handleBack() {
  151. uni.navigateTo({
  152. url: `/pages/chanpinXuanze/banben?dengjiId=` + this.dengjiId
  153. })
  154. },
  155. loadDataFromApi() {
  156. const req = {
  157. banbenId: this.banbenId
  158. }
  159. shuxueChanpinBanbenInfo(req).then(res => {
  160. this.banbenInfo = res.data
  161. this.curProcess = res.data.curProcess
  162. this.danyuanList = res.data.danyuanList || []
  163. cacheManager.set('xuexi-shuxue', res.data)
  164. cacheManager.updateObject('auth', {
  165. chanpinId: this.chanpinId,
  166. banbenId: this.banbenId,
  167. danyuanId: this.danyuanId,
  168. dengjiId: this.dengjiId
  169. })
  170. this.isFirstFlag = true
  171. }).catch(res => {
  172. this.isFirstFlag = false
  173. cacheManager.remove("xuexi-shuxue")
  174. toast("shuxueChanpinBanbenInfo接口错误重置isFirstFlag,清除xuexi-shuxue缓存")
  175. return false
  176. })
  177. },
  178. handlePlay(da, code) {
  179. let jieId = null;
  180. if (code == 'jixu') {
  181. if (!da.curJieId) {
  182. toast("无jieId");
  183. return;
  184. }
  185. jieId = da.curJieId;
  186. if (da.type == 1) {
  187. uni.navigateTo({
  188. url: `/pages/xinshuxue/lookShipin?jieId=${jieId}`
  189. })
  190. } else {
  191. uni.navigateTo({
  192. url: `/pages/xinshuxue/unitTest?jieId=${jieId}`
  193. })
  194. }
  195. } else {
  196. jieId = da.jieId;
  197. if (da.type == 1) {
  198. uni.navigateTo({
  199. url: `/pages/xinshuxue/lookShipin?jieId=${jieId}`
  200. })
  201. } else {
  202. uni.navigateTo({
  203. url: `/pages/xinshuxue/unitTest?jieId=${jieId}`
  204. })
  205. }
  206. }
  207. },
  208. handleClickDanyuan() {
  209. this.isShow = true;
  210. setTimeout(() => {
  211. this.$refs.dyRef.handleShow(this.danyuanId)
  212. }, 100)
  213. },
  214. }
  215. }
  216. </script>