message-plugin.vue 3.8 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. // 未集成 TUIRoom 时,请引入以下路径
  50. import MessageRoom from './message-room/message-room-default.vue';
  51. // 集成 TUIRoom 后,请注释以上路径,放开以下路径引入
  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. // 需要展示 ui 的判断逻辑
  66. const pluginMessageType = computed<{ pluginType: string; showStyle: string }>(() => {
  67. let typeObj = { pluginType: '', showStyle: '' };
  68. if (isCallMessage(messageModel.value)) {
  69. typeObj = {
  70. pluginType: 'call',
  71. showStyle:
  72. messageModel.value?.conversationType === TUIChatEngine.TYPES.CONV_GROUP ? 'tip' : 'bubble',
  73. };
  74. } else if (isRoomCardMessage(messageModel.value)) {
  75. typeObj = {
  76. pluginType: 'room',
  77. showStyle: 'bubble',
  78. };
  79. } else if (isCustomerServicePluginMessage(messageModel.value)) {
  80. typeObj = {
  81. pluginType: 'customer',
  82. showStyle: isCustomServiceMessageInvisible(messageModel.value) ? '' : 'bubble',
  83. };
  84. }
  85. return typeObj;
  86. });
  87. // 以下为messageTool等外部交互使用,无需特殊处理,勿动
  88. const resendMessage = (message: IMessageModel) => {
  89. emits('resendMessage', message);
  90. };
  91. const handleToggleMessageItem = (e: any, message: IMessageModel, isLongpress = false) => {
  92. emits('handleToggleMessageItem', e, message, isLongpress);
  93. };
  94. const handleH5LongPress = (e: any, message: IMessageModel, type: string) => {
  95. emits('handleH5LongPress', e, message, type);
  96. };
  97. </script>
  98. <style lang="scss" scoped>
  99. /* stylelint-disable-next-line no-empty-source */
  100. </style>