myVoice.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. <template>
  2. <view class="my-voice-page">
  3. <view class="top-tab-warp">
  4. <text
  5. :class="['item',status==opt.value?'item-active':'']"
  6. v-for="opt in statusOpt"
  7. :key="opt.value"
  8. @click="handleOptChange(opt)"
  9. >{{opt.lable}}({{opt.count}})</text>
  10. </view>
  11. <view class="empty-box" v-if="finished&&list.length==0">
  12. <image :src="globalImgUrls.activityNoAuth" mode="widthFix" />
  13. <view>暂无数据</view>
  14. </view>
  15. <view class="list-wrap" v-else>
  16. <view class="item" v-for="item in list" :key="item.BroadcastId" @click="handleGoDetail(item)">
  17. <view class="title">{{item.BroadcastName}}</view>
  18. <view class="time" v-if="item.PublishState==0">保存时间:{{item.ModifyTime|formatTime}}</view>
  19. <view class="time" v-else>发布时间:{{item.PublishTime|formatTime}}</view>
  20. <view class="flex audio-box" @click.stop="handlePlay(item)">
  21. <image
  22. :src="item.BroadcastId==curVoiceId&&!curAudioPaused?require('@/static/voice/playing.png'):require('@/static/voice/pause.png')"
  23. mode="widthFix"
  24. />
  25. <text>{{item.VoicePlaySeconds|formatVoiceTime}}</text>
  26. </view>
  27. <view class="btns-box">
  28. <button
  29. v-if="item.PublishState!=0"
  30. class="btn"
  31. open-type="share"
  32. :data-item="item"
  33. @click.stop=""
  34. >
  35. <image class="share-img" src="@/static/share-icon.png" mode="aspectFill"/>
  36. </button>
  37. <button class="btn" @click.stop="handleDelItem(item)">
  38. <image class="del-img" src="@/static/voice/del.png" mode="widthFix" v-if="item.IsAuthor" />
  39. </button>
  40. <button class="btn" @click.stop="handleSendMsgItem(item)" v-if="item.CouldSendMsg&&item.PublishState!=0">
  41. <image class="publish-img" src="@/static/voice/publish.png" mode="widthFix" />
  42. </button>
  43. <button class="btn" @click.stop="handlePublish(item)" v-if="item.PublishState==0">
  44. <image class="publish-img" src="./static/publish.png" mode="widthFix" />
  45. </button>
  46. </view>
  47. </view>
  48. </view>
  49. <!-- 音频悬浮 -->
  50. <view v-if="showPage">
  51. <audioBox v-if="showAudioPop"/>
  52. </view>
  53. <van-dialog id="van-dialog" />
  54. </view>
  55. </template>
  56. <script>
  57. import {apiVoiceList,apiVoicePlayRecord,apiVoiceDel,apiVoiceSendMsg,apiVoicePublish,apiMyVoiceCount} from '@/api/voice'
  58. import audioBox from '@/components/audioBox/audioBox.vue'
  59. const dayjs=require('@/utils/dayjs.min')
  60. export default {
  61. components:{
  62. audioBox
  63. },
  64. filters:{
  65. formatTime(e){
  66. return dayjs(e).format('YYYY-MM-DD HH:mm:ss')
  67. },
  68. formatVoiceTime(e){
  69. let m=parseInt(e/60)
  70. let s=parseInt(e%60)
  71. return `${m>9?m:'0'+m}:${s>9?s:'0'+s}`
  72. }
  73. },
  74. computed:{
  75. showAudioPop(){//是否显示音频弹窗
  76. return this.$store.state.audio.show
  77. },
  78. showAudioBigPop(){
  79. return this.$store.state.audio.showBig
  80. },
  81. curVoiceId(){//当前正在播放的音频id
  82. return this.$store.state.audio.voiceId
  83. },
  84. curAudioPaused(){//当前音频是否暂停状态
  85. return this.$store.state.audio.paused
  86. },
  87. },
  88. data() {
  89. return {
  90. page:1,
  91. pageSize:20,
  92. list:[],
  93. finished:false,
  94. status:0,//0-未发布 1-已发布 2-全部(我的语音播报列表)
  95. statusOpt:[
  96. {
  97. lable:'未发布',
  98. count:0,
  99. value:0,
  100. key:'Unpublished'
  101. },
  102. {
  103. lable:'已发布',
  104. count:0,
  105. value:1,
  106. key:'Published'
  107. },
  108. {
  109. lable:'全部',
  110. count:0,
  111. value:2,
  112. key:'All'
  113. }
  114. ],
  115. showPage:false,
  116. }
  117. },
  118. onLoad(){
  119. this.getCount()
  120. this.getList()
  121. this.addListenVoiceSuccess()
  122. },
  123. onShow(){
  124. this.showPage=true
  125. },
  126. onHide(){
  127. this.showPage=false
  128. },
  129. onUnload(){
  130. uni.$off('addVoiceSuccess')
  131. },
  132. onPullDownRefresh(){
  133. this.page=1
  134. this.list=[]
  135. this.finished=false
  136. this.getList()
  137. setTimeout(() => {
  138. uni.stopPullDownRefresh()
  139. }, 1500)
  140. },
  141. onReachBottom() {
  142. if(this.finished) return
  143. this.page++
  144. this.getList()
  145. },
  146. onShareAppMessage({from,target}) {
  147. console.log(from,target);
  148. let path='/pages/voice/voice'
  149. let title='语音播报'
  150. let imageUrl=''
  151. if(from=='button'){
  152. title=`${target.dataset.item.SectionName}:${target.dataset.item.BroadcastName}`
  153. path=`/pages-voice/voiceDetail?voiceId=${target.dataset.item.BroadcastId}`
  154. imageUrl=target.dataset.item.ImgUrl
  155. }
  156. return {
  157. title:title,
  158. path:path,
  159. imageUrl:imageUrl
  160. }
  161. },
  162. methods: {
  163. // 监听添加音频成功刷新列表
  164. addListenVoiceSuccess(){
  165. uni.$on('addVoiceSuccess',()=>{
  166. this.page=1
  167. this.list=[]
  168. this.finished=false
  169. this.getCount()
  170. this.getList()
  171. })
  172. },
  173. //获取列表数据
  174. async getList(){
  175. const res=await apiVoiceList({
  176. page_index:this.page,
  177. page_size:this.pageSize,
  178. author_id:Number(this.$store.state.user.userInfo.user_id),
  179. mine_status:this.status
  180. })
  181. if(res.code===200){
  182. let arr=res.data.List||[]
  183. this.list=[...this.list,...arr]
  184. if(arr.length===0){
  185. this.finished=true
  186. }
  187. }
  188. },
  189. //获取数量
  190. async getCount(){
  191. const res=await apiMyVoiceCount({author_id:this.$store.state.user.userInfo.user_id})
  192. if(res.code===200){
  193. this.statusOpt.forEach(item => {
  194. item.count=res.data[item.key]
  195. })
  196. }
  197. },
  198. //状态改变
  199. handleOptChange(item){
  200. this.status=item.value
  201. this.page=1
  202. this.list=[]
  203. this.finished=false
  204. this.getList()
  205. },
  206. //跳转详情
  207. handleGoDetail(item){
  208. if(item.PublishState==0){//未发布跳转编辑
  209. uni.navigateTo({
  210. url: '/pages-voice/addVoice?voiceId='+item.BroadcastId,
  211. });
  212. }else{
  213. uni.navigateTo({
  214. url: '/pages-voice/voiceDetail?voiceId='+item.BroadcastId,
  215. });
  216. }
  217. },
  218. //推送消息
  219. handleSendMsgItem(item){
  220. this.$dialog.confirm({
  221. title:'',
  222. message: '该操作将推送模板消息和客群,确认推送吗?',
  223. confirmButtonText:'确认'
  224. }).then(()=>{
  225. apiVoiceSendMsg({broadcast_id:item.BroadcastId}).then(res=>{
  226. if(res.code===200){
  227. uni.showToast({
  228. title:"推送成功",
  229. icon:'success'
  230. })
  231. item.CouldSendMsg=false
  232. }
  233. })
  234. }).catch(()=>{})
  235. },
  236. //删除音频
  237. handleDelItem(item){
  238. this.$dialog.confirm({
  239. title:'',
  240. message: '确定要删除该语音播报吗?',
  241. confirmButtonText:'确定'
  242. }).then(()=>{
  243. if(this.curVoiceId==item.BroadcastId&&!this.curAudioPaused){
  244. //删除的音频正好在播放则暂停
  245. this.globalBgMusic.stop()
  246. }
  247. apiVoiceDel({broadcast_id:Number(item.BroadcastId)}).then(res=>{
  248. if(res.code===200){
  249. uni.showToast({
  250. title:'操作成功',
  251. icon:'none'
  252. })
  253. this.page=1
  254. this.list=[]
  255. this.finished=false
  256. this.getList()
  257. this.getCount()
  258. }
  259. })
  260. }).catch(()=>{})
  261. },
  262. //未发布时点击立即发布并且推送
  263. handlePublish(item){
  264. this.$dialog.confirm({
  265. title:'',
  266. message: '该操作将发布并且推送模板消息和客群',
  267. confirmButtonText:'确认'
  268. }).then(async ()=>{
  269. const pubRes=await apiVoicePublish({
  270. broadcast_id:Number(item.BroadcastId),
  271. publish_type:1
  272. })
  273. if(pubRes.code===200){
  274. const sendRes=await apiVoiceSendMsg({broadcast_id:item.BroadcastId})
  275. if(sendRes.code===200){
  276. uni.showToast({
  277. title:'发布且推送成功',
  278. icon:'success'
  279. })
  280. setTimeout(() => {
  281. this.page=1
  282. this.list=[]
  283. this.finished=false
  284. this.getList()
  285. this.getCount()
  286. }, 1000);
  287. }else{
  288. uni.showToast({
  289. title:sendRes.msg,
  290. icon:'none'
  291. })
  292. }
  293. }else{
  294. uni.showToast({
  295. title:pubRes.msg,
  296. icon:'none'
  297. })
  298. }
  299. }).catch(()=>{})
  300. },
  301. //点击音频 播放或者暂停
  302. handlePlay(item){
  303. if(this.$store.state.audio.voiceId==item.BroadcastId){
  304. if(this.globalBgMusic.paused){
  305. this.globalBgMusic.play()
  306. }else{
  307. this.globalBgMusic.pause()
  308. }
  309. }else{
  310. const list=[{url:item.VoiceUrl,time:item.VoicePlaySeconds,title:item.BroadcastName,}]
  311. this.$store.commit('audio/addAudio',{
  312. list:list,
  313. voiceId:item.BroadcastId
  314. })
  315. this.handleVoicePlayRecord(item)
  316. }
  317. },
  318. //上报音频播放记录
  319. async handleVoicePlayRecord(item){
  320. const res=await apiVoicePlayRecord({
  321. broadcast_id:item.BroadcastId
  322. })
  323. if(res.code===200){
  324. console.log('上报音频播放记录');
  325. this.$store.commit('audio/addAudioRecordId',{recordId:res.data,source:2})
  326. }
  327. }
  328. },
  329. }
  330. </script>
  331. <style lang="scss" scoped>
  332. .empty-box{
  333. text-align: center;
  334. font-size: 32rpx;
  335. color: #999;
  336. padding-top: 150rpx;
  337. image{
  338. width: 600rpx;
  339. margin-bottom: 57rpx;
  340. }
  341. }
  342. .top-tab-warp{
  343. padding: 34rpx;
  344. position: sticky;
  345. top: 0;
  346. left: 0;
  347. background: #ffffff;
  348. z-index: 99;
  349. .item{
  350. box-sizing: border-box;
  351. width: 200rpx;
  352. text-align: center;
  353. padding: 20rpx 10rpx;
  354. background: #F5F5F5;
  355. border-radius: 4rpx;
  356. margin-right: 30rpx;
  357. display: inline-block;
  358. &:last-child{
  359. margin-right: 0;
  360. }
  361. }
  362. .item-active{
  363. background: #FDF8F2;
  364. color: #E3B377;
  365. }
  366. }
  367. .list-wrap{
  368. padding: 0 34rpx 34rpx 34rpx;
  369. .item{
  370. border-bottom: 1px solid #CDCDCD;
  371. padding: 30rpx 0;
  372. position: relative;
  373. .btns-box{
  374. position: absolute;
  375. bottom: 34rpx;
  376. right: 0;
  377. .btn{
  378. float: right;
  379. margin-left: 60rpx;
  380. background-color: transparent;
  381. line-height: 1;
  382. padding: 0;
  383. overflow: visible;
  384. &::after{
  385. border: none;
  386. }
  387. .publish-img{
  388. width: 34rpx;
  389. height: 34rpx;
  390. }
  391. .del-img{
  392. width: 34rpx;
  393. height: 34rpx;
  394. }
  395. .share-img{
  396. width: 32.5rpx;
  397. height: 32rpx;
  398. }
  399. .clock-img{
  400. width: 32rpx;
  401. height: 33.5rpx;
  402. }
  403. }
  404. }
  405. .title{
  406. font-size: 32rpx;
  407. }
  408. .time{
  409. font-size: 28rpx;
  410. color: #666;
  411. margin-top: 20rpx;
  412. margin-bottom: 30rpx;
  413. }
  414. .audio-box{
  415. width: 185rpx;
  416. height: 56rpx;
  417. align-items: center;
  418. justify-content: center;
  419. border-radius: 28rpx;
  420. background-color: #F4E1C9;
  421. color: #E3B377;
  422. image{
  423. width: 23rpx;
  424. height: 28rpx;
  425. margin-right: 20rpx;
  426. }
  427. }
  428. }
  429. }
  430. </style>