diff --git a/SlnMesnac.WPF/App.xaml.cs b/SlnMesnac.WPF/App.xaml.cs
index ec3de3a..e3e5f12 100644
--- a/SlnMesnac.WPF/App.xaml.cs
+++ b/SlnMesnac.WPF/App.xaml.cs
@@ -46,6 +46,8 @@ namespace SlnMesnac.WPF
var logPath = $"{appConfig.logPath}/Logs/{DateTime.UtcNow:yyyy-MM-dd}/";
Log.Information($"系统初始化完成,日志存放路径:{appConfig.logPath}");
+
+ this.DispatcherUnhandledException += App_DispatcherUnhandledException;
}
///
@@ -72,6 +74,14 @@ namespace SlnMesnac.WPF
// ...
}
+ private void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
+ {
+ // 处理异常
+ var info = e.Exception;
+ MessageBox.Show(e.Exception.Message);
+ // 防止默认的崩溃行为
+ e.Handled = true;
+ }
}
}
diff --git a/SlnMesnac.WPF/Attribute/RequirePermissionAttribute.cs b/SlnMesnac.WPF/Attribute/RequirePermissionAttribute.cs
new file mode 100644
index 0000000..b63f12c
--- /dev/null
+++ b/SlnMesnac.WPF/Attribute/RequirePermissionAttribute.cs
@@ -0,0 +1,67 @@
+using Rougamo;
+using Rougamo.Context;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+#region << 版 本 注 释 >>
+/*--------------------------------------------------------------------
+* 版权所有 (c) 2024 WenJY 保留所有权利。
+* CLR版本:4.0.30319.42000
+* 机器名称:T14-GEN3-7895
+* 命名空间:SlnMesnac.WPF.Attribute
+* 唯一标识:34a4538b-bbac-4b48-9e87-1662b859a705
+*
+* 创建者:WenJY
+* 电子邮箱:
+* 创建时间:2024-12-30 9:59:19
+* 版本:V1.0.0
+* 描述:
+*
+*--------------------------------------------------------------------
+* 修改人:
+* 时间:
+* 修改说明:
+*
+* 版本:V1.0.0
+*--------------------------------------------------------------------*/
+#endregion << 版 本 注 释 >>
+namespace SlnMesnac.WPF.Attribute
+{
+ ///
+ /// 权限过滤
+ ///
+ public class RequirePermissionAttribute : MoAttribute
+ {
+ private string _permissionName;
+
+ public RequirePermissionAttribute(string permissionName)
+ {
+ _permissionName = permissionName;
+ }
+ public override void OnEntry(MethodContext context)
+ {
+ Console.WriteLine($"{_permissionName}方法执行前");
+
+ bool hasPermission = CheckPermission(_permissionName);
+
+ if (!hasPermission)
+ {
+ // 如果用户没有权限,抛出异常或采取其他措施
+ throw new UnauthorizedAccessException("User does not have the required permission.");
+ }
+
+ base.OnEntry(context);
+ }
+
+ private bool CheckPermission(string permissionName)
+ {
+ // 这里实现你的权限检查逻辑
+ // 例如,从用户的权限集合中检查是否包含所需的权限
+ // 这只是一个示例,你可以根据实际需要实现
+ return false; // 假设用户总是有权限
+ }
+ }
+}
diff --git a/SlnMesnac.WPF/FodyWeavers.xml b/SlnMesnac.WPF/FodyWeavers.xml
new file mode 100644
index 0000000..a6a2edf
--- /dev/null
+++ b/SlnMesnac.WPF/FodyWeavers.xml
@@ -0,0 +1,3 @@
+
+
+
\ No newline at end of file
diff --git a/SlnMesnac.WPF/SlnMesnac.WPF.csproj b/SlnMesnac.WPF/SlnMesnac.WPF.csproj
index c218412..f0b5253 100644
--- a/SlnMesnac.WPF/SlnMesnac.WPF.csproj
+++ b/SlnMesnac.WPF/SlnMesnac.WPF.csproj
@@ -40,6 +40,7 @@
+
diff --git a/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs b/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs
index e2207a7..48fb4b3 100644
--- a/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs
+++ b/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs
@@ -3,6 +3,7 @@ using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Microsoft.Extensions.DependencyInjection;
using SlnMesnac.Serilog;
+using SlnMesnac.WPF.Attribute;
using SlnMesnac.WPF.Page.Generate;
using System;
using System.Windows;
@@ -76,6 +77,7 @@ namespace SlnMesnac.WPF.ViewModel
///
///
[RelayCommand]
+ [RequirePermission("FormControl")]
private void FormControl(object obj)
{
try