index.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. <template>
  2. <view class="ezy-xuexi-page3">
  3. <view class="icon-title-navBar-box">
  4. <text class="nav-bar-title">学习</text>
  5. </view>
  6. <!-- 滚动区域 -->
  7. <scroll-view
  8. v-if="existData"
  9. class="ezy-page-body xuexi-page-body"
  10. scroll-y
  11. :scroll-top="scrollTop"
  12. @scroll="handleScroll"
  13. >
  14. <view class="xxjl-card-box-padding">
  15. <view class="xxjl-card-box">
  16. <!-- 显示内容 -->
  17. <view class="card-body-box">
  18. <img :src="banbenInfo.cover" />
  19. <view class="body-right">
  20. <view class="right-name">{{ banbenInfo.chanpinName }}</view>
  21. <view>等级:{{banbenInfo.dengjiName}}</view>
  22. <view>版本:{{banbenInfo.name}}</view>
  23. <view>单元:{{banbenInfo.curDanyuanName}}</view>
  24. <view>课程:{{banbenInfo.curKechengName}}</view>
  25. </view>
  26. </view>
  27. <view class="card-progress-box">
  28. <view class="xx-progress-box">
  29. <view>学习进度</view>
  30. <progress :percent="curProcess" class="xx-progress" stroke-width="20"
  31. backgroundColor="#3c7dfd" activeColor="#ffd11c" />
  32. </view>
  33. <ezyActiveVue class="ezy-btn-active jxxx-btn" @aclick="handlePlay(banbenInfo,'jixu')"></ezyActiveVue>
  34. </view>
  35. </view>
  36. </view>
  37. <view class="xx-item-list">
  38. <!-- <view class="xx-item-title">— 以下为当前等级课程目录 —</view> -->
  39. <view v-for="(danyuanItem, index) in danyuanList" :key="danyuanItem.danyuanId">
  40. <!-- 单元标题(带唯一ID,用于位置查询) -->
  41. <view class="xx-item-title" @click="handleClickDanyuan(danyuanItem.danyuanId)" :id="`title-${danyuanItem.danyuanId}`">
  42. — {{ danyuanItem.danyuanName }} {{ danyuanItem.danyuanIntro }} —
  43. </view>
  44. <!-- 节列表 -->
  45. <ezyActiveVue
  46. class="ezy-list-item-active xx-item-box"
  47. v-for="jieItem in danyuanItem.jieList"
  48. :key="jieItem.jieId"
  49. @aclick="handlePlay(jieItem,'play')"
  50. >
  51. <view
  52. class="xx-item-status"
  53. :class="jieItem.wanchengFlag == 1 ? 'completed-status' : 'uncompleted-status'"
  54. ></view>
  55. <img :src="jieItem.cover" />
  56. <view class="xx-text-box">
  57. <view>{{ jieItem.jieName }}</view>
  58. <view>{{ jieItem.jieIntro }}</view>
  59. </view>
  60. <view class="xx-item-btn"></view>
  61. </ezyActiveVue>
  62. </view>
  63. <view class="xx-item-title">本级别最后一单元啦~</view>
  64. <view class="xx-more-btn" @click="moreBtn"></view>
  65. </view>
  66. </scroll-view>
  67. <!-- 回到顶部 -->
  68. <view class="go-top-btn" @click="goTopBtn"></view>
  69. <!-- 无数据占位 -->
  70. <view v-if="!existData" class="ezy-page-body">
  71. <view class="ezy-no-sj">
  72. <icon></icon>
  73. <text>暂无数据</text>
  74. </view>
  75. </view>
  76. <!-- 弹窗组件 -->
  77. <danyuanInfoVue ref="dyRef" v-if="isShow" @close="isShow = false"></danyuanInfoVue>
  78. <!-- 底部 tabBar -->
  79. <custom-tab-bar :show="true" :current-index="currentTabIndex" />
  80. </view>
  81. </template>
  82. <script>
  83. import ezyActiveVue from "@/components/ezyActive/ezyActive.vue";
  84. import CustomTabBar from '@/components/custom-tabbar/index.vue';
  85. import cacheManager from "@/utils/cacheManager.js";
  86. import {
  87. shuxueChanpinBanbenInfo,
  88. shuxueSave
  89. } from "@/api/chanpinneirong.js"
  90. import {
  91. onLoad,
  92. onShow,
  93. onHide,
  94. onUnload
  95. } from "@dcloudio/uni-app"
  96. import danyuanInfoVue from '@/pages/xinshuxue/components/danyuanInfo.vue';
  97. import {
  98. toast
  99. } from '../../utils/common';
  100. import {updateXuexiProcess} from "./useNeirongShuxue"
  101. export default {
  102. data() {
  103. return {
  104. canExitApp: false,
  105. danyuanList: [],
  106. banbenInfo: {},
  107. banbenId: '',
  108. danyuanId: '',
  109. chanpinId: '',
  110. dengjiId: '',
  111. curProcess: '',
  112. currentTabIndex: 1,
  113. existData: true,
  114. isShow: false,
  115. stickyHeight: 0, // 吸顶栏高度(px)
  116. currentStickyTitle: '', // 初始为空,不显示吸顶
  117. currentStickyIntro: '',
  118. currentDanyuanId:'',
  119. currentStickyDengjiId: '',
  120. titlePositions: [],
  121. scrollTop: 0,
  122. }
  123. },
  124. components: {
  125. CustomTabBar,
  126. danyuanInfoVue,
  127. ezyActiveVue
  128. },
  129. onLoad(options) {
  130. uni.hideTabBar()
  131. },
  132. onShow() {
  133. this.currentTabIndex = 1
  134. const cacheData = cacheManager.get('xuexi-shuxue');
  135. if (cacheData) {
  136. console.log('使用缓存数据');
  137. this.updateFromCache();
  138. } else {
  139. console.log('重新请求数据');
  140. const cacheDataAuth = cacheManager.get('auth');
  141. this.initFromOptions(cacheDataAuth);
  142. }
  143. },
  144. onHide() {
  145. console.log('学习页面隐藏')
  146. },
  147. onUnload() {
  148. // 页面卸载无需特殊处理
  149. },
  150. methods: {
  151. goTopBtn() {
  152. this.scrollTop = -1; // 先设一个无效值(确保变化)
  153. this.$nextTick(() => {
  154. this.scrollTop = 0; // 再滚到顶部
  155. });
  156. },
  157. moreBtn() {
  158. uni.switchTab({
  159. url: '/pages/chanpinXuanze/index'
  160. })
  161. },
  162. initFromOptions(options) {
  163. //console.log('options', options);
  164. this.chanpinId = options.chanpinId;
  165. this.danyuanId = options.danyuanId;
  166. this.banbenId = options.banbenId;
  167. this.dengjiId = options.dengjiId;
  168. this.loadDataFromApi();
  169. },
  170. // 从缓存更新数据方法
  171. updateFromCache() {
  172. updateXuexiProcess()
  173. const cacheData = cacheManager.get('xuexi-shuxue');
  174. console.log('cacheData 从缓存更新数据方法', cacheData);
  175. if (cacheData) {
  176. this.banbenInfo = { ...cacheData };
  177. this.curProcess = cacheData.curProcess;
  178. this.danyuanList = [...(cacheData.danyuanList || [])];
  179. this.banbenId = cacheData.banbenId
  180. // this.$nextTick(() => {
  181. // this.updateTitlePositions();
  182. // });
  183. }
  184. },
  185. loadDataFromApi() {
  186. this.banbenInfo = {}
  187. this.curProcess = ''
  188. this.danyuanList = []
  189. const req = {
  190. banbenId: this.banbenId
  191. }
  192. shuxueChanpinBanbenInfo(req).then(res => {
  193. if (res.code === 0) {
  194. this.banbenInfo = res.data;
  195. this.banbenInfo.danyuanId = res.data.curDanyuanId;
  196. this.curProcess =res.data.curProcess * 100;
  197. this.danyuanList = res.data.danyuanList || [];
  198. if (this.danyuanList.length ==0) {
  199. this.existData = false
  200. }else{
  201. this.existData = true
  202. }
  203. // 保存到缓存(新增了参数保存)
  204. const cacheData = {
  205. ...res.data,
  206. banbenId: this.banbenId,
  207. chanpinId: this.chanpinId,
  208. danyuanId: this.danyuanId,
  209. dengjiId: this.dengjiId
  210. };
  211. cacheManager.set('xuexi-shuxue', cacheData);
  212. // 更新全局auth信息
  213. cacheManager.updateObject('auth', {
  214. chanpinId: res.data.chanpinId,
  215. banbenId: this.banbenId,
  216. danyuanId: res.data.curDanyuanId,
  217. dengjiId: res.data.dengjiId
  218. });
  219. this.danyuanId = res.data.curDanyuanId
  220. this.dengjiId = res.data.dengjiId
  221. this.chanpinId = res.data.chanpinId
  222. // 数据加载完成后初始化观察器
  223. // this.$nextTick(() => {
  224. // this.updateTitlePositions();
  225. // });
  226. }
  227. }).catch(res => {
  228. cacheManager.remove("xuexi-shuxue");
  229. toast("加载失败,请重试");
  230. });
  231. },
  232. handleScroll(e) {
  233. const scrollTop = e.detail.scrollTop;
  234. console.log('scrollTop',scrollTop);
  235. },
  236. getJieAndDanyuan(data, jieId) {
  237. for (let danyuan of data.danyuanList) {
  238. for (let jie of danyuan.jieList) {
  239. if (jie.jieId == jieId) {
  240. return { danyuan, jie }
  241. }
  242. }
  243. }
  244. return null;
  245. },
  246. async saveAndNavigate(jieId, type, da, code) {
  247. console.log('this.banbenId',this.banbenId);
  248. console.log('this.danyuanIddanyuanId',da.danyuanId);
  249. if (code == 'jixu') {
  250. if (!this.banbenId || !da.danyuanId) {
  251. toast("banbenId或者danyuanId 丢失")
  252. return false
  253. }
  254. }
  255. let req = {
  256. "banbenId": this.banbenId,
  257. "danyuanId": da.danyuanId,
  258. "jieId": jieId
  259. }
  260. console.log('req',req);
  261. try {
  262. const res = await shuxueSave(req);
  263. if (res.code == 0 && res.data) {
  264. let curJieAndDanyuan = this.getJieAndDanyuan(this.banbenInfo, jieId);
  265. if (!curJieAndDanyuan) {
  266. toast("未找到课程信息");
  267. return false;
  268. }
  269. const cacheData = cacheManager.get('xuexi-shuxue') || {};
  270. cacheData.curDanyuanName = curJieAndDanyuan.danyuan.danyuanName;
  271. cacheData.curKechengName = curJieAndDanyuan.jie.jieIntro;
  272. cacheData.danyuanId = curJieAndDanyuan.jie.danyuanId;
  273. cacheData.curJieId = jieId;
  274. cacheData.type = curJieAndDanyuan.jie.type;
  275. cacheManager.set('xuexi-shuxue', cacheData);
  276. if (type == 1) {
  277. uni.navigateTo({ url: `/pages/xinshuxue/lookShipin?jieId=${jieId}` })
  278. } else {
  279. uni.navigateTo({ url: `/pages/xinshuxue/unitTest?jieId=${jieId}` })
  280. }
  281. } else {
  282. toast("保存位置出错");
  283. return false;
  284. }
  285. } catch (error) {
  286. toast("保存失败");
  287. return false;
  288. }
  289. },
  290. handlePlay(da, code) {
  291. let jieId = code === 'jixu' ? da.curJieId : da.jieId;
  292. if (!jieId) {
  293. toast("无课程ID");
  294. return;
  295. }
  296. this.saveAndNavigate(jieId, da.type, da, code);
  297. },
  298. handleClickDanyuan(danyuanId) {
  299. if (!danyuanId) {
  300. toast("danyuanId丢失")
  301. return false
  302. }
  303. this.isShow = true;
  304. setTimeout(() => {
  305. // 更新为点击的动态单元Id [临时]
  306. this.$refs.dyRef.handleShow(danyuanId)
  307. }, 100)
  308. },
  309. handleBack() {
  310. uni.navigateTo({
  311. url: `/pages/chanpinXuanze/banben?dengjiId=` + this.dengjiId
  312. })
  313. },
  314. },
  315. // 计算吸顶栏下方的偏移(确保内容不被遮挡)
  316. computed: {
  317. }
  318. }
  319. </script>