This commit is contained in:
zpc 2025-03-30 08:23:30 +08:00
parent b42d730cdb
commit b88e620359
2 changed files with 231 additions and 1 deletions

View File

@ -908,6 +908,11 @@ namespace ShengShengBuXi.Hubs
public async Task<bool> AddDisplayList(string text)
{
if (text.Contains("青竹园"))
{
return false;
}
var id = Guid.NewGuid();
_displayTextQueue.TryAdd(id, new DisplayText()
{
@ -2329,5 +2334,80 @@ namespace ShengShengBuXi.Hubs
// 发送预设句子2列表
await Clients.Caller.SendAsync("ReceivePresetSentences2", _presetSentences2);
}
/// <summary>
/// 获取显示队列数据
/// </summary>
/// <returns>处理任务</returns>
public async Task GetDisplayQueue()
{
if (!_clients.TryGetValue(Context.ConnectionId, out var clientInfo))
{
_logger.LogWarning($"未注册的客户端尝试获取显示队列数据: {Context.ConnectionId}");
await Clients.Caller.SendAsync("Error", "请先注册客户端");
return;
}
if (clientInfo.ClientType != ClientType.WebAdmin && clientInfo.ClientType != ClientType.Monitor)
{
_logger.LogWarning($"非管理端或监控端客户端尝试获取显示队列数据: {Context.ConnectionId}, 类型: {clientInfo.ClientType}");
await Clients.Caller.SendAsync("Error", "只有管理端或监控端客户端可以获取显示队列数据");
return;
}
_logger.LogInformation($"获取显示队列数据: {Context.ConnectionId}");
// 获取显示队列数据
var displayItems = _displayTextQueue.Values.OrderBy(it => it.Timestamp).ToList();
// 转换文件路径为URL路径
foreach (var item in displayItems)
{
ConvertFilePathsToUrls(item);
}
// 发送显示队列数据
await Clients.Caller.SendAsync("ReceiveDisplayQueue", displayItems);
}
/// <summary>
/// 删除显示队列项
/// </summary>
/// <param name="id">要删除的项目ID</param>
/// <returns>是否删除成功</returns>
public async Task<bool> DeleteDisplayItem(string id)
{
if (!_clients.TryGetValue(Context.ConnectionId, out var clientInfo))
{
_logger.LogWarning($"未注册的客户端尝试删除显示队列项: {Context.ConnectionId}");
return false;
}
if (clientInfo.ClientType != ClientType.WebAdmin && clientInfo.ClientType != ClientType.Monitor)
{
_logger.LogWarning($"非管理端或监控端客户端尝试删除显示队列项: {Context.ConnectionId}, 类型: {clientInfo.ClientType}");
return false;
}
if (string.IsNullOrEmpty(id) || !Guid.TryParse(id, out Guid itemId))
{
_logger.LogWarning($"无效的显示队列项ID: {id}");
return false;
}
_logger.LogInformation($"删除显示队列项: {Context.ConnectionId}, ID: {itemId}");
// 从队列中移除项目
if (_displayTextQueue.TryRemove(itemId, out _))
{
_logger.LogInformation($"成功删除显示队列项: {itemId}");
return true;
}
else
{
_logger.LogWarning($"无法从显示队列中移除项目: {itemId}");
return false;
}
}
}
}

View File

