优化
This commit is contained in:
@@ -1,61 +1,64 @@
|
||||
/**
|
||||
* AI模型配置 API 服务
|
||||
* 用于获取模型积分消耗配置
|
||||
* AI第三方服务配置 API 服务
|
||||
* 用于获取服务积分消耗配置
|
||||
*/
|
||||
|
||||
import http from './http'
|
||||
|
||||
const BASE_URL = '/webApi/api/tik/ai-model-config'
|
||||
const BASE_URL = '/webApi/api/tik/ai-service-config'
|
||||
|
||||
/**
|
||||
* 模型配置 API 服务
|
||||
* 服务配置 API 服务
|
||||
*/
|
||||
export const ModelConfigService = {
|
||||
export const ServiceConfigService = {
|
||||
/**
|
||||
* 获取所有启用的模型配置列表(按平台分组)
|
||||
* @returns {Promise<Object>} 按平台分组的模型配置
|
||||
* 格式: { platform: [{ modelCode, modelName, consumePoints }] }
|
||||
* 获取所有启用的服务配置列表(按平台分组)
|
||||
* @returns {Promise<Object>} 按平台分组的服务配置
|
||||
* 格式: { platform: [{ serviceCode, serviceName, consumePoints }] }
|
||||
*/
|
||||
async getEnabledModelConfigList() {
|
||||
async getEnabledServiceConfigList() {
|
||||
const { data } = await http.get(`${BASE_URL}/list-enabled`)
|
||||
return data || {}
|
||||
},
|
||||
|
||||
/**
|
||||
* 根据模型代码获取积分消耗
|
||||
* @param {Object} configMap - 配置映射(从 getEnabledModelConfigList 获取)
|
||||
* @param {string} modelCode - 模型代码
|
||||
* 根据服务代码获取积分消耗
|
||||
* @param {Object} configMap - 配置映射(从 getEnabledServiceConfigList 获取)
|
||||
* @param {string} serviceCode - 服务代码
|
||||
* @returns {number|null} 积分消耗,未找到返回 null
|
||||
*/
|
||||
getConsumePoints(configMap, modelCode) {
|
||||
if (!configMap || !modelCode) return null
|
||||
getConsumePoints(configMap, serviceCode) {
|
||||
if (!configMap || !serviceCode) return null
|
||||
|
||||
for (const platform of Object.values(configMap)) {
|
||||
const model = platform?.find(m => m.modelCode === modelCode)
|
||||
if (model) {
|
||||
return model.consumePoints
|
||||
const service = platform?.find(s => s.serviceCode === serviceCode)
|
||||
if (service) {
|
||||
return service.consumePoints
|
||||
}
|
||||
}
|
||||
return null
|
||||
},
|
||||
|
||||
/**
|
||||
* 根据模型代码获取模型名称
|
||||
* 根据服务代码获取服务名称
|
||||
* @param {Object} configMap - 配置映射
|
||||
* @param {string} modelCode - 模型代码
|
||||
* @returns {string|null} 模型名称,未找到返回 null
|
||||
* @param {string} serviceCode - 服务代码
|
||||
* @returns {string|null} 服务名称,未找到返回 null
|
||||
*/
|
||||
getModelName(configMap, modelCode) {
|
||||
if (!configMap || !modelCode) return null
|
||||
getServiceName(configMap, serviceCode) {
|
||||
if (!configMap || !serviceCode) return null
|
||||
|
||||
for (const platform of Object.values(configMap)) {
|
||||
const model = platform?.find(m => m.modelCode === modelCode)
|
||||
if (model) {
|
||||
return model.modelName
|
||||
const service = platform?.find(s => s.serviceCode === serviceCode)
|
||||
if (service) {
|
||||
return service.serviceName
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export default ModelConfigService
|
||||
// 兼容旧名称(逐步废弃)
|
||||
export const ModelConfigService = ServiceConfigService
|
||||
|
||||
export default ServiceConfigService
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
/**
|
||||
* 积分配置 Store
|
||||
* 管理AI模型积分消耗配置
|
||||
* 管理AI服务积分消耗配置
|
||||
*/
|
||||
|
||||
import { ref, computed } from 'vue'
|
||||
import { defineStore } from 'pinia'
|
||||
import { getJSON, setJSON } from '@/utils/storage'
|
||||
import ModelConfigService from '@/api/modelConfig'
|
||||
import ServiceConfigService from '@/api/modelConfig'
|
||||
|
||||
const STORAGE_KEY = 'points_config_v1'
|
||||
const CACHE_DURATION = 30 * 60 * 1000 // 30分钟缓存
|
||||
|
||||
export const usePointsConfigStore = defineStore('pointsConfig', () => {
|
||||
// 模型配置映射(按平台分组)
|
||||
// 服务配置映射(按平台分组)
|
||||
const configMap = ref({})
|
||||
// 是否已加载
|
||||
const isLoaded = ref(false)
|
||||
@@ -24,57 +24,66 @@ export const usePointsConfigStore = defineStore('pointsConfig', () => {
|
||||
// 所有平台列表
|
||||
const platforms = computed(() => Object.keys(configMap.value))
|
||||
|
||||
// 获取所有模型列表(扁平化)
|
||||
const allModels = computed(() => {
|
||||
const models = []
|
||||
// 获取所有服务列表(扁平化)
|
||||
const allServices = computed(() => {
|
||||
const services = []
|
||||
for (const [platform, list] of Object.entries(configMap.value)) {
|
||||
if (Array.isArray(list)) {
|
||||
list.forEach(model => {
|
||||
models.push({ ...model, platform })
|
||||
list.forEach(service => {
|
||||
services.push({ ...service, platform })
|
||||
})
|
||||
}
|
||||
}
|
||||
return models
|
||||
return services
|
||||
})
|
||||
|
||||
// 兼容:allModels 别名
|
||||
const allModels = allServices
|
||||
|
||||
/**
|
||||
* 根据模型代码获取积分消耗
|
||||
* @param {string} modelCode - 模型代码
|
||||
* 根据服务代码获取积分消耗
|
||||
* @param {string} serviceCode - 服务代码
|
||||
* @returns {number|null} 积分消耗
|
||||
*/
|
||||
const getConsumePoints = (modelCode) => {
|
||||
if (!modelCode) return null
|
||||
return ModelConfigService.getConsumePoints(configMap.value, modelCode)
|
||||
const getConsumePoints = (serviceCode) => {
|
||||
if (!serviceCode) return null
|
||||
return ServiceConfigService.getConsumePoints(configMap.value, serviceCode)
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据模型代码获取模型名称
|
||||
* @param {string} modelCode - 模型代码
|
||||
* @returns {string|null} 模型名称
|
||||
* 根据服务代码获取服务名称
|
||||
* @param {string} serviceCode - 服务代码
|
||||
* @returns {string|null} 服务名称
|
||||
*/
|
||||
const getModelName = (modelCode) => {
|
||||
if (!modelCode) return null
|
||||
return ModelConfigService.getModelName(configMap.value, modelCode)
|
||||
const getServiceName = (serviceCode) => {
|
||||
if (!serviceCode) return null
|
||||
return ServiceConfigService.getServiceName(configMap.value, serviceCode)
|
||||
}
|
||||
|
||||
// 兼容:getModelName 别名
|
||||
const getModelName = getServiceName
|
||||
|
||||
/**
|
||||
* 获取模型完整信息
|
||||
* @param {string} modelCode - 模型代码
|
||||
* @returns {Object|null} 模型信息 { modelCode, modelName, consumePoints, platform }
|
||||
* 获取服务完整信息
|
||||
* @param {string} serviceCode - 服务代码
|
||||
* @returns {Object|null} 服务信息 { serviceCode, serviceName, consumePoints, platform }
|
||||
*/
|
||||
const getModelInfo = (modelCode) => {
|
||||
if (!modelCode) return null
|
||||
const getServiceInfo = (serviceCode) => {
|
||||
if (!serviceCode) return null
|
||||
for (const [platform, list] of Object.entries(configMap.value)) {
|
||||
if (Array.isArray(list)) {
|
||||
const model = list.find(m => m.modelCode === modelCode)
|
||||
if (model) {
|
||||
return { ...model, platform }
|
||||
const service = list.find(s => s.serviceCode === serviceCode)
|
||||
if (service) {
|
||||
return { ...service, platform }
|
||||
}
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
// 兼容:getModelInfo 别名
|
||||
const getModelInfo = getServiceInfo
|
||||
|
||||
/**
|
||||
* 从本地存储恢复
|
||||
*/
|
||||
@@ -98,7 +107,7 @@ export const usePointsConfigStore = defineStore('pointsConfig', () => {
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载模型配置(从服务器)
|
||||
* 加载服务配置(从服务器)
|
||||
* @param {boolean} force - 是否强制刷新
|
||||
*/
|
||||
const loadConfig = async (force = false) => {
|
||||
@@ -115,14 +124,14 @@ export const usePointsConfigStore = defineStore('pointsConfig', () => {
|
||||
|
||||
isLoading.value = true
|
||||
try {
|
||||
const data = await ModelConfigService.getEnabledModelConfigList()
|
||||
const data = await ServiceConfigService.getEnabledServiceConfigList()
|
||||
configMap.value = data || {}
|
||||
lastLoadTime.value = now
|
||||
isLoaded.value = true
|
||||
await persistToStorage()
|
||||
return configMap.value
|
||||
} catch (error) {
|
||||
console.error('[pointsConfig] 加载模型配置失败:', error)
|
||||
console.error('[pointsConfig] 加载服务配置失败:', error)
|
||||
throw error
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
@@ -149,11 +158,14 @@ export const usePointsConfigStore = defineStore('pointsConfig', () => {
|
||||
isLoaded,
|
||||
isLoading,
|
||||
platforms,
|
||||
allModels,
|
||||
allServices,
|
||||
allModels, // 兼容
|
||||
// 方法
|
||||
getConsumePoints,
|
||||
getModelName,
|
||||
getModelInfo,
|
||||
getServiceName,
|
||||
getModelName, // 兼容
|
||||
getServiceInfo,
|
||||
getModelInfo, // 兼容
|
||||
loadConfig,
|
||||
formatPoints,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user