2025-02-26 03:33:50 +00:00
|
|
|
|
<!--
|
|
|
|
|
浮动气泡组件
|
|
|
|
|
提供一个可拖拽的浮动按钮,支持自定义点击事件和自动销毁功能
|
|
|
|
|
-->
|
2025-02-20 06:47:57 +00:00
|
|
|
|
<script setup>
|
2025-02-26 03:11:29 +00:00
|
|
|
|
import { watch, onUnmounted } from 'vue'
|
|
|
|
|
import { hideMinWindow1 } from './floating'
|
|
|
|
|
|
2025-02-27 01:23:01 +00:00
|
|
|
|
// 从 nuxt/app 导入 useNuxtApp
|
|
|
|
|
const { $i18n } = useNuxtApp()
|
|
|
|
|
|
|
|
|
|
// 替换原来的 useI18n
|
|
|
|
|
const t = (key) => $i18n.t(key)
|
2025-02-26 03:51:21 +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-20 06:47:57 +00:00
|
|
|
|
}
|
|
|
|
|
})
|
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()
|
|
|
|
|
})
|
2025-02-20 06:47:57 +00:00
|
|
|
|
</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-20 06:47:57 +00:00
|
|
|
|
>
|
2025-02-26 03:51:21 +00:00
|
|
|
|
{{ text || t('floatingBubble.backToLive') }}
|
2025-02-20 06:47:57 +00:00
|
|
|
|
</van-floating-bubble>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<style>
|
2025-02-26 03:33:50 +00:00
|
|
|
|
.van-floating-bubble {
|
2025-02-20 06:47:57 +00:00
|
|
|
|
width: 70px;
|
|
|
|
|
height: 70px;
|
2025-02-26 03:33:50 +00:00
|
|
|
|
border-radius: 5px!important;
|
2025-02-20 06:47:57 +00:00
|
|
|
|
}
|
|
|
|
|
</style>
|