🐞 fix: 修复音量调节

This commit is contained in:
imsyy
2024-12-11 17:57:56 +08:00
parent 191ab29a44
commit 9accf5d27d
3 changed files with 25 additions and 6 deletions

View File

@@ -66,6 +66,7 @@
"localforage": "^1.10.0",
"lodash-es": "^4.17.21",
"marked": "^14.1.4",
"md5": "^2.3.0",
"music-metadata": "7.14.0",
"pinia": "^2.3.0",
"pinia-plugin-persistedstate": "^4.1.3",
@@ -83,6 +84,7 @@
"@types/file-saver": "^2.0.7",
"@types/howler": "^2.2.12",
"@types/js-cookie": "^3.0.6",
"@types/md5": "^2.3.5",
"@types/node": "^22.10.1",
"@typescript-eslint/eslint-plugin": "^8.18.0",
"@typescript-eslint/parser": "^8.18.0",

11
pnpm-lock.yaml generated
View File

@@ -111,6 +111,9 @@ importers:
marked:
specifier: ^14.1.4
version: 14.1.4
md5:
specifier: ^2.3.0
version: 2.3.0
music-metadata:
specifier: 7.14.0
version: 7.14.0
@@ -151,6 +154,9 @@ importers:
'@types/js-cookie':
specifier: ^3.0.6
version: 3.0.6
'@types/md5':
specifier: ^2.3.5
version: 2.3.5
'@types/node':
specifier: ^22.10.1
version: 22.10.1
@@ -1182,6 +1188,9 @@ packages:
'@types/lodash@4.17.13':
resolution: {integrity: sha512-lfx+dftrEZcdBPczf9d0Qv0x+j/rfNCMuC6OcfXmO8gkfeNAY88PgKUbvG56whcN23gc27yenwF6oJZXGFpYxg==}
'@types/md5@2.3.5':
resolution: {integrity: sha512-/i42wjYNgE6wf0j2bcTX6kuowmdL/6PE4IVitMpm2eYKBUuYCprdcWVK+xEF0gcV6ufMCRhtxmReGfc6hIK7Jw==}
'@types/ms@0.7.34':
resolution: {integrity: sha512-nG96G3Wp6acyAgJqGasjODb+acrI7KltPiRxzHPXnP3NgI28bpQDRv53olbqGXbfcgF5aiiHmO3xpwEpS5Ld9g==}
@@ -5194,6 +5203,8 @@ snapshots:
'@types/lodash@4.17.13': {}
'@types/md5@2.3.5': {}
'@types/ms@0.7.34': {}
'@types/ndarray@1.0.14': {}

View File

@@ -760,20 +760,26 @@ class Player {
* 设置播放音量
* @param actions 音量
*/
setVolume(actions: number | WheelEvent) {
setVolume(actions: number | "up" | "down" | WheelEvent) {
const statusStore = useStatusStore();
const increment = 0.05;
// 直接设置
if (typeof actions === "number") {
actions = Math.max(0, Math.min(actions, 1));
} else {
const increment = 0.05;
const deltaY = actions.deltaY;
const volume = deltaY > 0 ? "down" : "up";
}
// 分类调节
else if (actions === "up" || actions === "down") {
statusStore.playVolume = Math.max(
0,
Math.min(statusStore.playVolume + (volume === "up" ? increment : -increment), 1),
Math.min(statusStore.playVolume + (actions === "up" ? increment : -increment), 1),
);
}
// 鼠标滚轮
else {
const deltaY = actions.deltaY;
const volumeChange = deltaY > 0 ? -increment : increment;
statusStore.playVolume = Math.max(0, Math.min(statusStore.playVolume + volumeChange, 1));
}
// 调整音量
this.player.volume(statusStore.playVolume);
}