emojiList.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { IEmojiList } from '../../../interface';
  2. import { EMOJI_TYPE } from '../../../constant';
  3. import { emojiConfig } from './emoji-config';
  4. export const basicEmojiUrl = emojiConfig.emojiBaseUrl;
  5. export const basicEmojiMap = emojiConfig.emojiUrlMapping;
  6. export const basicEmojiList = emojiConfig.emojiNameMapping;
  7. export const basicEmojiKey = emojiConfig.emojiKeyMapping;
  8. export const bigEmojiUrl = 'https://web.sdk.qcloud.com/im/assets/face-elem/';
  9. export const bigEmojiList: Array<any> = [
  10. {
  11. type: EMOJI_TYPE.BIG,
  12. index: 1,
  13. url: bigEmojiUrl,
  14. list: ['yz00', 'yz01', 'yz02', 'yz03', 'yz04', 'yz05', 'yz06', 'yz07', 'yz08',
  15. 'yz09', 'yz10', 'yz11', 'yz12', 'yz13', 'yz14', 'yz15', 'yz16', 'yz17'],
  16. },
  17. {
  18. type: EMOJI_TYPE.BIG,
  19. index: 2,
  20. url: bigEmojiUrl,
  21. list: ['ys00', 'ys01', 'ys02', 'ys03', 'ys04', 'ys05', 'ys06', 'ys07', 'ys08',
  22. 'ys09', 'ys10', 'ys11', 'ys12', 'ys13', 'ys14', 'ys15'],
  23. },
  24. {
  25. type: EMOJI_TYPE.BIG,
  26. index: 3,
  27. url: bigEmojiUrl,
  28. list: ['gcs00', 'gcs01', 'gcs02', 'gcs03', 'gcs04', 'gcs05', 'gcs06', 'gcs07',
  29. 'gcs08', 'gcs09', 'gcs10', 'gcs11', 'gcs12', 'gcs13', 'gcs14', 'gcs15', 'gcs16'],
  30. },
  31. ];
  32. export const emojiList: IEmojiList = [
  33. {
  34. type: EMOJI_TYPE.BASIC,
  35. url: basicEmojiUrl,
  36. list: Object.keys(basicEmojiList),
  37. },
  38. ...bigEmojiList,
  39. ];
  40. export const decodeTextMessage = (text: string) => {
  41. if (!text) {
  42. return '';
  43. }
  44. const reg = /(\[.+?\])/g;
  45. let txt: string = text;
  46. if (reg.test(text)) {
  47. txt = text.replace(reg, match => basicEmojiList[match] || match);
  48. }
  49. return txt;
  50. };
  51. // 把中文的 value [微笑] 转化为英文的 key [TUIEmoji_Smile]
  52. export const transformEmojiValueToKey = (text: string) => {
  53. if (!text) {
  54. return '';
  55. }
  56. const reg = /(\[.+?\])/g;
  57. let txt: string = text;
  58. if (reg.test(text)) {
  59. txt = text.replace(reg, match => basicEmojiKey[match] || match);
  60. }
  61. return txt;
  62. };