提交3123
This commit is contained in:
parent
29a4e92942
commit
3ed4da7571
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"SignalRHubUrl": "http://localhost:81/audiohub",
|
||||
"SignalRHubUrl": "http://115.159.44.16/audiohub",
|
||||
"ConfigBackupPath": "config.json",
|
||||
"AutoConnectToServer": true,
|
||||
"AllowOfflineStart": false
|
||||
|
|
|
|||
|
|
@ -2130,5 +2130,197 @@ namespace ShengShengBuXi.Hubs
|
|||
var clients = _clients.Values.ToList();
|
||||
await Clients.Caller.SendAsync("ClientList", clients);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取预设句子列表
|
||||
/// </summary>
|
||||
/// <returns>处理任务</returns>
|
||||
public async Task GetPresetSentences()
|
||||
{
|
||||
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}");
|
||||
|
||||
// 确保列表已加载
|
||||
if (_presetSentences.Count == 0)
|
||||
{
|
||||
LoadPresetSentencesFromFile();
|
||||
}
|
||||
|
||||
// 发送预设句子列表
|
||||
await Clients.Caller.SendAsync("ReceivePresetSentences", _presetSentences);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存预设句子列表
|
||||
/// </summary>
|
||||
/// <param name="sentences">句子列表</param>
|
||||
/// <returns>处理任务</returns>
|
||||
public async Task SavePresetSentences(List<string> sentences)
|
||||
{
|
||||
sentences = sentences.Where(it => !string.IsNullOrEmpty(it)).ToList();
|
||||
if (!_clients.TryGetValue(Context.ConnectionId, out var clientInfo))
|
||||
{
|
||||
_logger.LogWarning($"未注册的客户端尝试保存预设句子列表: {Context.ConnectionId}");
|
||||
await Clients.Caller.SendAsync("PresetSentencesSaved", false, "请先注册客户端");
|
||||
return;
|
||||
}
|
||||
|
||||
if (clientInfo.ClientType != ClientType.WebAdmin && clientInfo.ClientType != ClientType.Monitor)
|
||||
{
|
||||
_logger.LogWarning($"非管理端或监控端客户端尝试保存预设句子列表: {Context.ConnectionId}, 类型: {clientInfo.ClientType}");
|
||||
await Clients.Caller.SendAsync("PresetSentencesSaved", false, "只有管理端或监控端客户端可以保存预设句子列表");
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogInformation($"保存预设句子列表: {Context.ConnectionId}, 句子数量: {sentences?.Count ?? 0}");
|
||||
|
||||
if (sentences == null)
|
||||
{
|
||||
await Clients.Caller.SendAsync("PresetSentencesSaved", false, "句子列表不能为空");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// 更新内存中的列表
|
||||
_presetSentences.Clear();
|
||||
foreach (var sentence in sentences)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(sentence))
|
||||
{
|
||||
_presetSentences.Add(sentence.Trim());
|
||||
}
|
||||
}
|
||||
|
||||
// 确保目录存在
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(_sentencesFilePath));
|
||||
|
||||
// 保存到文件
|
||||
File.WriteAllLines(_sentencesFilePath, _presetSentences);
|
||||
|
||||
_logger.LogInformation($"成功保存预设句子到文件: {_presetSentences.Count} 条");
|
||||
|
||||
// 通知调用客户端保存成功
|
||||
await Clients.Caller.SendAsync("PresetSentencesSaved", true, $"成功保存 {_presetSentences.Count} 条预设句子");
|
||||
|
||||
// 通知其他管理端和监控端客户端预设句子已更新
|
||||
await Clients.OthersInGroup("webadmin").SendAsync("PresetSentencesUpdated");
|
||||
await Clients.OthersInGroup("monitor").SendAsync("PresetSentencesUpdated");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError($"保存预设句子失败: {ex.Message}");
|
||||
await Clients.Caller.SendAsync("PresetSentencesSaved", false, $"保存预设句子失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存预设句子2列表
|
||||
/// </summary>
|
||||
/// <param name="sentences">句子列表</param>
|
||||
/// <returns>处理任务</returns>
|
||||
public async Task SavePresetSentences2(List<string> sentences)
|
||||
{
|
||||
sentences = sentences.Where(it => !string.IsNullOrEmpty(it)).ToList();
|
||||
if (!_clients.TryGetValue(Context.ConnectionId, out var clientInfo))
|
||||
{
|
||||
_logger.LogWarning($"未注册的客户端尝试保存预设句子2列表: {Context.ConnectionId}");
|
||||
await Clients.Caller.SendAsync("PresetSentences2Saved", false, "请先注册客户端");
|
||||
return;
|
||||
}
|
||||
|
||||
if (clientInfo.ClientType != ClientType.WebAdmin && clientInfo.ClientType != ClientType.Monitor)
|
||||
{
|
||||
_logger.LogWarning($"非管理端或监控端客户端尝试保存预设句子2列表: {Context.ConnectionId}, 类型: {clientInfo.ClientType}");
|
||||
await Clients.Caller.SendAsync("PresetSentences2Saved", false, "只有管理端或监控端客户端可以保存预设句子2列表");
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogInformation($"保存预设句子2列表: {Context.ConnectionId}, 句子数量: {sentences?.Count ?? 0}");
|
||||
|
||||
if (sentences == null)
|
||||
{
|
||||
await Clients.Caller.SendAsync("PresetSentences2Saved", false, "句子列表不能为空");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// 更新内存中的列表
|
||||
_presetSentences2.Clear();
|
||||
foreach (var sentence in sentences)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(sentence))
|
||||
{
|
||||
_presetSentences2.Add(sentence.Trim());
|
||||
}
|
||||
}
|
||||
|
||||
// 确保目录存在
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(_sentences2FilePath));
|
||||
|
||||
// 保存到文件
|
||||
File.WriteAllLines(_sentences2FilePath, _presetSentences2);
|
||||
|
||||
_logger.LogInformation($"成功保存预设句子2到文件: {_presetSentences2.Count} 条");
|
||||
|
||||
// 通知调用客户端保存成功
|
||||
await Clients.Caller.SendAsync("PresetSentences2Saved", true, $"成功保存 {_presetSentences2.Count} 条预设句子2");
|
||||
|
||||
// 通知其他管理端和监控端客户端预设句子2已更新
|
||||
await Clients.OthersInGroup("webadmin").SendAsync("PresetSentencesUpdated");
|
||||
await Clients.OthersInGroup("monitor").SendAsync("PresetSentencesUpdated");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError($"保存预设句子2失败: {ex.Message}");
|
||||
await Clients.Caller.SendAsync("PresetSentences2Saved", false, $"保存预设句子2失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取预设句子2列表
|
||||
/// </summary>
|
||||
/// <returns>处理任务</returns>
|
||||
public async Task GetPresetSentences2()
|
||||
{
|
||||
if (!_clients.TryGetValue(Context.ConnectionId, out var clientInfo))
|
||||
{
|
||||
_logger.LogWarning($"未注册的客户端尝试获取预设句子2列表: {Context.ConnectionId}");
|
||||
await Clients.Caller.SendAsync("Error", "请先注册客户端");
|
||||
return;
|
||||
}
|
||||
|
||||
if (clientInfo.ClientType != ClientType.WebAdmin && clientInfo.ClientType != ClientType.Monitor)
|
||||
{
|
||||
_logger.LogWarning($"非管理端或监控端客户端尝试获取预设句子2列表: {Context.ConnectionId}, 类型: {clientInfo.ClientType}");
|
||||
await Clients.Caller.SendAsync("Error", "只有管理端或监控端客户端可以获取预设句子2列表");
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogInformation($"获取预设句子2列表: {Context.ConnectionId}");
|
||||
|
||||
// 确保列表已加载
|
||||
if (_presetSentences2.Count == 0)
|
||||
{
|
||||
LoadPresetSentences2FromFile();
|
||||
}
|
||||
|
||||
// 发送预设句子2列表
|
||||
await Clients.Caller.SendAsync("ReceivePresetSentences2", _presetSentences2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -53,6 +53,18 @@
|
|||
data-bs-target="#user-records" type="button" role="tab" aria-controls="user-records"
|
||||
aria-selected="false">用户记录</button>
|
||||
</li>
|
||||
<!-- 添加大屏文本选项卡 -->
|
||||
<li class="nav-item" role="presentation">
|
||||
<button class="nav-link" id="screen-text-tab" data-bs-toggle="tab"
|
||||
data-bs-target="#screen-text" type="button" role="tab" aria-controls="screen-text"
|
||||
aria-selected="false">大屏文本->文本1</button>
|
||||
</li>
|
||||
<!-- 添加大屏文本2选项卡 -->
|
||||
<li class="nav-item" role="presentation">
|
||||
<button class="nav-link" id="screen-text2-tab" data-bs-toggle="tab"
|
||||
data-bs-target="#screen-text2" type="button" role="tab" aria-controls="screen-text2"
|
||||
aria-selected="false">大屏文本->文本2</button>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="tab-content" id="myTabContent">
|
||||
<!-- 系统配置 -->
|
||||
|
|
@ -548,6 +560,43 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 大屏文本1 -->
|
||||
<div class="tab-pane fade" id="screen-text" role="tabpanel" aria-labelledby="screen-text-tab">
|
||||
<div class="mt-3">
|
||||
<div class="d-flex justify-content-between mb-3">
|
||||
<h4>大屏文本管理 - 文本集1</h4>
|
||||
<div>
|
||||
<button type="button" class="btn btn-primary me-2" onclick="getPresetSentences()">刷新</button>
|
||||
<button type="button" class="btn btn-success" onclick="savePresetSentences()">保存</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<p class="text-muted mb-2">每行一条文本,保存后将覆盖原有内容并写入文件</p>
|
||||
<textarea id="preset-sentences" class="form-control" rows="15" style="font-family: monospace;"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 大屏文本2 -->
|
||||
<div class="tab-pane fade" id="screen-text2" role="tabpanel" aria-labelledby="screen-text2-tab">
|
||||
<div class="mt-3">
|
||||
<div class="d-flex justify-content-between mb-3">
|
||||
<h4>大屏文本管理 - 文本集2</h4>
|
||||
<div>
|
||||
<button type="button" class="btn btn-primary me-2" onclick="getPresetSentences2()">刷新</button>
|
||||
<button type="button" class="btn btn-success" onclick="savePresetSentences2()">保存</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<p class="text-muted mb-2">每行一条文本,保存后将覆盖原有内容并写入文件</p>
|
||||
<textarea id="preset-sentences2" class="form-control" rows="15" style="font-family: monospace;"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -1476,6 +1525,34 @@
|
|||
showMessage("解析显示配置失败: " + error, "danger");
|
||||
}
|
||||
});
|
||||
|
||||
// 接收预设句子列表
|
||||
connection.on("ReceivePresetSentences", (sentences) => {
|
||||
log("接收到预设句子列表,数量: " + (sentences ? sentences.length : 0));
|
||||
const textArea = document.getElementById("preset-sentences");
|
||||
textArea.value = sentences ? sentences.join('\n') : '';
|
||||
showMessage("成功获取预设句子列表", "success");
|
||||
});
|
||||
|
||||
// 接收预设句子2列表
|
||||
connection.on("ReceivePresetSentences2", (sentences) => {
|
||||
log("接收到预设句子2列表,数量: " + (sentences ? sentences.length : 0));
|
||||
const textArea = document.getElementById("preset-sentences2");
|
||||
textArea.value = sentences ? sentences.join('\n') : '';
|
||||
showMessage("成功获取预设句子2列表", "success");
|
||||
});
|
||||
|
||||
// 预设句子保存结果
|
||||
connection.on("PresetSentencesSaved", (success, message) => {
|
||||
log("预设句子保存结果: " + message);
|
||||
showMessage(message, success ? "success" : "danger");
|
||||
});
|
||||
|
||||
// 预设句子2保存结果
|
||||
connection.on("PresetSentences2Saved", (success, message) => {
|
||||
log("预设句子2保存结果: " + message);
|
||||
showMessage(message, success ? "success" : "danger");
|
||||
});
|
||||
}
|
||||
|
||||
// 更新客户端列表
|
||||
|
|
@ -1897,5 +1974,103 @@
|
|||
setTimeout(getClientList, 500);
|
||||
}
|
||||
});
|
||||
|
||||
// 切换到大屏文本标签页时自动刷新预设句子
|
||||
document.getElementById('screen-text-tab').addEventListener('click', function () {
|
||||
if (connection && connection.state === signalR.HubConnectionState.Connected) {
|
||||
log("切换到大屏文本标签页,自动刷新预设句子");
|
||||
setTimeout(getPresetSentences, 500);
|
||||
}
|
||||
});
|
||||
|
||||
// 切换到大屏文本2标签页时自动刷新预设句子2
|
||||
document.getElementById('screen-text2-tab').addEventListener('click', function () {
|
||||
if (connection && connection.state === signalR.HubConnectionState.Connected) {
|
||||
log("切换到大屏文本2标签页,自动刷新预设句子2");
|
||||
setTimeout(getPresetSentences2, 500);
|
||||
}
|
||||
});
|
||||
|
||||
// 获取预设句子列表
|
||||
function getPresetSentences() {
|
||||
if (!connection || connection.state !== signalR.HubConnectionState.Connected) {
|
||||
showMessage("无法获取预设句子:未连接到服务器", "warning");
|
||||
return;
|
||||
}
|
||||
|
||||
log("正在获取预设句子列表...");
|
||||
|
||||
connection.invoke("GetPresetSentences")
|
||||
.then(() => {
|
||||
log("已成功发送获取预设句子列表请求");
|
||||
})
|
||||
.catch(err => {
|
||||
log("获取预设句子列表失败: " + err);
|
||||
showMessage("获取预设句子列表失败: " + err, "danger");
|
||||
});
|
||||
}
|
||||
|
||||
// 保存预设句子列表
|
||||
function savePresetSentences() {
|
||||
if (!connection || connection.state !== signalR.HubConnectionState.Connected) {
|
||||
showMessage("无法保存预设句子:未连接到服务器", "warning");
|
||||
return;
|
||||
}
|
||||
|
||||
const textArea = document.getElementById("preset-sentences");
|
||||
const sentences = textArea.value.split('\n').filter(line => line.trim() !== '');
|
||||
|
||||
log(`正在保存预设句子列表,共${sentences.length}条...`);
|
||||
|
||||
connection.invoke("SavePresetSentences", sentences)
|
||||
.then(result => {
|
||||
log("预设句子保存请求已发送");
|
||||
})
|
||||
.catch(err => {
|
||||
log("保存预设句子列表失败: " + err);
|
||||
showMessage("保存预设句子列表失败: " + err, "danger");
|
||||
});
|
||||
}
|
||||
|
||||
// 获取预设句子2列表
|
||||
function getPresetSentences2() {
|
||||
if (!connection || connection.state !== signalR.HubConnectionState.Connected) {
|
||||
showMessage("无法获取预设句子2:未连接到服务器", "warning");
|
||||
return;
|
||||
}
|
||||
|
||||
log("正在获取预设句子2列表...");
|
||||
|
||||
connection.invoke("GetPresetSentences2")
|
||||
.then(() => {
|
||||
log("已成功发送获取预设句子2列表请求");
|
||||
})
|
||||
.catch(err => {
|
||||
log("获取预设句子2列表失败: " + err);
|
||||
showMessage("获取预设句子2列表失败: " + err, "danger");
|
||||
});
|
||||
}
|
||||
|
||||
// 保存预设句子列表
|
||||
function savePresetSentences2() {
|
||||
if (!connection || connection.state !== signalR.HubConnectionState.Connected) {
|
||||
showMessage("无法保存预设句子2:未连接到服务器", "warning");
|
||||
return;
|
||||
}
|
||||
|
||||
const textArea = document.getElementById("preset-sentences2");
|
||||
const sentences = textArea.value.split('\n').filter(line => line.trim() !== '');
|
||||
|
||||
log(`正在保存预设句子2列表,共${sentences.length}条...`);
|
||||
|
||||
connection.invoke("SavePresetSentences2", sentences)
|
||||
.then(result => {
|
||||
log("预设句子2保存请求已发送");
|
||||
})
|
||||
.catch(err => {
|
||||
log("保存预设句子2列表失败: " + err);
|
||||
showMessage("保存预设句子2列表失败: " + err, "danger");
|
||||
});
|
||||
}
|
||||
</script>
|
||||
}
|
||||
Binary file not shown.
Loading…
Reference in New Issue
Block a user