93 lines
3.0 KiB
C#
93 lines
3.0 KiB
C#
using CORP_MAUI.Models;
|
||
|
||
namespace CORP_MAUI.Pages;
|
||
|
||
public partial class ProfilePage : ContentPage
|
||
{
|
||
private User _currentUser = new();
|
||
|
||
public ProfilePage()
|
||
{
|
||
InitializeComponent();
|
||
_ = LoadProfileAsync();
|
||
}
|
||
|
||
private async Task LoadProfileAsync()
|
||
{
|
||
try
|
||
{
|
||
LoadingIndicator.IsVisible = true;
|
||
LoadingIndicator.IsRunning = true;
|
||
|
||
// Загружаем профиль
|
||
User? user = await ServiceProvider.ApiService.GetCurrentUserAsync();
|
||
|
||
if (user != null)
|
||
{
|
||
_currentUser = user;
|
||
FullNameLabel.Text = _currentUser.FullName;
|
||
UsernameLabel.Text = $"@{_currentUser.Username}";
|
||
EmailLabel.Text = _currentUser.Email ?? "Не указано";
|
||
PositionLabel.Text = _currentUser.PositionName;
|
||
DepartmentLabel.Text = _currentUser.DepartmentName;
|
||
StatusLabel.Text = _currentUser.IsOnline ? "В сети" : "Не в сети";
|
||
StatusLabel.TextColor = _currentUser.IsOnline ? Colors.LimeGreen : Colors.Gray;
|
||
|
||
if (!string.IsNullOrEmpty(_currentUser.AvatarUrl))
|
||
{
|
||
AvatarImage.Source = _currentUser.AvatarUrl;
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
await DisplayAlert("Ошибка", $"Не удалось загрузить профиль: {ex.Message}", "OK");
|
||
}
|
||
finally
|
||
{
|
||
LoadingIndicator.IsVisible = false;
|
||
LoadingIndicator.IsRunning = false;
|
||
}
|
||
}
|
||
|
||
private async void OnRefreshClicked(object sender, EventArgs e)
|
||
{
|
||
await LoadProfileAsync();
|
||
}
|
||
|
||
private async void OnLogoutClicked(object sender, EventArgs e)
|
||
{
|
||
bool result = await DisplayAlert("Выход", "Вы уверены, что хотите выйти?", "Да", "Нет");
|
||
|
||
if (result)
|
||
{
|
||
try
|
||
{
|
||
// Обновляем статус пользователя
|
||
await ServiceProvider.ApiService.UpdateStatusAsync(false);
|
||
|
||
// Отключаем WebSocket
|
||
await ServiceProvider.WebSocketService.DisconnectAsync();
|
||
|
||
// Выходим из системы (очищаем токены)
|
||
ServiceProvider.ApiService.Logout();
|
||
|
||
// Очищаем сохраненные данные
|
||
SecureStorage.Remove("user_id");
|
||
SecureStorage.Remove("username");
|
||
|
||
// Переходим на страницу входа
|
||
if (Application.Current?.Windows.Count > 0)
|
||
{
|
||
Application.Current.Windows[0].Page = new NavigationPage(new LoginPage());
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
await DisplayAlert("Ошибка", $"Ошибка при выходе: {ex.Message}", "OK");
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|