chanpin1.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. <template>
  2. <view class="ezy-page-body xuexi-page-body">
  3. <!-- 滚动区域 -->
  4. <scroll-view v-if="existData" :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"
  35. @aclick="handleClickDanyuan(danyuanItem.danyuanId)" :id="`unit-title-${danyuanItem.danyuanId}`">
  36. <view class="dy-left-box">L{{banbenInfo.dengjiId}}</view>
  37. <view class="dy-right-box">
  38. <view class="right-content">
  39. <view>{{danyuanItem.danyuanName}}</view>
  40. <view class="dy-name">{{danyuanItem.danyuanIntro}}</view>
  41. </view>
  42. </view>
  43. </ezyActiveVue>
  44. <!-- 节列表 -->
  45. <ezyActiveVue class="ezy-list-item-active xx-item-box" v-for="jieItem in danyuanItem.jieList"
  46. :key="jieItem.jieId" @aclick="handlePlay(jieItem,'play')">
  47. <view class="xx-item-status"
  48. :class="jieItem.wanchengFlag == 1 ? 'completed-status' : 'uncompleted-status'"></view>
  49. <img :src="jieItem.cover" />
  50. <view class="xx-text-box">
  51. <view>{{ jieItem.jieName }}</view>
  52. <view>{{ jieItem.jieIntro }}</view>
  53. </view>
  54. <view v-if="jieItem.lock" class="xx-item-lock-btn"></view>
  55. <view v-else 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: false,
  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. 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. console.log('12311');
  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. if (this.danyuanList.length == 0) {
  173. this.existData = false
  174. } else {
  175. this.existData = true
  176. }
  177. // this.$nextTick(() => {
  178. // this.updateTitlePositions();
  179. // });
  180. }else{
  181. this.existData = false;
  182. }
  183. },
  184. loadDataFromApi(banbenId) {
  185. uni.showLoading({
  186. title: '加载中'
  187. });
  188. this.banbenInfo = {}
  189. this.curProcess = ''
  190. this.danyuanList = []
  191. const req = {
  192. banbenId: banbenId
  193. }
  194. shuxueChanpinBanbenInfo(req).then(res => {
  195. if (res.code === 0) {
  196. this.banbenInfo = res.data;
  197. this.banbenInfo.danyuanId = res.data.curDanyuanId;
  198. this.curProcess = res.data.curProcess * 100;
  199. this.danyuanList = res.data.danyuanList || [];
  200. if (this.danyuanList.length == 0) {
  201. this.existData = false
  202. } else {
  203. this.existData = true
  204. }
  205. const cacheData = {
  206. ...res.data,
  207. banbenId: banbenId,
  208. };
  209. cacheManager.set('contentInfo', cacheData);
  210. uni.hideLoading();
  211. }
  212. }).catch(res => {
  213. cacheManager.remove("contentInfo");
  214. toast("加载失败,请重试");
  215. uni.hideLoading();
  216. });
  217. },
  218. handleScroll(e) {
  219. const scrollTop = e.detail.scrollTop;
  220. console.log('scrollTop', scrollTop);
  221. this.showGoTop = scrollTop > this.scrollThreshold;
  222. },
  223. getJieAndDanyuan(data, jieId) {
  224. for (let danyuan of data.danyuanList) {
  225. for (let jie of danyuan.jieList) {
  226. if (jie.jieId == jieId) {
  227. return {
  228. danyuan,
  229. jie
  230. }
  231. }
  232. }
  233. }
  234. return null;
  235. },
  236. async saveAndNavigate(jieId, type, da, code) {
  237. console.log('this.banbenId', this.banbenId);
  238. console.log('this.danyuanIddanyuanId', da.danyuanId);
  239. if (code == 'jixu') {
  240. if (!this.banbenId || !da.danyuanId) {
  241. toast("banbenId或者danyuanId 丢失")
  242. return false
  243. }
  244. }
  245. let req = {
  246. "banbenId": this.banbenId,
  247. "danyuanId": da.danyuanId,
  248. "jieId": jieId
  249. }
  250. console.log('req', req);
  251. try {
  252. const res = await shuxueSave(req);
  253. if (res.code == 0 && res.data) {
  254. let curJieAndDanyuan = this.getJieAndDanyuan(this.banbenInfo, jieId);
  255. if (!curJieAndDanyuan) {
  256. toast("未找到课程信息");
  257. return false;
  258. }
  259. const cacheData = cacheManager.get('contentInfo') || {};
  260. cacheData.curDanyuanName = curJieAndDanyuan.danyuan.danyuanName;
  261. cacheData.curKechengName = curJieAndDanyuan.jie.jieIntro;
  262. cacheData.danyuanId = curJieAndDanyuan.jie.danyuanId;
  263. cacheData.curJieId = jieId;
  264. cacheData.type = curJieAndDanyuan.jie.type;
  265. cacheManager.set('contentInfo', cacheData);
  266. if (type == 1) {
  267. uni.navigateTo({
  268. url: `/pages/xinshuxue/lookShipin?jieId=${jieId}`
  269. })
  270. } else {
  271. uni.navigateTo({
  272. url: `/pages/xinshuxue/unitTest?jieId=${jieId}`
  273. })
  274. }
  275. } else {
  276. toast("保存位置出错");
  277. return false;
  278. }
  279. } catch (error) {
  280. toast("保存失败");
  281. return false;
  282. }
  283. },
  284. handlePlay(da, code) {
  285. if (da.lock && code == 'play') {
  286. // 加锁视频需要购买
  287. uni.navigateTo({
  288. url: "/pages/chanpinShop/cp1/dingdan"
  289. })
  290. return;
  291. }
  292. let jieId = code === 'jixu' ? da.curJieId : da.jieId;
  293. if (!jieId) {
  294. toast("无课程ID");
  295. return;
  296. }
  297. this.saveAndNavigate(jieId, da.type, da, code);
  298. },
  299. handleClickDanyuan(danyuanId) {
  300. if (!danyuanId) {
  301. toast("danyuanId丢失")
  302. return false
  303. }
  304. this.isShow = true;
  305. setTimeout(() => {
  306. // 更新为点击的动态单元Id [临时]
  307. this.$refs.dyRef.handleShow(danyuanId)
  308. }, 100)
  309. },
  310. handleBack() {
  311. uni.navigateTo({
  312. url: `/pages/chanpinXuanze/banben?dengjiId=` + this.dengjiId
  313. })
  314. },
  315. },
  316. // 计算吸顶栏下方的偏移(确保内容不被遮挡)
  317. computed: {
  318. }
  319. }
  320. </script>