chanpin1.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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 v-if="jieItem.lock" class="xx-item-btn-lock">锁</view>
  54. <view v-else class="xx-item-btn"></view>
  55. </ezyActiveVue>
  56. </view>
  57. <view class="xx-item-title">本级别最后一单元啦~</view>
  58. <view class="xx-more-btn" @click="moreBtn"></view>
  59. </view>
  60. </scroll-view>
  61. <!-- 回到顶部 -->
  62. <view v-show="showGoTop" class="go-top-btn" @click="goTopBtn"></view>
  63. <!-- 无数据占位 -->
  64. <view v-if="!existData" class="ezy-page-body">
  65. <view class="ezy-no-sj">
  66. <icon></icon>
  67. <text>暂无数据</text>
  68. </view>
  69. </view>
  70. <!-- 弹窗组件 -->
  71. <danyuanInfoVue ref="dyRef" v-if="isShow" @close="isShow = false"></danyuanInfoVue>
  72. </view>
  73. </template>
  74. <script>
  75. import ezyActiveVue from "@/components/ezyActive/ezyActive.vue";
  76. import CustomTabBar from '@/components/custom-tabbar/index.vue';
  77. import cacheManager from "@/utils/cacheManager.js";
  78. import {
  79. shuxueChanpinBanbenInfo,
  80. shuxueSave
  81. } from "@/api/chanpinneirong.js"
  82. import {
  83. onLoad,
  84. onShow,
  85. onHide,
  86. onUnload
  87. } from "@dcloudio/uni-app"
  88. import danyuanInfoVue from '@/pages/xinshuxue/components/danyuanInfo.vue';
  89. import {
  90. toast
  91. } from '../../utils/common';
  92. import {
  93. updateChanpin1Process
  94. } from "./useNeirongChanpin1"
  95. export default {
  96. data() {
  97. return {
  98. canExitApp: false,
  99. danyuanList: [],
  100. banbenInfo: {},
  101. banbenId: '',
  102. danyuanId: '',
  103. chanpinId: '',
  104. dengjiId: '',
  105. curProcess: '',
  106. existData: true,
  107. isShow: false,
  108. stickyHeight: 0, // 吸顶栏高度(px)
  109. currentStickyTitle: '', // 初始为空,不显示吸顶
  110. currentStickyIntro: '',
  111. currentDanyuanId: '',
  112. currentStickyDengjiId: '',
  113. titlePositions: [],
  114. scrollTop: 0,
  115. showGoTop: false,
  116. scrollThreshold: 300,
  117. }
  118. },
  119. components: {
  120. CustomTabBar,
  121. danyuanInfoVue,
  122. ezyActiveVue
  123. },
  124. onHide() {
  125. console.log('学习页面隐藏')
  126. },
  127. onUnload() {
  128. // 页面卸载无需特殊处理
  129. },
  130. methods: {
  131. initData(banbenId) {
  132. console.log('123111');
  133. const cacheData = cacheManager.get('contentInfo');
  134. if (cacheData) {
  135. console.log('使用缓存数据');
  136. this.updateFromCache();
  137. } else {
  138. console.log('重新请求数据');
  139. const cacheDataAuth = cacheManager.get('auth');
  140. this.initFromOptions(banbenId);
  141. }
  142. },
  143. goTopBtn() {
  144. // 替换原来的 uni.pageScrollTo
  145. this.scrollTop = Math.random(); // 先设置一个随机值
  146. this.$nextTick(() => {
  147. this.scrollTop = 0; // 再设置回0
  148. });
  149. this.showGoTop = false;
  150. },
  151. moreBtn() {
  152. uni.switchTab({
  153. url: '/pages/chanpinXuanze/index'
  154. })
  155. },
  156. initFromOptions(banbenId) {
  157. this.loadDataFromApi(banbenId);
  158. },
  159. // 从缓存更新数据方法
  160. updateFromCache() {
  161. updateChanpin1Process()
  162. const cacheData = cacheManager.get('contentInfo');
  163. console.log('cacheData 从缓存更新数据方法', cacheData);
  164. if (cacheData) {
  165. this.banbenInfo = {
  166. ...cacheData
  167. };
  168. this.curProcess = cacheData.curProcess;
  169. this.danyuanList = [...(cacheData.danyuanList || [])];
  170. this.banbenId = cacheData.banbenId
  171. // this.$nextTick(() => {
  172. // this.updateTitlePositions();
  173. // });
  174. }
  175. },
  176. loadDataFromApi(banbenId) {
  177. this.banbenInfo = {}
  178. this.curProcess = ''
  179. this.danyuanList = []
  180. const req = {
  181. banbenId: banbenId
  182. }
  183. shuxueChanpinBanbenInfo(req).then(res => {
  184. if (res.code === 0) {
  185. this.banbenInfo = res.data;
  186. this.banbenInfo.danyuanId = res.data.curDanyuanId;
  187. this.curProcess = res.data.curProcess * 100;
  188. this.danyuanList = res.data.danyuanList || [];
  189. if (this.danyuanList.length == 0) {
  190. this.existData = false
  191. } else {
  192. this.existData = true
  193. }
  194. const cacheData = {
  195. ...res.data,
  196. banbenId: banbenId,
  197. };
  198. cacheManager.set('contentInfo', cacheData);
  199. }
  200. }).catch(res => {
  201. cacheManager.remove("contentInfo");
  202. toast("加载失败,请重试");
  203. });
  204. },
  205. handleScroll(e) {
  206. const scrollTop = e.detail.scrollTop;
  207. console.log('scrollTop', scrollTop);
  208. this.showGoTop = scrollTop > this.scrollThreshold;
  209. },
  210. getJieAndDanyuan(data, jieId) {
  211. for (let danyuan of data.danyuanList) {
  212. for (let jie of danyuan.jieList) {
  213. if (jie.jieId == jieId) {
  214. return {
  215. danyuan,
  216. jie
  217. }
  218. }
  219. }
  220. }
  221. return null;
  222. },
  223. async saveAndNavigate(jieId, type, da, code) {
  224. console.log('this.banbenId', this.banbenId);
  225. console.log('this.danyuanIddanyuanId', da.danyuanId);
  226. if (code == 'jixu') {
  227. if (!this.banbenId || !da.danyuanId) {
  228. toast("banbenId或者danyuanId 丢失")
  229. return false
  230. }
  231. }
  232. let req = {
  233. "banbenId": this.banbenId,
  234. "danyuanId": da.danyuanId,
  235. "jieId": jieId
  236. }
  237. console.log('req', req);
  238. try {
  239. const res = await shuxueSave(req);
  240. if (res.code == 0 && res.data) {
  241. let curJieAndDanyuan = this.getJieAndDanyuan(this.banbenInfo, jieId);
  242. if (!curJieAndDanyuan) {
  243. toast("未找到课程信息");
  244. return false;
  245. }
  246. const cacheData = cacheManager.get('contentInfo') || {};
  247. cacheData.curDanyuanName = curJieAndDanyuan.danyuan.danyuanName;
  248. cacheData.curKechengName = curJieAndDanyuan.jie.jieIntro;
  249. cacheData.danyuanId = curJieAndDanyuan.jie.danyuanId;
  250. cacheData.curJieId = jieId;
  251. cacheData.type = curJieAndDanyuan.jie.type;
  252. cacheManager.set('contentInfo', cacheData);
  253. if (type == 1) {
  254. uni.navigateTo({
  255. url: `/pages/xinshuxue/lookShipin?jieId=${jieId}`
  256. })
  257. } else {
  258. uni.navigateTo({
  259. url: `/pages/xinshuxue/unitTest?jieId=${jieId}`
  260. })
  261. }
  262. } else {
  263. toast("保存位置出错");
  264. return false;
  265. }
  266. } catch (error) {
  267. toast("保存失败");
  268. return false;
  269. }
  270. },
  271. handlePlay(da, code) {
  272. if (da.lock && code == 'play') {
  273. // 加锁视频需要购买
  274. uni.navigateTo({
  275. url: "/pages/chanpinShop/cp1/dingdan"
  276. })
  277. return;
  278. }
  279. let jieId = code === 'jixu' ? da.curJieId : da.jieId;
  280. if (!jieId) {
  281. toast("无课程ID");
  282. return;
  283. }
  284. this.saveAndNavigate(jieId, da.type, da, code);
  285. },
  286. handleClickDanyuan(danyuanId) {
  287. if (!danyuanId) {
  288. toast("danyuanId丢失")
  289. return false
  290. }
  291. this.isShow = true;
  292. setTimeout(() => {
  293. // 更新为点击的动态单元Id [临时]
  294. this.$refs.dyRef.handleShow(danyuanId)
  295. }, 100)
  296. },
  297. handleBack() {
  298. uni.navigateTo({
  299. url: `/pages/chanpinXuanze/banben?dengjiId=` + this.dengjiId
  300. })
  301. },
  302. },
  303. // 计算吸顶栏下方的偏移(确保内容不被遮挡)
  304. computed: {
  305. }
  306. }
  307. </script>