index.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <template>
  2. <view>
  3. <view v-if="renderDom.type === 'image'" class="image-message">
  4. <image :src="renderDom.imageUrl" mode="widthFix" class="msg-img" @click="previewImage"></image>
  5. </view>
  6. <view v-if="renderDom.type === 'video'" class="video-message" @click="playerHander">
  7. <image :src="renderDom.videoCover" mode="aspectFill" class="poster"></image>
  8. <image :src="`${assetsUrl}talk-playing.png`" mode="aspectFit" class="video-icon"></image>
  9. </view>
  10. <view v-if="renderDom.type === 'system'" class="system-message" @click="playerHander">
  11. <view class="err-title" v-if="renderDom.text!==''">
  12. {{renderDom.text}}
  13. </view>
  14. <view class="err-line">
  15. <text class="err-text">{{renderDom.context}}</text>
  16. <text class="err-text" @click="toPath(renderDom.highlightLink)" :style="{'color':`${renderDom.highlightColor}`}">
  17. {{renderDom.highlightContext}}
  18. </text>
  19. </view>
  20. </view>
  21. <view v-if="renderDom.type === 'notSupport'" class="message-body-span text-message">
  22. <view class="message-body-span-text">{{ renderDom[0].text }}</view>
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. import { formateTime } from '../../../base/common.js';
  28. export default {
  29. data() {
  30. return {
  31. renderDom:null,
  32. assetsUrl:this.$util.assetsUrl
  33. };
  34. },
  35. components: {},
  36. props: {
  37. message: {
  38. type: Object,
  39. default: () => {}
  40. },
  41. isMine: {
  42. type: Boolean,
  43. default: true
  44. }
  45. },
  46. watch: {
  47. message: {
  48. handler: function(newVal) {
  49. this.message=newVal;
  50. this.renderDom=this.parseCustom(newVal);
  51. },
  52. immediate: true,
  53. deep: true
  54. }
  55. },
  56. methods: {
  57. // 解析音视频通话消息
  58. extractCallingInfoFromMessage(message) {
  59. const callingmessage = JSON.parse(message.payload.data);
  60. if (callingmessage.businessID !== 1) {
  61. return '';
  62. }
  63. const objectData = JSON.parse(callingmessage.data);
  64. switch (callingmessage.actionType) {
  65. case 1: {
  66. if (objectData.call_end >= 0 && !callingmessage.groupID) {
  67. return `通话时长:${formateTime(objectData.call_end)}`;
  68. }
  69. if (callingmessage.groupID) {
  70. return '结束群聊';
  71. }
  72. if (objectData.data && objectData.data.cmd === 'switchToAudio') {
  73. return '切换语音通话';
  74. }
  75. if (objectData.data && objectData.data.cmd === 'switchToVideo') {
  76. return '切换视频通话';
  77. }
  78. return '发起通话';
  79. }
  80. case 2:
  81. return '取消通话';
  82. case 3:
  83. if (objectData.data && objectData.data.cmd === 'switchToAudio') {
  84. return '切换语音通话';
  85. }
  86. if (objectData.data && objectData.data.cmd === 'switchToVideo') {
  87. return '切换视频通话';
  88. }
  89. return '已接听';
  90. case 4:
  91. return '拒绝通话';
  92. case 5:
  93. if (objectData.data && objectData.data.cmd === 'switchToAudio') {
  94. return '切换语音通话';
  95. }
  96. if (objectData.data && objectData.data.cmd === 'switchToVideo') {
  97. return '切换视频通话';
  98. }
  99. return '无应答';
  100. default:
  101. return '';
  102. }
  103. },
  104. parseCustom(message) {
  105. // 约定自定义消息的 data 字段作为区分,不解析的不进行展示
  106. let data=JSON.parse(message.payload.data);
  107. console.log(data)
  108. if(data.type===5){
  109. const renderDom={
  110. type:'image',
  111. name:'custom',
  112. imageUrl:data.path,
  113. }
  114. return renderDom;
  115. }
  116. if(data.type===6){
  117. const renderDom={
  118. type:'video',
  119. name:'custom',
  120. videoUrl:data.path,
  121. videoCover:`${data.path}?x-oss-process=video/snapshot,w_0,h_0,t_10,ar_auto,f_jpg`,
  122. width:data.width,
  123. height:data.height
  124. }
  125. return renderDom;
  126. }
  127. if(data.type===99&&data.systemMsgType===10){
  128. const renderDom={
  129. type:'system',
  130. name:'custom',
  131. text:'该消息已被屏蔽',
  132. flow:'out',
  133. context:data.context.substring(0,data.context.indexOf(data.highlightContext)),
  134. link:`/pages/webview/webview?url=${this.$util.protocal.behaviorStandar}`,
  135. highlightColor:`#${data.highlightColor.substring(2)}`,
  136. highlightContext:data.highlightContext
  137. }
  138. return renderDom;
  139. }
  140. if(data.type===99&&data.systemMsgType===4){
  141. const renderDom={
  142. type:'system',
  143. name:'custom',
  144. text:'',
  145. flow:'out',
  146. context:data.context.substring(data.context.indexOf(data.highlightContext),data.context.length),
  147. link:`/pages/mine/album`,
  148. highlightColor:`#${data.highlightColor.substring(2)}`,
  149. highlightContext:data.highlightContext
  150. }
  151. return renderDom;
  152. }
  153. return {type: 'notSupport',text: '[自定义消息]'};
  154. },
  155. previewImage() {
  156. uni.previewImage({
  157. current: this.renderDom.imageUrl,
  158. // 当前显示图片的http链接
  159. urls: [this.renderDom.imageUrl]
  160. });
  161. },
  162. playerHander() {
  163. uni.$emit('videoPlayerHandler', {
  164. isPlay: true,
  165. message: this.renderDom
  166. });
  167. },
  168. stopHander() {
  169. this.isPlay = false;
  170. }
  171. }
  172. };
  173. </script>
  174. <style>
  175. @import './index.css';
  176. </style>