chanpin1.vue 9.0 KB

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