message-plugin-layout.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <template>
  2. <div class="message-plugin">
  3. <!-- The following is displayed in the form of messageTip -->
  4. <div
  5. v-if="props.showStyle === 'tip'"
  6. class="message-plugin-tip"
  7. >
  8. <slot name="messageTip" />
  9. </div>
  10. <!-- The following is displayed in the form of messageBubble -->
  11. <div
  12. v-else-if="props.showStyle === 'bubble'"
  13. class="message-plugin-bubble-content"
  14. @longpress="handleToggleMessageItem($event, messageModel, true)"
  15. @click.prevent.right="handleToggleMessageItem($event, messageModel)"
  16. @touchstart="handleH5LongPress($event, messageModel, 'touchstart')"
  17. @touchend="handleH5LongPress($event, messageModel, 'touchend')"
  18. @mouseover="handleH5LongPress($event, messageModel, 'touchend')"
  19. >
  20. <MessageBubble
  21. :messageItem="messageModel"
  22. :content="messageModel.getMessageContent()"
  23. :blinkMessageIDList="props.blinkMessageIDList"
  24. :classNameList="props.bubbleClassNameList"
  25. @resendMessage="resendMessage(messageModel)"
  26. >
  27. <!-- web message-bubble is a named slot, content area slotName is messageElement -->
  28. <template #messageElement>
  29. <slot
  30. v-if="!isUniFrameWork"
  31. name="messageBubble"
  32. />
  33. </template>
  34. <!-- uni-app message-bubble is an anonymous slot, no slotName -->
  35. <slot
  36. v-if="isUniFrameWork"
  37. name="messageBubble"
  38. />
  39. </MessageBubble>
  40. </div>
  41. </div>
  42. </template>
  43. <script lang="ts" setup>
  44. import { computed } from '../../adapter-vue';
  45. import { TUIStore, IMessageModel } from '@tencentcloud/chat-uikit-engine';
  46. import MessageBubble from '../../components/TUIChat/message-list/message-elements/message-bubble.vue';
  47. import { isUniFrameWork } from '../../utils/env';
  48. interface IProps {
  49. message: IMessageModel;
  50. showStyle: string;
  51. bubbleClassNameList?: string[];
  52. blinkMessageIDList?: string[];
  53. }
  54. const props = withDefaults(defineProps<IProps>(), {
  55. message: () => ({} as IMessageModel),
  56. showStyle: '',
  57. bubbleClassNameList: () => [] as string[],
  58. blinkMessageIDList: () => [] as string[],
  59. });
  60. const emits = defineEmits(['resendMessage', 'handleToggleMessageItem', 'handleH5LongPress']);
  61. const messageModel = computed(() => TUIStore.getMessageModel(props.message?.ID));
  62. // The following is for external interaction such as messageTool, no special processing is required, do not change
  63. const resendMessage = (message: IMessageModel) => {
  64. emits('resendMessage', message);
  65. };
  66. const handleToggleMessageItem = (e: any, message: IMessageModel, isLongpress = false) => {
  67. emits('handleToggleMessageItem', e, message, isLongpress);
  68. };
  69. const handleH5LongPress = (e: any, message: IMessageModel, type: string) => {
  70. emits('handleH5LongPress', e, message, type);
  71. };
  72. </script>
  73. <style lang="scss" scoped>
  74. .message-plugin-tip {
  75. color: #999;
  76. font-size: 12px;
  77. overflow-wrap: anywhere;
  78. display: flex;
  79. place-content: center center;
  80. align-items: center;
  81. text-align: center;
  82. margin: 0 10px 10px;
  83. }
  84. .message-tip-highlight {
  85. animation: highlight 1000ms infinite;
  86. @keyframes highlight {
  87. 50% {
  88. color: #ff9c19;
  89. }
  90. }
  91. @keyframes highlight {
  92. 50% {
  93. color: #ff9c19;
  94. }
  95. }
  96. }
  97. :deep(.message-bubble-room) {
  98. .message-bubble-main-content {
  99. .message-body {
  100. .message-body-main {
  101. .message-body-content {
  102. &.content-in,
  103. &.content-out {
  104. background-color: transparent;
  105. border-radius: 0;
  106. padding: 0;
  107. }
  108. }
  109. }
  110. }
  111. }
  112. }
  113. </style>