index.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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.link)" :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. toPath(path){
  58. console.log(path)
  59. uni.navigateTo({
  60. url:path
  61. })
  62. },
  63. // 解析音视频通话消息
  64. extractCallingInfoFromMessage(message) {
  65. const callingmessage = JSON.parse(message.payload.data);
  66. if (callingmessage.businessID !== 1) {
  67. return '';
  68. }
  69. const objectData = JSON.parse(callingmessage.data);
  70. switch (callingmessage.actionType) {
  71. case 1: {
  72. if (objectData.call_end >= 0 && !callingmessage.groupID) {
  73. return `通话时长:${formateTime(objectData.call_end)}`;
  74. }
  75. if (callingmessage.groupID) {
  76. return '结束群聊';
  77. }
  78. if (objectData.data && objectData.data.cmd === 'switchToAudio') {
  79. return '切换语音通话';
  80. }
  81. if (objectData.data && objectData.data.cmd === 'switchToVideo') {
  82. return '切换视频通话';
  83. }
  84. return '发起通话';
  85. }
  86. case 2:
  87. return '取消通话';
  88. case 3:
  89. if (objectData.data && objectData.data.cmd === 'switchToAudio') {
  90. return '切换语音通话';
  91. }
  92. if (objectData.data && objectData.data.cmd === 'switchToVideo') {
  93. return '切换视频通话';
  94. }
  95. return '已接听';
  96. case 4:
  97. return '拒绝通话';
  98. case 5:
  99. if (objectData.data && objectData.data.cmd === 'switchToAudio') {
  100. return '切换语音通话';
  101. }
  102. if (objectData.data && objectData.data.cmd === 'switchToVideo') {
  103. return '切换视频通话';
  104. }
  105. return '无应答';
  106. default:
  107. return '';
  108. }
  109. },
  110. parseCustom(message) {
  111. // 约定自定义消息的 data 字段作为区分,不解析的不进行展示
  112. let data=JSON.parse(message.payload.data);
  113. console.log(message)
  114. if(data.type===5){
  115. const renderDom={
  116. type:'image',
  117. name:'custom',
  118. imageUrl:data.path,
  119. }
  120. return renderDom;
  121. }
  122. if(data.type===6){
  123. const renderDom={
  124. type:'video',
  125. name:'custom',
  126. videoUrl:data.path,
  127. videoCover:`${data.path}?x-oss-process=video/snapshot,w_0,h_0,t_10,ar_auto,f_jpg`,
  128. width:data.width,
  129. height:data.height
  130. }
  131. return renderDom;
  132. }
  133. if(data.type===99){
  134. if(data.systemMsgType===10){
  135. const renderDom={
  136. type:'system',
  137. name:'custom',
  138. text:data.context,
  139. flow:'out',
  140. context:data.context.substring(0,data.context.indexOf(data.highlightContext)),
  141. link:`/pages/webview/webview?url=${this.$util.protocal.behaviorStandar}`,
  142. highlightColor:`#${data.highlightColor.substring(2)}`,
  143. highlightContext:data.highlightContext
  144. }
  145. return renderDom;
  146. }
  147. if(data.systemMsgType===4){
  148. const renderDom={
  149. type:'system',
  150. name:'custom',
  151. text:'',
  152. flow:'out',
  153. context:data.context.substring(data.context.indexOf(data.highlightContext),data.context.length),
  154. link:`/pages/mine/album`,
  155. highlightColor:`#${data.highlightColor.substring(2)}`,
  156. highlightContext:data.highlightContext
  157. }
  158. return renderDom;
  159. }
  160. if(data.systemMsgType===3){
  161. const renderDom={
  162. type:'system',
  163. name:'custom',
  164. text:'',
  165. flow:'out',
  166. context:data.context,
  167. }
  168. return renderDom;
  169. }
  170. }
  171. return {type: 'notSupport',text: '[自定义消息]'};
  172. },
  173. previewImage() {
  174. uni.previewImage({
  175. current: this.renderDom.imageUrl,
  176. // 当前显示图片的http链接
  177. urls: [this.renderDom.imageUrl]
  178. });
  179. },
  180. playerHander() {
  181. uni.$emit('videoPlayerHandler', {
  182. isPlay: true,
  183. message: this.renderDom
  184. });
  185. },
  186. stopHander() {
  187. this.isPlay = false;
  188. }
  189. }
  190. };
  191. </script>
  192. <style>
  193. @import './index.css';
  194. </style>