chanpin1.vue 8.7 KB

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