kun-galgame-vue/src/store/modules/settings.ts

41 lines
1.1 KiB
TypeScript
Raw Normal View History

2023-05-12 18:23:22 +00:00
// KUNGalgame 设置面板的 store
import { ref } from 'vue'
import { defineStore } from 'pinia'
2023-05-26 09:07:35 +00:00
// 设置面板配置
interface KUNGalgameSettings {
// 是否显示设置面板
settings: boolean
// 主页宽度
mainPageWidth: string
2023-05-27 02:39:57 +00:00
// 背景图
background: string
2023-05-26 09:07:35 +00:00
}
// 读出 localStorage 中主页的宽度数据
const loadMainPageWidth =
(localStorage.getItem('KUNGalgame-main-page-width') as string) || '61.8%'
2023-05-27 02:39:57 +00:00
// 读出 localStorage 中网站的背景图数据
const loadKUNGalgameBackground =
(localStorage.getItem('KUNGalgame-background') as string) || ''
2023-05-26 09:07:35 +00:00
const kungalgameSettings: KUNGalgameSettings = {
// false -> settings panel off, true -> settings panel on
settings: false,
mainPageWidth: loadMainPageWidth,
2023-05-27 02:39:57 +00:00
background: loadKUNGalgameBackground,
2023-05-26 09:07:35 +00:00
}
2023-05-12 18:23:22 +00:00
export const useSettingsPanelStore = defineStore('settings', () => {
2023-05-14 07:16:28 +00:00
const showSettings = ref<boolean>(kungalgameSettings.settings)
2023-05-26 09:07:35 +00:00
const showMainPageWidth = ref<string>(kungalgameSettings.mainPageWidth)
2023-05-27 02:39:57 +00:00
const showKUNGalgameBackground = ref<string>(kungalgameSettings.background)
2023-05-12 18:23:22 +00:00
return {
showSettings,
2023-05-26 09:07:35 +00:00
showMainPageWidth,
2023-05-27 02:39:57 +00:00
showKUNGalgameBackground,
2023-05-12 18:23:22 +00:00
}
})