myVoice.vue 15 KB

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