åŒèš â
åšæ°åæ¶ä»£ïŒè倩已ç»æ䞺æ们ç掻çäžéšåïŒèEmojiè¡šæ åæ¯æ们衚蟟æ æåæ 绪çéèŠæ¹åŒä¹äžãæ以ïŒäžºä»ä¹äžæè¿äºå¯ç±çå°åŸæ èå ¥äœ çè倩宀ã项ç®äžå¢ðð€©ïŒ
线äžäœéª â
è倩宀æ建åèïŒå³æ¶é讯蜻æŸå®ç°ïŒWebSocketãVue 3 å Node.js çŒé çå€äººå®æ¶äº€æµå¹³å°
äœéªå°åâïŒxioayi
ææåŠäž
æŽäœå®ç°æè·¯ â
- ç©æçè·å(emoji)
- å°è£ äžäžªemojiç»ä»¶(æè¿äœ¿çšãè¡šæ åç±»)
- ç»èå€ç(åŠå æ å€æå ¥ïŒéæ©åæå ¥ç)
- åšèå€©å®€å ·äœäœ¿çš(éæ©è¡šæ ãæå ¥èŸå ¥æ¡ã页é¢å±ç€º)
ç©æè·å â
äžé¢è¿äž€äžªçœç«éœæ¯å¯ä»¥å 莹è·åçïŒcopyå欢çè¡šæ yydsïŒïŒïŒ ð,ð,ð,ð,ð ,ð€£,ð
å°è£ äžäžªemojiç»ä»¶ â
å€çemojiè¡šæ â
- è¿ééèŠå°è£ äžäžªèŸ å©åœæ°æ¥åž®æ们蜬ææ°ç»è¿è¡ååš
/**
*
* @param inputs åæ°äžäžªæå€äžªå笊䞲
* @returns è¿åäºç»Žæ°ç»
*/
function splitEmoji(...inputs: string[]): string[][] {
const emojiRegex: RegExp = /\p{Emoji}/u;
const emojiArrays: string[][] = [];
inputs.forEach((input) => {
const emojiArray: string[] = [];
for (const char of input) {
if (emojiRegex.test(char)) {
emojiArray.push(char);
}
}
emojiArrays.push(emojiArray);
});
return emojiArrays;
}
å°è£ emojiç»ä»¶ â
- æ¿å°å€ç奜çemojiæ°æ®**{type:xxx,value:['ð','ð','ð','ð']}**
- æ ¹æ®props.all å€æèŠå±ç€ºçç±»å«ïŒå¹¶è¿è¡æž²æ
- å€ç亀äºïŒç¹å»æäžè¡šæ ïŒå°±æå®äŒ ç»ç¶ç»ä»¶ïŒå¹¶è®¡å ¥æè¿äœ¿çšåè¡š
<template>
<div class="emoji">
<div v-if="emoji.historyList?.length">
<p>æè¿äœ¿çš</p>
<ul class="history" :class="emoji.historyList?.length ? 'historyShow' : ''">
<li v-for="(item, index) in [...new Set(emoji.historyList)]" :key="index" @click.stop="chooseEmojiDefault(item)"
v-html="item"></li>
</ul>
</div>
<div v-for="items in emojiObj" :key="items.name">
<template v-if="items.name && items.value?.length">
<p>{{ items.name }}</p>
<ul class="default">
<li v-for="(item, index) in items.value" :key="index" @click.stop="chooseEmojiDefault(item)" v-html="item"></li>
</ul>
</template>
</div>
</div>
</template>
<script lang="ts" setup>
import { ref, reactive } from "vue";
import { getAllTypeEmojis } from './utils'
const emit = defineEmits(["emojiHandle"]);
const props = defineProps({
all: {
type: Boolean,
default: false
}
})
const res = getAllTypeEmojis()
const emojiObj = ref({})
if (props.all) {
emojiObj.value = res
} else {
emojiObj.value = {
defEmojis: res.defEmojis
}
}
const emoji = reactive({
chooseItem: "",
historyList: [],
allEmoji: emojiObj.value,
});
const chooseEmojiDefault = (item: string) => {
emoji.chooseItem = item;
emoji.historyList.unshift(item);
emit("emojiHandle", item);
return item;
};
</script>
<style lang="less" scoped>
</style>
è倩宀äžäœ¿çšè¡šæ â
è¿éæäž€äžªå ³é®ç¹ïŒæå ¥äœçœ®è®°åœãæå ¥å笊䞲æŒæ¥
- æå ¥äœçœ®å³å æ æäœçœ®
- å笊䞲æŒæ¥ïŒæªåå æ åå笊+è¡šæ +å æ åå笊
inputäžå æ äœçœ®çè·å â
- domæ䞀䞪å±æ§ïŒselectionEndåselectionStart åå«ä»£è¡šå æ èµ·å§äœçœ®
- è®°åœå æ ç»æäœçœ®ïŒçäžéæ©äºå¥œæå ¥
/**
* è·åå
æ çèµ·å§äœçœ®
*/
const selectEmoji = () => {
const Textarea = document.querySelector(".message-input");
console.log(Textarea?.selectionStart,Textarea?.selectionEnd)
};
éæ©è¡šæ å€ç â
- æ¿å°éæ©è¡šæ
- æå ¥å¹¶æŒæ¥åç¬Šäž²ïŒ æªåå æ åå笊+è¡šæ +å æ åå笊
/**
* éæ©è¡šæ
ïŒå¹¶æè¡šæ
æå
¥èŸå
¥æ¡
* @param {*} item éæ©çè¡šæ
*/
const emojiHandle = (item) => {
const msg = message.value;
if (!cursor.value) {
message.value += item;
} else {
message.value = msg.slice(0, cursor.value) + item + msg.slice(cursor.value);
}
};
å®æŽä»£ç â
ä»åºå°åxiaoyi1255
- emojiç»ä»¶äžå ±äžäžªæä»¶ïŒ utils.tsãemojis.jsãindex.vue
- test.vue 䜿çšç€ºäŸ
- utils.ts
import {
defEmojis,
allEmojis,
expressionEmojis,
animalEmojis,
personEmojis,
guestrueEmojis,
publicEmojis,
twelveEmojis,
} from './emojis'
/**
*
* @param inputs åæ°äžäžªæå€äžªå笊䞲
* @returns è¿åäºç»Žæ°ç»
*/
function splitEmoji(...inputs: string[]): string[][] {
const emojiRegex: RegExp = /\p{Emoji}/u;
const emojiArrays: string[][] = [];
inputs.forEach((input) => {
const emojiArray: string[] = [];
for (const char of input) {
if (emojiRegex.test(char)) {
emojiArray.push(char);
}
}
emojiArrays.push(emojiArray);
});
return [...new Set(emojiArrays)];
}
/**
*
* @returns è¡šæ
对象 allEmojis,expressionEmojis,animalEmojis,personEmojis,guestrueEmojis,publicEmojis,twelveEmojis
*/
const getAllTypeEmojis = () => {
const emojiArr = splitEmoji(allEmojis,expressionEmojis,animalEmojis,personEmojis,guestrueEmojis,publicEmojis,twelveEmojis,defEmojis)
const emojiObj = {
defEmojis: {name:"é»è®€è¡šæ
", value:emojiArr[7]},
guestrueEmojis: {name:"æå¿è¡šæ
", value:emojiArr[4]},
publicEmojis: {name:"å
Œ
±è¡šæ
", value:emojiArr[5]},
expressionEmojis: {name:"èžéšè¡šæ
", value:emojiArr[1]},
animalEmojis: {name:"åšç©è¡šæ
", value:emojiArr[2]},
personEmojis: {name:"人ç©è¡šæ
", value:emojiArr[3]},
twelveEmojis: {name: "12çè", value: emojiArr[6]},
allEmojis: {name:"ææè¡šæ
", value:emojiArr[0]},
}
return emojiObj
}
const emojiMap = {
defEmojis: 'é»è®€è¡šæ
',
allEmojis: 'ææè¡šæ
',
expressionEmojis: 'èžéšè¡šæ
',
animalEmojis: 'åšç©è¡šæ
',
personEmojis: "人ç©è¡šæ
",
guestrueEmojis: 'æå¿è¡šæ
',
publicEmojis: 'å
Œ
±è¡šæ
',
twelveEmojis: '12çè',
}
export {
getAllTypeEmojis,
emojiMap
}
- emojis.js
/**
* è¿éåæŸæ以Emojiç©æ
*/
// é»è®€
const defEmojis = "ð,ð,ð,ð,ð
,ð€£,ð,ð,ð,ð,ð,ð,ð,ð,ð,â¹,ð®,ð¯,ð²,ð³,ð¥º,ðŠ,ð§,ðš,ð°,ð¥,ð¢,ð,ð±,ð,ð£,ð,ð,ð©,ð«,ð¥±,ð€,ð¡,ð ,ð€¬,ð,ð¿,ð,â ,ð©,ð€¡,ð¹,ðº,ð»,ðœ,ðŸ,ð€,ðº,ðž,ð¹,ð»,ðŒ,ðœ,ð,ð¿,ðŸ,ð,ð,ð,ð,ð,ð,ð,ð,ð,ð,ð,ð,â£,ð,â€ïžâð¥,â€ïžâð©¹,â€,ð§¡,ðš,ðŠ,ð«,ð,ð¯,â€âð©¹,â€âð¥,ð¥µ,ð€§,ð€®,ð€¢,ð€,ð€,ð·,ðŽ,ð€€,ð€¯,ð€ ,ð¥³,ð¥ž,ð,ð€,ð§,ð,ð,ð€,ð,ð€©,ð,ð¥°,ðâðš,ð€,ð,ð¯,ðš,ðïžâðšïž,âº,ð,ð,ð¥²,ð,ð,ð,ð€ª,ð,ð§ââïž,ð§ââ¡ïž,ðšð¿âðŠŒââ¡ïž,ðð»,ðð»,ð€žðŒââ,ððŸââïž,ðµðœââ,ððŸ,ð€,ððŒââïž,ðŠ,ðŽ,ð,ð,ðº,ð»,ðŠ,ðŠ,ð¢,ðŠ,ð,ð,ðŠ,ð,ðš".replaceAll(',', '')
// å
šéš
const allEmojis = "ðððððððð¥ððððððð«ð¥ð
ð«ð¥¥ð¥ðð¥ð¥ðœð¶ïžð«ð¥ð¥¬ð¥Šð§ð§
ðð¥ð°ðð¥ð¥ð«ð¥šð¥¯ð¥ð§ð§ððð¥©ð¥ððððð¥ªð®ð¯ð«ð¥ð§ð¥ð³ð¥ð²ð«ð¥£ð¥ð¿ð§ð§ð¥«ð±ððððððð ð¢ð£ð€ð¥ð¥®ð¡ð¥ð¥ ð¥¡ðŠªðŠð§ðšð©ðªðð°ð§ð¥§ð«ð¬ðð®ð¯ðŒð¥âð«ðµð¶ðŸð·ðžð¹ðºð»ð¥ð¥ð¥€ð§ð§ð§ð§ð¥¢ðœïžðŽð¥ð£ðŸðïžâ°ïžðð»ðïžðïžðïžðïžðïžðïžðïžðïžððïžðïžð ð¡ð¢ð£ð€ð¥ðŠðšð©ðªð«ð¬ðð¯ð°ððŒðœâªðððâ©ïžðâ²âºðððïžðð
ðððð ð¡ð¢ðððð
ðððððððððððððððððððððð»ððððïžðïžðµðºð²ðŽðð£ïžð€ïžâœðšð¥ðŠð§ââµð€ð³ïžâŽïžð¥ïžð¢âïžð©ïžð«ð¬ðªðºððð ð¡ð°ïžððžðªð ðâ±ïžððððŽðµð¶ð·ð¿ðððð
ðððð¥ð«ðŠðšðµððŠðŠ§ð¶ððŠ®ðâðŠºð©ðºðŠðŠð±ððââ¬ðŠð¯ð
ððŽððŠðŠðŠðŠ¬ð®ðððð·ðððœððððªð«ðŠðŠððŠ£ðŠðŠðððð¹ð°ðð¿ïžðŠ«ðŠðŠð»ð»ââïžðšðŒðŠ¥ðŠŠðŠšðŠðŠ¡ðŸðŠððð£ð€ð¥ðŠð§ðïžðŠ
ðŠðŠ¢ðŠðŠ€ðª¶ðŠ©ðŠðŠðžðð¢ðŠðð²ððŠðŠð³ðð¬ðŠðð ð¡ðŠððððŠððððª²ððŠðª³ð·ïžðžïžðŠðŠðª°ðª±ðŠ ððžð®ðµïžð¹ð¥ðºð»ðŒð·ð±ðªŽð²ð³ðŽðµðŸð¿âïžðððððð°ðŠðŠðŠðŠðððððªšððððððððððððâïžððâðð âïžâ
âïžð€ïžð¥ïžðŠïžð§ïžðšïžð©ïžðªïžð«ïžð¬ïžðâïžââ¡âïžâïžââïžð¥ð§ððâšðððððððð
ð€£ððððððð¥°ðð€©ððâºïžððð¥²ðððð€ªðð€ð€ð€ð€«ð€ð€ð€šððð¶ðððð¬ð€¥ðððªð€€ðŽð·ð€ð€ð€¢ð€®ð€§ð¥µð¥¶ð¥Žðµð€¯ð€ ð¥³ð¥žðð€ð§ðððâ¹ïžð®ð¯ð²ð³ð¥ºðŠð§ðšð°ð¥ð¢ðð±ðð£ððð©ð«ð¥±ð€ð¡ð ð€¬ðð¿ðâ ïžð©ð€¡ð¹ðºð»ðœðŸð€ðºðžð¹ð»ðŒðœðð¿ðŸððð€ðïžâððð€ð€âïžð€ð€ð€ð€ðððððâïžððâðð€ð€ðððð€²ð€ðâïžð
ð€³ðªðŠŸðŠ¿ðŠµðŠ¶ððŠ»ðð§ ð«ð«ðŠ·ðŠŽððïžð
ðð¶ð§ðŠð§ð§ð±ðšð§ðšâðŠ°ðšâðŠ±ðšâðŠ³ðšâðŠ²ð©ð©âðŠ°ð§âðŠ°ð©âðŠ±ð§âðŠ±ð©âðŠ³ð§âðŠ³ð©âðŠ²ð§âðŠ²ð±ââïžð±ââïžð§ðŽðµððââïžðââïžððââïžðââïžð
ð
ââïžð
ââïžððââïžðââïžððââïžðââïžððââïžðââïžð§ð§ââïžð§ââïžððââïžðââïžð€Šð€Šââïžð€Šââïžð€·ð€·ââïžð€·ââïžð§ââïžðšââïžð©ââïžð§âððšâðð©âðð§âð«ðšâð«ð©âð«ð§ââïžðšââïžð©ââïžð§âðŸðšâðŸð©âðŸð§âð³ðšâð³ð©âð³ð§âð§ðšâð§ð©âð§ð§âððšâðð©âðð§âðŒðšâðŒð©âðŒð§âð¬ðšâð¬ð©âð¬ð§âð»ðšâð»ð©âð»ð§âð€ðšâð€ð©âð€ð§âðšðšâðšð©âðšð§ââïžðšââïžð©ââïžð§âððšâðð©âðð§âððšâðð©âðð®ð®ââïžð®ââïžðµïžðµïžââïžðµïžââïžððââïžðââïžð¥·ð·ð·ââïžð·ââïžð€Žðžð³ð³ââïžð³ââïžð²ð§ð€µð€µââïžð€µââïžð°ð°ââïžð°ââïžð€°ð€±ð©âðŒðšâðŒð§âðŒðŒð
ð€¶ð§âððŠžðŠžââïžðŠžââïžðŠ¹ðŠ¹ââïžðŠ¹ââïžð§ð§ââïžð§ââïžð§ð§ââïžð§ââïžð§ð§ââïžð§ââïžð§ð§ââïžð§ââïžð§ð§ââïžð§ââïžð§ð§ââïžð§ââïžð§ð§ââïžð§ââïžððââïžðââïžððââïžðââïžð¶ð¶ââïžð¶ââïžð§ð§ââïžð§ââïžð§ð§ââïžð§ââïžð§âðŠ¯ðšâðŠ¯ð©âðŠ¯ð§âðŠŒðšâðŠŒð©âðŠŒð§âðŠœðšâðŠœð©âðŠœððââïžðââïžððºðŽïžð¯ð¯ââïžð¯ââïžð§ð§ââïžð§ââïžð§ð§âð€âð§ðð«ð¬ðð©ââ€ïžâðâðšðšââ€ïžâðâðšð©ââ€ïžâðâð©ðð©ââ€ïžâðšðšââ€ïžâðšð©ââ€ïžâð©ðªðšâð©âðŠðšâð©âð§ðšâð©âð§âðŠðšâð©âðŠâðŠðšâð©âð§âð§ðšâðšâðŠðšâðšâð§ðšâðšâð§âðŠðšâðšâðŠâðŠðšâðšâð§âð§ð©âð©âðŠð©âð©âð§ð©âð©âð§âðŠð©âð©âðŠâðŠð©âð©âð§âð§ðšâðŠðšâðŠâðŠðšâð§ðšâð§âðŠðšâð§âð§ð©âðŠð©âðŠâðŠð©âð§ð©âð§âðŠð©âð§âð§ð£ïžð€ð¥ð«ð£ð§³ðâïžðð§µð§¶ðð¶ïžð¥œð¥ŒðŠºðððð§£ð§€ð§¥ð§Šððð¥»ð©±ð©²ð©³ððððððð©Žððð¥Ÿð¥¿ð ð¡ð©°ð¢ððð©ðð§¢ðªâïžðððŒð©žðð³ïžð£ðððªðºðºïžð§ð§±ððŠœðŠŒð¢ïžðïžð§³ââ³ââ°â±ïžâ²ïžð°ïžð¡ïžâ±ïžð§šððððððð§§ððð€¿ðªðªð®ðªð§¿ð¹ïžð§žðª
ðªðŒïžð§µðª¡ð§¶ðª¢ðïžð¿ðð¯ðïžðïžðïžð»ðªð±ð²âïžððð ððð»ð¥ïžðšïžâšïžð±ïžð²ïžðœðŸð¿ðð§®ð¥ðïžðœïžðºð·ðžð¹ðŒððð¯ïžð¡ðŠð®ðªððððððððððððð°ðïžððð·ïžð°ðªðŽðµð¶ð·ðžð³ð§Ÿâïžð§ðšð©ð€ð¥ðŠð«ðªð¬ðð®ð³ïžâïžâïžðïžðïžðïžðïžððððïžð
ððïžðïžðððððððððïžððâïžðïžðïžðïžððððððïžðšðªâïžâïžð ïžð¡ïžâïžð«ðªð¡ïžðªð§ðªð©âïžðïžâïžðŠ¯ðâïžðªð§°ð§²ðªâïžð§ªð§«ð§¬ð¬ðð¡ðð©žðð©¹ð©ºðªðªðªðïžðïžðªðœðª ð¿ððª€ðªð§Žð§·ð§¹ð§ºð§»ðª£ð§Œðª¥ð§œð§¯ðð¬â°ïžðªŠâ±ïžð¿ðª§ð°ðŽïžð§ð§ââïžð§ââïžð€ºðâ·ïžððïžðïžââïžðïžââïžððââïžðââïžð£ð£ââïžð£ââïžððââïžðââïžâ¹ïžâ¹ïžââïžâ¹ïžââïžðïžðïžââïžðïžââïžðŽðŽââïžðŽââïžðµðµââïžðµââïžð€žð€žââïžð€žââïžð€Œð€Œââïžð€Œââïžð€œð€œââïžð€œââïžð€Ÿð€Ÿââïžð€Ÿââïžð€¹ð€¹ââïžð€¹ââïžð§ð§ââïžð§ââïžðªð¹ðŒð¶ðïžðïžð«ðïžðð
ð¥ð¥ð¥âœâŸð¥ðððððŸð¥ð³ðððð¥ððžð¥ð¥ð¥
â³âžïžð£ðœð¿ð·ð¥ð¯ð±ð®ð°ð²ð§©âïžððšð§µð§¶ðŒð€ð§ð·ðªðžð¹ðºð»ð¥ðªð¬ð¹ððððððððâ£ïžðâ€ïžð§¡ððððð€ð€ð€ð¯ð¢ð¬ðïžâðšïžðšïžð¯ïžðð€ð®âšïžðððð§ðððððððððð ðð¡ðð¢ðð£ðð€ðð¥ððŠðâ ïžâ¥ïžâŠïžâ£ïžðððŽððððð¢ð£ð¯ðððµð¶ð¹ðð§ð®ð°â¿ð¹ðºð»ðŒðŸâ ïžðžâð«ð³ðð¯ð±ð·ðµðâ¢ïžâ£ïžâ¬ïžâïžâ¡ïžâïžâ¬ïžâïžâ¬
ïžâïžâïžâïžâ©ïžâªïžâ€Žïžâ€µïžððððððððâïžðïžâ¡ïžâžïžâ¯ïžâïžâŠïžâªïžâ®ïžðð¯âââââââââââââðððâ¶ïžâ©âïžâ¯ïžâïžâªâ®ïžðŒâ«ðœâ¬âžïžâ¹ïžâºïžâïžðŠð
ðð¶ð³ðŽâïžâïžâïžââââŸïžâŒïžâïžââââã°ïžð±ð²âïžâ»ïžâïžð±ðð°ââ
âïžâïžâââ°â¿ ãœïžâ³ïžâŽïžâïžÂ©ïžÂ®ïžâ¢ïž#ïžâ£*ïžâ£0ïžâ£1ïžâ£2ïžâ£3ïžâ£4ïžâ£5ïžâ£6ïžâ£7ïžâ£8ïžâ£9ïžâ£ðð ð¡ð¢ð£ð€ð
°ïžðð
±ïžðððâ¹ïžðâïžððð
Ÿïžðð
¿ïžðððððïžð·ïžð¶ð¯ðð¹ðð²ððžðŽð³ãïžãïžðºðµðŽð ð¡ð¢ðµð£ð€â«âªð¥ð§ðšð©ðŠðªð«â¬â¬âŒïžâ»ïžâŸâœâªïžâ«ïžð¶ð·ðžð¹ðºð»ð ðð³ð²ðð©ððŽð³ïžð³ïžâðð³ïžââ§ïž"
// è¡šæ
const expressionEmojis = 'ðððððð
ð€£ððððððð¥°ðð€©ððâºïžððð¥²ðððð€ªðð€ð€ð€ð€«ð€ð€ð€šððð¶ðððð¬ð€¥ðððªð€€ðŽð·ð€ð€ð€¢ð€®ð€§ð¥µð¥¶ð¥Žðµð€¯ð€ ð¥³ð¥žðð€ð§ðððâ¹ïžð®ð¯ð²ð³ð¥ºðŠð§ðšð°ð¥ð¢ðð±ðð£ððð©ð«ð¥±ð€ð¡ð ð€¬ðð¿ðâ ïžð©ð€¡ð¹ðºð»'
// å°åšç©
const animalEmojis = "ðð¥ð«ðŠðšðµððŠðŠ§ð¶ððŠ®ðâðŠºð©ðºðŠðŠð±ððââ¬ðŠð¯ð
ððŽððŠðŠðŠðŠ¬ð®ðððð·ðððœððððªð«ðŠðŠððŠ£ðŠðŠðððð¹ð°ðð¿ïžðŠ«ðŠðŠð»ð»ââïžðšðŒðŠ¥ðŠŠðŠšðŠðŠ¡ðŸðŠððð£ð€ð¥ðŠð§ðïžðŠ
ðŠðŠ¢ðŠðŠ€ðª¶ðŠ©ðŠðŠðžðð¢ðŠðð²ððŠðŠð³ðð¬ðŠðð ð¡ðŠððððŠððððª²ððŠðª³ð·ïžðžïžðŠðŠðª°ðª±ðŠ ððžð®ðµïžð¹ð¥ðºð»ðŒð·ð±ðªŽð²ð³ðŽðµðŸð¿âïžðððððð°ðŠðŠðŠðŠ"
// 人ç©
const personEmojis = "ð¶ð§ðŠð§ð§ð±ðšð§ðšâðŠ°ðšâðŠ±ðšâðŠ³ðšâðŠ²ð©ð©âðŠ°ð§âðŠ°ð©âðŠ±ð§âðŠ±ð©âðŠ³ð§âðŠ³ð©âðŠ²ð§âðŠ²ð±ââïžð±ââïžð§ðŽðµððââïžðââïžððââïžðââïžð
ð
ââïžð
ââïžððââïžðââïžððââïžðââïžððââïžðââïžð§ð§ââïžð§ââïžððââïžðââïžð€Šð€Šââïžð€Šââïžð€·ð€·ââïžð€·ââïžð§ââïžðšââïžð©ââïžð§âððšâðð©âðð§âð«ðšâð«ð©âð«ð§ââïžðšââïžð©ââïžð§âðŸðšâðŸð©âðŸð§âð³ðšâð³ð©âð³ð§âð§ðšâð§ð©âð§ð§âððšâðð©âðð§âðŒðšâðŒð©âðŒð§âð¬ðšâð¬ð©âð¬ð§âð»ðšâð»ð©âð»ð§âð€ðšâð€ð©âð€ð§âðšðšâðšð©âðšð§ââïžðšââïžð©ââïžð§âððšâðð©âðð§âððšâðð©âðð®ð®ââïžð®ââïžðµïžðµïžââïžðµïžââïžððââïžðââïžð¥·ð·ð·ââïžð·ââïžð€Žðžð³ð³ââïžð³ââïžð²ð§ð€µð€µââïžð€µââïžð°ð°ââïžð°ââïžð€°ð€±ð©âðŒðšâðŒð§âðŒðŒð
ð€¶ð§âððŠžðŠžââïžðŠžââïžðŠ¹ðŠ¹ââïžðŠ¹ââïžð§ð§ââïžð§ââïžð§ð§ââïžð§ââïžð§ð§ââïžð§ââïžð§ð§ââïžð§ââïžð§ð§ââïžð§ââïžð§ð§ââïžð§ââïžð§ð§ââïžð§ââïžððââïžðââïžððââïžðââïžð¶ð¶ââïžð¶ââïžð§ð§ââïžð§ââïžð§ð§ââïžð§ââïžð§âðŠ¯ðšâðŠ¯ð©âðŠ¯ðšâðŠŒð§âðŠœðšâðŠœð©âðŠœððââïžðââïžððºðŽïžð¯ð¯ââïžð¯ââïžð§ð§ââïžð§ââïžð§ð§âð€âð§ðð«ð¬"
// æå¿
const guestrueEmojis = "ðªððâððââðððâððððâ"
// å
Œ
±
const publicEmojis = "â»ð§ð®ð°â¿ð¹ðºð»ðŒðŸâ ðžâð«ð³ðð¯ð±ð·ðð"
// çè
const twelveEmojis = "ððð
ððððððððð"
export {
defEmojis,
allEmojis,
expressionEmojis,
animalEmojis,
personEmojis,
guestrueEmojis,
publicEmojis,
twelveEmojis,
}
- index.vue
<template>
<div class="emoji">
<div v-if="emoji.historyList?.length">
<p>æè¿äœ¿çš</p>
<ul class="history" :class="emoji.historyList?.length ? 'historyShow' : ''">
<li v-for="(item, index) in [...new Set(emoji.historyList)]" :key="index" @click.stop="chooseEmojiDefault(item)"
v-html="item"></li>
</ul>
</div>
<div v-for="items in emojiObj" :key="items.name">
<template v-if="items.name && items.value?.length">
<p>{{ items.name }}</p>
<ul class="default">
<li v-for="(item, index) in items.value" :key="index" @click.stop="chooseEmojiDefault(item)" v-html="item"></li>
</ul>
</template>
</div>
</div>
</template>
<script lang="ts" setup>
import { ref, reactive } from "vue";
import { getAllTypeEmojis } from './utils'
const emit = defineEmits(["emojiHandle"]);
const props = defineProps({
all: {
type: Boolean,
default: false
}
})
const res = getAllTypeEmojis()
console.log(res)
const emojiObj = ref({})
if (props.all) {
emojiObj.value = res
} else {
emojiObj.value = {
defEmojis: res.defEmojis
}
}
const emoji = reactive({
chooseItem: "",
historyList: [],
allEmoji: emojiObj.value,
});
const chooseEmojiDefault = (item: string) => {
emoji.chooseItem = item;
emoji.historyList.unshift(item);
emit("emojiHandle", item);
return item;
};
</script>
<style lang="less" scoped>
.history::-webkit-scrollbar,
.default::-webkit-scrollbar {
display: none;
}
.emoji {
text-align: left;
width: 70vw;
max-height: 20vh;
background: #fff;
overflow-y: auto;
p {
font-size: 14px;
padding: 1vh;
}
.history,
.default {
width: 100%;
height: 20vh;
overflow-y: auto;
li {
display: inline-block;
padding: 1vh;
font-size: 26px;
width: 32px;
height: 32px;
line-height: 1;
overflow: hidden;
cursor: pointer;
}
li:hover {
background-color: #ececec;
}
}
.history {
height: 0;
width: 100%;
position: relative;
transition: all 2.5s;
}
.historyShow {
height: 40px;
}
}
@media screen and (max-width: 800px) {
.emoji {
width: 80vw;
}
}
</style>
- test.vue 䜿çšç€ºäŸ
<template>
<smile-outlined
style="font-size: 22px; margin: 0 2vh"
@click="selectEmoji"
/>
<Popover v-model:open="visible" title="" placement="top">
<template #content>
<div>
<Emoji @emojiHandle="emojiHandle" :all="false" />
</div>
</template>
</Popover>
<Textarea
:maxlength="100"
@pressEnter="sendMessage"
class="message-input"
v-model:value.trim="message"
placeholder="å蜊åéæ¶æ¯..."
/>
</template>
<script setup>
import Emoji from "@/components/emoji/index.vue";
import { SmileOutlined } from "@ant-design/icons-vue";
import { Textarea, Popover } from "ant-design-vue";
const cursor = ref(0);
const message = ref('')
const visible = ref(false)
// åéæ¶æ¯
const sendMessage = () => {}
/**
* ç¹å»å±ç€ºè¡šæ
*/
const selectEmoji = () => {
const Textarea = document.querySelector(".message-input");
cursor.value = Textarea?.selectionEnd;
visible.value = !visible.value;
};
/**
* éæ©è¡šæ
ïŒå¹¶æè¡šæ
æå
¥èŸå
¥æ¡
* @param {*} item éæ©çè¡šæ
*/
const emojiHandle = (item) => {
const msg = message.value;
if (!cursor.value) {
message.value += item;
} else {
message.value = msg.slice(0, cursor.value) + item + msg.slice(cursor.value);
}
};
</script>
æ»ç» â
- æŽäœå®ç°èµ·æ¥æºç®åçïŒæ²¡æèž©ä»ä¹å
- æè¿äœ¿çšç®åæ¯ååšåéçïŒå·æ°å°±æ²¡äºïŒåæèèåŒå ¥è§è²ïŒåå ¥æ°æ®åºïŒ
- è¡šæ å ç»ä»¶ç®æçå·²ç»å°è£ äºå¥œäºïŒéèŠçå°äŒäŒŽèªå~
ç»è¯ïŒ â
åŠææ¬æå¯¹äœ ææ¶è·ïŒéº»çŠåšåšå莢çå°æïŒç¹ç¹å ³æ³šãç¹ç¹èµïŒïŒïŒððð
åŠææäžå¯¹ãå¯ä»¥äŒåçå°æ¹æ¬¢è¿åšè¯è®ºåºæåºïŒè°¢è°¢ðð