index.vue 6.3 KB

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