fix(component): 🐛 修复聊天框内右键菜单问题

修复mac下右键会选中文本问题|修复艾特框不消失问题|修复聊天框右键菜单emoji表情栏样式问题
This commit is contained in:
nongyehong 2024-10-30 10:35:28 +08:00
parent e222216e1d
commit e59630b70e
6 changed files with 27 additions and 5 deletions

View File

@ -141,7 +141,7 @@ const handleEnter = (el: any) => {
requestAnimationFrame(() => { requestAnimationFrame(() => {
requestAnimationFrame(() => { requestAnimationFrame(() => {
el.style.height = `${h}px` el.style.height = `${h}px`
el.style.transition = '0.5s' el.style.transition = '0.3s'
}) })
}) })
} }
@ -168,6 +168,8 @@ const handleAfterEnter = (el: any) => {
.context-menu { .context-menu {
@include menu-item-style(); @include menu-item-style();
.emoji-list { .emoji-list {
-webkit-backdrop-filter: blur(10px);
background: var(--bg-menu);
@apply size-fit p-4px select-none; @apply size-fit p-4px select-none;
.emoji-item { .emoji-item {
@apply size-28px rounded-4px text-16px cursor-pointer hover:bg-[--emoji-hover]; @apply size-28px rounded-4px text-16px cursor-pointer hover:bg-[--emoji-hover];

View File

@ -166,7 +166,7 @@ const handleAitKeyChange = (direction: 1 | -1) => {
const newIndex = Math.max(0, Math.min(currentIndex + direction, personList.value.length - 1)) const newIndex = Math.max(0, Math.min(currentIndex + direction, personList.value.length - 1))
selectedAitKey.value = personList.value[newIndex].uid selectedAitKey.value = personList.value[newIndex].uid
// (使key) // (使key)
virtualListInst.value?.scrollTo({ key: selectedAitKey.value }) virtualListInst.value?.scrollTo({ index: newIndex })
} }
const closeMenu = (event: any) => { const closeMenu = (event: any) => {

View File

@ -173,6 +173,7 @@
</n-flex> </n-flex>
<!-- 气泡样式 --> <!-- 气泡样式 -->
<ContextMenu <ContextMenu
@contextmenu="handleMacSelect"
@mouseenter="handleMouseEnter(item.message.id)" @mouseenter="handleMouseEnter(item.message.id)"
@mouseleave="handleMouseLeave" @mouseleave="handleMouseLeave"
class="w-fit" class="w-fit"
@ -381,6 +382,9 @@ const hoverBubble = ref<{
}>({ }>({
key: -1 key: -1
}) })
/** 记录右键菜单时选中的气泡的元素(用于处理mac右键会选中文本的问题) */
const recordEL = ref()
const isMac = computed(() => type() === 'macos')
const { removeTag, userUid } = useCommon() const { removeTag, userUid } = useCommon()
const { const {
handleScroll, handleScroll,
@ -515,9 +519,24 @@ const scrollBottom = () => {
}) })
} }
/**
* 解决mac右键会选中文本的问题
* @param event
*/
const handleMacSelect = (event: any) => {
if (isMac.value) {
event.target.classList.add('select-none')
recordEL.value = event.target
}
}
const closeMenu = (event: any) => { const closeMenu = (event: any) => {
if (!event.target.matches('.bubble', 'bubble-oneself')) { if (!event.target.matches('.bubble', 'bubble-oneself')) {
activeBubble.value = -1 activeBubble.value = -1
// mac
if (isMac.value) {
recordEL.value.classList.remove('select-none')
}
} }
if (!event.target.matches('.active-reply')) { if (!event.target.matches('.active-reply')) {
/** 解决更替交换回复气泡时候没有触发动画的问题 */ /** 解决更替交换回复气泡时候没有触发动画的问题 */

View File

@ -215,13 +215,11 @@ export const useMsgInput = (messageInputDom: Ref) => {
/** 当输入框手动输入值的时候触发input事件(使用vueUse的防抖) */ /** 当输入框手动输入值的时候触发input事件(使用vueUse的防抖) */
const handleInput = useDebounceFn(async (e: Event) => { const handleInput = useDebounceFn(async (e: Event) => {
const inputElement = e.target as HTMLInputElement const inputElement = e.target as HTMLInputElement
console.log('input', inputElement)
// 如果输入框中只有<br />标签,则清空输入框内容 // 如果输入框中只有<br />标签,则清空输入框内容
// TODO: 为什么这里输入后会有一个br标签? // TODO: 为什么这里输入后会有一个br标签?
if (inputElement.innerHTML === '<br>') { if (inputElement.innerHTML === '<br>') {
inputElement.innerHTML = '' inputElement.innerHTML = ''
msgInput.value = inputElement.innerHTML msgInput.value = inputElement.innerHTML
return
} }
msgInput.value = inputElement.innerHTML || '' msgInput.value = inputElement.innerHTML || ''
const { range, selection } = getEditorRange()! const { range, selection } = getEditorRange()!

View File

@ -15,6 +15,9 @@
} }
} }
.bubble { .bubble {
&::selection {
background: red; /* 设置选中背景为透明 */
}
@include bubble; @include bubble;
} }
.bubble-oneself { .bubble-oneself {

View File

@ -31,7 +31,7 @@
.fade-move, .fade-move,
.fade-enter-active, .fade-enter-active,
.fade-leave-active { .fade-leave-active {
transition: all 0.8s cubic-bezier(0.55, 0, 0.1, 1); transition: all 0.6s cubic-bezier(0.55, 0, 0.1, 1);
} }
.fade-enter-from, .fade-enter-from,