2023-05-26 13:04:12 +08:00
|
|
|
import { type Ref, ref } from "vue"
|
2022-04-22 01:16:02 +08:00
|
|
|
import { defineStore } from "pinia"
|
|
|
|
import layoutSettings from "@/config/layout"
|
2022-04-21 18:20:39 +08:00
|
|
|
|
2023-05-26 13:04:12 +08:00
|
|
|
type SettingsStore = {
|
|
|
|
// 使用映射类型来遍历 layoutSettings 对象的键
|
|
|
|
[Key in keyof typeof layoutSettings]: Ref<(typeof layoutSettings)[Key]>
|
|
|
|
}
|
2022-04-21 18:20:39 +08:00
|
|
|
|
2023-05-26 13:04:12 +08:00
|
|
|
export const useSettingsStore = defineStore("settings", () => {
|
|
|
|
/** 状态对象 */
|
|
|
|
const state = {} as SettingsStore
|
|
|
|
// 遍历 layoutSettings 对象的键值对
|
|
|
|
for (const [key, value] of Object.entries(layoutSettings)) {
|
|
|
|
// 使用类型断言来指定 key 的类型,将 value 包装在 ref 函数中,创建一个响应式变量
|
|
|
|
state[key as keyof SettingsStore] = ref(value)
|
2022-12-08 18:06:01 +08:00
|
|
|
}
|
2023-05-26 13:04:12 +08:00
|
|
|
|
|
|
|
return state
|
2022-04-21 18:20:39 +08:00
|
|
|
})
|