chanpin1.vue 9.6 KB

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