Files
Shuodedaoli-Deskpet/renderer/src/App.vue

92 lines
1.8 KiB
Vue
Raw Normal View History

2025-08-05 23:30:00 +08:00
<script setup>
2025-08-06 14:15:15 +08:00
import { ref, onMounted } from "vue";
import petGif from "./assets/pet.gif";
2025-08-06 14:15:15 +08:00
// 配置数据
const tooltips = [
2025-08-06 14:15:15 +08:00
"说的道理~",
"尊尼获加",
"为什么不开大!!",
"(凤鸣)",
];
const soundFiles = ["example.mp3"];
2025-08-06 14:15:15 +08:00
// 状态管理
const showTooltip = ref(false);
const currentTooltip = ref("");
const position = ref({ x: 0, y: 0 });
2025-08-06 14:15:15 +08:00
// 点击事件处理
const handleClick = () => {
2025-08-06 14:15:15 +08:00
const randomSound = soundFiles[Math.floor(Math.random() * soundFiles.length)];
window.electronAPI?.playSound(randomSound);
currentTooltip.value = tooltips[Math.floor(Math.random() * tooltips.length)];
showTooltip.value = true;
setTimeout(() => (showTooltip.value = false), 2000);
};
// 初始化位置监听
onMounted(() => {
if (window.electronAPI) {
window.electronAPI.onUpdatePosition((pos) => {
position.value = pos;
});
}
});
2025-08-05 23:30:00 +08:00
</script>
<template>
2025-08-06 14:15:15 +08:00
<div
class="pet-container"
:style="{ left: `${position.x}px`, top: `${position.y}px` }"
>
<img :src="petGif" class="pet-gif" @click="handleClick" draggable="false" />
<transition name="fade">
<div v-if="showTooltip" class="tooltip">
{{ currentTooltip }}
</div>
</transition>
2025-08-05 23:30:00 +08:00
</div>
</template>
<style scoped>
2025-08-06 14:15:15 +08:00
.pet-container {
position: absolute;
width: 300px;
height: 300px;
-webkit-app-region: no-drag;
2025-08-05 23:30:00 +08:00
}
2025-08-06 14:15:15 +08:00
.pet-gif {
width: 100%;
height: 100%;
cursor: pointer;
2025-08-06 14:15:15 +08:00
user-select: none;
-webkit-user-drag: none;
}
.tooltip {
position: absolute;
2025-08-06 14:15:15 +08:00
bottom: -40px;
left: 50%;
transform: translateX(-50%);
background: rgba(0, 0, 0, 0.7);
color: white;
padding: 8px 16px;
border-radius: 20px;
font-size: 14px;
2025-08-06 14:15:15 +08:00
white-space: nowrap;
}
2025-08-06 14:15:15 +08:00
.fade-enter-active,
.fade-leave-active {
transition: opacity 0.3s;
2025-08-05 23:30:00 +08:00
}
2025-08-06 14:15:15 +08:00
.fade-enter-from,
.fade-leave-to {
opacity: 0;
2025-08-05 23:30:00 +08:00
}
2025-08-06 14:15:15 +08:00
</style>