40 lines
917 B
TypeScript
40 lines
917 B
TypeScript
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)
|
||
}
|