!提交代码
This commit is contained in:
54
货架标准上位机/Converters/AuthConverter.cs
Normal file
54
货架标准上位机/Converters/AuthConverter.cs
Normal file
@ -0,0 +1,54 @@
|
||||
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 货架标准上位机
|
||||
{
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
}
|
31
货架标准上位机/Converters/AuthVisConverter.cs
Normal file
31
货架标准上位机/Converters/AuthVisConverter.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Data;
|
||||
using System.Windows;
|
||||
using HandyControl.Tools;
|
||||
|
||||
namespace 货架标准上位机
|
||||
{
|
||||
/// <summary>
|
||||
/// 权限转换器
|
||||
/// </summary>
|
||||
public class AuthVisConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (DesignerHelper.IsInDesignMode)
|
||||
return Visibility.Visible;
|
||||
|
||||
return AuthConverter.IsAuth(parameter) ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
31
货架标准上位机/Converters/AuthVisHidConverter.cs
Normal file
31
货架标准上位机/Converters/AuthVisHidConverter.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Data;
|
||||
using System.Windows;
|
||||
using HandyControl.Tools;
|
||||
|
||||
namespace 货架标准上位机
|
||||
{
|
||||
/// <summary>
|
||||
/// 权限转换器
|
||||
/// </summary>
|
||||
public class AuthVisHidConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (DesignerHelper.IsInDesignMode)
|
||||
return Visibility.Visible;
|
||||
|
||||
return AuthConverter.IsAuth(parameter) ? Visibility.Visible : Visibility.Hidden;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user