添加了 Mqtt 的界面和添加对话框

This commit is contained in:
2025-07-04 22:39:44 +08:00
parent 8325717b95
commit f86ce8194b
12 changed files with 452 additions and 14 deletions

View File

@@ -18,12 +18,15 @@ public partial class DataServices : ObservableRecipient, IRecipient<LoadMessage>
[ObservableProperty] private List<Device> _devices;
[ObservableProperty] private List<VariableTable> _variableTables;
[ObservableProperty] private List<MenuBean> menuTrees;
[ObservableProperty] private List<Mqtt> _mqtts;
private readonly DeviceRepository _deviceRepository;
private readonly MenuRepository _menuRepository;
private readonly MqttRepository _mqttRepository;
public event Action<List<Device>> OnDeviceListChanged;
public event Action<List<MenuBean>> OnMenuTreeListChanged;
public event Action<List<Mqtt>> OnMqttListChanged;
partial void OnDevicesChanged(List<Device> devices)
@@ -36,6 +39,11 @@ public partial class DataServices : ObservableRecipient, IRecipient<LoadMessage>
OnMenuTreeListChanged?.Invoke(MenuTrees);
}
partial void OnMqttsChanged(List<Mqtt> mqtts)
{
OnMqttListChanged?.Invoke(mqtts);
}
public DataServices(ILogger<DataServices> logger)
{
@@ -43,6 +51,7 @@ public partial class DataServices : ObservableRecipient, IRecipient<LoadMessage>
IsActive = true;
_deviceRepository = new DeviceRepository();
_menuRepository = new MenuRepository();
_mqttRepository = new MqttRepository();
}
@@ -60,6 +69,7 @@ public partial class DataServices : ObservableRecipient, IRecipient<LoadMessage>
case LoadTypes.All:
await LoadDevices();
await LoadMenus();
await LoadMqtts();
break;
case LoadTypes.Devices:
await LoadDevices();
@@ -67,6 +77,9 @@ public partial class DataServices : ObservableRecipient, IRecipient<LoadMessage>
case LoadTypes.Menu:
await LoadMenus();
break;
case LoadTypes.Mqtts:
await LoadMqtts();
break;
}
}
catch (Exception e)
@@ -90,4 +103,9 @@ public partial class DataServices : ObservableRecipient, IRecipient<LoadMessage>
DataServicesHelper.SortMenus(menu);
}
}
private async Task LoadMqtts()
{
Mqtts = await _mqttRepository.GetAll();
}
}

View File

@@ -43,6 +43,34 @@ public class DialogService :IDialogService
}
public async Task<Mqtt> ShowAddMqttDialog()
{
var mqtt = new Mqtt();
MqttDialogViewModel vm = new MqttDialogViewModel(mqtt);
vm.Title = "添加MQTT";
vm.PrimaryButContent = "添加MQTT";
return await ShowConentDialog(vm, mqtt);
}
public async Task<Mqtt> ShowEditMqttDialog(Mqtt mqtt)
{
MqttDialogViewModel vm = new MqttDialogViewModel(mqtt);
vm.Title = "编辑MQTT";
vm.PrimaryButContent = "编辑MQTT";
return await ShowConentDialog(vm, mqtt);
}
private static async Task<Mqtt> ShowConentDialog(MqttDialogViewModel viewModel, Mqtt mqtt)
{
var dialog = new MqttDialog(viewModel);
var res = await dialog.ShowAsync();
if (res == ContentDialogResult.Primary)
{
return mqtt;
}
return null;
}
public async Task<bool> ShowConfrimeDialog(string title, string message,string buttonText="确认")
{
ConfrimDialogViewModel vm = new ConfrimDialogViewModel();

View File

@@ -7,7 +7,8 @@ public interface IDialogService
{
Task<Device> ShowAddDeviceDialog();
Task<Device> ShowEditDeviceDialog(Device device);
Task<Mqtt> ShowAddMqttDialog();
Task<Mqtt> ShowEditMqttDialog(Mqtt mqtt);
Task<bool> ShowConfrimeDialog(string title, string message,string buttonText="确认");
Task<VariableTable> ShowAddVarTableDialog();