2024-01-22 11:25:13 +08:00
|
|
|
import { defineStore } from "pinia";
|
2024-01-22 15:06:29 +08:00
|
|
|
import { ref, watch } from "vue";
|
2024-01-22 11:25:13 +08:00
|
|
|
|
|
|
|
export const useSettings = defineStore("settings", () => {
|
2024-01-23 14:45:26 +08:00
|
|
|
const initialSettings = localStorage.getItem("settings");
|
|
|
|
const settings = ref(
|
|
|
|
initialSettings
|
|
|
|
? JSON.parse(initialSettings)
|
|
|
|
: {
|
|
|
|
resolution: {
|
|
|
|
width: 1920,
|
|
|
|
height: 1080,
|
|
|
|
},
|
|
|
|
carousel: false,
|
|
|
|
carouselTime: 10, // s
|
|
|
|
fullscreen: false,
|
|
|
|
eqStatus: true,
|
|
|
|
}
|
|
|
|
);
|
2024-01-22 15:06:29 +08:00
|
|
|
|
2024-01-23 14:45:26 +08:00
|
|
|
const clearFullscreenFlag = (e) => {
|
|
|
|
if (!document.fullscreenElement) {
|
|
|
|
settings.value.fullscreen = false;
|
|
|
|
}
|
|
|
|
};
|
2024-01-22 15:06:29 +08:00
|
|
|
|
|
|
|
watch(
|
|
|
|
() => settings.value.fullscreen,
|
|
|
|
(val) => {
|
2024-01-23 14:45:26 +08:00
|
|
|
const mainContainer = document.getElementById("main-container");
|
2024-01-22 15:06:29 +08:00
|
|
|
if (val) {
|
2024-01-23 14:45:26 +08:00
|
|
|
mainContainer.requestFullscreen().then(() => {
|
|
|
|
document.removeEventListener("fullscreenchange", clearFullscreenFlag);
|
|
|
|
document.addEventListener("fullscreenchange", clearFullscreenFlag);
|
2024-01-22 15:06:29 +08:00
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
2024-01-23 14:45:26 +08:00
|
|
|
if (document.fullscreenElement) document.exitFullscreen();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
watch(
|
|
|
|
() => settings.value,
|
|
|
|
(val) => {
|
|
|
|
localStorage.setItem("settings", JSON.stringify(val));
|
|
|
|
},
|
|
|
|
{
|
|
|
|
immediate: true,
|
|
|
|
deep: true,
|
2024-01-22 15:06:29 +08:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2024-01-22 14:23:50 +08:00
|
|
|
function rewriteSettings(payload) {
|
|
|
|
settings.value = payload;
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateSettings({ type, value }) {
|
|
|
|
switch (type) {
|
|
|
|
case "carousel":
|
|
|
|
settings.value.carousel = !settings.value.carousel;
|
|
|
|
break;
|
|
|
|
case "fullscreen":
|
|
|
|
settings.value.fullscreen = !settings.value.fullscreen;
|
|
|
|
break;
|
|
|
|
case "eq":
|
|
|
|
settings.value.eqStatus = !settings.value.eqStatus;
|
|
|
|
break;
|
|
|
|
case "resolution":
|
|
|
|
settings.value.resolution.height = value.height;
|
|
|
|
settings.value.resolution.width = value.width;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2024-01-23 15:39:15 +08:00
|
|
|
return { settings, updateSettings, rewriteSettings };
|
2024-01-22 11:25:13 +08:00
|
|
|
});
|