index.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <template>
  2. <view>
  3. <view v-if="renderDom[0].type === 'order'" :class="'custom-message ' + (isMine ? 'my-custom' : '')">
  4. <image class="custom-image" :src="renderDom[0].imageUrl"></image>
  5. <view class="custom-content">
  6. <view class="custom-content-title">{{ renderDom[0].title }}</view>
  7. <view class="custom-content-description">{{ renderDom[0].description }}</view>
  8. <view class="custom-content-price">{{ renderDom[0].price }}</view>
  9. </view>
  10. </view>
  11. <view v-if="renderDom[0].type === 'consultion'" :class="'custom-message ' + (isMine ? 'my-custom' : '')">
  12. <view class="custom-content">
  13. <view class="custom-content-title">{{ renderDom[0].title }}</view>
  14. <view v-for="(item, index) in renderDom[0].item" :key="index" class="custom-content-description" :id="item.key">{{ item.key }}</view>
  15. <view class="custom-content-description">{{ renderDom[0].description }}</view>
  16. </view>
  17. </view>
  18. <view v-if="renderDom[0].type === 'evaluation'" :class="'custom-message ' + (isMine ? 'my-custom' : '')">
  19. <view class="custom-content">
  20. <view class="custom-content-title">{{ renderDom[0].title }}</view>
  21. <view class="custom-content-score">
  22. <image v-for="(item, index) in renderDom[0].score" :key="index" class="score-star" src="/static/images/star.png"></image>
  23. </view>
  24. <view class="custom-content-description">{{ renderDom[0].description }}</view>
  25. </view>
  26. </view>
  27. <view v-if="renderDom[0].type === 'group_create'" :class="'custom-message ' + (isMine ? 'my-custom' : '')">
  28. <view class="custom-content-text">{{ renderDom[0].text }}</view>
  29. </view>
  30. <view v-if="renderDom[0].type === 'c2cCalling' || renderDom[0].type === 'groupCalling'" :class="'custom-message ' + (isMine ? 'my-custom' : '')">
  31. <view class="custom-content-text">{{ renderDom[0].text }}</view>
  32. </view>
  33. <view v-if="renderDom[0].type === 'notSupport'" class="message-body-span text-message">
  34. <view class="message-body-span-text">{{ renderDom[0].text }}</view>
  35. </view>
  36. <view v-if="renderDom[0].type === 'finish'" :class="'custom-message ' + (isMine ? 'my-custom' : '')">
  37. <view class="custom-content-text">{{ renderDom[0].text }}</view>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. import { formateTime } from '../../../base/common.js';
  43. export default {
  44. data() {
  45. return {};
  46. },
  47. components: {},
  48. props: {
  49. message: {
  50. type: Object,
  51. default: () => {}
  52. },
  53. isMine: {
  54. type: Boolean,
  55. default: true
  56. }
  57. },
  58. watch: {
  59. message: {
  60. handler: function(newVal) {
  61. this.setData({
  62. message: newVal,
  63. renderDom: this.parseCustom(newVal)
  64. });
  65. },
  66. immediate: true,
  67. deep: true
  68. }
  69. },
  70. methods: {
  71. // 解析音视频通话消息
  72. extractCallingInfoFromMessage(message) {
  73. const callingmessage = JSON.parse(message.payload.data);
  74. if (callingmessage.businessID !== 1) {
  75. return '';
  76. }
  77. const objectData = JSON.parse(callingmessage.data);
  78. switch (callingmessage.actionType) {
  79. case 1: {
  80. if (objectData.call_end >= 0 && !callingmessage.groupID) {
  81. return `通话时长:${formateTime(objectData.call_end)}`;
  82. }
  83. if (callingmessage.groupID) {
  84. return '结束群聊';
  85. }
  86. if (objectData.data && objectData.data.cmd === 'switchToAudio') {
  87. return '切换语音通话';
  88. }
  89. if (objectData.data && objectData.data.cmd === 'switchToVideo') {
  90. return '切换视频通话';
  91. }
  92. return '发起通话';
  93. }
  94. case 2:
  95. return '取消通话';
  96. case 3:
  97. if (objectData.data && objectData.data.cmd === 'switchToAudio') {
  98. return '切换语音通话';
  99. }
  100. if (objectData.data && objectData.data.cmd === 'switchToVideo') {
  101. return '切换视频通话';
  102. }
  103. return '已接听';
  104. case 4:
  105. return '拒绝通话';
  106. case 5:
  107. if (objectData.data && objectData.data.cmd === 'switchToAudio') {
  108. return '切换语音通话';
  109. }
  110. if (objectData.data && objectData.data.cmd === 'switchToVideo') {
  111. return '切换视频通话';
  112. }
  113. return '无应答';
  114. default:
  115. return '';
  116. }
  117. },
  118. parseCustom(message) {
  119. // 约定自定义消息的 data 字段作为区分,不解析的不进行展示
  120. if (message.payload.data === 'order') {
  121. const extension = JSON.parse(message.payload.extension);
  122. const renderDom = [
  123. {
  124. type: 'order',
  125. name: 'custom',
  126. title: extension.title || '',
  127. imageUrl: extension.imageUrl || '',
  128. price: extension.price || 0,
  129. description: message.payload.description
  130. }
  131. ];
  132. return renderDom;
  133. } // 客服咨询
  134. if (message.payload.data === 'consultion') {
  135. const extension = JSON.parse(message.payload.extension);
  136. const renderDom = [
  137. {
  138. type: 'consultion',
  139. title: extension.title || '',
  140. item: extension.item || 0,
  141. description: extension.description
  142. }
  143. ];
  144. return renderDom;
  145. } // 服务评价
  146. if (message.payload.data === 'evaluation') {
  147. const extension = JSON.parse(message.payload.extension);
  148. const renderDom = [
  149. {
  150. type: 'evaluation',
  151. title: message.payload.description,
  152. score: extension.score,
  153. description: extension.comment
  154. }
  155. ];
  156. return renderDom;
  157. } // 群消息解析
  158. // 群消息解析
  159. if (message.payload.data === 'group_create') {
  160. const renderDom = [
  161. {
  162. type: 'group_create',
  163. text: message.payload.extension
  164. }
  165. ];
  166. return renderDom;
  167. }
  168. if (message.payload.data === 'finish') {
  169. console.log(111)
  170. const renderDom = [
  171. {
  172. type: 'finish',
  173. text: message.payload.extension
  174. }
  175. ];
  176. return renderDom;
  177. }
  178. // 音视频通话消息解析
  179. const callingmessage = JSON.parse(message.payload.data);
  180. if (callingmessage.businessID === 1) {
  181. if (message.conversationType === 'GROUP') {
  182. if (message.payload.data.actionType === 5) {
  183. message.nick = message.payload.data.inviteeList ? message.payload.data.inviteeList.join(',') : message.from;
  184. }
  185. const _text = this.extractCallingInfoFromMessage(message);
  186. const groupText = `${_text}`;
  187. const renderDom = [
  188. {
  189. type: 'groupCalling',
  190. text: groupText,
  191. userIDList: []
  192. }
  193. ];
  194. return renderDom;
  195. }
  196. if (message.conversationType === 'C2C') {
  197. const c2cText = this.extractCallingInfoFromMessage(message);
  198. const renderDom = [
  199. {
  200. type: 'c2cCalling',
  201. text: c2cText
  202. }
  203. ];
  204. return renderDom;
  205. }
  206. }
  207. if (message.payload.data === 'group_create') {
  208. const renderDom = [
  209. {
  210. type: 'group_create',
  211. text: message.payload.extension
  212. }
  213. ];
  214. return renderDom;
  215. }
  216. return [
  217. {
  218. type: 'notSupport',
  219. text: '[自定义消息]'
  220. }
  221. ];
  222. }
  223. }
  224. };
  225. </script>
  226. <style>
  227. @import './index.css';
  228. </style>