chanpin1.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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. currentTabIndex: 1,
  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. this.currentTabIndex = 1
  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. cacheManager.set('contentInfo', res.data);
  196. }
  197. }).catch(res => {
  198. cacheManager.remove("contentInfo");
  199. toast("加载失败,请重试");
  200. });
  201. },
  202. handleScroll(e) {
  203. const scrollTop = e.detail.scrollTop;
  204. console.log('scrollTop', scrollTop);
  205. this.showGoTop = scrollTop > this.scrollThreshold;
  206. },
  207. getJieAndDanyuan(data, jieId) {
  208. for (let danyuan of data.danyuanList) {
  209. for (let jie of danyuan.jieList) {
  210. if (jie.jieId == jieId) {
  211. return {
  212. danyuan,
  213. jie
  214. }
  215. }
  216. }
  217. }
  218. return null;
  219. },
  220. async saveAndNavigate(jieId, type, da, code) {
  221. console.log('this.banbenId', this.banbenId);
  222. console.log('this.danyuanIddanyuanId', da.danyuanId);
  223. if (code == 'jixu') {
  224. if (!this.banbenId || !da.danyuanId) {
  225. toast("banbenId或者danyuanId 丢失")
  226. return false
  227. }
  228. }
  229. let req = {
  230. "banbenId": this.banbenId,
  231. "danyuanId": da.danyuanId,
  232. "jieId": jieId
  233. }
  234. console.log('req', req);
  235. try {
  236. const res = await shuxueSave(req);
  237. if (res.code == 0 && res.data) {
  238. let curJieAndDanyuan = this.getJieAndDanyuan(this.banbenInfo, jieId);
  239. if (!curJieAndDanyuan) {
  240. toast("未找到课程信息");
  241. return false;
  242. }
  243. const cacheData = cacheManager.get('contentInfo') || {};
  244. cacheData.curDanyuanName = curJieAndDanyuan.danyuan.danyuanName;
  245. cacheData.curKechengName = curJieAndDanyuan.jie.jieIntro;
  246. cacheData.danyuanId = curJieAndDanyuan.jie.danyuanId;
  247. cacheData.curJieId = jieId;
  248. cacheData.type = curJieAndDanyuan.jie.type;
  249. cacheManager.set('contentInfo', cacheData);
  250. if (type == 1) {
  251. uni.navigateTo({
  252. url: `/pages/xinshuxue/lookShipin?jieId=${jieId}`
  253. })
  254. } else {
  255. uni.navigateTo({
  256. url: `/pages/xinshuxue/unitTest?jieId=${jieId}`
  257. })
  258. }
  259. } else {
  260. toast("保存位置出错");
  261. return false;
  262. }
  263. } catch (error) {
  264. toast("保存失败");
  265. return false;
  266. }
  267. },
  268. handlePlay(da, code) {
  269. let jieId = code === 'jixu' ? da.curJieId : da.jieId;
  270. if (!jieId) {
  271. toast("无课程ID");
  272. return;
  273. }
  274. this.saveAndNavigate(jieId, da.type, da, code);
  275. },
  276. handleClickDanyuan(danyuanId) {
  277. if (!danyuanId) {
  278. toast("danyuanId丢失")
  279. return false
  280. }
  281. this.isShow = true;
  282. setTimeout(() => {
  283. // 更新为点击的动态单元Id [临时]
  284. this.$refs.dyRef.handleShow(danyuanId)
  285. }, 100)
  286. },
  287. handleBack() {
  288. uni.navigateTo({
  289. url: `/pages/chanpinXuanze/banben?dengjiId=` + this.dengjiId
  290. })
  291. },
  292. },
  293. // 计算吸顶栏下方的偏移(确保内容不被遮挡)
  294. computed: {
  295. }
  296. }
  297. </script>