注册服务
This commit is contained in:
@@ -178,87 +178,41 @@ const formatDate = (dateString: string) => {
|
||||
// 加载服务列表
|
||||
const loadServices = async () => {
|
||||
try {
|
||||
// 这里应该调用后端API获取服务列表
|
||||
// 暂时使用模拟数据
|
||||
services.value = [
|
||||
{
|
||||
id: '1',
|
||||
service_id: 'service-001',
|
||||
name: '图像分类服务',
|
||||
algorithm_name: 'image-classification',
|
||||
version: '1.0.0',
|
||||
status: 'running',
|
||||
host: '192.168.1.100',
|
||||
port: 8000,
|
||||
api_url: 'http://192.168.1.100:8000/execute',
|
||||
start_time: new Date().toISOString(),
|
||||
last_heartbeat: new Date().toISOString(),
|
||||
description: '基于ResNet的图像分类服务',
|
||||
config: {
|
||||
cpu_limit: '2核',
|
||||
memory_limit: '4GB',
|
||||
replicas: 2,
|
||||
timeout: 30
|
||||
},
|
||||
logs: [
|
||||
'[2024-01-01 10:00:00] 服务启动成功',
|
||||
'[2024-01-01 10:05:00] 注册到服务中心',
|
||||
'[2024-01-01 10:10:00] 处理请求: 图像分类',
|
||||
'[2024-01-01 10:15:00] 请求处理完成,耗时: 120ms'
|
||||
]
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
service_id: 'service-002',
|
||||
name: '文本分类服务',
|
||||
algorithm_name: 'text-classification',
|
||||
version: '1.0.0',
|
||||
status: 'stopped',
|
||||
host: '192.168.1.101',
|
||||
port: 8001,
|
||||
api_url: 'http://192.168.1.101:8001/execute',
|
||||
start_time: new Date().toISOString(),
|
||||
last_heartbeat: new Date().toISOString(),
|
||||
description: '基于BERT的文本分类服务',
|
||||
config: {
|
||||
cpu_limit: '4核',
|
||||
memory_limit: '8GB',
|
||||
replicas: 1,
|
||||
timeout: 60
|
||||
},
|
||||
logs: [
|
||||
'[2024-01-01 09:00:00] 服务启动成功',
|
||||
'[2024-01-01 09:30:00] 服务停止'
|
||||
]
|
||||
},
|
||||
{
|
||||
id: '3',
|
||||
service_id: 'service-003',
|
||||
name: '目标检测服务',
|
||||
algorithm_name: 'object-detection',
|
||||
version: '2.0.0',
|
||||
status: 'running',
|
||||
host: '192.168.1.102',
|
||||
port: 8002,
|
||||
api_url: 'http://192.168.1.102:8002/execute',
|
||||
start_time: new Date().toISOString(),
|
||||
last_heartbeat: new Date().toISOString(),
|
||||
description: '基于YOLOv5的目标检测服务',
|
||||
config: {
|
||||
cpu_limit: '8核',
|
||||
memory_limit: '16GB',
|
||||
replicas: 1,
|
||||
timeout: 120
|
||||
},
|
||||
logs: [
|
||||
'[2024-01-01 11:00:00] 服务启动成功',
|
||||
'[2024-01-01 11:05:00] 注册到服务中心',
|
||||
'[2024-01-01 11:10:00] 处理请求: 目标检测',
|
||||
'[2024-01-01 11:15:00] 请求处理完成,耗时: 500ms'
|
||||
]
|
||||
// 从本地存储获取token
|
||||
const token = localStorage.getItem('token')
|
||||
if (!token) {
|
||||
ElMessage.error('未登录,请重新登录')
|
||||
return
|
||||
}
|
||||
|
||||
// 调用后端API获取服务列表
|
||||
const response = await fetch('http://0.0.0.0:8001/api/v1/services', {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${token}`
|
||||
}
|
||||
]
|
||||
console.log('服务列表加载完成')
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('获取服务列表失败')
|
||||
}
|
||||
|
||||
const data = await response.json()
|
||||
if (data.success) {
|
||||
// 处理服务数据,添加缺失的字段
|
||||
services.value = data.services.map((service: any) => ({
|
||||
...service,
|
||||
last_heartbeat: service.last_heartbeat || null,
|
||||
start_time: service.start_time || null,
|
||||
description: service.description || '',
|
||||
config: service.config || {},
|
||||
logs: []
|
||||
}))
|
||||
console.log('服务列表加载完成', services.value)
|
||||
} else {
|
||||
throw new Error(data.message || '获取服务列表失败')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载服务列表失败:', error)
|
||||
ElMessage.error('加载服务列表失败')
|
||||
|
||||
Reference in New Issue
Block a user