40 lines
917 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { defineStore } from 'pinia'
import { readConfig } from '@/utils/readJson.ts'
import { store } from '@/stores'
export interface Config {
title: string
subTitle: string
centerTitle: string
taskPromptWords: string[]
agentRepository: {
storageVersionIdentifier: string
}
}
export const useConfigStore = defineStore('config', () => {
const config = ref<Config>({} as Config)
// 异步调用readConfig
async function initConfig() {
config.value = await readConfig<Config>('config.json')
}
return {
config,
initConfig
}
})
/**
* 用于在组件外部如在Pinia Store 中)使用 Pinia 提供的 store 实例。
* 官方文档解释了如何在组件外部使用 Pinia Store
* https://pinia.vuejs.org/core-concepts/outside-component-usage.html#using-a-store-outside-of-a-component
*/
export function useConfigStoreHook() {
return useConfigStore(store)
}