123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616 |
- <template>
- <view class="voice-play-page" v-if="isAuth">
- <!-- 由于目前板块较少 先去掉底部弹出筛选 改为平铺展示在tab上 -->
- <!-- <view class="top-filter-box">
- <image src="@/static/question/select.png" mode="aspectFill" @click="showFilter = true" />
- <text @click="showFilter = true">筛选</text>
- </view> -->
- <view class="top-filter-box">
- <van-tabs
- id="tabs"
- :ellipsis="false"
- :active="activeId"
- color="#E3B377"
- line-width="18px"
- @change="onTabsChange"
- >
- <van-tab
- :title="item.SectionName"
- :name="item.SectionId"
- v-for="item in tabsList"
- :key="item.SectionId"
- ></van-tab>
- </van-tabs>
- </view>
-
- <view class="empty-box" v-if="list.length==0&&finished">
- <image
- :src="globalImgUrls.activityNoAuth"
- mode="widthFix"
- />
- <view>暂无数据</view>
- </view>
- <view class="list-wrap" :class="showAudioPop?showAudioBigPop?'list-bot3':'list-bot2':'list-bot1'" v-else>
- <view class="item" v-for="item in list" :key="item.BroadcastId" @click="handleGoDetail(item)">
- <view class="title">{{item.BroadcastName}}</view>
- <view class="time">发布时间:{{item.PublishTime|formatTime}}</view>
- <view class="flex audio-box" @click.stop="handlePlay(item)">
- <image
- :src="item.BroadcastId==curVoiceId&&!curAudioPaused?require('@/static/voice/playing.png'):require('@/static/voice/pause.png')"
- mode="widthFix"
- />
- <text>{{item.VoicePlaySeconds|formatVoiceTime}}</text>
- </view>
- <view class="opt-box">
- <image style="width:34rpx;height:34rpx" src="@/static/voice/publish.png" mode="widthFix" @click.stop="handleSendMsgItem(item)" v-if="item.CouldSendMsg"/>
- <image style="width:34rpx;height:34rpx" src="@/static/voice/del.png" mode="widthFix" v-if="item.IsAuthor" @click.stop="handleDelItem(item)" />
- <sharePoster
- :showSlot="true"
- :shareData="getItemShareData(item)"
- >
- <image style="width:32rpx;height:32rpx" src="@/static/voice/creat-poster-icon.png" mode="aspectFill" />
- </sharePoster>
- <button
- class="share-btn"
- open-type="share"
- :data-item="item"
- @click.stop=""
- >
- <image class="share-img" src="@/static/share-icon.png" mode="aspectFill"/>
- </button>
- </view>
- </view>
- </view>
- <navigator url="/pages-voice/addVoice" v-if="IsVoiceAdmin">
- <view :class="['add-btn',showAudioPop?showAudioBigPop?'add-btn-bot3':'add-btn-bot2':'add-btn-bot1']">新建语音</view>
- </navigator>
- <!-- 筛选弹窗 -->
- <van-popup
- :show="showFilter"
- position="bottom"
- :close-on-click-overlay="true"
- @close="showFilter = false"
- round
- >
- <view class="fliter-wrap-list">
- <view class="flex top">
- <text style="color:#000">全部筛选</text>
- <text style="color:#E3B377" @click="showFilter=false">取消</text>
- </view>
- <van-tree-select
- :items="options"
- :main-active-index="mainActiveIndex"
- :active-id="activeId"
- @click-nav="onClickNav"
- @click-item="onClickItem"
- main-active-class="main-active-class"
- content-active-class="content-active-class"
- />
- </view>
- </van-popup>
- <!-- 音频悬浮 -->
- <view v-if="showPage">
- <audioBox v-if="showAudioPop"/>
- </view>
-
- <!-- 跳转去提问悬浮按钮 -->
- <dragButton :existTabBar="true">
- <navigator url="/pages-question/hasQuestion">
- <view class="to-question-fixed-box">
- <image src="@/static/toquestion-icon.png" mode="widthFix" />
- <text>我要提问</text>
- </view>
- </navigator>
- </dragButton>
-
- <van-dialog id="van-dialog" />
- </view>
- <noAuth :info="noAuthData" v-else/>
- </template>
- <script>
- import {apiVoiceList,apiVoiceSectionList,apiVoicePlayRecord,apiVoiceDel,apiVoiceSendMsg} from '@/api/voice'
- import {apiGetSceneToParams} from '@/api/common'
- import noAuth from './components/noAuth.vue'
- import audioBox from '@/components/audioBox/audioBox.vue'
- import dragButton from '@/components/dragButton/dragButton.vue'
- import sharePoster from '@/components/sharePoster/sharePoster.vue'
- const dayjs=require('@/utils/dayjs.min')
- export default {
- components:{
- noAuth,
- audioBox,
- dragButton,
- sharePoster
- },
- filters:{
- formatTime(e){
- return dayjs(e).format('YYYY-MM-DD HH:mm:ss')
- },
- formatVoiceTime(e){
- let m=parseInt(e/60)
- let s=parseInt(e%60)
- return `${m>9?m:'0'+m}:${s>9?s:'0'+s}`
- }
- },
- computed:{
- showAudioPop(){//是否显示音频弹窗
- return this.$store.state.audio.show
- },
- showAudioBigPop(){
- return this.$store.state.audio.showBig
- },
- curVoiceId(){//当前正在播放的音频id
- return this.$store.state.audio.voiceId
- },
- curAudioPaused(){//当前音频是否暂停状态
- return this.$store.state.audio.paused
- },
- },
- data() {
- return {
- list:[],
- page:1,
- pageSize:20,
- finished:false,
- voiceId:0,//分享时进入的音频id
- IsVoiceAdmin:false,//是否是语音管理员
- isAuth:true,
- noAuthData:null,
- showFilter:false,
- options:[],
- mainActiveIndex:0,
- activeId:0,//选择的板块id
- tabsList:[],//顶部滑动筛选数据
- showPage:false,
- }
- },
- onLoad(options){
- this.init(options)
- this.addListenVoiceSuccess()
- },
- onShow(){
- //无权限时刷新列表
- if(!this.isAuth){
- this.getOptionsList()
- }else{
- this.$nextTick(()=>{
- this.selectComponent('#tabs').resize();// 解决初始渲染 vant tab 底部条
- })
- }
-
- this.showPage=true
- },
- onHide(){
- this.showPage=false
- },
- onUnload(){
- uni.$off('addVoiceSuccess')
- },
- onShareAppMessage({from,target}) {
- console.log(from,target);
- let path='/pages/voice/voice'
- let title='语音播报'
- let imageUrl=''
- if(from=='button'){
- title=`${target.dataset.item.SectionName}:${target.dataset.item.BroadcastName}`
- path=`/pages-voice/voiceDetail?voiceId=${target.dataset.item.BroadcastId}`
- imageUrl=target.dataset.item.ImgUrl
- }
- return {
- title:title,
- path:path,
- imageUrl:imageUrl
- }
- },
- onPullDownRefresh(){
- this.voiceId=0
- this.page=1
- this.list=[]
- this.finished=false
- this.getOptionsList()
- setTimeout(() => {
- uni.stopPullDownRefresh()
- }, 1500)
- },
- onReachBottom() {
- if(this.finished) return
- this.page++
- this.getVoiceList()
- },
- methods: {
- handleGoDetail(item){
- uni.navigateTo({
- url: '/pages-voice/voiceDetail?voiceId='+item.BroadcastId,
- });
- },
- // 监听添加音频成功刷新列表
- addListenVoiceSuccess(){
- uni.$on('addVoiceSuccess',()=>{
- this.voiceId=0
- this.page=1
- this.list=[]
- this.finished=false
- this.getVoiceList()
- this.getOptionsList()
- })
- },
- async init(options){
- if(options.scene){
- const res=await apiGetSceneToParams({scene_key:options.scene})
- if(res.code===200){
- const obj=JSON.parse(res.data)
- this.voiceId=obj.voiceId
- }
- }else{
- this.voiceId=options.voiceId||0
- }
- this.getOptionsList()
- },
- // 获取音频列表
- async getVoiceList(){
- const res=await apiVoiceList({
- page_index:this.page,
- page_size:this.pageSize,
- broadcast_id:Number(this.voiceId),
- section_id:Number(this.activeId)
- })
- if(res.code===200){
- this.IsVoiceAdmin=res.data.IsVoiceAdmin
- let arr=res.data.List||[]
- this.list=[...this.list,...arr]
- if(arr.length===0){
- this.finished=true
- }
- // 如果有voiceId 则说明是分享进入的 如果没有数据则提示
- if(this.voiceId!=0&&arr.length===0){
- uni.showToast({
- title:'该语音播报不存在',
- icon:'none'
- })
- setTimeout(() => {
- this.voiceId=0
- this.page=1
- this.list=[]
- this.finished=false
- this.getVoiceList()
- this.getOptionsList()
- }, 1500);
- }
- this.isAuth=true
- }else if(res.code===403){
- //无权限用户
- this.isAuth=false
- this.noAuthData=res.data
- }
- },
- //获取筛选数据
- async getOptionsList(){
- const res=await apiVoiceSectionList()
- if(res.code!==200) return
- const arr=res.data||[]
- let temarr=[]
- this.options=arr.map(item=>{
- let obj={
- text:'',
- children:[]
- }
- obj.text=item.VarietyName
- obj.children=item.Children.map(_item=>{
- temarr.push(_item)
- return {
- text:_item.SectionName,
- id:_item.SectionId
- }
- })
- return obj
- })
- this.tabsList=temarr||[]
- this.activeId=temarr[0].SectionId
- this.$nextTick(()=>{
- this.selectComponent('#tabs')?.resize();// 解决初始渲染 vant tab 底部条
- })
- this.getVoiceList()
- },
- // 顶部tab切换
- onTabsChange(e){
- this.activeId=e.detail.name
- this.voiceId=0
- this.page=1
- this.list=[]
- this.finished=false
- this.getVoiceList()
- },
- onClickNav({detail}){
- console.log(detail);
- this.mainActiveIndex=detail.index
- },
- onClickItem({detail}){
- console.log(detail);
- if(this.activeId==detail.id){
- this.activeId=0
- }else{
- this.activeId=detail.id
- }
- this.voiceId=0
- this.page=1
- this.list=[]
- this.finished=false
- this.getVoiceList()
- this.showFilter=false
- },
- //推送消息
- handleSendMsgItem(item){
- this.$dialog.confirm({
- title:'',
- message: '该操作将推送模板消息和客群,确认推送吗?',
- confirmButtonText:'确认'
- }).then(()=>{
- apiVoiceSendMsg({broadcast_id:item.BroadcastId}).then(res=>{
- if(res.code===200){
- uni.showToast({
- title:"推送成功",
- icon:'success'
- })
- item.CouldSendMsg=false
- }
- })
- }).catch(()=>{})
- },
-
- //删除音频
- handleDelItem(item){
- this.$dialog.confirm({
- title:'',
- message: '确定要删除该语音播报吗?',
- confirmButtonText:'确定'
- }).then(()=>{
- if(this.curVoiceId==item.BroadcastId&&!this.curAudioPaused){
- //删除的音频正好在播放则暂停
- this.globalBgMusic.stop()
- }
-
- apiVoiceDel({broadcast_id:Number(item.BroadcastId)}).then(res=>{
- if(res.code===200){
- uni.showToast({
- title:'操作成功',
- icon:'none'
- })
- this.page=1
- this.list=[]
- this.finished=false
- this.getVoiceList()
- }
- })
- }).catch(()=>{})
- },
- //点击音频 播放或者暂停
- handlePlay(item){
- if(this.$store.state.audio.voiceId==item.BroadcastId){
- if(this.globalBgMusic.paused){
- this.globalBgMusic.play()
- }else{
- this.globalBgMusic.pause()
- }
- }else{
- const list=[{url:item.VoiceUrl,time:item.VoicePlaySeconds,title:item.BroadcastName,}]
- this.$store.commit('audio/addAudio',{
- list:list,
- voiceId:item.BroadcastId
- })
- this.handleVoicePlayRecord(item)
- }
- },
- //上报音频播放记录
- async handleVoicePlayRecord(item){
- const res=await apiVoicePlayRecord({
- broadcast_id:item.BroadcastId
- })
- if(res.code===200){
- console.log('上报音频播放记录');
- this.$store.commit('audio/addAudioRecordId',{recordId:res.data,source:2})
- }
- },
- //语音详情生成海报参数
- getItemShareData(item){
- return {
- type:'voice_detail',
- code_page:'pages-voice/voiceDetail',
- code_scene:JSON.stringify({voiceId:item.BroadcastId}),
- data:{
- title:item.BroadcastName,
- img:item.ImgUrl
- }
- }
- }
- },
- }
- </script>
- <style lang="scss">
- .top-filter-box{
- .van-tab{
- font-size: 28rpx;
- color: #777;
- }
- .van-tab--active{
- font-weight: bold;
- font-size: 32rpx;
- color: #333333;
- }
- }
- .voice-play-page{
-
- .fliter-wrap-list{
- background-color: #fff;
- padding-top: 53rpx;
- padding-bottom: 100rpx;
- .top{
- font-size: 32rpx;
- justify-content: space-between;
- margin-bottom: 40rpx;
- padding: 0 34rpx;
- }
- .van-sidebar{
- flex-shrink: 0;
- }
- .van-tree-select__content{
- overflow-x: hidden;
- }
- .main-active-class{
- border-color: #E3B377;
- }
- .content-active-class{
- color: #E3B377;
- }
- }
- }
- </style>
- <style lang="scss" scoped>
- .voice-play-page{
- .top-filter-box{
-
- background-color: white;
- box-shadow: 0px 4rpx 4rpx 0px rgba(198,198,198,0.2500);
- position: sticky;
- top: 0;
- left: 0;
- z-index: 99;
- // image{
- // width: 34rpx;
- // height: 34rpx;
- // }
- // color: #E3B377;
- // font-size: 28rpx;
- }
- }
- .empty-box{
- text-align: center;
- font-size: 32rpx;
- color: #999;
- padding-top: 150rpx;
- image{
- width: 80vw;
- margin-bottom: 57rpx;
- }
- }
- .list-wrap{
- padding: 0 34rpx 34rpx 34rpx;
- .item{
- border-bottom: 1px solid #CDCDCD;
- padding: 30rpx 0;
- position: relative;
- .opt-box{
- position: relative;
- float: right;
- bottom: 40rpx;
- display: flex;
- image{
- margin-left: 40rpx;
- }
- .share-btn{
- background-color: transparent;
- width: 36rpx;
- height: 36rpx;
- line-height: 1;
- padding: 0;
- margin-left: 40rpx;
- &::after{
- border: none;
- }
- .share-img{
- width: 32.5rpx;
- height: 32rpx;
- margin-left: 0;
- }
- }
-
- }
- .title{
- font-size: 32rpx;
- }
- .time{
- font-size: 28rpx;
- color: #666;
- margin-top: 20rpx;
- margin-bottom: 30rpx;
- }
- .audio-box{
- width: 185rpx;
- height: 56rpx;
- align-items: center;
- justify-content: center;
- border-radius: 28rpx;
- background-color: #F4E1C9;
- color: #E3B377;
- image{
- width: 23rpx;
- height: 28rpx;
- margin-right: 20rpx;
- }
- }
- }
- }
- .list-bot1{
- padding-bottom: 200rpx;
- }
- .list-bot2{
- padding-bottom: 340rpx;
- }
- .list-bot3{
- padding-bottom: 440rpx;
- }
- .add-btn{
- position: fixed;
- width: 514rpx;
- height: 80rpx;
- text-align: center;
- line-height: 80rpx;
- color: #E3B377;
- font-size: 32rpx;
- left: 50%;
- bottom: calc(150rpx + constant(safe-area-inset-bottom));
- bottom: calc(150rpx + env(safe-area-inset-bottom));
- transform: translateX(-50%);
- background: #333333;
- box-shadow: 0px 4rpx 20rpx rgba(160, 126, 84, 0.25);
- border-radius: 40rpx;
- }
- .add-btn-bot1{
- bottom: calc(120rpx + constant(safe-area-inset-bottom));
- bottom: calc(120rpx + env(safe-area-inset-bottom));
- }
- .add-btn-bot2{
- bottom: calc(260rpx + constant(safe-area-inset-bottom));
- bottom: calc(260rpx + env(safe-area-inset-bottom));
- }
- .add-btn-bot3{
- bottom: calc(355rpx + constant(safe-area-inset-bottom));
- bottom: calc(355rpx + env(safe-area-inset-bottom));
- }
- </style>
|