Files
wcs/货架标准上位机/Converters/AuthConverter.cs
2024-10-17 12:59:41 +08:00

55 lines
1.6 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 HandyControl.Tools;
using Newtonsoft.Json.Linq;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
namespace WCS管理系统
{
/// <summary>
/// 权限转换器转为bool
/// </summary>
public class AuthConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (DesignerHelper.IsInDesignMode)
return true;
return AuthConverter.IsAuth(parameter);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
/// <summary>
/// 是否有权限
/// </summary>
/// <param name="value">认证项</param>
/// <returns></returns>
public static bool IsAuth(object value)
{
if (UserInfoView.viewModel.User == null || UserInfoView.viewModel.Roles == null || !UserInfoView.viewModel.Roles.Any())
return false;
if (UserInfoView.viewModel.User.IsAdmin || UserInfoView.viewModel.Roles.Any(o => o.IsAdmin))
return true;
if (value == null)
return false;
if (UserInfoView.viewModel.Roles.Any(o => o.Auths.Contains((int)value)))
return true;
else
return false;
}
}
}