【新增】:mall 客服实现 emoji 表情选择和消息发送

This commit is contained in:
puhui999
2024-07-02 16:45:32 +08:00
parent 1abfec766e
commit 9c05ff35db
4 changed files with 151 additions and 189 deletions

View File

@ -49,6 +49,11 @@ export const emojiList = [
{ name: '[恶魔]', file: 'emo.png' }
]
export interface Emoji {
name: string
url: string
}
export const emojiPage = {}
emojiList.forEach((item, index) => {
if (!emojiPage[Math.floor(index / 30) + 1]) {
@ -59,6 +64,8 @@ emojiList.forEach((item, index) => {
// 后端上传地址
const staticUrl = import.meta.env.VITE_STATIC_URL
// 后缀
const suffix = '/static/img/chat/emoji/'
// 处理表情
export function replaceEmoji(data: string) {
@ -72,7 +79,7 @@ export function replaceEmoji(data: string) {
newData = newData.replace(
item,
`<img class="chat-img" style="width: 24px;height: 24px;margin: 0 3px;" src="${
staticUrl + '/static/img/chat/emoji/' + emojiFile
staticUrl + suffix + emojiFile
}"/>`
)
})
@ -81,6 +88,14 @@ export function replaceEmoji(data: string) {
return newData
}
// 获得所有表情
export function getEmojiList(): Emoji[] {
return emojiList.map((item) => ({
url: staticUrl + suffix + item.file,
name: item.name
})) as Emoji[]
}
function selEmojiFile(name: string) {
for (const index in emojiList) {
if (emojiList[index].name === name) {