初步实现功能
This commit is contained in:
3550
renderer/package-lock.json
generated
3550
renderer/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -15,6 +15,7 @@
|
||||
"@vitejs/plugin-vue": "^6.0.0",
|
||||
"@vue/tsconfig": "^0.7.0",
|
||||
"concurrently": "^9.2.0",
|
||||
"electron-builder": "^26.0.12",
|
||||
"typescript": "~5.8.3",
|
||||
"vite": "^7.0.4",
|
||||
"vue-tsc": "^2.2.12",
|
||||
|
@ -1,39 +1,48 @@
|
||||
<script setup>
|
||||
import { ref, onMounted } from 'vue'
|
||||
import petVideo from './assets/pet.mp4'
|
||||
import { ref, onMounted } from "vue";
|
||||
import petGif from "./assets/pet.gif";
|
||||
|
||||
// 配置数据
|
||||
const tooltips = [
|
||||
"说的道理",
|
||||
]
|
||||
const sounds = [
|
||||
|
||||
]
|
||||
"说的道理~",
|
||||
"尊尼获加",
|
||||
"为什么不开大!!",
|
||||
"(凤鸣)",
|
||||
];
|
||||
const soundFiles = ["example.mp3"];
|
||||
|
||||
const showTooltip = ref(false)
|
||||
const currentTooltip = ref('')
|
||||
// 状态管理
|
||||
const showTooltip = ref(false);
|
||||
const currentTooltip = ref("");
|
||||
const position = ref({ x: 0, y: 0 });
|
||||
|
||||
// 点击事件处理
|
||||
const handleClick = () => {
|
||||
// 随机播放音效
|
||||
const sound = sounds[Math.floor(Math.random() * sounds.length)]
|
||||
window.electronAPI.playSound(sound)
|
||||
|
||||
// 随机显示提示
|
||||
showTooltip.value = true
|
||||
currentTooltip.value = tooltips[Math.floor(Math.random() * tooltips.length)]
|
||||
setTimeout(() => showTooltip.value = false, 2000)
|
||||
}
|
||||
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;
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="container">
|
||||
<!-- MP4素材播放 -->
|
||||
<video
|
||||
autoplay loop muted
|
||||
:src="petVideo"
|
||||
@click="handleClick"
|
||||
/>
|
||||
|
||||
<!-- 文字提示框 -->
|
||||
<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 }}
|
||||
@ -43,22 +52,24 @@ const handleClick = () => {
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.container {
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
overflow: hidden;
|
||||
.pet-container {
|
||||
position: absolute;
|
||||
width: 300px;
|
||||
height: 300px;
|
||||
-webkit-app-region: no-drag;
|
||||
}
|
||||
|
||||
video {
|
||||
.pet-gif {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: contain;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
-webkit-user-drag: none;
|
||||
}
|
||||
|
||||
.tooltip {
|
||||
position: absolute;
|
||||
bottom: 20px;
|
||||
bottom: -40px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
background: rgba(0, 0, 0, 0.7);
|
||||
@ -66,12 +77,15 @@ video {
|
||||
padding: 8px 16px;
|
||||
border-radius: 20px;
|
||||
font-size: 14px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.fade-enter-active, .fade-leave-active {
|
||||
transition: opacity 0.5s;
|
||||
.fade-enter-active,
|
||||
.fade-leave-active {
|
||||
transition: opacity 0.3s;
|
||||
}
|
||||
.fade-enter, .fade-leave-to {
|
||||
.fade-enter-from,
|
||||
.fade-leave-to {
|
||||
opacity: 0;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
BIN
renderer/src/assets/pet.gif
Normal file
BIN
renderer/src/assets/pet.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.5 MiB |
@ -1,7 +1,11 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [vue()],
|
||||
})
|
||||
base: './',
|
||||
build: {
|
||||
assetsInlineLimit: 0
|
||||
// 强制所有资源作为文件输出
|
||||
}
|
||||
})
|
Reference in New Issue
Block a user