From 7b9044f4df510c41774e829ba9bd4d84c6ca27e1 Mon Sep 17 00:00:00 2001 From: "@fawn-nine" <1271023382@qq.com> Date: Fri, 1 Sep 2023 18:04:41 +0800 Subject: [PATCH] 2023.09.01 --- App.vue | 4 +- components/cx-audio-play/cx-audio-play.vue | 50 +- pages.json | 18 + pages/bookShop/classify.vue | 6 +- pages/bookShop/commodityDetail.vue | 30 +- pages/bookShop/orderLCont.vue | 2 +- pages/clock/clock.vue | 922 ++++++++++++++++++--- pages/library/library.vue | 30 +- pages/listen/home.vue | 10 +- pages/listen/listen.vue | 81 +- pages/peanut/home.vue | 27 +- pages/peanut/mine.vue | 8 +- utils/music.js | 207 +++-- 13 files changed, 1135 insertions(+), 260 deletions(-) diff --git a/App.vue b/App.vue index 8bab8f2..6b92edd 100644 --- a/App.vue +++ b/App.vue @@ -23,7 +23,7 @@ export default { // 取出播放列表 uni.getStorage({ key: 'playData', - success: function (res) { + success: function (res) { // 本地有播放数据就用本地的 console.log(res.data,'取出的本地数据'); if(res.data.myList.length<=0){ store.commit('setUserInfo',{'playVisible': false}) @@ -36,7 +36,7 @@ export default { store.commit('setUserInfo',{'currentTime': 0}); }, - fail:function(e){ + fail:function(e){ // 如果没有,就查询一下线上的播放记录 console.log('本地无数据'); music.setList([]) store.commit('setUserInfo',{'playingInfo': {'bookid':0,'chapterId':0}}); diff --git a/components/cx-audio-play/cx-audio-play.vue b/components/cx-audio-play/cx-audio-play.vue index ad6e21a..194da3c 100644 --- a/components/cx-audio-play/cx-audio-play.vue +++ b/components/cx-audio-play/cx-audio-play.vue @@ -121,13 +121,19 @@ loading: true, //锁 加载 audioMannager:null ,// 背景音乐 saveInterVal:null, - fengImg:'' + fengImg:'', + } }, created() { this.libLIst = this.$bgm.musicList - this.fengImg = this.userInfo.fengImg + this.fengImg = this.userInfo.fengImg + this.userInfo.playTimes ? this.setUserInfo({'currentTime': this.userInfo.playTimes}) : '' + + console.log(this.userInfo.currentTime,'组件读到的历史记录') + }, + computed: { ...mapState(['userInfo']), timer() { @@ -195,33 +201,6 @@ }, - - - - - - // 存储听书进度 - saveListenRate(){ - console.log('存储听书进度') - this.$emit('saveRate',this.currentTime) - }, - // 顺序播放 - orderPlay(val){ - // console.log(val) - if(val){ - uni.showToast({ - title:'开启顺序播放', - icon:'none' - }) - this.orderPlayBtn = true - }else{ - uni.showToast({ - title:'关闭顺序播放', - icon:'none' - }) - this.orderPlayBtn = false - } - }, // 显示播放列表 showLib(){ this.LibVisible = true @@ -236,18 +215,7 @@ }else{ this.$bgm.play() } - console.log('拖动') - //此处滑动进度条--开始播放 - // if (this.slideYes && !this.succes) { - // //#ifdef H5 - // this.videoContext.play() - // //#endif - // //#ifndef H5 - // this.videoContext.play() - // //#endif - // this.succes = true - // } - + console.log('拖动') this.$bgm.seek(data.detail.value) //获取秒数 }, diff --git a/pages.json b/pages.json index 747a131..48488f3 100644 --- a/pages.json +++ b/pages.json @@ -406,6 +406,24 @@ } } + ,{ + "path" : "pages/clock/index", + "style" : + { + "navigationBarTitleText": "读书打卡列表", + "enablePullDownRefresh": false + } + + } + ,{ + "path" : "pages/clock/clockList", + "style" : + { + "navigationBarTitleText": "打卡记录1", + "enablePullDownRefresh": false + } + + } ], "globalStyle": { "navigationBarTextStyle": "black", diff --git a/pages/bookShop/classify.vue b/pages/bookShop/classify.vue index 614c8b2..956e6ff 100644 --- a/pages/bookShop/classify.vue +++ b/pages/bookShop/classify.vue @@ -137,7 +137,7 @@ this.$http .post('book/shopcategory/getOneLevel') .then(res => { - console.log(res,'一级分类') + //console.log(res,'一级分类') this.oneLevel = res.list // this.current = e.type this.getTowLevel(this.oneLevel[0]) @@ -151,7 +151,7 @@ this.$http .post(`book/shopcategory/getTwoLevel?catId=${e.catId}`) .then(res => { - console.log(res,'二级分类') + //console.log(res,'二级分类') this.towLevel = res.list if (this.towLevel == '') { this.commodityList = [] @@ -182,7 +182,7 @@ 'catId': e.catId }) .then(res => { - console.log(res,'二级分类') + // console.log(res,'二级分类') this.commodityList = res.list }) }, diff --git a/pages/bookShop/commodityDetail.vue b/pages/bookShop/commodityDetail.vue index dff5418..1a8d952 100644 --- a/pages/bookShop/commodityDetail.vue +++ b/pages/bookShop/commodityDetail.vue @@ -27,12 +27,12 @@ - + 书名:{{productInfo.productName}} @@ -156,6 +156,7 @@ cartList: [], // 购物车列表 commentsList:[], // 评论列表 productId:null, // 商品评论 + listenList:[] // 关联得听书 } }, onLoad(e) { @@ -171,6 +172,12 @@ musicPlay }, methods: { + goToListen(id){ + // 跳转到听书 + uni.navigateTo({ + url: "../listen/listen?bookid="+ id + }); + }, // 放大图片 previewImage(url){ console.log(url) @@ -246,10 +253,12 @@ console.log(e.id,'e.id') this.$http .post('/book/shopproduct/info/' + e.id) - .then(res => { + .then(res => { + console.log('shopproduct',res) this.productInfo = res.shopProduct + this.listenList = res.shopProduct.bookidsimages if (this.productInfo.productImageList == null || this.productInfo.productImageList == '') { - this.swiperlist.push('../../static/icon/home_ban_1.jpg') + this.swiperlist.push(this.productInfo.productImages) } else { let imgList = this.productInfo.productImageList.split(",") // if(this.productInfo.productDetails != null){ @@ -454,7 +463,12 @@ formatRichText (html) { //控制小程序中图片大小 } + align-items: center; + justify-content: space-between; + padding: 20rpx; + .dakaBtn { + color: #55aa7f; + display: flex; + padding: 3rpx 5rpx; + border: #55aa7f 1px solid; + border-radius: 10rpx; + } + } + + .scroll-view_H { + white-space: nowrap; + margin: 20px 0; + width: 100%; + + .item { + border: 1px dashed #999; + width: calc(100% - 6rpx); + // margin: 0 6rpx; + text-align: center; + display: inline-block; + background-color: #F0FDFF; + border-radius: 20rpx; + padding: 6rpx 3rpx; + + .day {display: block; + font-size: 26rpx; + color: #999; + + em { + font-size: 36rpx; + font-style: normal; + font-weight: bold; + padding-right: 2px; + } + } + + .checkbox-mark { + display: none; + } + + .buka { + display: inline-block; padding: 0 6rpx; + color: #888; + // border: 1px solid #888; + margin: 10px 0; + border-radius: 15rpx; + margin-bottom: 0; ; + } + + .weidaka { + color: #A3B4B5; + margin: 10px 0; font-size: 24; + border-radius: 20rpx; + margin-bottom: 0; + display: block; + } + .daka{ + display: inline-block; padding: 0 6rpx; + border: 1px solid #55aaff; + color: #55aaff; + margin: 10px 0; + border-radius: 20rpx; + margin-bottom: 0; + display: block; + } + } + + .item.havSign { + border: 1px solid #55aa7f; + + text-align: center; + display: inline-block; + background-color: #55aa7f; + border-radius: 20rpx; + padding: 6px 6px; + + .day { + font-size: 26rpx; + color: #fff; + em { + font-size: 32rpx; + font-style: normal; + font-weight: bold; + padding-right: 2px; + } + } + + .checkbox-mark { + display: block; + } + } + .item.current{ + border: 1px solid #55aaff; + + text-align: center; + display: inline-block; + background-color: #edf9ff; + border-radius: 20rpx; + padding: 6px 6px; + .day { + font-size: 26rpx; + color: #55aaff; + em { + font-size: 32rpx; + font-style: normal; + font-weight: bold; + padding-right: 2px; + } + } + } + .item.linshiDay{ + border: 1px solid #55aaff; + + text-align: center; + display: inline-block; + background-color: #55aaff; + border-radius: 20rpx; + padding: 6px 6px; + .day { + font-size: 26rpx; + color: #fff; + em { + font-size: 32rpx; + font-style: normal; + font-weight: bold; + padding-right: 2px; + } + } + .buka{color: #fff; } + } + } + + .dp_title { + font-size: 32rpx; + margin-bottom: 50rpx; + color: #555; + text-align: center; + font-weight: bold; + } + + .mb30 { + margin-bottom: 30rpx; + } + + .tanchu { + padding: 40rpx 30rpx 40rpx 30rpx; + position: relative; + } + + .cuIcon-emoji { + background: url(../../static/biaoqing.png) no-repeat; + background-size: contain; + display: block; + margin-right: 20rpx; + width: 30px; + } + + .cuIcon-keyboard { + background: url(../../static/biaoqing.png) no-repeat; + background-size: contain; + display: block; + width: 30px; + } + + .leaveBtn { + position: fixed; + width: calc(100% - 4px); + background: #fff; + bottom: 1rpx; + left: 1px; + z-index: 1; + } + + .task { + margin-top: 40rpx 20rpx; + + .taskinfo { + video { + width: 100%; + } + } + } + + .subContent { + margin-top: 20rpx; + background-color: #fff; + overflow: hidden; + + .clockTitle { + color: #55aa7f; + font-size: 38rpx; + text-align: center; + display: block; + margin-top: 30rpx; + } + } + + .container1 { + .margin-top { + margin-top: 30rpx; + overflow: hidden; + } + } + + .container { + padding: 30rpx; + } + + .calendar_container { + //min-height: calc(60vh); + background-color: #fff; + //padding: 30rpx; + box-sizing: border-box; + padding-bottom: 20rpx; + border-radius: 20rpx; + margin-bottom: 20rpx; + } + + .task { + padding: 30rpx 20rpx; + background-color: #f5f5f5; + background-color: #fff; + padding-bottom: 50rpx; + + .title { + margin-top: 30rpx; + padding: 30rpx; + color: #002968; + background-color: #fff; + font-size: 46rpx; + padding: 20rpx; + } + + .item {} + + .video { + border-radius: 0 0 20rpx 20rpx; + } + + .txt { + margin-top: 30rpx; + color: #666; + line-height: 50rpx; + } + } + + .haveNo { + background: #fff; + + .box { + height: 20vh; + display: flex; + align-items: center; + + button { + width: 50%; + margin: 0 auto; + } + } + + .subform { + padding: 0 20rpx; + margin-top: 30rpx; + + .btns { + width: 400rpx; + margin: 0 auto; + margin-bottom: 40rpx; + justify-content: space-between; + } + } + } + + .had { + padding: 60rpx; + margin-top: 30rpx; + background-color: #fff; + + h3 { + color: #8c9a92; + font-size: 34rpx; + } + + .content { + line-height: 60rpx; + margin-top: 30rpx; + font-size: 30rpx; + color: #0e0e15; + } + + .images { + height: 150rpx; + overflow: hidden; + margin-top: 30rpx; + + image { + width: 150rpx; + margin: 0 10rpx; + } + } + + .opBtns { + margin-top: 30rpx; + + span { + color: #b3b3b3; + padding-left: 20rpx; + font-size: 24rpx; + } + } + } + + .flexbox { + display: flex; + } + \ No newline at end of file diff --git a/pages/library/library.vue b/pages/library/library.vue index 1704f02..0e32bc4 100644 --- a/pages/library/library.vue +++ b/pages/library/library.vue @@ -14,27 +14,30 @@ - + - + - - 读 书 + + + 读 书 - + + 听 书 - + + 评 书 @@ -54,15 +57,15 @@ - + 读 书 - + 听 书 - + 评 书 @@ -250,8 +253,7 @@ var booidArr = [] if(res.pages.list[i].bookId != null){ booidArr = res.pages.list[i].bookId.split(',') - //res.pages.list[i].bookId = booidArr - console.log(booidArr,'booidArr') + //res.pages.list[i].bookId = booidArr res.pages.list[i].bookId = booidArr }else{ res.pages.list[i].bookId = [] @@ -315,7 +317,11 @@ @import '@/style/mixin.scss'; .listenItem{ .btns{margin-top: 60rpx; margin-left: 20rpx; font-size: 34rpx; justify-content: space-between; - .item{ margin-bottom:30rpx;} + .item{ margin-bottom:30rpx; + image{ + width: 24px !important;height:24px;display: block; margin-right: 10rpx; + } + } } .info{width: 50%; image{width:100% ; height: 280rpx; border-radius: 20rpx;} diff --git a/pages/listen/home.vue b/pages/listen/home.vue index b81551f..67296b6 100644 --- a/pages/listen/home.vue +++ b/pages/listen/home.vue @@ -22,7 +22,7 @@ {{item.bookName}} - + @@ -43,7 +43,7 @@ {{item.productName}} - + @@ -234,7 +234,7 @@ if(res.pages.list[i].bookId != null){ booidArr = res.pages.list[i].bookId.split(',') //res.pages.list[i].bookId = booidArr - console.log(booidArr,'booidArr') + // console.log(booidArr,'booidArr') res.pages.list[i].bookId = booidArr }else{ res.pages.list[i].bookId = [] diff --git a/pages/listen/listen.vue b/pages/listen/listen.vue index b980cae..355bacf 100644 --- a/pages/listen/listen.vue +++ b/pages/listen/listen.vue @@ -39,7 +39,7 @@ - + 已购买 @@ -71,9 +71,10 @@ {{item.chapterName}}   - + :class="[freeChapterCount < index && isBuy == false ? 'graytitle' : '', + userInfo.playingInfo.bookid==item.bookid && userInfo.playingInfo.chapterId == item.chapterId ? 'playing' : '']" @click="listenOne(item, index)"> + {{item.chapterName}}   + @@ -114,10 +115,12 @@ playid:null, // 正在播放的章节id playchapName:'', // 正在播放的章节名称 playIndex:null, // 正在播放的序号值 + onlineH:{}, // 线上的历史听书 currentTime:{ time:0, flag:'' }, + freeChapterCount:0, // 免费章节数 pageTab:[ {name: '正在播放'}, {name: '播放列表'} @@ -194,12 +197,40 @@ }, plays() { // 播放音频 this.muteBgMusic = !this.muteBgMusic - console.log(this.muteBgMusic,this.muteBgMusic?'已关闭音乐####':'已开启音乐####'); - - - }, - addMusicList(){ - + console.log(this.muteBgMusic,this.muteBgMusic?'已关闭音乐####':'已开启音乐####'); + }, + // 获取线上听书进度 + getListenRate(val,op){ + let data = { + bookId: this.bookid, + userId: this.userInfo.id, + } + $http.request({ + url: "book/listening/getReadRate", + method: "POST", // POST、GET、PUT、DELETE,具体说明查看官方文档 + data, + header: { //默认 无 说明:请求头 + 'Content-Type': 'application/json' + }, + }).then(res => { + console.log(res,'历史记录') + if(res.readRate.chapterId){ + var item = res.readRate + // 有听书进度时 + this.onlineH.playIndex = bgm.musicList.findIndex(function(info){ + // console.log(info,'info') + if(item.chapterId == info.chapterId && item.bookId == info.bookid ){ + return info; + } + }) + //store.commit('setUserInfo',{'playingInfo':bgm.musicList[bgm.playIndex] }) + console.log('线上的播放index是:',this.onlineH.playIndex) + }else{ + // 没有听书进度 + } + }) + }, + addMusicList(){ if (this.userInfo.playFlag) { // 暂停 // this.$music.playBgm({mute:true}) @@ -222,6 +253,7 @@ // 'myList' : this.libLIst, // // 'fengImg' : this.fengImg, // } + // 显示播放组件 this.setUserInfo({'playVisible':true}) uni.setStorage({ @@ -275,17 +307,21 @@ // 购买 buyBook(){ - uni.showModal({ - title: '提示', - cancelText: '暂不购买', - confirmText:'立即购买', - content: '确定花费¥95元购买本书电子版吗?', - success: function (res) { - if (res.confirm) { - console.log('用户点击确定'); - } - } - }); + uni.navigateTo({ + url: '../bookShop/settlementBook?type=2&list=' + this.bookid + }); + // uni.showModal({ + // title: '提示', + // cancelText: '暂不购买', + // confirmText:'立即购买', + // content: '确定花费¥95元购买本书电子版吗?', + // success: function (res) { + // if (res.confirm) { + // console.log('用户点击确定'); + // } + // } + // }); + }, // 信息介绍跳转 @@ -430,7 +466,8 @@ if(res.BookCatalogue.length > 0){ this.libLIst = res.BookCatalogue // this.fengImg = res.images - this.isBuy = res.buy + this.isBuy = res.buy + this.freeChapterCount = res.freeChapterCount }else{ uni.showToast({ title:'暂无可听章节哦~', diff --git a/pages/peanut/home.vue b/pages/peanut/home.vue index 9993036..a06b1cd 100644 --- a/pages/peanut/home.vue +++ b/pages/peanut/home.vue @@ -10,24 +10,24 @@ - - + + 读书打卡 - + 听书 - + 书评 - + 图书馆 @@ -619,12 +619,12 @@ margin: 30rpx 20rpx; justify-content: space-between; display: flex; color: #333; - .dianzishu{ margin-right:10rpx; - background-color:#f8d6f4 ; border: 2px solid #edcce9; - } - .chaoshi{background-color:#fff2d8 ; border: 2px solid #ede6d3; } - .shuping{ background-color: #d6ffda; border: 2px solid #bae9bf;} - .shuguan{ background-color:#e3f9f9 ; border: 2px solid #d7eced; } + // .dianzishu{ margin-right:10rpx; + // background-color:#f8d6f4 ; border: 2px solid #edcce9; + // } + // .chaoshi{background-color:#fff2d8 ; border: 2px solid #ede6d3; } + // .shuping{ background-color: #d6ffda; border: 2px solid #bae9bf;} + // .shuguan{ background-color:#e3f9f9 ; border: 2px solid #d7eced; } .hn_cl_tit { padding-bottom: 10rpx; width: 23%; text-align: center; @@ -633,15 +633,14 @@ //display: flex; align-content: center; justify-content: center; - image { - + image { width: 110upx; height:110upx; display: block; margin: 0 auto; margin: 0 20rpx; } - text{ display:block; font-size: 34rpx;} + text{ display:block; margin-top: 10px; font-size: 36rpx; color: #000; font-weight:blod;} } diff --git a/pages/peanut/mine.vue b/pages/peanut/mine.vue index 84eca16..532652b 100644 --- a/pages/peanut/mine.vue +++ b/pages/peanut/mine.vue @@ -59,7 +59,10 @@ 我的订单 - 我的图书 + 我的听书 + + + 我的打卡 听书设置 @@ -67,6 +70,9 @@ 我的评价 + + 购物车 + diff --git a/utils/music.js b/utils/music.js index 4f5d974..15b1f06 100644 --- a/utils/music.js +++ b/utils/music.js @@ -2,10 +2,13 @@ import store from '@/store/index.js' import $http from '@/config/requestConfig.js'; const bgm = uni.getBackgroundAudioManager(); // const bgm = uni.createInnerAudioContext(); + bgm.musicList = [] // 播放目录 bgm.src = '' +bgm.htimes = 0 // 历史播放秒数 bgm.cTime = 0 bgm.title = '' +bgm.interval=null // 存储定时器 bgm.loop = true; bgm.coverImgUrl = '' bgm.oldIndex = 0 // 前面一首的播放索引 @@ -42,24 +45,35 @@ var music = { } // 没有就添加添加url到播放器,播放新的 if(bgm.src == ''){ - console.log(bgm.playIndex,'播放的索引',store.state.userInfo.playIndex) + console.log(bgm.playIndex,'播放的索引',store.state.userInfo.playIndex,'播放的时长',store.state.userInfo.playTimes) store.commit('setUserInfo',{'playTitle': bgm.musicList[bgm.playIndex].chapterName}) store.commit('setUserInfo',{'fengImg': bgm.musicList[bgm.playIndex].images}) store.commit('setUserInfo',{'playingInfo': bgm.musicList[bgm.playIndex]}) console.log(store.state.userInfo,'chapterName',bgm.playIndex) - this.getChartUrl() + store.state.userInfo.playTimes ? bgm.htimes = store.state.userInfo.playTimes : '' + this.getChartUrl() + // 获取历史秒数 + }else{ - // 如果有正在播放的url,暂停改为播放 - // bgm.play() + } } bgm.onPause(()=>{ console.log('暂停背景音乐'); + this.saveTimes() + clearInterval(bgm.interval) store.commit('setUserInfo',{'playFlag': false}) + }) bgm.onPlay(() => { store.commit('setUserInfo',{'playFlag': true}) console.log('开始播放音乐#######'); + uni.hideLoading() + + bgm.interval = setInterval(()=>{ + console.log('存一次') + this.saveIndex() + },180000) }) bgm.onError((res) => { console.log(res) @@ -91,7 +105,10 @@ var music = { // 可以播放时 // console.log('可以播放时') uni.hideLoading() - this.saveIndex() + // this.saveIndex() + console.log('历史播放进度,秒数', bgm.htimes) + bgm.seek(bgm.htimes) + bgm.htimes = 0 // 重置播放秒数 // store.commit('setUserInfo',{'duration':bgm.duration}) // store.commit('setUserInfo',{'playTitle': bgm.title}) // store.commit('setUserInfo',{'fengImg': bgm.coverImgUrl}) @@ -108,20 +125,68 @@ var music = { // 添加播放列表 setList(list,op,playindex){ bgm.musicList = list - + bgm.oldIndex = bgm.playIndex // 暂存上一个播放得index + console.log('地址异常报错前index:',bgm.oldIndex) playindex ? bgm.playIndex = playindex : bgm.playIndex = 0 - console.log(bgm.playIndex,'playindex') + + // console.log(bgm.playIndex,'playindex') store.commit('setUserInfo',{'playingInfo': {}}) - if(op == 'autoPlay'){ - if(bgm._options.src == ''){ - // this.getChartUrl() - this.playBgm({mute:false}) - console.log('playBgm') - }else{ - this.getChartUrl() // 获取对应的播放路径 - // console.log('getChartUrl') + this.getListenRate(bgm.musicList[0], op) + // if(op == 'autoPlay'){ + // store.commit('setUserInfo',{'playTimes': 0}) + // if(bgm._options.src == ''){ + // // this.getChartUrl() + // this.playBgm({mute:false}) + // console.log('playBgm') + // }else{ + // this.getChartUrl() // 获取对应的播放路径 + // // console.log('getChartUrl') + // } + // } + }, + // 获取线上听书进度 + getListenRate(val,op){ + let data = { + bookId: val.bookid, + userId: store.state.userInfo.id, + } + $http.request({ + url: "book/listening/getReadRate", + method: "POST", // POST、GET、PUT、DELETE,具体说明查看官方文档 + data, + header: { //默认 无 说明:请求头 + 'Content-Type': 'application/json' + }, + }).then(res => { + console.log(res,'历史记录') + if(res.readRate.chapterId){ + var item = res.readRate + // 有听书进度时 + bgm.playIndex = bgm.musicList.findIndex(function(info){ + // console.log(info,'info') + if(item.chapterId == info.chapterId && item.bookId == info.bookid ){ + return info; + } + }) + store.commit('setUserInfo',{'playingInfo':bgm.musicList[bgm.playIndex] }) + console.log('线上的播放index是:',bgm.playIndex) + console.log('线上的播放index是:', store.state.userInfo.playingInfo) + }else{ + // 没有听书进度 } - } + + if(op == 'autoPlay'){ + store.commit('setUserInfo',{'playTimes': 0}) + if(bgm._options.src == ''){ + // this.getChartUrl() + this.playBgm({mute:false}) + console.log('playBgm') + }else{ + this.getChartUrl() // 获取对应的播放路径 + // console.log('getChartUrl') + } + } + }) }, // 获取章节url getChartUrl(){ @@ -132,70 +197,113 @@ var music = { 'chapterid': bgm.musicList[bgm.playIndex].chapterId } console.log(data,'data') - $http.post('book/bookchaptercontent/appBooksChapterContent', data) + $http.post('book/bookchaptercontent/appBooksChapterContent', data) + // $http.post('book/bookchaptercontent/getCatal', data) .then(res => { console.log(res,'res') if(res.code == 0){ // bgm.stop() // 有听权限时 - if(res.bookCatalogue[0].url.length > 10){ + if(res.bookCatalogue[0].url){ // 空值url:null bgm.src = res.bookCatalogue[0].url - bgm.title = res.bookCatalogue[0].name - bgm.coverImgUrl = res.image - + // bgm.title = res.bookCatalogue[0].name + // bgm.coverImgUrl = res.image + // store.commit('setUserInfo',{'playIndex': bgm.playIndex}) + // store.commit('setUserInfo',{'playTitle': bgm.title}) + // store.commit('setUserInfo',{'playingInfo':bgm.musicList[bgm.playIndex] }) + // store.commit('setUserInfo',{'fengImg': bgm.coverImgUrl}) // bgm.pause() // this.setCoverImg(bgm.musicList[bgm.playIndex].images) - }else{ - bgm.src = '' - bgm.title = '' - bgm.coverImgUrl = '' + }else{ + // bgm.src = '' + // bgm.title = '' + // bgm.coverImgUrl = '../../static/icon/fengziIcon.jpg' // this.setCoverImg('../../static/icon/x1.jpg') - bgm.stop() + // bgm.stop() + bgm.playIndex = bgm.oldIndex + console.log('地址异常报错后index:',bgm.playIndex) + store.commit('setUserInfo',{'playIndex': bgm.playIndex}) + store.commit('setUserInfo',{'playingInfo':bgm.musicList[bgm.playIndex] }) uni.showToast({ title:'音频地址异常', icon:'error', duration:2000 }) // store.commit('setUserInfo',{'playFlag': false}) - } - store.commit('setUserInfo',{'playTitle': bgm.title}) - store.commit('setUserInfo',{'fengImg': bgm.coverImgUrl}) + } + } console.log(res.bookCatalogue,'单章节信息') - }).catch((e)=>{ + }).catch((e)=>{ + console.log(e,'e') // bgm.pause() bgm.playIndex = bgm.oldIndex // bgm.stop() - store.commit('setUserInfo',{'playFlag': false}) - uni.showModal({ - title: '提示', - cancelText: '暂不购买', - confirmText:'立即购买', - content: '抱歉!当前章节不支持试听,购买后可收听', - success: function (res) { - if (res.confirm) { - console.log('用户点击确定'); - uni.navigateTo({ - url: '../bookShop/settlementBook?type=2&list=' + data.bookid - }); - } - } - }); + // store.commit('setUserInfo',{'playFlag': false}) + + uni.showModal({ + title: '提示', + cancelText: '暂不购买', + confirmText:'立即购买', + content: '抱歉!当前章节不支持试听,购买后可收听', + success: function (res) { + if (res.confirm) { + console.log('用户点击确定'); + uni.navigateTo({ + url: '../bookShop/settlementBook?type=2&list=' + data.bookid + }); + } + } + }); + + // uni.showModal({ + // title: '提示', + // confirmText:'知道了', + // content: '当前书籍音频功能未开通,请联系管理员', + // success: function (res) { + // if (res.confirm) { + // console.log('用户点击确定'); + // } + // } + // }); + }) - }, + }, // 存储播放信息 saveIndex(){ + console.log(bgm.playIndex,'存储得index') store.commit('setUserInfo',{'playIndex': bgm.playIndex}) store.commit('setUserInfo',{'duration':bgm.duration}) store.commit('setUserInfo',{'playTitle': bgm.title}) store.commit('setUserInfo',{'fengImg': bgm.coverImgUrl}) store.commit('setUserInfo',{'playFlag': true}) - store.commit('setUserInfo',{'playingInfo': bgm.musicList[bgm.playIndex]}) + store.commit('setUserInfo',{'playingInfo': bgm.musicList[bgm.playIndex]}) + store.commit('setUserInfo',{'playTimes': bgm.currentTime}) + this.saveRate(bgm.musicList[bgm.playIndex]) }, - // 存储播放 + // 存储播放(本地) saveTimes(){ store.commit('setUserInfo',{'playTimes': bgm.currentTime}) }, + // 存储播放进度(线上) + saveRate(val){ + console.log(val,'要存储的播放信息',) + $http.post('book/listening/save', { + 'userId': store.state.userInfo.id, + 'bookId': val.bookid, + 'chapterId': val.chapterId, + 'chapterName': val.chapterName, + //'precent': bgm.currentTime + 'precent': Math.ceil(bgm.currentTime), + //'contentId' + 'loadAnimate':'none', // 请求加载动画 + }) + .then(res => { + if(res.code == 0){ + console.log(res,'存储完成') + } + }).catch((e)=>{}) + }, // 设置播放index setPlayIndex(opName){ // 切换音频 if(opName == 'next'){ // 下一首 @@ -256,7 +364,8 @@ var music = { console.log('success'); } }); - + bgm.htimes = 0 + bgm.oldIndex = bgm.playIndex bgm.playIndex = bgm.musicList.findIndex(function(info){ // console.log(info,'info') if(item.chapterId == info.chapterId && item.bookid == info.bookid ){