🎨 更新机器人状态统计逻辑,调整前端显示信息,优化删除确认交互
All checks were successful
BuildImage / build-image (push) Successful in 1m52s
All checks were successful
BuildImage / build-image (push) Successful in 1m52s
This commit is contained in:
parent
0bd777d959
commit
e91c9ec94b
@ -25,9 +25,25 @@ func ListRobots(c *fiber.Ctx) error {
|
|||||||
return fiber.NewError(fiber.StatusInternalServerError, "获取机器人列表失败")
|
return fiber.NewError(fiber.StatusInternalServerError, "获取机器人列表失败")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
total := len(robots)
|
||||||
|
online := 0
|
||||||
|
offline := 0
|
||||||
|
for _, robot := range robots {
|
||||||
|
if robot.Status == model.RobotStatusOnline {
|
||||||
|
online++
|
||||||
|
} else {
|
||||||
|
offline++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return c.Render("robot/index", fiber.Map{
|
return c.Render("robot/index", fiber.Map{
|
||||||
"Title": "机器人列表",
|
"Title": "机器人列表",
|
||||||
"Robots": robots,
|
"Robots": robots,
|
||||||
|
"Status": map[string]int{
|
||||||
|
"Total": total,
|
||||||
|
"Online": online,
|
||||||
|
"Offline": offline,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,23 +37,23 @@
|
|||||||
|
|
||||||
<!-- 统计信息 -->
|
<!-- 统计信息 -->
|
||||||
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
|
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
|
||||||
<div class="clean-card px-6 py-4 flex items-center">
|
|
||||||
<div class="w-12 h-12 rounded-full bg-emerald-50 border border-emerald-100 flex items-center justify-center text-emerald-500 mr-4">
|
|
||||||
<i class="fas fa-check-circle text-xl"></i>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<p class="text-sm text-gray-600">在线机器人</p>
|
|
||||||
<p class="text-2xl font-semibold text-gray-800" id="online-count">{{.OnlineCount}}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="clean-card px-6 py-4 flex items-center">
|
<div class="clean-card px-6 py-4 flex items-center">
|
||||||
<div class="w-12 h-12 rounded-full bg-blue-50 border border-blue-100 flex items-center justify-center text-blue-500 mr-4">
|
<div class="w-12 h-12 rounded-full bg-blue-50 border border-blue-100 flex items-center justify-center text-blue-500 mr-4">
|
||||||
<i class="fas fa-robot text-xl"></i>
|
<i class="fas fa-robot text-xl"></i>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<p class="text-sm text-gray-600">总机器人</p>
|
<p class="text-sm text-gray-600">总机器人</p>
|
||||||
<p class="text-2xl font-semibold text-gray-800" id="filtered-count">{{len .Robots}}</p>
|
<p class="text-2xl font-semibold text-gray-800" id="filtered-count">{{.Status.Total}}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="clean-card px-6 py-4 flex items-center">
|
||||||
|
<div class="w-12 h-12 rounded-full bg-emerald-50 border border-emerald-100 flex items-center justify-center text-emerald-500 mr-4">
|
||||||
|
<i class="fas fa-check-circle text-xl"></i>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p class="text-sm text-gray-600">在线机器人</p>
|
||||||
|
<p class="text-2xl font-semibold text-gray-800" id="online-count">{{.Status.Online}}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -63,7 +63,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<p class="text-sm text-gray-600">离线机器人</p>
|
<p class="text-sm text-gray-600">离线机器人</p>
|
||||||
<p class="text-2xl font-semibold text-gray-800" id="offline-count">{{.OfflineCount}}</p>
|
<p class="text-2xl font-semibold text-gray-800" id="offline-count">{{.Status.Offline}}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -150,55 +150,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
|
||||||
// 计算不同状态机器人数量
|
|
||||||
let onlineCount = 0;
|
|
||||||
let offlineCount = 0;
|
|
||||||
let errorCount = 0;
|
|
||||||
|
|
||||||
document.querySelectorAll('.robot-card').forEach(card => {
|
|
||||||
const status = card.dataset.status;
|
|
||||||
if (status === 'online') {
|
|
||||||
onlineCount++;
|
|
||||||
} else if (status === 'error') {
|
|
||||||
errorCount++;
|
|
||||||
} else {
|
|
||||||
offlineCount++;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// 更新统计数字
|
|
||||||
document.getElementById('online-count').textContent = onlineCount;
|
|
||||||
document.getElementById('offline-count').textContent = offlineCount;
|
|
||||||
document.getElementById('error-count').textContent = errorCount;
|
|
||||||
|
|
||||||
// 删除机器人确认
|
|
||||||
document.querySelectorAll('.delete-robot').forEach(btn => {
|
|
||||||
btn.addEventListener('click', async function(e) {
|
|
||||||
e.preventDefault();
|
|
||||||
const robotId = this.dataset.id;
|
|
||||||
const robotName = this.dataset.robotName || '此机器人';
|
|
||||||
|
|
||||||
if (window.confirm(`确定要删除 ${robotName} 吗?此操作不可恢复!`)) {
|
|
||||||
// 使用fetch API发送DELETE请求
|
|
||||||
fetch(`/admin/robots/${robotId}`, { method: 'DELETE' })
|
|
||||||
.then(response => {
|
|
||||||
if (response.ok) {
|
|
||||||
window.location.reload();
|
|
||||||
} else {
|
|
||||||
throw new Error('删除失败');
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error('Error:', error);
|
|
||||||
alert('删除失败: ' + error.message);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user