import { defineStore } from 'pinia' import { getConfig } from '~~/api/app' interface AppSate { config: Record } export const useAppStore = defineStore({ id: 'appStore', state: (): AppSate => ({ config: {} }), getters: { getImageUrl: (state) => (url: string) => url ? `${state.config.domain}${url}` : '', getWebsiteConfig: (state) => state.config.website || {}, getLoginConfig: (state) => state.config.login || {}, getCopyrightConfig: (state) => state.config.copyright || [], getQrcodeConfig: (state) => state.config.qrcode || {}, getAdminUrl: (state) => state.config.admin_url, getSiteStatistics: (state) => state.config.siteStatistics || {} }, actions: { async getConfig() { try { const config = await getConfig() // 确保 config 是对象(避免接口返回非对象值) this.config = typeof config === 'object' && config !== null ? config : {} } catch (error) { console.error('获取配置失败:', error) this.config = {} // 出错时兜底为空对象 } } } })