337 lines
8.1 KiB
Vue
337 lines
8.1 KiB
Vue
<template>
|
||
<view>
|
||
<z-nav-bar :title="bookInfo.name+'-讲书'"></z-nav-bar>
|
||
<view class="mainContent">
|
||
<view class="title">{{talkBookDetail.title}}</view>
|
||
<view class="voices" v-if="talkBookDetail.voices != '' && audioShow">
|
||
<!-- <audio style="text-align: left; overflow: hidden;" :src="talkBookDetail.voices" @play="audioPlay"
|
||
poster="../../static/icon/home_icon_0.png" :name="talkBookDetail.title"
|
||
:author="bookInfo.author.authorName" :action="audioAction" controls @timeupdate="updateTime"></audio> -->
|
||
<!-- 下面自己写了个播放器 -->
|
||
<view class="audiobox">
|
||
<view class="audioinfo">
|
||
<image class="audioimg" :src="bookInfo.images" mode="aspectFit"></image>
|
||
<image class="audioimgstart" v-if="!this.paused" mode="aspectFit" src="../../static/audiostart.png" @click="start"></image>
|
||
<image class="audioimgstart" v-else mode="aspectFit" src="../../static/audiostop.png" @click="start"></image>
|
||
<view>
|
||
<view class="audiotitle">{{talkBookDetail.title}}</view>
|
||
<view class="audioauthor">{{bookInfo.author.authorName}}</view>
|
||
<view class="audioauthor">{{currentTime+'/'+duration}}秒</view>
|
||
<slider class="audioslider" block-size="12" v-model="currentTime" :max="duration" @change="changeTime"></slider>
|
||
<!-- <view @click="start">点击播放/暂停</view> -->
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
<view class="content" v-if="talkBookDetail.content != ''" v-html="talkBookDetail.content"></view>
|
||
<view class="content" v-else></view>
|
||
<view class="time">
|
||
<text>{{talkBookDetail.createTime}}</text>
|
||
</view>
|
||
<view class="tuijin" v-if="!isBuy && bookInfo.productId != null">
|
||
<p>觉得这本书还不错?</p>
|
||
<view class="flexbox"
|
||
style="justify-content: space-between; border: 1px solid #55aa7f; padding: 10rpx; border-radius: 10rpx;">
|
||
<view class="flexbox">
|
||
<view class="img">
|
||
<image v-if="bookInfo.images != ''" :src="bookInfo.images" mode="aspectFit"></image>
|
||
<image v-else src="../../static/icon/wufeng.jpg" mode="aspectFit"></image>
|
||
</view>
|
||
<view>
|
||
<text style=" display: inline-block; margin-top: 40rpx;">{{bookInfo.name}}</text><br />
|
||
<text>作者:{{bookInfo.author.authorName}}</text>
|
||
</view>
|
||
</view>
|
||
<view class="btn" @click="gotoBuy()">
|
||
<text>立即购买</text>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
<!-- <view class="opbtn flexbox">
|
||
<view class="">上一章</view>
|
||
<view class="">下一章</view>
|
||
</view> -->
|
||
</view>
|
||
<music-play :playData="playData"></music-play>
|
||
<!-- 公共组件-每个页面必须引入 -->
|
||
<public-module></public-module>
|
||
</view>
|
||
</template>
|
||
|
||
<script>
|
||
import musicPlay from '@/components/music.vue'
|
||
import {
|
||
mapState,
|
||
mapMutations
|
||
} from 'vuex';
|
||
export default {
|
||
data() {
|
||
return {
|
||
audioAction: {
|
||
method: 'pause'
|
||
},
|
||
audioShow: false,
|
||
voicesImg: '',
|
||
isBuy: false,
|
||
playData: {},
|
||
teachId: null, // 讲书id
|
||
bookId: null, // 书籍id
|
||
bookInfo: {
|
||
author: {
|
||
authorName: ''
|
||
}
|
||
}, // 书籍信息
|
||
talkBookDetail: {},
|
||
windowWidth: 0,
|
||
audio: null,
|
||
duration: 10,
|
||
currentTime: 0,
|
||
paused: false
|
||
}
|
||
},
|
||
onLoad(e) {
|
||
this.windowWidth = uni.getSystemInfoSync().windowWidth;
|
||
console.log(e, 'onLoad')
|
||
this.bookId = e.bookId
|
||
this.teachId = e.teachId
|
||
|
||
// 初始化播放器实例
|
||
this.audio = uni.createInnerAudioContext();
|
||
},
|
||
onShow() {
|
||
this.getBookInfo()
|
||
this.getTalkBookDetail()
|
||
},
|
||
onHide() {
|
||
this.audio.pause() // 暂停播放
|
||
},
|
||
onUnload() {
|
||
this.audio.destroy() // 销毁播放器
|
||
},
|
||
computed: {
|
||
...mapState(['userInfo'])
|
||
},
|
||
methods: {
|
||
...mapMutations(['setUserInfo']),
|
||
start(){
|
||
this.initAudio() // 开始播放
|
||
},
|
||
initAudio(){
|
||
this.audio.onTimeUpdate(()=>{
|
||
this.duration = this.audio.duration.toFixed()
|
||
this.currentTime = this.audio.currentTime.toFixed()
|
||
})
|
||
this.paused = this.audio.paused
|
||
// console.log('paused',this.paused)
|
||
if(this.paused){
|
||
this.audio.play()
|
||
}else{
|
||
this.audio.pause()
|
||
}
|
||
},
|
||
updateTime(e){
|
||
this.currentTime = e.detail.currentTime.toFixed()
|
||
this.duration = e.detail.duration.toFixed()
|
||
},
|
||
changeTime(e){
|
||
this.audio.seek(e.detail.value) // 设置播放位置
|
||
},
|
||
audioPlay(){
|
||
console.log('播放讲书',this.$music)
|
||
this.$music.setCloseBgm() // 关闭听书音频
|
||
this.setUserInfo({'playFlag': false})
|
||
},
|
||
// 购买
|
||
gotoBuy() {
|
||
uni.navigateTo({
|
||
url: '../bookShop/commodityDetail?id=' + this.bookInfo.productId
|
||
});
|
||
},
|
||
getBookInfo() {
|
||
// 获取书本基本信息
|
||
this.$http
|
||
.post('book/book/getBookInfo', {
|
||
'bookId': this.bookId,
|
||
'userId': this.userInfo.id
|
||
})
|
||
.then(res => {
|
||
if (res.code == 0) {
|
||
console.log(res, 'res')
|
||
this.bookInfo = res.book
|
||
|
||
if (!this.bookInfo.author || this.bookInfo.author == null) {
|
||
this.bookInfo.author = {
|
||
'authorName': '未知'
|
||
}
|
||
console.log(this.bookInfo.author.authorName, 'this.bookInfo.author.authorName')
|
||
}
|
||
//console.log(this.bookInfo.author.authorName,'this.bookInfo.author.authorName')
|
||
this.voicesImg = res.book.images
|
||
// this.bookInfo.name = res.book.name
|
||
this.isBuy = res.book.isBuy
|
||
console.log(this.voicesImg, 'this.voicesImg')
|
||
// this.freeChapterCount = res.book.freeChapterCount
|
||
} else {
|
||
console.log(res.msg)
|
||
}
|
||
console.log(res, '书籍基本信息')
|
||
}).catch((error) => {
|
||
console.log(error)
|
||
})
|
||
},
|
||
// 获取讲书详情
|
||
getTalkBookDetail() {
|
||
this.audioShow = false
|
||
this.$http
|
||
.post('book/teach/getTeachDetail', {
|
||
'teachId': this.teachId
|
||
})
|
||
.then(res => {
|
||
if (res.code == 0) {
|
||
console.log(res, 'res')
|
||
this.talkBookDetail = res.bookTeach
|
||
|
||
this.audio.src = this.talkBookDetail.voices // 设置播放资源路径
|
||
this.audio.onCanplay((e)=>{
|
||
this.duration = this.audio.duration.toFixed() // 初始化进度条和音频秒数
|
||
})
|
||
|
||
// this.isBuy = res.book.isBuy
|
||
// this.freeChapterCount = res.book.freeChapterCount
|
||
} else {
|
||
console.log(res.msg)
|
||
}
|
||
this.audioShow = true
|
||
console.log(res, '讲书信息')
|
||
}).catch((error) => {
|
||
console.log(error)
|
||
this.audioShow = true
|
||
})
|
||
},
|
||
},
|
||
components: {
|
||
musicPlay
|
||
},
|
||
}
|
||
</script>
|
||
|
||
<style scoped lang="scss">
|
||
.mainContent {
|
||
margin: 20rpx 10rpx;
|
||
padding: 20rpx;
|
||
background-color: #fff;
|
||
border-radius: 10rpx;
|
||
}
|
||
|
||
.flexbox {
|
||
display: flex;
|
||
}
|
||
|
||
.voices {
|
||
margin: 10rpx auto;
|
||
text-align: center;
|
||
|
||
}
|
||
|
||
/deep/ .uni-audio-name {
|
||
// white-space: wrap !important;
|
||
width: 340rpx;
|
||
}
|
||
|
||
.title {
|
||
font-size: 30rpx;
|
||
color: #55aa7f;
|
||
font-weight: bold;
|
||
margin: 40rpx 0;
|
||
}
|
||
|
||
.time {
|
||
text-align: right;
|
||
font-size: 24rpx;
|
||
margin-top: 20rpx;
|
||
color: #999;
|
||
}
|
||
|
||
.content {
|
||
font-size: 28rpx;
|
||
text-align: justify;
|
||
color: #666;
|
||
line-height: 48rpx;
|
||
}
|
||
|
||
.tuijin {
|
||
font-size: 26rpx;
|
||
|
||
margin-top: 20rpx;
|
||
|
||
.img {
|
||
width: 150rpx;
|
||
height: 150rpx;
|
||
overflow: hidden;
|
||
}
|
||
|
||
image {
|
||
height: 150rpx;
|
||
width: 100%;
|
||
}
|
||
|
||
p {
|
||
font-size: 28rpx;
|
||
margin-bottom: 20rpx;
|
||
color: #55aa7f;
|
||
}
|
||
}
|
||
|
||
.btn {
|
||
margin-right: 20rpx;
|
||
|
||
text {
|
||
display: inline-block;
|
||
margin-top: 52rpx;
|
||
font-size: 30rpx;
|
||
padding: 5px 8px;
|
||
background: #55aa7f;
|
||
color: #fff;
|
||
border-radius: 5px;
|
||
}
|
||
}
|
||
// 自定义播放器样式
|
||
.audiobox{
|
||
border: 2rpx solid #d6d5d5;
|
||
border-radius: 8px;
|
||
.audioinfo{
|
||
display: flex;
|
||
.audioimg{
|
||
padding: 10rpx;
|
||
width: 180rpx;
|
||
height: 220rpx;
|
||
border-radius: 5px;
|
||
}
|
||
.audioimgstart{
|
||
position: absolute;
|
||
padding: 20rpx;
|
||
width: 180rpx;
|
||
height: 220rpx;
|
||
border-radius: 5px;
|
||
}
|
||
.audiotitle{
|
||
padding: 10rpx;
|
||
font-size: 28rpx;
|
||
text-align: left;
|
||
}
|
||
.audioauthor{
|
||
padding: 4rpx;
|
||
font-size: 24rpx;
|
||
text-align: left;
|
||
color: #999;
|
||
}
|
||
.audioslider{
|
||
width: 400rpx;
|
||
}
|
||
}
|
||
|
||
|
||
}
|
||
|
||
// .opbtn{font-size: 14rpx;}
|
||
</style> |