index.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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. shuxueSave
  71. } from "@/api/chanpinneirong.js"
  72. import danyuanInfoVue from '@/pages/xinshuxue/components/danyuanInfo.vue';
  73. import {
  74. toast
  75. } from '../../utils/common';
  76. export default {
  77. data() {
  78. return {
  79. danyuanList: [],
  80. currentUnitName: "",
  81. isShow: true,
  82. banbenInfo: {},
  83. banbenId: '',
  84. danyuanId: '',
  85. chanpinId: '',
  86. dengjiId: '',
  87. curProcess: '',
  88. cacheManagerLocal: null,
  89. isFirstFlag: false
  90. }
  91. },
  92. components: {
  93. CustomTabBar,
  94. danyuanInfoVue
  95. },
  96. onShow() {
  97. console.log('学习页面显示,尝试恢复滚动位置')
  98. console.log('this.isFirstFlag', this.isFirstFlag);
  99. if (!this.isFirstFlag) {
  100. return false
  101. }
  102. this.chanpinId = cacheManager.get('auth').chanpinId
  103. this.danyuanId = cacheManager.get('auth').danyuanId
  104. this.banbenId = cacheManager.get('auth').banbenId
  105. //用于返回
  106. this.dengjiId = cacheManager.get('auth').dengjiId
  107. this.cacheManagerLocal = cacheManager.get('xuexi-shuxue') || {}
  108. // 使用缓存
  109. this.banbenInfo = this.cacheManagerLocal
  110. this.curProcess = this.cacheManagerLocal.curProcess
  111. this.danyuanList = this.cacheManagerLocal.danyuanList || []
  112. },
  113. onHide() {
  114. console.log('学习页面隐藏,保存滚动位置')
  115. this.isFirstFlag = true
  116. },
  117. onLoad(options) {
  118. if (this.isFirstFlag) {
  119. return false
  120. }
  121. console.log('options', options);
  122. if (!cacheManager.get('xuexi-shuxue')) {
  123. console.log('没有缓存');
  124. this.chanpinId = options.chanpinId
  125. this.danyuanId = options.danyuanId
  126. this.banbenId = options.banbenId
  127. this.dengjiId = options.dengjiId
  128. this.loadDataFromApi()
  129. } else {
  130. toast("使用xuexi-shuxue缓存,并且this.isFirstFlag 为false")
  131. return false
  132. }
  133. },
  134. methods: {
  135. // 继续学习按钮是否可以点击
  136. jisuanWanchengStatus(dagangList) {
  137. // 查找第一个未完成的项目
  138. const firstUncompleted = danyuanList.find(item => item.wanchengFlag == 0);
  139. if (firstUncompleted) {
  140. return {
  141. allCompleted: false,
  142. firstUncompleted: firstUncompleted
  143. };
  144. } else {
  145. return {
  146. allCompleted: true,
  147. firstUncompleted: null
  148. };
  149. }
  150. },
  151. handleBack() {
  152. uni.navigateTo({
  153. url: `/pages/chanpinXuanze/banben?dengjiId=` + this.dengjiId
  154. })
  155. },
  156. loadDataFromApi() {
  157. const req = {
  158. banbenId: this.banbenId
  159. }
  160. shuxueChanpinBanbenInfo(req).then(res => {
  161. this.banbenInfo = res.data
  162. this.curProcess = res.data.curProcess
  163. this.danyuanList = res.data.danyuanList || []
  164. cacheManager.set('xuexi-shuxue', res.data)
  165. cacheManager.updateObject('auth', {
  166. chanpinId: this.chanpinId,
  167. banbenId: this.banbenId,
  168. danyuanId: this.danyuanId,
  169. dengjiId: this.dengjiId
  170. })
  171. this.isFirstFlag = true
  172. }).catch(res => {
  173. this.isFirstFlag = false
  174. cacheManager.remove("xuexi-shuxue")
  175. toast("shuxueChanpinBanbenInfo接口错误重置isFirstFlag,清除xuexi-shuxue缓存")
  176. return false
  177. })
  178. },
  179. getJieAndDanyuan(data, jieId) {
  180. // 循环单元
  181. for (let danyuan of data.danyuanList) {
  182. // 循环节
  183. for (let jie of danyuan.jieList) {
  184. if (jie.jieId == jieId) {
  185. return {
  186. danyuan: danyuan,
  187. jie: jie
  188. }
  189. }
  190. }
  191. }
  192. return null;
  193. },
  194. handlePlay(da, code) {
  195. console.log('da', da);
  196. let jieId = null;
  197. if (code == 'jixu') {
  198. if (!da.curJieId) {
  199. toast("无jieId");
  200. return;
  201. }
  202. jieId = da.curJieId;
  203. let req = {
  204. "banbenId": this.banbenId,
  205. "danyuanId": this.danyuanId,
  206. "jieId": jieId
  207. }
  208. shuxueSave(req).then(res => {
  209. console.log('res', res);
  210. if (res.code == 0 && res.data) {
  211. let curJieAndDanyuan = this.getJieAndDanyuan(da, jieId)
  212. console.log('curJieAndDanyuan', curJieAndDanyuan);
  213. if (!curJieAndDanyuan) {
  214. toast("curJieAndDanyuan没找到")
  215. return false
  216. }
  217. cacheManager.updateObject('xuexi-shuxue', {
  218. curDanyuanName: curJieAndDanyuan.danyuan.danyuanName,
  219. curKechengName: curJieAndDanyuan.danyuan.danyuanIntro,
  220. curJieId: jieId,
  221. type: curJieAndDanyuan.jie.type
  222. })
  223. if (da.type == 1) {
  224. uni.navigateTo({
  225. url: `/pages/xinshuxue/lookShipin?jieId=${jieId}`
  226. })
  227. } else {
  228. uni.navigateTo({
  229. url: `/pages/xinshuxue/unitTest?jieId=${jieId}`
  230. })
  231. }
  232. } else {
  233. toast("save位置出错")
  234. return false
  235. }
  236. })
  237. } else {
  238. jieId = da.jieId;
  239. let req = {
  240. "banbenId": this.banbenId,
  241. "danyuanId": this.danyuanId,
  242. "jieId": jieId
  243. }
  244. shuxueSave(req).then(res => {
  245. console.log('res', res);
  246. if (res.code == 0 && res.data) {
  247. let curJieAndDanyuan = this.getJieAndDanyuan(this.banbenInfo, jieId)
  248. console.log('curJieAndDanyuan', curJieAndDanyuan);
  249. if (!curJieAndDanyuan) {
  250. toast("curJieAndDanyuan没找到")
  251. return false
  252. }
  253. cacheManager.updateObject('xuexi-shuxue', {
  254. curDanyuanName: curJieAndDanyuan.danyuan.danyuanName,
  255. curKechengName: curJieAndDanyuan.danyuan.danyuanIntro,
  256. curJieId: jieId,
  257. type: curJieAndDanyuan.jie.type
  258. })
  259. if (da.type == 1) {
  260. uni.navigateTo({
  261. url: `/pages/xinshuxue/lookShipin?jieId=${jieId}`
  262. })
  263. } else {
  264. uni.navigateTo({
  265. url: `/pages/xinshuxue/unitTest?jieId=${jieId}`
  266. })
  267. }
  268. } else {
  269. toast("save位置出错")
  270. return false
  271. }
  272. })
  273. }
  274. },
  275. handleClickDanyuan() {
  276. this.isShow = true;
  277. setTimeout(() => {
  278. this.$refs.dyRef.handleShow(this.danyuanId)
  279. }, 100)
  280. },
  281. }
  282. }
  283. </script>