:feature: 更新微信状态显示逻辑,添加设备绑定提示,并优化消息结构
Some checks failed
BuildImage / build-image (push) Has been cancelled
Some checks failed
BuildImage / build-image (push) Has been cancelled
This commit is contained in:
parent
b256d82855
commit
fb94ce31a6
@ -95,6 +95,8 @@ func CreateRobot(c *fiber.Ctx) error {
|
|||||||
Nickname: robotName,
|
Nickname: robotName,
|
||||||
Status: model.RobotStatusOffline,
|
Status: model.RobotStatusOffline,
|
||||||
}
|
}
|
||||||
|
// 处理一下设备 Id 和设备名称,防止后面出现空值
|
||||||
|
robot.CheckDevice()
|
||||||
|
|
||||||
db := model.GetDB()
|
db := model.GetDB()
|
||||||
if err = db.Create(&robot).Error; err != nil {
|
if err = db.Create(&robot).Error; err != nil {
|
||||||
@ -230,10 +232,6 @@ func RobotLogin(c *fiber.Ctx) error {
|
|||||||
}
|
}
|
||||||
return fiber.NewError(fiber.StatusInternalServerError, "查询数据库失败")
|
return fiber.NewError(fiber.StatusInternalServerError, "查询数据库失败")
|
||||||
}
|
}
|
||||||
// 处理一下设备信息
|
|
||||||
if robot.CheckDevice() {
|
|
||||||
db.Save(&robot)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查机器人是否已在线,如果在线则无需登录
|
// 检查机器人是否已在线,如果在线则无需登录
|
||||||
if robot.Status == model.RobotStatusOnline {
|
if robot.Status == model.RobotStatusOnline {
|
||||||
|
@ -5,19 +5,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ContentType 表示消息类型的枚举
|
|
||||||
type ContentType string
|
|
||||||
|
|
||||||
const (
|
|
||||||
ContentTypeText ContentType = "text"
|
|
||||||
ContentTypeImage ContentType = "image"
|
|
||||||
ContentTypeVoice ContentType = "voice"
|
|
||||||
ContentTypeVideo ContentType = "video"
|
|
||||||
ContentTypeFile ContentType = "file"
|
|
||||||
ContentTypeLocation ContentType = "location"
|
|
||||||
ContentTypeSystem ContentType = "system"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Message 表示微信消息
|
// Message 表示微信消息
|
||||||
type Message struct {
|
type Message struct {
|
||||||
BaseModel
|
BaseModel
|
||||||
@ -32,6 +19,7 @@ type Message struct {
|
|||||||
FromUser string // 发送者
|
FromUser string // 发送者
|
||||||
GroupUser string // 群成员
|
GroupUser string // 群成员
|
||||||
ToUser string // 接收者
|
ToUser string // 接收者
|
||||||
|
FileUrl string `gorm:"column:file_url"` // 文件地址
|
||||||
}
|
}
|
||||||
|
|
||||||
// TableName 指定表名
|
// TableName 指定表名
|
||||||
|
@ -114,7 +114,13 @@
|
|||||||
|
|
||||||
<!-- 操作区域 -->
|
<!-- 操作区域 -->
|
||||||
<div class="bg-gray-50 px-6 py-3 flex justify-between items-center">
|
<div class="bg-gray-50 px-6 py-3 flex justify-between items-center">
|
||||||
<span class="text-xs text-gray-500">微信状态: {{if eq .Status "online"}}在线{{else}}离线{{end}}</span>
|
<span class="text-xs text-gray-500">
|
||||||
|
{{if .WechatID}}
|
||||||
|
微信状态: {{if eq .Status "online"}}在线{{else}}离线{{end}}
|
||||||
|
{{else}}
|
||||||
|
初始化完成,待绑定微信账号
|
||||||
|
{{end}}
|
||||||
|
</span>
|
||||||
<div class="flex space-x-2">
|
<div class="flex space-x-2">
|
||||||
<a href="/admin/robots/{{.ID}}" class="p-1.5 rounded-md text-gray-600 hover:bg-gray-100 hover:text-gray-900" title="查看详情">
|
<a href="/admin/robots/{{.ID}}" class="p-1.5 rounded-md text-gray-600 hover:bg-gray-100 hover:text-gray-900" title="查看详情">
|
||||||
<i class="fas fa-eye"></i>
|
<i class="fas fa-eye"></i>
|
||||||
|
@ -56,7 +56,11 @@
|
|||||||
<div class="flex justify-between text-sm">
|
<div class="flex justify-between text-sm">
|
||||||
<span class="text-gray-600">状态</span>
|
<span class="text-gray-600">状态</span>
|
||||||
<span class="{{if eq .Robot.Status "online"}}text-emerald-600{{else if eq .Robot.Status "error"}}text-red-600{{else}}text-gray-600{{end}}">
|
<span class="{{if eq .Robot.Status "online"}}text-emerald-600{{else if eq .Robot.Status "error"}}text-red-600{{else}}text-gray-600{{end}}">
|
||||||
{{if eq .Robot.Status "online"}}在线{{else if eq .Robot.Status "error"}}错误{{else}}离线{{end}}
|
{{if .robot.WechatID}}
|
||||||
|
{{if eq .Robot.Status "online"}}在线{{else if eq .Robot.Status "error"}}错误{{else}}离线{{end}}
|
||||||
|
{{else}}
|
||||||
|
待绑定微信号
|
||||||
|
{{end}}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex justify-between text-sm">
|
<div class="flex justify-between text-sm">
|
||||||
@ -190,7 +194,7 @@
|
|||||||
|
|
||||||
// 容器ID可能长度不一致,确保使用完整ID
|
// 容器ID可能长度不一致,确保使用完整ID
|
||||||
const containerId = "{{.Robot.ContainerID}}";
|
const containerId = "{{.Robot.ContainerID}}";
|
||||||
|
|
||||||
// WebSocket连接
|
// WebSocket连接
|
||||||
let logsSocket = null;
|
let logsSocket = null;
|
||||||
|
|
||||||
@ -198,43 +202,43 @@
|
|||||||
function connectLogsWebSocket() {
|
function connectLogsWebSocket() {
|
||||||
logsLoading.style.display = 'flex';
|
logsLoading.style.display = 'flex';
|
||||||
containerLogs.textContent = '正在连接到WebSocket...';
|
containerLogs.textContent = '正在连接到WebSocket...';
|
||||||
|
|
||||||
// 关闭已存在的WebSocket连接
|
// 关闭已存在的WebSocket连接
|
||||||
if (logsSocket) {
|
if (logsSocket) {
|
||||||
logsSocket.close();
|
logsSocket.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建新的WebSocket连接
|
// 创建新的WebSocket连接
|
||||||
const wsProtocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
const wsProtocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||||
const wsUrl = `${wsProtocol}//${window.location.host}/api/v1/ws/containers/${containerId}/logs`;
|
const wsUrl = `${wsProtocol}//${window.location.host}/api/v1/ws/containers/${containerId}/logs`;
|
||||||
|
|
||||||
logsSocket = new WebSocket(wsUrl);
|
logsSocket = new WebSocket(wsUrl);
|
||||||
|
|
||||||
// 连接打开时
|
// 连接打开时
|
||||||
logsSocket.onopen = function() {
|
logsSocket.onopen = function() {
|
||||||
containerLogs.textContent = '已连接,等待日志数据...';
|
containerLogs.textContent = '已连接,等待日志数据...';
|
||||||
logsLoading.style.display = 'none';
|
logsLoading.style.display = 'none';
|
||||||
};
|
};
|
||||||
|
|
||||||
// 收到消息时
|
// 收到消息时
|
||||||
logsSocket.onmessage = function(event) {
|
logsSocket.onmessage = function(event) {
|
||||||
// 如果是第一条消息,清空容器
|
// 如果是第一条消息,清空容器
|
||||||
if (containerLogs.textContent === '已连接,等待日志数据...') {
|
if (containerLogs.textContent === '已连接,等待日志数据...') {
|
||||||
containerLogs.textContent = '';
|
containerLogs.textContent = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加新日志
|
// 添加新日志
|
||||||
containerLogs.textContent += event.data;
|
containerLogs.textContent += event.data;
|
||||||
|
|
||||||
// 自动滚动到底部
|
// 自动滚动到底部
|
||||||
containerLogs.scrollTop = containerLogs.scrollHeight;
|
containerLogs.scrollTop = containerLogs.scrollHeight;
|
||||||
};
|
};
|
||||||
|
|
||||||
// 连接关闭时
|
// 连接关闭时
|
||||||
logsSocket.onclose = function() {
|
logsSocket.onclose = function() {
|
||||||
containerLogs.textContent += '\n\n连接已关闭。点击刷新按钮重新连接。';
|
containerLogs.textContent += '\n\n连接已关闭。点击刷新按钮重新连接。';
|
||||||
};
|
};
|
||||||
|
|
||||||
// 发生错误时
|
// 发生错误时
|
||||||
logsSocket.onerror = function(error) {
|
logsSocket.onerror = function(error) {
|
||||||
containerLogs.textContent = '连接错误: ' + JSON.stringify(error);
|
containerLogs.textContent = '连接错误: ' + JSON.stringify(error);
|
||||||
@ -252,7 +256,7 @@
|
|||||||
if (data.success && data.logs) {
|
if (data.success && data.logs) {
|
||||||
containerLogs.textContent = data.logs;
|
containerLogs.textContent = data.logs;
|
||||||
containerLogs.scrollTop = containerLogs.scrollHeight;
|
containerLogs.scrollTop = containerLogs.scrollHeight;
|
||||||
|
|
||||||
// 加载历史日志后连接WebSocket获取实时日志
|
// 加载历史日志后连接WebSocket获取实时日志
|
||||||
connectLogsWebSocket();
|
connectLogsWebSocket();
|
||||||
} else {
|
} else {
|
||||||
@ -327,7 +331,7 @@
|
|||||||
// 重新加载初始日志,然后会自动重连WebSocket
|
// 重新加载初始日志,然后会自动重连WebSocket
|
||||||
loadInitialLogs();
|
loadInitialLogs();
|
||||||
});
|
});
|
||||||
|
|
||||||
logLines.addEventListener('change', function() {
|
logLines.addEventListener('change', function() {
|
||||||
// 先断开WebSocket连接
|
// 先断开WebSocket连接
|
||||||
if (logsSocket) {
|
if (logsSocket) {
|
||||||
@ -336,7 +340,7 @@
|
|||||||
// 重新加载初始日志,然后会自动重连WebSocket
|
// 重新加载初始日志,然后会自动重连WebSocket
|
||||||
loadInitialLogs();
|
loadInitialLogs();
|
||||||
});
|
});
|
||||||
|
|
||||||
refreshBtn.addEventListener('click', function() {
|
refreshBtn.addEventListener('click', function() {
|
||||||
this.classList.add('animate-spin');
|
this.classList.add('animate-spin');
|
||||||
loadStats();
|
loadStats();
|
||||||
@ -347,7 +351,7 @@
|
|||||||
|
|
||||||
// 定期更新状态
|
// 定期更新状态
|
||||||
setInterval(loadStats, 5000); // 每5秒更新一次
|
setInterval(loadStats, 5000); // 每5秒更新一次
|
||||||
|
|
||||||
// 页面关闭时断开WebSocket连接
|
// 页面关闭时断开WebSocket连接
|
||||||
window.addEventListener('beforeunload', function() {
|
window.addEventListener('beforeunload', function() {
|
||||||
if (logsSocket) {
|
if (logsSocket) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user