fix: 集成一下父亲容器

This commit is contained in:
tim
2025-10-15 19:52:30 +08:00
parent 4f248e8a71
commit a68c925c68

View File

@@ -38,6 +38,8 @@
<div <div
v-if="panelVisible" v-if="panelVisible"
class="reactions-panel" class="reactions-panel"
ref="reactionsPanelRef"
:style="panelInlineStyle"
@mouseenter="cancelHide" @mouseenter="cancelHide"
@mouseleave="scheduleHide" @mouseleave="scheduleHide"
> >
@@ -57,7 +59,7 @@
</template> </template>
<script setup> <script setup>
import { computed, onMounted, ref, watch } from 'vue' import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue'
import { toast } from '~/main' import { toast } from '~/main'
import { authState, getToken } from '~/utils/auth' import { authState, getToken } from '~/utils/auth'
import { reactionEmojiMap } from '~/utils/reactions' import { reactionEmojiMap } from '~/utils/reactions'
@@ -141,6 +143,8 @@ const displayedReactions = computed(() => {
const panelTypes = computed(() => sortedReactionTypes.value) const panelTypes = computed(() => sortedReactionTypes.value)
const panelVisible = ref(false) const panelVisible = ref(false)
const reactionsPanelRef = ref(null)
const panelInlineStyle = ref({})
let hideTimer = null let hideTimer = null
const openPanel = () => { const openPanel = () => {
clearTimeout(hideTimer) clearTimeout(hideTimer)
@@ -156,6 +160,33 @@ const cancelHide = () => {
clearTimeout(hideTimer) clearTimeout(hideTimer)
} }
const updatePanelInlineStyle = () => {
if (!panelVisible.value) return
const panelEl = reactionsPanelRef.value
if (!panelEl) return
const parentEl = panelEl.closest('.reactions-container')?.parentElement
if (!parentEl) return
const parentWidth = parentEl.clientWidth - 20
panelInlineStyle.value = {
width: 'max-content',
maxWidth: `${parentWidth}px`,
}
}
watch(panelVisible, async (visible) => {
if (visible) {
await nextTick()
updatePanelInlineStyle()
}
})
watch(panelTypes, async () => {
if (panelVisible.value) {
await nextTick()
updatePanelInlineStyle()
}
})
const toggleReaction = async (type) => { const toggleReaction = async (type) => {
const token = getToken() const token = getToken()
if (!token) { if (!token) {
@@ -231,11 +262,16 @@ const toggleReaction = async (type) => {
onMounted(async () => { onMounted(async () => {
await initialize() await initialize()
window.addEventListener('resize', updatePanelInlineStyle)
}) })
defineExpose({ defineExpose({
toggleReaction, toggleReaction,
}) })
onBeforeUnmount(() => {
window.removeEventListener('resize', updatePanelInlineStyle)
})
</script> </script>
<style> <style>
@@ -288,7 +324,7 @@ defineExpose({
.reactions-panel { .reactions-panel {
position: absolute; position: absolute;
bottom: 50px; bottom: 40px;
background-color: var(--background-color); background-color: var(--background-color);
border: 1px solid var(--normal-border-color); border: 1px solid var(--normal-border-color);
border-radius: 20px; border-radius: 20px;