feat:冗余代码清理
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { ElNotification } from 'element-plus'
|
||||
import { pick } from 'lodash'
|
||||
|
||||
import { ElMessage } from 'element-plus'
|
||||
import api from '@/api/index.ts'
|
||||
|
||||
import SvgIcon from '@/components/SvgIcon/index.vue'
|
||||
import { agentMapDuty } from '@/layout/components/config.ts'
|
||||
import { type Agent, useAgentsStore } from '@/stores'
|
||||
@@ -39,82 +37,41 @@ const handleFileSelect = (event: Event) => {
|
||||
}
|
||||
}
|
||||
|
||||
// 在validateApiConfig函数中添加更详细的日志
|
||||
// 验证API配置:三个字段必须同时存在或同时不存在
|
||||
const validateApiConfig = (agent: any) => {
|
||||
const hasApiUrl = 'apiUrl' in agent
|
||||
const hasApiKey = 'apiKey' in agent
|
||||
const hasApiModel = 'apiModel' in agent
|
||||
|
||||
// 三个字段必须同时存在或同时不存在
|
||||
if (hasApiUrl !== hasApiKey || hasApiKey !== hasApiModel) {
|
||||
console.error('❌ API配置不完整:', {
|
||||
agentName: agent.Name,
|
||||
missingFields: {
|
||||
apiUrl: !hasApiUrl,
|
||||
apiKey: !hasApiKey,
|
||||
apiModel: !hasApiModel
|
||||
}
|
||||
})
|
||||
return false
|
||||
}
|
||||
|
||||
if (hasApiUrl && hasApiKey && hasApiModel) {
|
||||
console.log('✅ API配置完整,将使用自定义API配置:', {
|
||||
apiUrl: agent.apiUrl,
|
||||
apiKey: agent.apiKey ? '***' + agent.apiKey.slice(-4) : '未设置',
|
||||
apiModel: agent.apiModel
|
||||
})
|
||||
} else {
|
||||
console.log('ℹ️ 未设置API配置,将使用默认URL配置')
|
||||
}
|
||||
|
||||
return true
|
||||
return hasApiUrl === hasApiKey && hasApiKey === hasApiModel
|
||||
}
|
||||
|
||||
const readFileContent = (file: File) => {
|
||||
console.log('📁 开始读取文件:', file.name, '大小:', file.size, '类型:', file.type)
|
||||
|
||||
const reader = new FileReader()
|
||||
reader.onload = e => {
|
||||
try {
|
||||
console.log('📄 文件读取完成,开始解析JSON')
|
||||
const content = e.target?.result as string
|
||||
const jsonData = JSON.parse(content)
|
||||
|
||||
console.log('🔍 解析的JSON数据:', jsonData)
|
||||
console.log(
|
||||
'📊 数据类型:',
|
||||
Array.isArray(jsonData) ? '数组' : '对象',
|
||||
'长度:',
|
||||
Array.isArray(jsonData) ? jsonData.length : 'N/A'
|
||||
)
|
||||
|
||||
if (!Array.isArray(jsonData)) {
|
||||
console.error('❌ JSON格式错误: 必须为数组格式')
|
||||
ElMessage.error('JSON格式错误: 必须为数组格式')
|
||||
return
|
||||
}
|
||||
|
||||
console.log('🔍 开始验证智能体数据...')
|
||||
const validAgents = jsonData.filter((agent, index) => {
|
||||
console.log(`🔍 验证第${index + 1}个智能体:`, agent.Name || '未命名')
|
||||
const validAgents = jsonData.filter((agent) => {
|
||||
// 验证必需字段
|
||||
if (!agent.Name || typeof agent.Name !== 'string') {
|
||||
console.error(`❌ 智能体${index + 1}缺少Name字段或格式错误`)
|
||||
return false
|
||||
}
|
||||
if (!agent.Icon || typeof agent.Icon !== 'string') {
|
||||
console.error(`❌ 智能体${index + 1}缺少Icon字段或格式错误`)
|
||||
return false
|
||||
}
|
||||
if (!agent.Profile || typeof agent.Profile !== 'string') {
|
||||
console.error(`❌ 智能体${index + 1}缺少Profile字段或格式错误`)
|
||||
return false
|
||||
}
|
||||
|
||||
// 验证API配置
|
||||
if (!validateApiConfig(agent)) {
|
||||
console.error(`❌ 智能体${index + 1}API配置验证失败`)
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -137,21 +94,17 @@ const readFileContent = (file: File) => {
|
||||
api
|
||||
.setAgents(processedAgents)
|
||||
.then(() => {
|
||||
console.log('✅ 后端API调用成功')
|
||||
ElMessage.success('智能体上传成功')
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('❌ 后端API调用失败:', error)
|
||||
.catch(() => {
|
||||
ElMessage.error('智能体上传失败')
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('❌ JSON解析错误:', error)
|
||||
} catch {
|
||||
ElMessage.error('JSON解析错误')
|
||||
}
|
||||
}
|
||||
|
||||
reader.onerror = error => {
|
||||
console.error('❌ 文件读取错误:', error)
|
||||
reader.onerror = () => {
|
||||
ElMessage.error('文件读取错误')
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user