import { updatePreferences } from '@vben/preferences'; import { acceptHMRUpdate, defineStore } from 'pinia'; import { ConfigApi } from '#/api'; interface AccessState { /** * 配置信息 */ appInfo: ConfigApi.AppInfo | null; } /** * @zh_CN 配置信息相关 */ export const useAppStore = defineStore('web-info', { actions: { setAppInfo(appInfo: ConfigApi.AppInfo | null) { this.appInfo = appInfo; updatePreferences({ app: { watermark: appInfo?.openWatermark, name: appInfo?.webTitle, }, }); }, async loadAppInfo() { const appInfo = await ConfigApi.getWebInfo(); this.setAppInfo(appInfo); return appInfo; }, }, state: (): AccessState => ({ appInfo: null, }), persist: { // 持久化 pick: ['appInfo.webWatermark'], }, }); // 解决热更新问题 const hot = import.meta.hot; if (hot) { hot.accept(acceptHMRUpdate(useAppStore, hot)); }