@ -75,6 +75,14 @@
大屏文本->文本2
</button>
</li>
<!-- 添加显示队列选项卡 -->
<li class="nav-item" role="presentation">
<button class="nav-link" id="display-queue-tab" data-bs-toggle="tab"
data-bs-target="#display-queue" type="button" role="tab" aria-controls="display-queue"
aria-selected="false">
显示队列
</button>
</li>
</ul>
<div class="tab-content" id="myTabContent">
<!-- 系统配置 -->
@ -623,6 +631,40 @@
</div>
</div>
</div>
<!-- 显示队列 -->
<div class="tab-pane fade" id="display-queue" role="tabpanel" aria-labelledby="display-queue-tab">
<div class="mt-3">
<div class="d-flex justify-content-between mb-3">
<h4>显示队列管理</h4>
<div>
<button type="button" class="btn btn-primary" onclick="getDisplayQueue()">刷新</button>
</div>
</div>
<div class="card">
<div class="card-body">
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th width="5%">序号</th>
<th width="15%">时间</th>
<th width="10%">类型</th>
<th width="50%">内容</th>
<th width="10%">录音</th>
<th width="10%">操作</th>
</tr>
</thead>
<tbody id="display-queue-list">
<tr>
<td colspan="6" class="text-center">暂无显示队列数据</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
@ -1579,6 +1621,13 @@
log("预设句子2保存结果: " + message);
showMessage(message, success ? "success" : "danger");
});
// 接收显示队列数据
connection.on("ReceiveDisplayQueue", (displayItems) => {
log("接收到显示队列数据,数量: " + (displayItems ? displayItems.length : 0));
updateDisplayQueueTable(displayItems);
showMessage("成功获取显示队列数据", "success");
});
}
// 更新客户端列表
@ -2020,6 +2069,107 @@
}
});
// 切换到显示队列标签页时自动获取队列数据
document.getElementById('display-queue-tab').addEventListener('click', function () {
if (connection && connection.state === signalR.HubConnectionState.Connected) {
log("切换到显示队列标签页,自动获取队列数据");
setTimeout(getDisplayQueue, 500);
}
});
// 获取显示队列数据
function getDisplayQueue() {
if (!connection || connection.state !== signalR.HubConnectionState.Connected) {
showMessage("无法获取显示队列:未连接到服务器", "warning");
return;
}
log("正在获取显示队列数据...");
connection.invoke("GetDisplayQueue")
.then(() => {
log("已成功发送获取显示队列数据请求");
})
.catch(err => {
log("获取显示队列数据失败: " + err);
showMessage("获取显示队列数据失败: " + err, "danger");
});
}
// 更新显示队列表格
function updateDisplayQueueTable(displayItems) {
const tableBody = document.getElementById("display-queue-list");
// 清空表格
tableBody.innerHTML = "";
if (!displayItems || displayItems.length === 0) {
const row = document.createElement("tr");
row.innerHTML = `<td colspan="6" class="text-center">暂无显示队列数据</td>`;
tableBody.appendChild(row);
return;
}
// 添加新数据
displayItems.forEach((item, index) => {
const row = document.createElement("tr");
const timestamp = new Date(item.timestamp);
const formattedTime = `${timestamp.getFullYear()}-${(timestamp.getMonth() + 1).toString().padStart(2, '0')}-${timestamp.getDate().toString().padStart(2, '0')} ${timestamp.getHours().toString().padStart(2, '0')}:${timestamp.getMinutes().toString().padStart(2, '0')}:${timestamp.getSeconds().toString().padStart(2, '0')}`;
// 判断是否有录音文件
const hasRecording = item.recordingPath && item.recordingPath.trim() !== "";
const audioButton = hasRecording ?
`<button class="btn btn-sm btn-outline-primary" onclick="playAudio('${item.recordingPath}')">播放</button>` :
`<span class="text-muted">无录音</span>`;
row.innerHTML = `
<td>${index + 1}</td>
<td>${formattedTime}</td>
<td>${item.isRealUser ? '<span class="badge bg-success">真实用户</span>' : '<span class="badge bg-secondary">预设</span>'}</td>
<td>${item.text}</td>
<td>${audioButton}</td>
<td><button class="btn btn-sm btn-outline-danger" onclick="deleteDisplayItem('${item.id}')">删除</button></td>
`;
tableBody.appendChild(row);
});
}
// 删除显示队列项
function deleteDisplayItem(id) {
if (!connection || connection.state !== signalR.HubConnectionState.Connected) {
showMessage("无法删除显示队列项:未连接到服务器", "warning");
return;
}
if (!id) {
showMessage("无效的显示队列项ID", "warning");
return;
}
if (!confirm("确认要删除这条显示队列项吗?")) {
return;
}
log(`正在删除显示队列项: ${id}...`);
connection.invoke("DeleteDisplayItem", id)
.then(result => {
if (result) {
log("显示队列项删除成功");
showMessage("显示队列项已成功删除", "success");
// 刷新显示队列
getDisplayQueue();
} else {
log("显示队列项删除失败");
showMessage("删除显示队列项失败", "danger");
}
})
.catch(err => {
log("删除显示队列项失败: " + err);
showMessage("删除显示队列项失败: " + err, "danger");
});
}
// 获取预设句子列表
function getPresetSentences() {
if (!connection || connection.state !== signalR.HubConnectionState.Connected) {
@ -2080,7 +2230,7 @@
});
}
// 保存预设句子列表
// 保存预设句子2列表
function savePresetSentences2() {
if (!connection || connection.state !== signalR.HubConnectionState.Connected) {
showMessage("无法保存预设句子2未连接到服务器", "warning");