mirror of
http://git.xinwangdao.com/cnnc-embedded-parts-detect/detect.git
synced 2025-06-24 13:34:13 +08:00
141 lines
3.2 KiB
C#
141 lines
3.2 KiB
C#
![]() |
using System;
|
|||
|
using System.Reactive;
|
|||
|
using detect.gui.Api;
|
|||
|
using detect.gui.Models;
|
|||
|
using ReactiveUI;
|
|||
|
using Serilog;
|
|||
|
using xwd.utils;
|
|||
|
|
|||
|
namespace detect.gui.VWMS;
|
|||
|
|
|||
|
public class MainWindowModel : ViewModelBase<MainWindowModel>
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 当前登录用户
|
|||
|
/// </summary>
|
|||
|
private UserModel? _currentUser;
|
|||
|
|
|||
|
public UserModel? CurrentUser
|
|||
|
{
|
|||
|
get => _currentUser;
|
|||
|
set => this.RaiseAndSetIfChanged(ref _currentUser, value);
|
|||
|
}
|
|||
|
|
|||
|
private bool _isHomeView;
|
|||
|
|
|||
|
public bool IsHomeView
|
|||
|
{
|
|||
|
get => _isHomeView;
|
|||
|
set => this.RaiseAndSetIfChanged(ref _isHomeView, value);
|
|||
|
}
|
|||
|
|
|||
|
private bool _isDetectTaskView;
|
|||
|
|
|||
|
public bool IsDetectTaskView
|
|||
|
{
|
|||
|
get => _isDetectTaskView;
|
|||
|
set => this.RaiseAndSetIfChanged(ref _isDetectTaskView, value);
|
|||
|
}
|
|||
|
|
|||
|
private bool _isDeviceView;
|
|||
|
|
|||
|
public bool IsDeviceView
|
|||
|
{
|
|||
|
get => _isDeviceView;
|
|||
|
set => this.RaiseAndSetIfChanged(ref _isDeviceView, value);
|
|||
|
}
|
|||
|
|
|||
|
private bool _isLogView;
|
|||
|
|
|||
|
public bool IsLogView
|
|||
|
{
|
|||
|
get => _isLogView;
|
|||
|
set => this.RaiseAndSetIfChanged(ref _isLogView, value);
|
|||
|
}
|
|||
|
|
|||
|
private bool _isUserView;
|
|||
|
|
|||
|
public bool IsUserView
|
|||
|
{
|
|||
|
get => _isUserView;
|
|||
|
set => this.RaiseAndSetIfChanged(ref _isUserView, value);
|
|||
|
}
|
|||
|
|
|||
|
private readonly string[] _localRoutes =
|
|||
|
[
|
|||
|
"#/dashboard",
|
|||
|
"#/data/task",
|
|||
|
"#/data/device",
|
|||
|
"#/system/log",
|
|||
|
"#/system/user"
|
|||
|
];
|
|||
|
|
|||
|
private string? _address;
|
|||
|
|
|||
|
public string? Address
|
|||
|
{
|
|||
|
get => _address;
|
|||
|
set => this.RaiseAndSetIfChanged(ref _address, value);
|
|||
|
}
|
|||
|
|
|||
|
// public ReactiveCommand<string, Unit> GotoCommand { get; }
|
|||
|
public ReactiveCommand<Unit, Unit> LogoutCommand { get; }
|
|||
|
|
|||
|
public MainWindowModel()
|
|||
|
{
|
|||
|
ApiService.Instance().StartService();
|
|||
|
|
|||
|
// GotoCommand = ReactiveCommand.Create<string>((p) => Goto(p));
|
|||
|
LogoutCommand = ReactiveCommand.Create(Logout);
|
|||
|
|
|||
|
this.WhenAnyValue(x => x.IsHomeView).Subscribe(p =>
|
|||
|
{
|
|||
|
if (!p) return;
|
|||
|
SetAddress(0);
|
|||
|
});
|
|||
|
|
|||
|
this.WhenAnyValue(x => x.IsDetectTaskView).Subscribe(p =>
|
|||
|
{
|
|||
|
if (!p) return;
|
|||
|
SetAddress(1);
|
|||
|
});
|
|||
|
|
|||
|
this.WhenAnyValue(x => x.IsDeviceView).Subscribe(p =>
|
|||
|
{
|
|||
|
if (!p) return;
|
|||
|
SetAddress(2);
|
|||
|
});
|
|||
|
|
|||
|
|
|||
|
this.WhenAnyValue(x => x.IsLogView).Subscribe(p =>
|
|||
|
{
|
|||
|
if (!p) return;
|
|||
|
SetAddress(3);
|
|||
|
});
|
|||
|
|
|||
|
this.WhenAnyValue(x => x.IsUserView).Subscribe(p =>
|
|||
|
{
|
|||
|
if (!p) return;
|
|||
|
SetAddress(4);
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
public void Dispose()
|
|||
|
{
|
|||
|
ApiService.Instance().StopService();
|
|||
|
}
|
|||
|
|
|||
|
private void Logout()
|
|||
|
{
|
|||
|
CurrentUser = null;
|
|||
|
}
|
|||
|
|
|||
|
public void SetAddress(int index)
|
|||
|
{
|
|||
|
var isOnLine = AppSettingsManager.Manager().GetBool("Embedded.IsOnline");
|
|||
|
var path = AppSettingsManager.Manager().GetString("Embedded.Path", "./dist/index.html");
|
|||
|
var prefix = isOnLine ? path : AppDomain.CurrentDomain.BaseDirectory + path;
|
|||
|
Address = $"{prefix}{_localRoutes[index]}";
|
|||
|
Log.Information("current address: {address}", Address);
|
|||
|
}
|
|||
|
}
|