fix:全局按钮播放音效完成

This commit is contained in:
2026-05-19 17:24:02 +08:00
parent f44c22c594
commit 74ca0bb3d7
14 changed files with 36 additions and 22 deletions

View File

@@ -1,4 +1,5 @@
export const audioFils = { export const audioFils = {
点击按钮: "https://static.shelingxingqiu.com/shootmini/static/audio/%E7%82%B9%E5%87%BB%E6%8C%89%E9%92%AE.mp3",
"20CM全环靶": "https://static.shelingxingqiu.com/shootmini/static/audio/20CM%E5%85%A8%E7%8E%AF%E9%9D%B6-%E6%97%A0%E6%95%88.mp3", "20CM全环靶": "https://static.shelingxingqiu.com/shootmini/static/audio/20CM%E5%85%A8%E7%8E%AF%E9%9D%B6-%E6%97%A0%E6%95%88.mp3",
"40CM全环靶": "https://static.shelingxingqiu.com/shootmini/static/audio/40CM%E5%85%A8%E7%8E%AF%E9%9D%B6-%E6%97%A0%E6%95%88.mp3", "40CM全环靶": "https://static.shelingxingqiu.com/shootmini/static/audio/40CM%E5%85%A8%E7%8E%AF%E9%9D%B6-%E6%97%A0%E6%95%88.mp3",
// 激光已校准: // 激光已校准:

View File

@@ -31,7 +31,7 @@ function handleTabClick(index) {
v-for="(tab, index) in tabs" v-for="(tab, index) in tabs"
:key="index" :key="index"
class="tab-item" class="tab-item"
@click="handleTabClick(index)" @click="$clickSound(() => handleTabClick(index))"
:style="{ :style="{
width: index === 1 ? '36%' : '20%', width: index === 1 ? '36%' : '20%',
}" }"

View File

@@ -206,7 +206,7 @@ const goCalibration = async () => {
<button hover-class="none" @click="() => (showHint = false)"> <button hover-class="none" @click="() => (showHint = false)">
取消 取消
</button> </button>
<button hover-class="none" @click="cancelMatching">确认</button> <button hover-class="none" @click="$clickSound(cancelMatching)">确认</button>
</view> </view>
</view> </view>
<view v-if="hintType === 4" class="tip-content"> <view v-if="hintType === 4" class="tip-content">

View File

@@ -112,7 +112,7 @@ const createRoom = debounce(async () => {
<text>40厘米全环靶</text> <text>40厘米全环靶</text>
</view> </view>
</view> </view>
<SButton :onClick="createRoom">创建房间</SButton> <SButton :onClick="() => $clickSound(createRoom)">创建房间</SButton>
</view> </view>
</template> </template>

View File

@@ -123,7 +123,7 @@ onBeforeUnmount(() => {
</text> </text>
</view> </view>
</view> </view>
<button hover-class="none" @click="stopMatch">取消匹配</button> <button hover-class="none" @click="$clickSound(stopMatch)">取消匹配</button>
</view> </view>
</template> </template>

View File

@@ -2,12 +2,25 @@ import { createSSRApp } from 'vue'
import { createPinia } from 'pinia' import { createPinia } from 'pinia'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate' import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
import App from './App.vue' import App from './App.vue'
import audioManager from './audioManager'
export function createApp() { export function createApp() {
const app = createSSRApp(App) const app = createSSRApp(App)
const pinia = createPinia() const pinia = createPinia()
pinia.use(piniaPluginPersistedstate) pinia.use(piniaPluginPersistedstate)
app.use(pinia) app.use(pinia)
/**
* 全局点击音效工具函数,用于在任意按钮/元素点击时自动播放音效。
* 用法:@click="$clickSound(handler)" 或 @click="$clickSound(() => doSomething())"
* @param {Function} handler - 原始点击回调函数(可选,点击时直接调用)
* @param {string} [soundKey='点击按钮'] - audioManager 中的音效 key
*/
app.config.globalProperties.$clickSound = (handler, soundKey = '点击按钮') => {
audioManager.play(soundKey);
if (typeof handler === 'function') handler();
};
return { return {
app app
} }

View File

@@ -443,7 +443,7 @@ onBeforeUnmount(() => {
<PlayerSeats v-if="room.battleType === 2" :total="room.count || 10" :players="players" <PlayerSeats v-if="room.battleType === 2" :total="room.count || 10" :players="players"
:removePlayer="removePlayer" :isOwner="owner.id === user.id" /> :removePlayer="removePlayer" :isOwner="owner.id === user.id" />
<view> <view>
<SButton :disabled="!canClick" :onClick="getReady"> <SButton :disabled="!canClick" :onClick="() => $clickSound(getReady)">
{{ {{
allReady.value allReady.value
? "即将进入对局..." ? "即将进入对局..."

View File

@@ -141,7 +141,7 @@ onLoad(async (options) => {
<image src="../static/founded-room.png" mode="widthFix" /> <image src="../static/founded-room.png" mode="widthFix" />
<view> <view>
<input placeholder="输入房间号" v-model="roomNumber" placeholder-style="color: #ccc" /> <input placeholder="输入房间号" v-model="roomNumber" placeholder-style="color: #ccc" />
<view @click="enterRoom(roomNumber)">进入房间</view> <view @click="$clickSound(() => enterRoom(roomNumber))">进入房间</view>
</view> </view>
</view> </view>
<view class="create-room"> <view class="create-room">
@@ -155,7 +155,7 @@ onLoad(async (options) => {
</view> </view>
</view> </view>
<view> <view>
<SButton width="80%" :rounded="30" :onClick="onCreateRoom"> <SButton width="80%" :rounded="30" :onClick="() => $clickSound(onCreateRoom)">
创建约战房 创建约战房
</SButton> </SButton>
</view> </view>

View File

@@ -178,7 +178,7 @@ onShareTimeline(() => {
v-else v-else
src="https://static.shelingxingqiu.com/attachment/2026-01-04/dffohwtk1gwh0xfa6h.png" src="https://static.shelingxingqiu.com/attachment/2026-01-04/dffohwtk1gwh0xfa6h.png"
mode="widthFix" mode="widthFix"
@click="() => toPage('/pages/my-device')" @click="$clickSound(() => toPage('/pages/my-device'))"
/> />
<block v-if="user.id"> <block v-if="user.id">
<text v-if="!device.deviceId">绑定我的智能弓</text> <text v-if="!device.deviceId">绑定我的智能弓</text>
@@ -196,10 +196,10 @@ onShareTimeline(() => {
</BubbleTip> </BubbleTip>
</view> </view>
<view class="play-card"> <view class="play-card">
<view @click="() => toPage('/pages/practise')"> <view @click="$clickSound(() => toPage('/pages/practise'))">
<image src="../static/my-practise.png" mode="widthFix"/> <image src="../static/my-practise.png" mode="widthFix"/>
</view> </view>
<view @click="() => toPage('/pages/friend-battle')"> <view @click="$clickSound(() => toPage('/pages/friend-battle'))">
<image src="../static/friend-battle.png" mode="widthFix"/> <image src="../static/friend-battle.png" mode="widthFix"/>
</view> </view>
</view> </view>
@@ -211,7 +211,7 @@ onShareTimeline(() => {
/> />
<button <button
class="into-btn" class="into-btn"
@click="() => toPage('/pages/ranking')" @click="$clickSound(() => toPage('/pages/ranking'))"
hover-class="none" hover-class="none"
></button> ></button>
<view class="ranking-players" @click="toRankListPage"> <view class="ranking-players" @click="toRankListPage">

View File

@@ -130,7 +130,7 @@ onShow(() => {
<template> <template>
<Container title="弓箭绑定"> <Container title="弓箭绑定">
<view v-if="!device.deviceId" class="scan-code"> <view v-if="!device.deviceId" class="scan-code">
<button hover-class="none" @click="handleScan"> <button hover-class="none" @click="$clickSound(handleScan)">
<image src="../static/scan.png" mode="widthFix" /> <image src="../static/scan.png" mode="widthFix" />
</button> </button>
<button hover-class="none" @click="showTip = true"> <button hover-class="none" @click="showTip = true">
@@ -269,7 +269,7 @@ onShow(() => {
</view> </view>
</view> </view>
<view :style="{ marginTop: '240rpx' }"> <view :style="{ marginTop: '240rpx' }">
<SButton :onClick="unbindDevice" width="80vw" :rounded="40" <SButton :onClick="() => $clickSound(unbindDevice)" width="80vw" :rounded="40"
>解绑</SButton >解绑</SButton
> >
</view> </view>

View File

@@ -114,7 +114,7 @@ onMounted(async () => {
/> />
</view> </view>
<template #bottom> <template #bottom>
<SButton :rounded="50" :onClick="toEditPage">下一步</SButton> <SButton :rounded="50" :onClick="() => $clickSound(toEditPage)">下一步</SButton>
</template> </template>
</Container> </Container>
</template> </template>

View File

@@ -198,7 +198,7 @@ onLoad((options) => {
</ScreenHint2> </ScreenHint2>
</view> </view>
<template #bottom> <template #bottom>
<SButton :rounded="50" :onClick="onSubmit"> <SButton :rounded="50" :onClick="() => $clickSound(onSubmit)">
{{ currentGroup === groups ? "保存并查看分析" : "下一组" }} {{ currentGroup === groups ? "保存并查看分析" : "下一组" }}
</SButton> </SButton>
</template> </template>

View File

@@ -329,10 +329,10 @@ onShareTimeline(() => {
</view> </view>
</view> </view>
<view> <view>
<button hover-class="none" @click="toRecordPage" class="image-btn"> <button hover-class="none" @click="$clickSound(toRecordPage)" class="image-btn">
<image src="../static/record-btn.png" mode="widthFix" /> <image src="../static/record-btn.png" mode="widthFix" />
</button> </button>
<button hover-class="none" @click="startScoring" class="image-btn"> <button hover-class="none" @click="$clickSound(startScoring)" class="image-btn">
<image src="../static/start-scoring.png" mode="widthFix" /> <image src="../static/start-scoring.png" mode="widthFix" />
</button> </button>
</view> </view>

View File

@@ -281,27 +281,27 @@ onShow(async () => {
<image <image
src="../static/rank/battle1v1.svg" src="../static/rank/battle1v1.svg"
mode="widthFix" mode="widthFix"
@click.stop="() => toMatchPage(1, 2)" @click.stop="$clickSound(() => toMatchPage(1, 2))"
/> />
<image <image
src="../static/rank/battle2v2.svg" src="../static/rank/battle2v2.svg"
mode="widthFix" mode="widthFix"
@click.stop="() => toMatchPage(2, 4)" @click.stop="$clickSound(() => toMatchPage(2, 4))"
/> />
<image <image
src="../static/rank/battle3v3.svg" src="../static/rank/battle3v3.svg"
mode="widthFix" mode="widthFix"
@click.stop="() => toMatchPage(3, 6)" @click.stop="$clickSound(() => toMatchPage(3, 6))"
/> />
<image <image
src="../static/rank/battle5.svg" src="../static/rank/battle5.svg"
mode="widthFix" mode="widthFix"
@click.stop="() => toMatchPage(4, 5)" @click.stop="$clickSound(() => toMatchPage(4, 5))"
/> />
<image <image
src="../static/rank/battle10.svg" src="../static/rank/battle10.svg"
mode="widthFix" mode="widthFix"
@click.stop="() => toMatchPage(5, 10)" @click.stop="$clickSound(() => toMatchPage(5, 10))"
/> />
</view> </view>
</view> </view>