forked from lengyibai/wzry
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
173 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 52 additions & 52 deletions
104
src/components/business/Global/Control/components/K-Message/hooks/useMessage.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,52 @@ | ||
import { reactive } from "vue"; | ||
|
||
import { usePlayAudio } from "@/hooks"; | ||
import { dayjs } from "@/utils/tool"; | ||
|
||
const { playAudio } = usePlayAudio(); | ||
|
||
const ExposeData = { | ||
/** 消息队列 */ | ||
messages: reactive<Global.Message.Info[]>([]), | ||
}; | ||
const { messages } = ExposeData; | ||
|
||
export const useMessage = () => { | ||
const ExposeMethods = { | ||
openMsg(text = "未设置提示", type: Global.Message.Status = "info") { | ||
/** 获取文字长度 */ | ||
const text_length = text.split("").length / 3; | ||
/** 通过文字长度,设置显示时长 */ | ||
const time = text_length > 3 ? text_length : text_length + 1; | ||
|
||
//延迟提醒,避免与点击操作同时播放 | ||
const msgName: Record<string, Partial<keyof Global.Audio.Key>> = { | ||
info: "n74s", | ||
warning: "p6q3", | ||
error: "vw31", | ||
}; | ||
|
||
//播放指定名称的音效 | ||
playAudio(msgName[type]); | ||
|
||
//创建消息内容 | ||
const msgText: Global.Message.Info = { | ||
id: dayjs().valueOf(), | ||
text, | ||
type, | ||
duration: time, | ||
}; | ||
|
||
//将消息内容添加进消息队列 | ||
messages.unshift(msgText); | ||
setTimeout(() => { | ||
messages.pop(); | ||
}, time * 1000); | ||
}, | ||
}; | ||
|
||
return { | ||
...ExposeData, | ||
...ExposeMethods, | ||
}; | ||
}; | ||
import { reactive } from "vue"; | ||
|
||
import { usePlayAudio } from "@/hooks"; | ||
import { dayjs } from "@/utils/tool"; | ||
|
||
const ExposeData = { | ||
/** 消息队列 */ | ||
messages: reactive<Global.Message.Info[]>([]), | ||
}; | ||
const { messages } = ExposeData; | ||
|
||
export const useMessage = () => { | ||
const { playAudio } = usePlayAudio(); | ||
|
||
const ExposeMethods = { | ||
openMsg(text = "未设置提示", type: Global.Message.Status = "info") { | ||
/** 获取文字长度 */ | ||
const text_length = text.split("").length / 3; | ||
/** 通过文字长度,设置显示时长 */ | ||
const time = text_length > 3 ? text_length : text_length + 1; | ||
|
||
//延迟提醒,避免与点击操作同时播放 | ||
const msgName: Record<string, Partial<keyof Global.Audio.Key>> = { | ||
info: "n74s", | ||
warning: "p6q3", | ||
error: "vw31", | ||
}; | ||
|
||
//播放指定名称的音效 | ||
playAudio(msgName[type]); | ||
|
||
//创建消息内容 | ||
const msgText: Global.Message.Info = { | ||
id: dayjs().valueOf(), | ||
text, | ||
type, | ||
duration: time, | ||
}; | ||
|
||
//将消息内容添加进消息队列 | ||
messages.unshift(msgText); | ||
setTimeout(() => { | ||
messages.pop(); | ||
}, time * 1000); | ||
}, | ||
}; | ||
|
||
return { | ||
...ExposeData, | ||
...ExposeMethods, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,115 +1,115 @@ | ||
import { _getAudioLink } from "@/utils/concise"; | ||
import { _debounce } from "@/utils/tool"; | ||
|
||
/** 音量 */ | ||
let volume = 0.5; | ||
/** 启用音效 */ | ||
let status = true; | ||
/** 音效类型 */ | ||
const sound_type: Global.Audio.Key = { | ||
gz76: "atlas", | ||
bq69: "activity", | ||
kj62: "btn", | ||
p60v: "back", | ||
cy87: "cancel", | ||
ba09: "close", | ||
e6b4: "confirm_dialog", | ||
pj83: "confirm", | ||
h2w0: "default", | ||
kh79: "delete", | ||
u4c5: "detail", | ||
h7t9: "epigraph", | ||
ph23: "equip", | ||
vw31: "error", | ||
d5e2: "fold", | ||
iv51: "hero", | ||
p53r: "into", | ||
al41: "key", | ||
e84n: "login", | ||
n74s: "message", | ||
le78: "mode", | ||
za86: "num", | ||
v6p0: "show", | ||
gz43: "skin", | ||
n4r4: "tab", | ||
rt25: "tip", | ||
p6q3: "warning", | ||
o7r6: "raffle", | ||
jo36: "raffle_obtain", | ||
fz02: "knapsack", | ||
h3w0: "store", | ||
bg51: "receipt", | ||
o3l2: "shop", | ||
wm14: "activate", | ||
jy55: "yibao", | ||
hy43: "back_small", | ||
pk92: "tv", | ||
//au63: "", | ||
//gk90: "", | ||
//e90x: "", | ||
//kj35: "", | ||
//zm31: "", | ||
//dh38: "", | ||
}; | ||
|
||
/** | ||
* @description: 播放音效 | ||
* @param name 音效随机标识 | ||
*/ | ||
const play = (name: keyof Global.Audio.Key) => { | ||
const audio = new Audio(); | ||
audio.src = _getAudioLink(sound_type[name]); | ||
audio.volume = volume; | ||
audio.play().catch(() => {}); | ||
}; | ||
|
||
/** @description 部分场景可能会导致音效累积播放,需要进行防抖处理 */ | ||
const debouncePlayAudio = _debounce((name: keyof Global.Audio.Key) => { | ||
play(name); | ||
}, 50); | ||
|
||
/** @description 播放音效 */ | ||
const usePlayAudio = () => { | ||
const ExposeMethods = { | ||
/** | ||
* @description: 调用播放 | ||
* @param name 音效名 | ||
*/ | ||
playAudio(name: keyof Global.Audio.Key = "h2w0") { | ||
if (!status) return; | ||
|
||
/** | ||
* fz02:背包页面在保存的时候会出现栈溢出,导致音量频繁触发 | ||
* n4r4:悬浮音效防抖处理 | ||
* n74s、p6q3、vw31 消息提醒防抖处理 | ||
* za86:滑动音效防抖处理 | ||
*/ | ||
if (["fz02", "n4r4", "n74s", "p6q3", "vw31", "za86"].includes(name)) { | ||
debouncePlayAudio(name); | ||
} else { | ||
play(name); | ||
} | ||
}, | ||
|
||
/** | ||
* @description: 音量调节 | ||
* @param v 音量:1-100 | ||
*/ | ||
setAudioVolume(v: number) { | ||
volume = (v / 100) * 0.75; | ||
}, | ||
|
||
/** @description 设置音效功能开关 | ||
* @param v 开关状态 | ||
*/ | ||
setAudioSwitch(v: boolean) { | ||
status = v; | ||
}, | ||
}; | ||
|
||
return { | ||
...ExposeMethods, | ||
}; | ||
}; | ||
|
||
export { usePlayAudio }; | ||
import { _getAudioLink } from "@/utils/concise"; | ||
import { _debounce } from "@/utils/tool"; | ||
|
||
/** 音量 */ | ||
let volume = 0.5; | ||
/** 启用音效 */ | ||
let status = true; | ||
/** 音效类型 */ | ||
const sound_type: Global.Audio.Key = { | ||
gz76: "atlas", | ||
bq69: "activity", | ||
kj62: "btn", | ||
p60v: "back", | ||
cy87: "cancel", | ||
ba09: "close", | ||
e6b4: "confirm_dialog", | ||
pj83: "confirm", | ||
h2w0: "default", | ||
kh79: "delete", | ||
u4c5: "detail", | ||
h7t9: "epigraph", | ||
ph23: "equip", | ||
vw31: "error", | ||
d5e2: "fold", | ||
iv51: "hero", | ||
p53r: "into", | ||
al41: "key", | ||
e84n: "login", | ||
n74s: "message", | ||
le78: "mode", | ||
za86: "num", | ||
v6p0: "show", | ||
gz43: "skin", | ||
n4r4: "tab", | ||
rt25: "tip", | ||
p6q3: "warning", | ||
o7r6: "raffle", | ||
jo36: "raffle_obtain", | ||
fz02: "knapsack", | ||
h3w0: "store", | ||
bg51: "receipt", | ||
o3l2: "shop", | ||
wm14: "activate", | ||
jy55: "yibao", | ||
hy43: "back_small", | ||
pk92: "tv", | ||
//au63: "", | ||
//gk90: "", | ||
//e90x: "", | ||
//kj35: "", | ||
//zm31: "", | ||
//dh38: "", | ||
}; | ||
|
||
/** | ||
* @description: 播放音效 | ||
* @param name 音效随机标识 | ||
*/ | ||
const play = (name: keyof Global.Audio.Key) => { | ||
const audio = new Audio(); | ||
audio.src = _getAudioLink(sound_type[name]); | ||
audio.volume = volume; | ||
audio.play().catch(() => {}); | ||
}; | ||
|
||
/** @description 部分场景可能会导致音效累积播放,需要进行防抖处理 */ | ||
const debouncePlayAudio = _debounce((name: keyof Global.Audio.Key) => { | ||
play(name); | ||
}, 50); | ||
|
||
/** @description 播放音效 */ | ||
const usePlayAudio = () => { | ||
const ExposeMethods = { | ||
/** | ||
* @description: 调用播放 | ||
* @param name 音效名 | ||
*/ | ||
playAudio(name: keyof Global.Audio.Key = "h2w0") { | ||
if (!status) return; | ||
|
||
/** | ||
* fz02:背包页面在保存的时候会出现栈溢出,导致音量频繁触发 | ||
* n4r4:悬浮音效防抖处理 | ||
* n74s、p6q3、vw31 消息提醒防抖处理 | ||
* za86:滑动音效防抖处理 | ||
*/ | ||
if (["fz02", "n4r4", "n74s", "p6q3", "vw31", "za86"].includes(name)) { | ||
debouncePlayAudio(name); | ||
} else { | ||
play(name); | ||
} | ||
}, | ||
|
||
/** | ||
* @description: 音量调节 | ||
* @param v 音量:1-100 | ||
*/ | ||
setAudioVolume(v: number) { | ||
volume = (v / 100) * 0.75; | ||
}, | ||
|
||
/** @description 设置音效功能开关 | ||
* @param v 开关状态 | ||
*/ | ||
setAudioSwitch(v: boolean) { | ||
status = v; | ||
}, | ||
}; | ||
|
||
return { | ||
...ExposeMethods, | ||
}; | ||
}; | ||
|
||
export { usePlayAudio }; |