message-emoji-react.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <template>
  2. <div class="dialog-emoji" :class="env?.isH5?'dialog-emoji-h5':''" v-if="type === 'dropdown'">
  3. <div class="face-list collapse">
  4. <ul class="face-list-collapse">
  5. <li
  6. class="face-list-item"
  7. v-for="(childrenItem, childrenIndex) in emojiCollapseList"
  8. :key="childrenIndex"
  9. @click.stop="select(childrenItem)"
  10. >
  11. <img :src="emojiUrl + emojiMap[childrenItem]" />
  12. </li>
  13. </ul>
  14. <div class="face-list-button" @click.stop="isCollapse = !isCollapse">
  15. <i class="icon" :class="[isCollapse ? 'icon-expand' : 'icon-collapse']"></i>
  16. </div>
  17. </div>
  18. <ul class="face-list face-list-expand" v-show="!isCollapse">
  19. <li
  20. class="face-list-item"
  21. v-for="(childrenItem, childrenIndex) in emojiExpandList"
  22. :key="childrenIndex"
  23. @click.stop="select(childrenItem)"
  24. >
  25. <img :src="emojiUrl + emojiMap[childrenItem]" />
  26. </li>
  27. </ul>
  28. </div>
  29. <div v-if="type === 'content'" class="emoji-content">
  30. <ul class="emoji-react" ref="container">
  31. <li
  32. class="emoji-react-item"
  33. v-for="(val, key) in handleEmojiReact(message)"
  34. :key="key"
  35. v-show="val && val?.length"
  36. @click.stop="select(key)"
  37. >
  38. <img :src="emojiUrl + emojiMap[key]" />
  39. <div class="emoji-react-item-content">
  40. <span>{{ handleEmojiReactItem(val) }}</span>
  41. </div>
  42. </li>
  43. </ul>
  44. </div>
  45. </template>
  46. <script lang="ts">
  47. import { defineComponent, watch, reactive, toRefs, computed, ref, onMounted, nextTick } from 'vue';
  48. import TIM from '../../../../TUICore/tim';
  49. import { emojiUrl, emojiMap, emojiName } from '../utils/emojiMap';
  50. import { JSONToObject } from '../utils/utils';
  51. import TUIChat from '../index.vue';
  52. import { Message } from '@tencentcloud/chat';
  53. export default defineComponent({
  54. props: {
  55. message: {
  56. type: Object,
  57. default: () => ({}),
  58. },
  59. emojiList: {
  60. type: Array,
  61. default: () => [],
  62. },
  63. type: {
  64. type: String,
  65. default: '',
  66. },
  67. },
  68. emits: ['handleCollapse'],
  69. setup(props: any, ctx: any) {
  70. const { TUIServer } = TUIChat;
  71. const data = reactive({
  72. message: {} as Message,
  73. emojiUrl,
  74. emojiMap,
  75. emojiName,
  76. isCollapse: true,
  77. types: TIM.TYPES,
  78. env: TUIServer.TUICore.TUIEnv,
  79. type: props.type,
  80. emojiReacts: {},
  81. allMemberList: [],
  82. });
  83. const container = ref({} as HTMLElement);
  84. const emojiCollapseList = computed(() => {
  85. return data.emojiName.slice(0, 6);
  86. });
  87. const emojiExpandList = computed(() => {
  88. return data.emojiName.slice(6);
  89. });
  90. const select = (item: any) => {
  91. TUIServer.emojiReact(data.message, item);
  92. };
  93. const handleEmojiReact = (message: any) => {
  94. try {
  95. if (!message?.cloudCustomData) return;
  96. const reactList = JSONToObject(message?.cloudCustomData)?.messageReact?.reacts;
  97. if (!reactList) return;
  98. data.emojiReacts = reactList;
  99. return reactList;
  100. } catch (err) {
  101. console.warn(err);
  102. }
  103. };
  104. const handleEmojiReactItem = (userIDList: any) => {
  105. let res = '';
  106. userIDList?.forEach((item: any, index: any) => {
  107. const memberInfo = data.allMemberList?.find((member: any) => member.userID === item);
  108. res = res + (memberInfo ? (memberInfo as any)?.nick : item) + ', ';
  109. });
  110. if (res.length) res = res.substring(0, res.lastIndexOf(','));
  111. return res;
  112. };
  113. const handleAllMemberList = (message: any) => {
  114. const TUIChatStore = TUIServer?.currentStore;
  115. switch (message?.conversationType) {
  116. case TIM.TYPES.CONV_C2C:
  117. data.allMemberList = [
  118. {
  119. userID: TUIChatStore?.conversation?.userProfile?.userID,
  120. nick: TUIChatStore?.conversation?.userProfile?.nick,
  121. },
  122. {
  123. userID: TUIChatStore?.selfInfo?.userID,
  124. nick: TUIChatStore?.selfInfo?.nick,
  125. },
  126. ] as any;
  127. break;
  128. case TIM.TYPES.CONV_GROUP:
  129. data.allMemberList = TUIChatStore?.allMemberList?.memberList;
  130. break;
  131. default:
  132. break;
  133. }
  134. };
  135. watch(
  136. () => props.message,
  137. (newVal: any, oldVal: any) => {
  138. data.message = props.message;
  139. if (newVal?.conversationID !== oldVal?.conversationID) {
  140. handleAllMemberList(newVal);
  141. }
  142. },
  143. { deep: true, immediate: true }
  144. );
  145. watch(
  146. ()=>data.isCollapse,
  147. (newVal, oldVal) => {
  148. if (newVal === oldVal) return;
  149. if (!data?.env?.isH5) return;
  150. ctx.emit('handleCollapse', newVal);
  151. }
  152. )
  153. return {
  154. ...toRefs(data),
  155. emojiCollapseList,
  156. emojiExpandList,
  157. select,
  158. handleEmojiReact,
  159. handleEmojiReactItem,
  160. container,
  161. };
  162. },
  163. });
  164. </script>
  165. <style lang="scss" scoped>
  166. @import url('../../../styles/common.scss');
  167. @import url('../../../styles/icon.scss');
  168. .dialog-emoji {
  169. margin-left: 2px;
  170. background: #ffffff;
  171. border: 1px solid #e0e0e0;
  172. box-shadow: 0 4px 12px 0 rgba(0, 0, 0, 0.06);
  173. width: 242px;
  174. min-height: 28px;
  175. height: fit-content;
  176. padding: 2px 6px;
  177. word-break: keep-all;
  178. top: 30px;
  179. border-radius: 8px;
  180. &-h5{
  181. margin: 0 5px;
  182. border: none;
  183. border-bottom: 1px solid #e0e0e0;
  184. box-shadow: none;
  185. border-radius: 10px 10px 0 0;
  186. }
  187. .collapse {
  188. padding: 2px 0px;
  189. }
  190. .face-list {
  191. display: flex;
  192. overflow: hidden;
  193. flex-wrap: nowrap;
  194. flex-direction: row;
  195. &-collapse {
  196. display: flex;
  197. overflow: hidden;
  198. flex-wrap: nowrap;
  199. justify-content: space-between;
  200. align-items: center;
  201. flex: 1;
  202. }
  203. &-expand {
  204. border-top: 1px solid #e0e0e0;
  205. display: flex;
  206. overflow-x: hidden;
  207. flex-wrap: wrap;
  208. max-height: 90px;
  209. overflow-y: auto;
  210. }
  211. &-button {
  212. padding: 5px 7px;
  213. height: 20px;
  214. line-height: 20px;
  215. text-align: center;
  216. align-items: center;
  217. i {
  218. text-align: center;
  219. }
  220. }
  221. li {
  222. margin: 4px;
  223. display: flex;
  224. flex-direction: row;
  225. align-items: center;
  226. flex-direction: row;
  227. img {
  228. width: 22px;
  229. height: 22px;
  230. }
  231. }
  232. }
  233. }
  234. .emoji-content {
  235. .emoji-react {
  236. margin-top: 3px;
  237. display: flex;
  238. flex-direction: row;
  239. flex-wrap: wrap;
  240. align-items: center;
  241. &-item {
  242. width: fit-content;
  243. height: 20px;
  244. background: rgba(0, 0, 0, 0.05);
  245. border-radius: 12px;
  246. padding: 2px 6px;
  247. margin: 2px;
  248. overflow: hidden;
  249. text-overflow: ellipsis;
  250. max-width: 200px;
  251. display: flex;
  252. img {
  253. width: 16px;
  254. height: 16px;
  255. padding: 2px;
  256. }
  257. &-content {
  258. overflow: hidden;
  259. text-overflow: ellipsis;
  260. font-size: 10px;
  261. color: #999999;
  262. align-self: center;
  263. span {
  264. margin: 2px;
  265. font-size: 10px;
  266. color: #999999;
  267. overflow: hidden;
  268. text-overflow: ellipsis;
  269. white-space: nowrap;
  270. }
  271. }
  272. }
  273. }
  274. }
  275. </style>