|
|
@@ -273,6 +273,67 @@ export const unique = (arr) => {
|
|
|
return arr;
|
|
|
};
|
|
|
|
|
|
+
|
|
|
+// 点击声效 - 缓存对象,避免重复创建
|
|
|
+let hitAudioContext = null
|
|
|
+let lastHitPlayTime = 0
|
|
|
+const HIT_MIN_INTERVAL = 100
|
|
|
+
|
|
|
+const initHitAudio = () => {
|
|
|
+ if (hitAudioContext) return
|
|
|
+ try {
|
|
|
+ if (uni.getSystemInfoSync().platform === 'windows') return
|
|
|
+
|
|
|
+ hitAudioContext = uni.createInnerAudioContext()
|
|
|
+ hitAudioContext.autoplay = false
|
|
|
+ hitAudioContext.src = '/static/hit.mp3'
|
|
|
+ hitAudioContext.volume = 1
|
|
|
+ } catch (e) {
|
|
|
+ console.error('[hitRemind] 初始化失败:', e)
|
|
|
+ hitAudioContext = null
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+export const hitRemind = () => {
|
|
|
+ try {
|
|
|
+ // 防抖:100ms 内只播放一次
|
|
|
+ const now = Date.now()
|
|
|
+ if (now - lastHitPlayTime < HIT_MIN_INTERVAL) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 初始化音频
|
|
|
+ if (!hitAudioContext) {
|
|
|
+ initHitAudio()
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!hitAudioContext) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新时间戳
|
|
|
+ lastHitPlayTime = now
|
|
|
+
|
|
|
+ // 停止之前的播放
|
|
|
+ try {
|
|
|
+ hitAudioContext.stop()
|
|
|
+ } catch (e) {
|
|
|
+ // 忽略停止失败
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置音量并播放
|
|
|
+ hitAudioContext.volume = 1
|
|
|
+ try {
|
|
|
+ hitAudioContext.play()
|
|
|
+ } catch (playError) {
|
|
|
+ console.error('[hitRemind] 播放异常:', playError)
|
|
|
+ hitAudioContext = null
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ console.error('[hitRemind] 执行出错:', e)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
//#ifdef APP-PLUS
|
|
|
const CLDialog=uni.requireNativePlugin("CL-Dialog")
|
|
|
//#endif
|
|
|
@@ -373,4 +434,5 @@ export default {
|
|
|
getCheckLogin,
|
|
|
unique,
|
|
|
confirmModal,
|
|
|
+ hitRemind,
|
|
|
}
|