2025-07-23 01:11:42 +08:00
|
|
|
|
import { defineStore } from 'pinia'
|
|
|
|
|
|
import { useApiFetch } from '~/composables/useApiFetch'
|
2025-08-12 00:27:10 +08:00
|
|
|
|
import { parseApiResponse } from '~/composables/useApi'
|
2025-07-23 01:11:42 +08:00
|
|
|
|
|
|
|
|
|
|
export const useSystemConfigStore = defineStore('systemConfig', {
|
|
|
|
|
|
state: () => ({
|
|
|
|
|
|
config: null as any,
|
|
|
|
|
|
initialized: false
|
|
|
|
|
|
}),
|
|
|
|
|
|
actions: {
|
2025-08-11 01:34:07 +08:00
|
|
|
|
async initConfig(force = false, useAdminApi = false) {
|
2025-07-23 01:11:42 +08:00
|
|
|
|
if (this.initialized && !force) return
|
|
|
|
|
|
try {
|
2025-08-11 01:34:07 +08:00
|
|
|
|
// 根据上下文选择API:管理员页面使用管理员API,其他页面使用公开API
|
|
|
|
|
|
const apiUrl = useAdminApi ? '/system/config' : '/public/system-config'
|
|
|
|
|
|
const response = await useApiFetch(apiUrl)
|
2025-08-08 16:51:05 +08:00
|
|
|
|
console.log('Store API响应:', response) // 调试信息
|
|
|
|
|
|
|
2025-08-12 00:27:10 +08:00
|
|
|
|
// 使用parseApiResponse正确解析API响应
|
|
|
|
|
|
const data = parseApiResponse(response)
|
2025-08-08 16:51:05 +08:00
|
|
|
|
console.log('Store 处理后的数据:', data) // 调试信息
|
2025-08-12 00:27:10 +08:00
|
|
|
|
console.log('Store 自动处理状态:', data.auto_process_ready_resources)
|
|
|
|
|
|
console.log('Store 自动转存状态:', data.auto_transfer_enabled)
|
2025-08-08 16:51:05 +08:00
|
|
|
|
|
2025-07-23 01:11:42 +08:00
|
|
|
|
this.config = data
|
|
|
|
|
|
this.initialized = true
|
|
|
|
|
|
} catch (e) {
|
2025-08-08 16:51:05 +08:00
|
|
|
|
console.error('Store 获取系统配置失败:', e) // 调试信息
|
2025-07-23 01:11:42 +08:00
|
|
|
|
// 可根据需要处理错误
|
|
|
|
|
|
this.config = null
|
|
|
|
|
|
this.initialized = false
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
setConfig(newConfig: any) {
|
|
|
|
|
|
this.config = newConfig
|
|
|
|
|
|
this.initialized = true
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|