message-plugin.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <MessagePluginLayout
  3. :message="props.message"
  4. :showStyle="pluginMessageType.showStyle"
  5. :bubbleClassNameList="[pluginMessageType.pluginType === 'room' ? 'message-bubble-room':'']"
  6. @resendMessage="resendMessage"
  7. @handleToggleMessageItem="handleToggleMessageItem"
  8. @handleH5LongPress="handleH5LongPress"
  9. >
  10. <template #messageTip>
  11. <MessageCallGroup
  12. :message="props.message"
  13. :signalingInfo="messageSignalingInfo"
  14. :customContent="messageCustomContent"
  15. :blinkMessageIDList="props.blinkMessageIDList"
  16. />
  17. </template>
  18. <template #messageBubble>
  19. <MessageCallC2C
  20. v-if="pluginMessageType.pluginType === 'call'"
  21. :message="props.message"
  22. :signalingInfo="messageSignalingInfo"
  23. :customContent="messageCustomContent"
  24. />
  25. <MessageCustomerService
  26. v-if="pluginMessageType.pluginType === 'customer'"
  27. :message="props.message"
  28. />
  29. <MessageRoom
  30. v-if="pluginMessageType.pluginType === 'room'"
  31. :message="props.message"
  32. />
  33. </template>
  34. </MessagePluginLayout>
  35. </template>
  36. <script lang="ts" setup>
  37. import { computed } from '../../adapter-vue';
  38. import { TUIStore } from '@tencentcloud/chat-uikit-engine';
  39. import TUIChatEngine, { IMessageModel } from '@tencentcloud/chat-uikit-engine';
  40. import {
  41. isCustomerServicePluginMessage,
  42. isCustomServiceMessageInvisible,
  43. } from './message-customer/index';
  44. import { isCallMessage, isRoomCardMessage } from './index';
  45. import MessagePluginLayout from './message-plugin-layout.vue';
  46. import MessageCallGroup from './message-call/message-call-group.vue';
  47. import MessageCallC2C from './message-call/message-call-c2c.vue';
  48. import MessageCustomerService from './message-customer/message-customer-service.vue';
  49. // If TUIRoom is not integrated, please introduce the following path
  50. import MessageRoom from './message-room/message-room-default.vue';
  51. // After integrating TUIRoom, please comment the above path and open the following path to import
  52. // import MessageRoom from './message-room/message-room.vue';
  53. interface IProps {
  54. message: IMessageModel;
  55. blinkMessageIDList?: string[];
  56. }
  57. const props = withDefaults(defineProps<IProps>(), {
  58. message: () => ({} as IMessageModel),
  59. blinkMessageIDList: () => [] as string[],
  60. });
  61. const emits = defineEmits(['resendMessage', 'handleToggleMessageItem', 'handleH5LongPress']);
  62. const messageModel = computed(() => TUIStore.getMessageModel(props.message.ID));
  63. const messageSignalingInfo = computed(() => messageModel?.value?.getSignalingInfo());
  64. const messageCustomContent = computed(() => messageModel?.value?.getMessageContent());
  65. const pluginMessageType = computed<{ pluginType: string; showStyle: string }>(() => {
  66. let typeObj = { pluginType: '', showStyle: '' };
  67. if (isCallMessage(messageModel.value)) {
  68. typeObj = {
  69. pluginType: 'call',
  70. showStyle:
  71. messageModel.value?.conversationType === TUIChatEngine.TYPES.CONV_GROUP ? 'tip' : 'bubble',
  72. };
  73. } else if (isRoomCardMessage(messageModel.value)) {
  74. typeObj = {
  75. pluginType: 'room',
  76. showStyle: 'bubble',
  77. };
  78. } else if (isCustomerServicePluginMessage(messageModel.value)) {
  79. typeObj = {
  80. pluginType: 'customer',
  81. showStyle: isCustomServiceMessageInvisible(messageModel.value) ? '' : 'bubble',
  82. };
  83. }
  84. return typeObj;
  85. });
  86. // The following are for external interaction such as messageTool, no special processing is required, please do not touch
  87. const resendMessage = (message: IMessageModel) => {
  88. emits('resendMessage', message);
  89. };
  90. const handleToggleMessageItem = (e: any, message: IMessageModel, isLongpress = false) => {
  91. emits('handleToggleMessageItem', e, message, isLongpress);
  92. };
  93. const handleH5LongPress = (e: any, message: IMessageModel, type: string) => {
  94. emits('handleH5LongPress', e, message, type);
  95. };
  96. </script>
  97. <style lang="scss" scoped>
  98. /* stylelint-disable-next-line no-empty-source */
  99. </style>