| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291 |
- <template>
- <view class="ezy-xuexi-page">
- <view class="icon-title-navBar-box">
- <view @click="handleBack" class="nav-bar-icon"></view>
- <text class="nav-bar-title">学习</text>
- </view>
- <view class="ezy-page-body xuexi-page-body">
- <view class="change-dy-box">
- <!-- 显示内容 -->
- <view class="change-dy-content">
- <view>{{ banbenInfo.chanpinName }}</view>
- <view>
- <text>等级</text>
- <text>{{banbenInfo.dengjiName}}</text>
- </view>
- <view>
- <text>版本</text>
- <text>{{banbenInfo.name}}</text>
- </view>
- <view>
- <text>单元</text>
- <text>{{banbenInfo.curDanyuanName}}</text>
- </view>
- <view>
- <text>课程</text>
- <text>{{banbenInfo.curKechengName}}</text>
- </view>
- <view>
- <view class="xx-progress-box">
- <view>当前学习进度</view>
- <progress :percent="curProcess" class="xx-progress" stroke-width="10"
- backgroundColor="#3c7dfd" activeColor="#ffd11c" />
- </view>
- <view class="jxxx-btn" @click="handlePlay(banbenInfo,'jixu')">继续学习</view>
- </view>
- </view>
- </view>
- <view class="xx-scroll-body">
- <view class="xx-item-list">
- <view v-for="danyuanItem in danyuanList" :key="danyuanItem.danyuanId">
- <view @click="handleClickDanyuan">
- <view>L{{danyuanItem.danyuanId}}</view>
- <view>{{danyuanItem.danyuanName}}</view>
- <view>{{danyuanItem.danyuanIntro}}</view>
- </view>
- <view class="xx-item-box" v-for="jieItem in danyuanItem.jieList" :key="jieItem.jieId"
- @click="handlePlay(jieItem,'play')">
- <view class="xx-item-status"
- :class="jieItem.wanchengFlag == 1 ? 'completed-status' : 'uncompleted-status'"> </view>
- <img :src="jieItem.cover" />
- <view class="xx-text-box">
- <view>{{ jieItem.jieName }}</view>
- <view>{{ jieItem.jieIntro }}</view>
- </view>
- <view class="xx-item-btn"></view>
- </view>
- </view>
- </view>
- </view>
- </view>
- <danyuanInfoVue ref="dyRef" v-if="isShow" @close="isShow= false"></danyuanInfoVue>
- <CustomTabBar :currentTabNumber="1"></CustomTabBar>
- </view>
- </template>
- <script>
- import CustomTabBar from '@/components/custom-tabbar/custom-tabbar.vue';
- import cacheManager from "@/utils/cacheManager.js";
- import {
- shuxueChanpinBanbenInfo,
- shuxueSave
- } from "@/api/chanpinneirong.js"
- import danyuanInfoVue from '@/pages/xinshuxue/components/danyuanInfo.vue';
- import {
- toast
- } from '../../utils/common';
- export default {
- data() {
- return {
- danyuanList: [],
- currentUnitName: "",
- isShow: true,
- banbenInfo: {},
- banbenId: '',
- danyuanId: '',
- chanpinId: '',
- dengjiId: '',
- curProcess: '',
- cacheManagerLocal: null,
- isFirstFlag: false
- }
- },
- components: {
- CustomTabBar,
- danyuanInfoVue
- },
- onShow() {
- console.log('学习页面显示,尝试恢复滚动位置')
- console.log('this.isFirstFlag', this.isFirstFlag);
- if (!this.isFirstFlag) {
- return false
- }
- this.chanpinId = cacheManager.get('auth').chanpinId
- this.danyuanId = cacheManager.get('auth').danyuanId
- this.banbenId = cacheManager.get('auth').banbenId
- //用于返回
- this.dengjiId = cacheManager.get('auth').dengjiId
- this.cacheManagerLocal = cacheManager.get('xuexi-shuxue') || {}
- // 使用缓存
- this.banbenInfo = this.cacheManagerLocal
- this.curProcess = this.cacheManagerLocal.curProcess
- this.danyuanList = this.cacheManagerLocal.danyuanList || []
- },
- onHide() {
- console.log('学习页面隐藏,保存滚动位置')
- this.isFirstFlag = true
- },
- onLoad(options) {
- if (this.isFirstFlag) {
- return false
- }
- console.log('options', options);
- if (!cacheManager.get('xuexi-shuxue')) {
- console.log('没有缓存');
- this.chanpinId = options.chanpinId
- this.danyuanId = options.danyuanId
- this.banbenId = options.banbenId
- this.dengjiId = options.dengjiId
- this.loadDataFromApi()
- } else {
- toast("使用xuexi-shuxue缓存,并且this.isFirstFlag 为false")
- return false
- }
- },
- methods: {
- // 继续学习按钮是否可以点击
- jisuanWanchengStatus(dagangList) {
- // 查找第一个未完成的项目
- const firstUncompleted = danyuanList.find(item => item.wanchengFlag == 0);
- if (firstUncompleted) {
- return {
- allCompleted: false,
- firstUncompleted: firstUncompleted
- };
- } else {
- return {
- allCompleted: true,
- firstUncompleted: null
- };
- }
- },
- handleBack() {
- uni.navigateTo({
- url: `/pages/chanpinXuanze/banben?dengjiId=` + this.dengjiId
- })
- },
- loadDataFromApi() {
- const req = {
- banbenId: this.banbenId
- }
- shuxueChanpinBanbenInfo(req).then(res => {
- this.banbenInfo = res.data
- this.curProcess = res.data.curProcess
- this.danyuanList = res.data.danyuanList || []
- cacheManager.set('xuexi-shuxue', res.data)
- cacheManager.updateObject('auth', {
- chanpinId: this.chanpinId,
- banbenId: this.banbenId,
- danyuanId: this.danyuanId,
- dengjiId: this.dengjiId
- })
- this.isFirstFlag = true
- }).catch(res => {
- this.isFirstFlag = false
- cacheManager.remove("xuexi-shuxue")
- toast("shuxueChanpinBanbenInfo接口错误重置isFirstFlag,清除xuexi-shuxue缓存")
- return false
- })
- },
- getJieAndDanyuan(data, jieId) {
- // 循环单元
- for (let danyuan of data.danyuanList) {
- // 循环节
- for (let jie of danyuan.jieList) {
- if (jie.jieId == jieId) {
- return {
- danyuan: danyuan,
- jie: jie
- }
- }
- }
- }
- return null;
- },
- handlePlay(da, code) {
- console.log('da', da);
- let jieId = null;
- if (code == 'jixu') {
- if (!da.curJieId) {
- toast("无jieId");
- return;
- }
- jieId = da.curJieId;
- let req = {
- "banbenId": this.banbenId,
- "danyuanId": this.danyuanId,
- "jieId": jieId
- }
- shuxueSave(req).then(res => {
- console.log('res', res);
- if (res.code == 0 && res.data) {
- let curJieAndDanyuan = this.getJieAndDanyuan(da, jieId)
- console.log('curJieAndDanyuan', curJieAndDanyuan);
- if (!curJieAndDanyuan) {
- toast("curJieAndDanyuan没找到")
- return false
- }
- cacheManager.updateObject('xuexi-shuxue', {
- curDanyuanName: curJieAndDanyuan.danyuan.danyuanName,
- curKechengName: curJieAndDanyuan.danyuan.danyuanIntro,
- curJieId: jieId,
- type: curJieAndDanyuan.jie.type
- })
- if (da.type == 1) {
- uni.navigateTo({
- url: `/pages/xinshuxue/lookShipin?jieId=${jieId}`
- })
- } else {
- uni.navigateTo({
- url: `/pages/xinshuxue/unitTest?jieId=${jieId}`
- })
- }
- } else {
- toast("save位置出错")
- return false
- }
- })
- } else {
- jieId = da.jieId;
- let req = {
- "banbenId": this.banbenId,
- "danyuanId": this.danyuanId,
- "jieId": jieId
- }
- shuxueSave(req).then(res => {
- console.log('res', res);
- if (res.code == 0 && res.data) {
- let curJieAndDanyuan = this.getJieAndDanyuan(this.banbenInfo, jieId)
- console.log('curJieAndDanyuan', curJieAndDanyuan);
- if (!curJieAndDanyuan) {
- toast("curJieAndDanyuan没找到")
- return false
- }
- cacheManager.updateObject('xuexi-shuxue', {
- curDanyuanName: curJieAndDanyuan.danyuan.danyuanName,
- curKechengName: curJieAndDanyuan.danyuan.danyuanIntro,
- curJieId: jieId,
- type: curJieAndDanyuan.jie.type
- })
- if (da.type == 1) {
- uni.navigateTo({
- url: `/pages/xinshuxue/lookShipin?jieId=${jieId}`
- })
- } else {
- uni.navigateTo({
- url: `/pages/xinshuxue/unitTest?jieId=${jieId}`
- })
- }
- } else {
- toast("save位置出错")
- return false
- }
- })
- }
- },
- handleClickDanyuan() {
- this.isShow = true;
- setTimeout(() => {
- this.$refs.dyRef.handleShow(this.danyuanId)
- }, 100)
- },
- }
- }
- </script>
|