@page "/settings" @inject XiaoZhi_AgentService XiaoZhiAgent @implements IDisposable

🔧 连接设置

配置小智AI服务器连接参数

🌐

服务器URL

WebSocket服务器连接地址

🏷️

MAC地址

设备唯一标识符

🔄

OTA地址

设备更新和配置服务器地址

📊

OTA状态信息

设备连接和配置状态

连接状态: @(XiaoZhiAgent.IsConnected ? "✅ 已连接" : "❌ 未连接")
OTA状态: @XiaoZhiAgent.OtaStatus
@if (XiaoZhiAgent.LastOtaCheckTime.HasValue) {
最后检查: @XiaoZhiAgent.LastOtaCheckTime?.ToString("yyyy-MM-dd HH:mm:ss")
} @if (!string.IsNullOrEmpty(XiaoZhiAgent.ActivationCode)) {
激活码: @XiaoZhiAgent.ActivationCode
} @if (!string.IsNullOrEmpty(XiaoZhiAgent.ActivationMessage)) {
激活消息: @XiaoZhiAgent.ActivationMessage
}
当前版本: @XiaoZhiAgent.CurrentVersion
@if (!string.IsNullOrEmpty(XiaoZhiAgent.LatestVersion)) {
最新版本: @XiaoZhiAgent.LatestVersion
更新状态: @(XiaoZhiAgent.NeedUpdate ? "⚠️ 需要更新" : "✅ 已是最新")
} @if (!string.IsNullOrEmpty(XiaoZhiAgent.FirmwareVersion)) {
固件版本: @XiaoZhiAgent.FirmwareVersion
} @if (!string.IsNullOrEmpty(XiaoZhiAgent.FirmwareUrl)) {
固件下载: 🔗 下载更新
} @if (XiaoZhiAgent.ServerTime.HasValue) {
服务器时间: @XiaoZhiAgent.ServerTime?.ToString("yyyy-MM-dd HH:mm:ss")
} @if (!string.IsNullOrEmpty(XiaoZhiAgent.MqttEndpoint)) {
MQTT服务器: @XiaoZhiAgent.MqttEndpoint
}
🎙️

VAD阈值

语音活动检测阈值 (毫秒)

🐛

调试模式

启用调试日志输出

@if (XiaoZhiAgent.IsDebugMode) {
📋

调试日志

实时消息和OTA状态日志

共 @XiaoZhiAgent.DebugLogs.Count 条日志
@if (XiaoZhiAgent.DebugLogs.Count == 0) {
暂无日志信息
} else { @foreach (var log in XiaoZhiAgent.DebugLogs.Reverse()) {
@log
} }
}
@if (!string.IsNullOrEmpty(statusMessage)) {
@statusMessage
}
@code { private bool isSaving = false; private bool isApplying = false; private string statusMessage = ""; private string statusType = ""; private Timer? refreshTimer; protected override void OnInitialized() { // 启动定时器,每秒刷新一次界面(仅在调试模式下) refreshTimer = new Timer(async _ => { if (XiaoZhiAgent.IsDebugMode) { await InvokeAsync(StateHasChanged); } }, null, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1)); } public void Dispose() { refreshTimer?.Dispose(); } private async Task SaveSettings() { isSaving = true; statusMessage = ""; try { XiaoZhiAgent.SaveSettings(); statusMessage = "设置已保存成功!"; statusType = "success"; // 3秒后清除消息 await Task.Delay(3000); statusMessage = ""; } catch (Exception ex) { statusMessage = $"保存失败: {ex.Message}"; statusType = "error"; } finally { isSaving = false; } } private async Task ApplySettings() { isApplying = true; statusMessage = ""; try { await XiaoZhiAgent.ApplySettings(); statusMessage = "设置已应用,连接已重新建立!"; statusType = "success"; // 3秒后清除消息 await Task.Delay(3000); statusMessage = ""; } catch (Exception ex) { statusMessage = $"应用失败: {ex.Message}"; statusType = "error"; } finally { isApplying = false; } } private async Task ResetSettings() { XiaoZhiAgent.ResetSettings(); statusMessage = "设置已恢复为默认值"; statusType = "info"; StateHasChanged(); // 3秒后清除消息 await Task.Delay(3000); statusMessage = ""; StateHasChanged(); } private async Task ManualOtaCheck() { statusMessage = "正在进行OTA检查..."; statusType = "info"; StateHasChanged(); try { await XiaoZhiAgent.ManualOtaCheck(); statusMessage = "OTA检查完成"; statusType = "success"; } catch (Exception ex) { statusMessage = $"OTA检查失败: {ex.Message}"; statusType = "error"; } StateHasChanged(); // 3秒后清除消息 await Task.Delay(3000); statusMessage = ""; StateHasChanged(); } private void ClearLogs() { XiaoZhiAgent.ClearDebugLogs(); statusMessage = "调试日志已清空"; statusType = "info"; StateHasChanged(); // 3秒后清除消息 _ = Task.Run(async () => { await Task.Delay(3000); statusMessage = ""; await InvokeAsync(StateHasChanged); }); } }