emoji.js
3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**emoji正则 */
const emoji = [
['微笑', '撇嘴', '色', '发呆', '得意', '流泪', '害羞', '闭嘴'],
['睡', '大哭', '尴尬', '发怒', '调皮', '呲牙', '惊讶', '难过'],
['酷', '囧', '抓狂', '吐', '微笑', '愉快', '白眼', '傲慢'],
['饥饿', '困', '惊恐', '流汗', '憨笑', '大兵', '奋斗', '咒骂'],
['疑问', '嘘', '晕', '折磨', '衰', '骷髅', '敲打', '再见'],
['擦汗', '抠鼻', '鼓掌', '糗大了', '坏笑', '左哼哼', '右哼哼', '哈欠'],
['鄙视', '委屈', '快哭了', '阴险', '亲亲', '吓', '可怜', '菜刀'],
['西瓜', '啤酒', '篮球', '乒乓', '咖啡', '饭', '猪头', '玫瑰'],
['凋谢', '示爱', '爱心', '心碎', '蛋糕', '闪电', '炸弹', '刀'],
['足球', '瓢虫', '便便', '月亮', '太阳', '礼物', '拥抱', '强'],
['弱', '握手', '胜利', '抱拳', '勾引', '拳头', '差劲', '爱你'],
['NO', 'OK', '爱情', '飞吻', '跳跳', '发抖', '怄火', '转圈'],
['磕头', '回头', '跳绳', '投降', '挥手', '激动', '街舞', '左太极'],
['右太极', '嘿哈', '捂脸', '奸笑', '机智', '皱眉', '耶', '社会社会'],
['让我看看', '666', '红包', '蜡烛', '烟花', '福', '庆祝', '爆竹']
]
const emojiReg = /([^\u0020-\u007E\u00A0-\u00BE\u2E80-\uA4CF\uF900-\uFAFF\uFE30-\uFE4F\uFF00-\uFFEF\u0080-\u009F\u2000-\u201f\u2026\u2022\u20ac])/g
/**过滤表情 */
export function haveEmoji(value) {
let val = false
value = value.replace(/\s/g, '').trimStart().trimEnd()
if (emojiReg.test(value) && !/\s/g.test(value)) {
showToast({
icon: 'error',
title: '不能输入表情'
})
val = true
}
return val
}
/**替换表情 */
export function replaceEmoji(value) {
let val = value.replace(emojiReg, '')
return val.trimStart().trimEnd()
}
// 表情回显 文本内容
export function showEmoji(value) {
if (!value) return
let a = decodeURIComponent(value).replace(/[(\r\n)|(\n)|(↵)]+/g, '\n')
let b = a.split('\n')
let filterContent = ''
b && b.forEach((val, index) => {
let spaceVal = val.replace(/ /g, '\xa0')
let filterValue = spaceVal.replace(/\[[\u4E00-\u9FA5_A-Z0-9_]{1,4}\]/gi, (res) => {
const list = emoji.flat(Infinity)
let word = res.replace(/\[|\]/gi,'');
let index = parseInt(list.indexOf(word)) + 1
if (index < 10) {
index = '00' + index
} else if (index >= 10 && index < 100) {
index = '0' + index
}
return `<img webp style="width: 40rpx; height: 40rpx;display:inline-block;" src="https://img01.glsx.com.cn/weapp/resource/saas/scrm/emoji/${index}.png" />`;
})
filterContent = filterContent + `<view style="display: block">${filterValue}</view>`
})
return filterContent
// let filterValue = a.replace(/\[[\u4E00-\u9FA5]{1,3}\]/gi, (res) => {
// const list = emoji.flat(Infinity)
// let word = res.replace(/\[|\]/gi,'');
// let index = parseInt(list.indexOf(word)) + 1
// if (index < 10) {
// index = '00' + index
// } else if (index >= 10 && index < 100) {
// index = '0' + index
// }
// console.log(index, word)
// return `<img webp style="width: 40rpx; height: 40rpx;display:inline-block;" src="https://img01.glsx.com.cn/weapp/resource/saas/scrm/emoji/${index}.png" />`;
// })
// return filterValue
}