emoji-picker-dialog.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <template>
  2. <div
  3. ref="emojiPickerDialog"
  4. :class="{
  5. 'emoji-picker': true,
  6. 'emoji-picker-h5': !isPC
  7. }"
  8. >
  9. <ul
  10. ref="emojiPickerListRef"
  11. :class="['emoji-picker-list', !isPC && 'emoji-picker-h5-list']"
  12. >
  13. <li
  14. v-for="(childrenItem, childrenIndex) in currentEmojiList"
  15. :key="childrenIndex"
  16. class="emoji-picker-list-item"
  17. @click="select(childrenItem, childrenIndex)"
  18. >
  19. <img
  20. v-if="currentTabItem.type === EMOJI_TYPE.BASIC"
  21. class="emoji"
  22. :src="currentTabItem.url + basicEmojiMap[childrenItem]"
  23. >
  24. <img
  25. v-else-if="currentTabItem.type === EMOJI_TYPE.BIG"
  26. class="emoji-big"
  27. :src="currentTabItem.url + childrenItem + '@2x.png'"
  28. >
  29. <img
  30. v-else
  31. class="emoji-custom"
  32. :src="currentTabItem.url + childrenItem"
  33. >
  34. </li>
  35. </ul>
  36. <ul class="emoji-picker-tab">
  37. <li
  38. v-for="(item, index) in list"
  39. :key="index"
  40. class="emoji-picker-tab-item"
  41. @click="toggleEmojiTab(index)"
  42. >
  43. <Icon
  44. v-if="item.type === EMOJI_TYPE.BASIC"
  45. class="icon"
  46. :file="faceIcon"
  47. />
  48. <img
  49. v-else-if="item.type === EMOJI_TYPE.BIG"
  50. class="icon-big"
  51. :src="item.url + item.list[0] + '@2x.png'"
  52. >
  53. <img
  54. v-else
  55. class="icon-custom"
  56. :src="item.url + item.list[0]"
  57. >
  58. </li>
  59. <li
  60. v-if="isUniFrameWork"
  61. class="send-btn"
  62. @click="sendMessage"
  63. >
  64. 发送
  65. </li>
  66. </ul>
  67. </div>
  68. </template>
  69. <script lang="ts" setup>
  70. import { ref, onMounted, onUnmounted } from '../../../../adapter-vue';
  71. import {
  72. TUIChatService,
  73. TUIStore,
  74. StoreName,
  75. IConversationModel,
  76. SendMessageParams,
  77. } from '@tencentcloud/chat-uikit-engine';
  78. import Icon from '../../../common/Icon.vue';
  79. import faceIcon from '../../../../assets/icon/face.png';
  80. import { EMOJI_TYPE } from '.././../../../constant';
  81. import { isPC, isUniFrameWork } from '../../../../utils/env';
  82. import { IEmojiList, IEmojiListItem } from '../../../../interface';
  83. import { isEnabledMessageReadReceiptGlobal } from '../../utils/utils';
  84. import { emojiList, basicEmojiMap, basicEmojiList } from '../../utils/emojiList';
  85. const emits = defineEmits(['insertEmoji', 'onClose', 'sendMessage']);
  86. const list = ref<IEmojiList>(emojiList);
  87. const currentTabIndex = ref<number>(0);
  88. const currentTabItem = ref<IEmojiListItem>(list?.value[0]);
  89. const currentEmojiList = ref<string[]>(list?.value[0]?.list);
  90. const currentConversation = ref();
  91. const emojiPickerDialog = ref();
  92. const emojiPickerListRef = ref();
  93. onMounted(() => {
  94. TUIStore.watch(StoreName.CONV, {
  95. currentConversation: onCurrentConversationUpdate,
  96. });
  97. });
  98. onUnmounted(() => {
  99. TUIStore.unwatch(StoreName.CONV, {
  100. currentConversation: onCurrentConversationUpdate,
  101. });
  102. });
  103. const toggleEmojiTab = (index: number) => {
  104. currentTabIndex.value = index;
  105. currentTabItem.value = list?.value[index];
  106. currentEmojiList.value = list?.value[index]?.list;
  107. // 滚动条回滚到顶部
  108. // 原生 web & h5
  109. if (!isUniFrameWork) {
  110. emojiPickerListRef?.value && (emojiPickerListRef.value.scrollTop = 0);
  111. }
  112. };
  113. const select = (item: any, index: number) => {
  114. const options: any = {
  115. emoji: { key: item, name: basicEmojiList[item] },
  116. type: currentTabItem?.value?.type,
  117. };
  118. switch (currentTabItem?.value?.type) {
  119. case EMOJI_TYPE.BASIC:
  120. options.url = currentTabItem?.value?.url + basicEmojiMap[item];
  121. if (isUniFrameWork) {
  122. uni.$emit('insert-emoji', options);
  123. } else {
  124. emits('insertEmoji', options);
  125. }
  126. break;
  127. case EMOJI_TYPE.BIG:
  128. sendFaceMessage(index, currentTabItem.value);
  129. break;
  130. case EMOJI_TYPE.CUSTOM:
  131. sendFaceMessage(index, currentTabItem.value);
  132. break;
  133. default:
  134. break;
  135. }
  136. isPC && emits('onClose');
  137. };
  138. const sendFaceMessage = (index: number, listItem: IEmojiListItem) => {
  139. const options = {
  140. to:
  141. currentConversation?.value?.groupProfile?.groupID
  142. || currentConversation?.value?.userProfile?.userID,
  143. conversationType: currentConversation?.value?.type,
  144. payload: {
  145. index: listItem.index,
  146. data: listItem.list[index],
  147. },
  148. needReadReceipt: isEnabledMessageReadReceiptGlobal(),
  149. } as SendMessageParams;
  150. TUIChatService.sendFaceMessage(options);
  151. };
  152. function sendMessage() {
  153. uni.$emit('send-message-in-emoji-picker');
  154. }
  155. function onCurrentConversationUpdate(conversation: IConversationModel) {
  156. currentConversation.value = conversation;
  157. }
  158. </script>
  159. <style lang="scss" scoped src="./style/index.scss"></style>