Files
SamplePreSystem-CS/SamplePreSystem.UI/ViewModel/Login/UserInfoViewModel.cs
2026-04-30 11:34:41 +08:00

73 lines
2.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using CommunityToolkit.Mvvm.ComponentModel;
using Models.Const;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SamplePreSystem.UI.ViewModel.Login
{
public partial class UserInfoViewModel :ObservableObject
{
[ObservableProperty]
public string userName;
[ObservableProperty]
public string userRoles;
public UserInfoViewModel()
{
InitializeUserInfo();
}
private void InitializeUserInfo()
{
// 获取当前登录用户信息
if (SystemConst.loginUserInfo != null && SystemConst.loginUserInfo.user != null)
{
UserName = SystemConst.loginUserInfo.user.username;
// 这里需要获取用户角色信息
// 由于当前登录用户信息中没有直接包含角色信息,我们需要通过查询获取
// 这里暂时显示占位符,实际项目中需要从数据库查询
UserRoles = "获取中...";
// 异步获取角色信息
Task.Run(() =>
{
try
{
// 这里应该调用BLL层的方法获取用户角色
// 由于系统中已有UsersBll类我们可以使用它
SamplePre.ProcessBll.BLL.UsersBll usersBll = new SamplePre.ProcessBll.BLL.UsersBll();
var userExt = usersBll.GetUsers().FirstOrDefault(u => u.username == UserName);
if (userExt != null)
{
UserRoles = userExt.all_role_names;
}
else
{
UserRoles = "未知角色";
}
}
catch (Exception ex)
{
UserRoles = "获取角色失败";
}
});
}
else
{
UserName = "未登录";
UserRoles = "无";
}
}
}
}