liveh5-nuxt/app/components/floatingBubble/index.vue

52 lines
1020 B
Vue
Raw Normal View History

2025-02-26 03:33:50 +00:00
<!--
浮动气泡组件
提供一个可拖拽的浮动按钮支持自定义点击事件和自动销毁功能
-->
<script setup>
2025-02-26 03:11:29 +00:00
import { watch, onUnmounted } from 'vue'
import { hideMinWindow1 } from './floating'
2025-02-26 03:51:21 +00:00
const { t } = useI18n()
2025-02-26 03:33:50 +00:00
// 组件属性定义
2025-02-26 03:11:29 +00:00
const props = defineProps({
2025-02-26 03:33:50 +00:00
/** 点击气泡时的回调函数 */
2025-02-26 03:11:29 +00:00
onClick: {
type: Function,
2025-02-26 03:33:50 +00:00
default: () => {}
},
2025-02-26 03:51:21 +00:00
/** 气泡文本内容(可选,默认使用国际化文本) */
2025-02-26 03:33:50 +00:00
text: {
type: String,
2025-02-26 03:51:21 +00:00
default: null
}
})
2025-02-26 03:11:29 +00:00
2025-02-20 10:53:53 +00:00
const route = useRoute()
2025-02-26 03:33:50 +00:00
// 路由变化监听器:当用户返回首页时自动销毁气泡
2025-02-26 03:11:29 +00:00
2025-02-26 03:33:50 +00:00
// 组件卸载时自动清理资源
2025-02-26 03:11:29 +00:00
onUnmounted(() => {
hideMinWindow1()
})
</script>
<template>
<van-floating-bubble
2025-02-26 03:33:50 +00:00
axis="xy"
magnetic="x"
:offset="{ x: 300, y: 50 }"
@click="onClick"
>
2025-02-26 03:51:21 +00:00
{{ text || t('floatingBubble.backToLive') }}
</van-floating-bubble>
</template>
<style>
2025-02-26 03:33:50 +00:00
.van-floating-bubble {
width: 70px;
height: 70px;
2025-02-26 03:33:50 +00:00
border-radius: 5px!important;
}
</style>