voice.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <style>
  2. /**基本聊天数据**/
  3. .msg{padding: 20rpx;}
  4. .msg .msg-in{width: calc(100% - 160rpx); margin-left: 30rpx;}
  5. .msg .loading-msg{width:20px;height:20px;animation:rotate 1.5s linear infinite;margin-left: 20rpx;}
  6. .msg .msg-err{width:20px;height:20px;margin-left: 20rpx;}
  7. .msg .avatar{width: 80rpx;height: 80rpx;border-radius: 50%;overflow: hidden;margin-top: 6px;}
  8. .msg .avatar image{width: 80rpx;height: 80rpx;border-radius: 50%;}
  9. .msg .content{position: relative;min-height: 20px;font-size: 16px;background-color: #fff;max-width: calc(100% - 140rpx);padding: 20rpx;border-radius: 8rpx;word-break:break-all;display:inline-block;}
  10. .msg .content .i{width: 0;height: 0;left: -10px;position: absolute;border-top: 10px solid transparent; border-right: 10px solid #fff; border-bottom: 10px solid transparent;}
  11. .msg .content .vimg{max-width: 200rpx;}
  12. .msg .msg-in .emojis{width: 180rpx;}
  13. .msg .nickname{font-size: 12px;margin-bottom:6px;}
  14. .me-msg{padding: 20rpx;}
  15. .msg-in{width: calc(100% - 140rpx); margin-right: 20rpx;}
  16. .me-msg .loading-msg{width:20px;height:20px;animation:rotate 1.5s linear infinite;margin-right: 20rpx;}
  17. .me-msg .msg-err{width:20px;height:20px;margin-right: 20rpx;}
  18. .me-msg .avatar{width: 80rpx;height: 80rpx;border-radius: 50%;overflow: hidden;}
  19. .me-msg .avatar image{width: 80rpx;height: 80rpx;border-radius: 50%;}
  20. .me-msg .content{position: relative;min-height: 20px;font-size: 16px;background-color: #cceaff;max-width: calc(100% - 140rpx);padding: 20rpx;border-radius: 8rpx;word-break:break-all;display:inline-block;}
  21. .me-msg .content .i{width: 0;height: 0;right: -10px;position: absolute;border-top: 10px solid transparent; border-left: 10px solid #cceaff; border-bottom: 10px solid transparent;}
  22. .me-msg .content .vimg{max-width: 200rpx;}
  23. .me-msg .msg-in .emojis{width: 180rpx;}
  24. .me-msg .content .up{position: absolute;width: calc(100% - 40rpx);height: calc(100% - 40rpx);top: 20rpx;left: 20rpx; background: rgba(0,0,0,0.4);color: #fff; font-size: 14px;}
  25. .me-msg .nickname{font-size: 12px;margin-bottom:6px;margin-right: 6px;}
  26. /**结束**/
  27. </style>
  28. <template>
  29. <view>
  30. <view class="msg fx-r" v-if="item.sendUser.uid != user.uid">
  31. <view class="avatar" @longtap="tapLongUserItem" hover-class="avatar-hover"><image :src="utils.getAvatar(item.sendUser.avatar,'chat')" mode="aspectFill" ></image></view>
  32. <view class="msg-in">
  33. <view class="nickname">{{item.sendUser.nickname}}</view>
  34. <view class="content" @longtap="tapLongItem" @tap="playa">
  35. <view class="i"></view>
  36. <text style="color: 2c2c2c;,margin-right: 3rpx;margin-right: 60px;">{{parseInt(inItem.time/1000)}} "</text>
  37. <image v-if="playlyurl != inItem.filePath" src="/static/chat/yyy.png" style="width: 15px;height: 15px; margin-left:4px;" mode="widthFix"></image>
  38. <image v-if="playlyurl == inItem.filePath" src="/static/chat/yyy.gif" style="width: 15px;height: 15px; margin-left:4px;" mode="widthFix"></image>
  39. </view>
  40. </view>
  41. </view>
  42. <view class="me-msg fx-r fx-ae" v-else>
  43. <view class="msg-in fx-h fx-be fx-ae">
  44. <view class="nickname">{{item.sendUser.nickname}}</view>
  45. <view class="msg-in fx-r fx-bc fx-ae">
  46. <image v-if="item.isSend == 0" class="loading-msg" src="/static/chat/xloading.png"></image>
  47. <image v-if="item.isSend == -1" @tap="tapRsend" class="msg-err" src="/static/chat/waring.png"></image>
  48. <view class="content" @longtap="tapLongItem" @tap="playa">
  49. <view class="i"></view>
  50. <text style="color: 2c2c2c;,margin-right: 3rpx;margin-right: 60px;">{{parseInt(inItem.time/1000)}} "</text>
  51. <image v-if="playlyurl != inItem.filePath" src="/static/chat/yyy.png" style="width: 15px;height: 15px; margin-left:4px;" mode="widthFix"></image>
  52. <image v-if="playlyurl == inItem.filePath" src="/static/chat/yyy.gif" style="width: 15px;height: 15px; margin-left:4px;" mode="widthFix"></image>
  53. </view>
  54. </view>
  55. </view>
  56. <view class="avatar" hover-class="avatar-hover"><image :src="utils.getAvatar(item.sendUser.avatar,'chat')" mode="aspectFill" ></image></view>
  57. </view>
  58. </view>
  59. </template>
  60. <script>
  61. import {mapState,mapMutations } from 'vuex';
  62. export default {
  63. computed: mapState(['user','sysData']),
  64. name: 'voice',
  65. props:{
  66. item : {
  67. type: Object,
  68. default: ()=>{return {data:{}} }
  69. }
  70. },
  71. watch:{
  72. item:{
  73. immediate:true,
  74. handler(val) {
  75. if(this.utils.isJSON(val.data)) {
  76. this.inItem = JSON.parse(val.data);
  77. } else {
  78. this.inItem = {};
  79. }
  80. }
  81. }
  82. },
  83. data() {
  84. return{
  85. playlyurl:""
  86. }
  87. },
  88. created() {
  89. //console.log(this.item);
  90. },
  91. mounted() {
  92. },
  93. methods: {
  94. tapRsend:function() {
  95. this.$emit('rsend',this.item);
  96. },
  97. tapLongItem:function(ev){
  98. this.$emit('longItem',{
  99. dom : ev,
  100. data : this.item
  101. });
  102. },
  103. playa:function(){
  104. var innerAudioContext = uni.createInnerAudioContext();
  105. innerAudioContext.autoplay = true;
  106. if(this.playlyurl == this.inItem.filePath){
  107. this.playlyurl = ''
  108. innerAudioContext.stop()
  109. }else{
  110. this.playlyurl = this.inItem.filePath
  111. innerAudioContext.src = this.inItem.filePath
  112. innerAudioContext.play()
  113. innerAudioContext.onEnded(()=>{
  114. this.playlyurl = ''
  115. })
  116. }
  117. },
  118. tapLongUserItem:function(ev){
  119. this.$emit('longUserItem',{
  120. dom : ev,
  121. data : this.item
  122. });
  123. },
  124. tapUser:function(type){
  125. this.$emit('userItem',type == 0 ? this.user.uid : this.item.sendUser.uid);
  126. }
  127. }
  128. }
  129. </script>