跳转登录页面时先跳转EmptyWindow避免不执行OnNavigatedFrom方法

This commit is contained in:
maqiao 2025-01-15 18:57:17 +08:00
parent 58a6035add
commit 714a037b71
14 changed files with 181 additions and 51 deletions

View File

@ -37,7 +37,7 @@
<!-- 按处方还药或者按取药记录还药 1:处方ReturnDrugWindow22药品ReturnDrugWindow--> <!-- 按处方还药或者按取药记录还药 1:处方ReturnDrugWindow22药品ReturnDrugWindow-->
<add key="returnDrugMode" value="1" /> <add key="returnDrugMode" value="1" />
<!-- 自动退出时间单位秒为0时不自动退出 --> <!-- 自动退出时间单位秒为0时不自动退出 -->
<add key="autoExit" value="0"/> <add key="autoExit" value="5"/>
<!-- 无操作退出录像时间单位秒为0时不退出录像 --> <!-- 无操作退出录像时间单位秒为0时不退出录像 -->
<add key="stopRecord" value="180"/> <add key="stopRecord" value="180"/>

View File

@ -256,6 +256,9 @@ namespace DM_Weight
containerRegistry.RegisterForNavigation<ShowMessageDialog, ShowMessageDialogViewModel>(); containerRegistry.RegisterForNavigation<ShowMessageDialog, ShowMessageDialogViewModel>();
containerRegistry.RegisterForNavigation<EmptyWindow, EmptyWindowViewModel>();
} }
} }
} }

View File

@ -71,6 +71,7 @@
<PackageReference Include="MaterialDesignThemes" Version="4.8.0" /> <PackageReference Include="MaterialDesignThemes" Version="4.8.0" />
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.39" /> <PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.39" />
<PackageReference Include="Prism.Unity" Version="8.1.97" /> <PackageReference Include="Prism.Unity" Version="8.1.97" />
<PackageReference Include="SharpPromise" Version="1.7.0" />
<PackageReference Include="SqlSugarCore" Version="5.1.4.67" /> <PackageReference Include="SqlSugarCore" Version="5.1.4.67" />
<PackageReference Include="SuperSimpleTcp" Version="3.0.10" /> <PackageReference Include="SuperSimpleTcp" Version="3.0.10" />
<PackageReference Include="System.Drawing.Common" Version="7.0.0" /> <PackageReference Include="System.Drawing.Common" Version="7.0.0" />

View File

@ -1338,6 +1338,7 @@ namespace DM_Weight.Port
{ {
try try
{ {
logger.Info($"写数量:{drawerNo}-{colNo}{quantity}");
canBusSerial.DiscardInBuffer(); canBusSerial.DiscardInBuffer();
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
string strQuantity = quantity.ToString("X"); string strQuantity = quantity.ToString("X");

View File

@ -436,7 +436,7 @@ namespace DM_Weight.ViewModels
//newStock.NeedNum = 0; //newStock.NeedNum = 0;
//newStock.Quantity = jiaoStock.Quantity + csStock.TakeQuantity; //newStock.Quantity = jiaoStock.Quantity + csStock.TakeQuantity;
UpdateJJStock.Add(newStock); UpdateJJStock.Add(newStock);
csStock.TakeQuantity = 0; csStockList[j].TakeQuantity = 0;
jiaoStock.NeedNum = jiaoStock.NeedNum - csStock.TakeQuantity; jiaoStock.NeedNum = jiaoStock.NeedNum - csStock.TakeQuantity;
} }
else else
@ -454,13 +454,13 @@ namespace DM_Weight.ViewModels
newStock.ManuNo = jiaoStock.ManuNo; newStock.ManuNo = jiaoStock.ManuNo;
newStock.DrawerNo = jiaoStock.DrawerNo; newStock.DrawerNo = jiaoStock.DrawerNo;
newStock.DrugId = jiaoStock.DrugId; newStock.DrugId = jiaoStock.DrugId;
newStock.AddToJJNum = addNum; newStock.AddToJJNum = jiaoStock.NeedNum;
newStock.Id = jjStockManuNo.Id; newStock.Id = jjStockManuNo.Id;
//newStock.MachineId = jiaoStock.MachineId; //newStock.MachineId = jiaoStock.MachineId;
//newStock.NeedNum = 0; //newStock.NeedNum = 0;
//newStock.Quantity = jiaoStock.Quantity + csStock.TakeQuantity; //newStock.Quantity = jiaoStock.Quantity + csStock.TakeQuantity;
UpdateJJStock.Add(newStock); UpdateJJStock.Add(newStock);
csStock.TakeQuantity = csStock.TakeQuantity - jiaoStock.NeedNum; csStockList[j].TakeQuantity = csStock.TakeQuantity - jiaoStock.NeedNum;
jiaoStock.NeedNum = 0; jiaoStock.NeedNum = 0;
break; break;
} }
@ -500,7 +500,7 @@ namespace DM_Weight.ViewModels
newStock.MachineId = jiaoStock.MachineId; newStock.MachineId = jiaoStock.MachineId;
newStock.DrawerType = 1; newStock.DrawerType = 1;
AddJJStock.Add(newStock); AddJJStock.Add(newStock);
csStock.TakeQuantity = csStock.TakeQuantity - newStock.AddToJJNum; csStockList[j].TakeQuantity = csStock.TakeQuantity - newStock.AddToJJNum;
break; break;
} }
} }

View File

@ -470,6 +470,7 @@ namespace DM_Weight.ViewModels
//} //}
//MessageBox.Show("返回值:" + dialogResult.Result.ToString()); //MessageBox.Show("返回值:" + dialogResult.Result.ToString());
} }
int AddToJiaoJieClickNum = 1;
//设置选中药箱的复选框状态 //设置选中药箱的复选框状态
private void SetIsSelected(ChannelStock channelStock) private void SetIsSelected(ChannelStock channelStock)
{ {

View File

@ -356,7 +356,7 @@ namespace DM_Weight.ViewModels
for (int i = 0; i < singleChannels.Count; i++) for (int i = 0; i < singleChannels.Count; i++)
{ {
_portUtil.WriteQuantityMethod((singleChannels[i].Quantity + singleChannels[i].AddQuantity), singleChannels[i].DrawerNo, singleChannels[i].ColNo); _portUtil.WriteQuantityMethod((singleChannels[i].Quantity + singleChannels[i].AddQuantity), singleChannels[i].DrawerNo, singleChannels[i].ColNo);
//await _portUtil.WriteChannelInfoMethod(2, (singleChannels[i].Quantity + singleChannels[i].AddQuantity).ToString(), singleChannels[i].DrawerNo, singleChannels[i].ColNo); //await _portUtil.WriteChannelIn foMethod(2, (singleChannels[i].Quantity + singleChannels[i].AddQuantity).ToString(), singleChannels[i].DrawerNo, singleChannels[i].ColNo);
//await Task.Delay(200); //await Task.Delay(200);
//await _portUtil.ShowContentMethod(singleChannels[i].DrawerNo, singleChannels[i].ColNo); //await _portUtil.ShowContentMethod(singleChannels[i].DrawerNo, singleChannels[i].ColNo);
Thread.Sleep(150); Thread.Sleep(150);

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DM_Weight.ViewModels
{
internal class EmptyWindowViewModel
{
}
}

View File

@ -161,7 +161,7 @@ namespace DM_Weight.ViewModels
// } // }
// } // }
// } // }
SetProperty(ref _selectedChildMenu, value); SetProperty(ref _selectedChildMenu, value);
//} //}
} }
} }
@ -215,12 +215,14 @@ namespace DM_Weight.ViewModels
logger.Info($"用户【{Operator?.Nickname}】退出登录"); logger.Info($"用户【{Operator?.Nickname}】退出登录");
Operator = null; Operator = null;
Reviewer = null; Reviewer = null;
System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() => //System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
{ //{
_regionManager.RequestNavigate("MainRegion", "LoginWindow");
})); _regionManager.RequestNavigate("ContentRegion", "EmptyWindow");
//_regionManager.RequestNavigate("MainRegion", "BeforeLogin"); _regionManager.RequestNavigate("MainRegion", "LoginWindow");
//}));
//_regionManager.RequestNavigate("MainRegion", "BeforeLogin");
} }
else else
{ {
@ -490,7 +492,7 @@ namespace DM_Weight.ViewModels
//public DelegateCommand CheckWDCommand { get => new DelegateCommand(CheckAction); } //public DelegateCommand CheckWDCommand { get => new DelegateCommand(CheckAction); }
//private void CheckAction() //private void CheckAction()
//{ //{
//GetWD(); //GetWD();
//} //}
@ -522,6 +524,7 @@ namespace DM_Weight.ViewModels
Reviewer = null; Reviewer = null;
Application.Current.Dispatcher.Invoke(() => Application.Current.Dispatcher.Invoke(() =>
{ {
_regionManager.RequestNavigate("ContentRegion", "EmptyWindow");
_regionManager.RequestNavigate("MainRegion", "LoginWindow"); _regionManager.RequestNavigate("MainRegion", "LoginWindow");
}); });
AlertMsg alertMsg = new AlertMsg AlertMsg alertMsg = new AlertMsg
@ -539,34 +542,57 @@ namespace DM_Weight.ViewModels
SelectedChildMenu = premissions[0].Children[0]; SelectedChildMenu = premissions[0].Children[0];
_regionManager.RequestNavigate("ContentRegion", premissions[0].Children[0].PremissionPath); _regionManager.RequestNavigate("ContentRegion", premissions[0].Children[0].PremissionPath);
FindDrawerCount(); FindDrawerCount();
int autoExit = Convert.ToInt32(ConfigurationManager.AppSettings["autoExit"] ?? "0"); int autoExit = Convert.ToInt32(ConfigurationManager.AppSettings["autoExit"] ?? "0");
int stopRecord = Convert.ToInt32(ConfigurationManager.AppSettings["stopRecord"] ?? "0");
if (autoExit > 0) if (autoExit > 0)
{ {
System.Timers.Timer timer = new System.Timers.Timer(); //int interval = autoExit * 1000;
timer.Interval = 1000; new PromiseUtil<int>().taskAsyncLoop(1000, 0, async (options, next, stop) =>
timer.Elapsed += (sender, e) =>
{ {
// 串口无人操作 try
if (!_portUtil.Operate)
{ {
// 30秒内无人操作鼠标键盘 if (!_portUtil.Operate)
if ((DateTime.Now - _portUtil.dateTime).TotalSeconds > autoExit && CheckComputerFreeState.GetLastInputTime() > autoExit)
{ {
logger.Info($"设备30秒内无人操作用户【{Operator?.Nickname}】自动退出登录"); // 无人操作鼠标键盘
//_chkFunction.HIKStopDVRRecord(); if ((DateTime.Now - _portUtil.dateTime).TotalSeconds > autoExit && CheckComputerFreeState.GetLastInputTime() > autoExit)
Operator = null;
Reviewer = null;
Application.Current.Dispatcher.Invoke(() =>
{ {
_regionManager.RequestNavigate("MainRegion", "LoginWindow"); logger.Info($"设备{autoExit}内无人操作,用户【{Operator?.Nickname}】自动退出登录,_portUtil.Operate:{_portUtil.Operate},totalSecond:{(DateTime.Now - _portUtil.dateTime).TotalSeconds},lastInputTime:{CheckComputerFreeState.GetLastInputTime()},autoExit:{autoExit}");
timer.Stop();
}); Operator = null;
Reviewer = null;
//Application.Current.Dispatcher.Invoke(() =>
//{
stop();
System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
{
_regionManager.RequestNavigate("ContentRegion", "EmptyWindow");
_regionManager.RequestNavigate("MainRegion", "LoginWindow");
}));
//});
//timer.Dispose();
}
else
{
if (Operator == null)
{
stop();
}
else
{
next();
}
}
}
else
{
_portUtil.dateTime = DateTime.Now;
next();
} }
} }
}; catch (Exception ex)
timer.Start(); {
logger.Info($"自动退出异常:{ex.Message}");
}
});
} }
//#region 温度查询定时 //#region 温度查询定时
//int interval = Convert.ToInt32(ConfigurationManager.AppSettings["Interval"]); //int interval = Convert.ToInt32(ConfigurationManager.AppSettings["Interval"]);

View File

@ -60,7 +60,7 @@ namespace DM_Weight.ViewModels
get => ReadAppSetting("loginUser"); get => ReadAppSetting("loginUser");
} }
private HkcChangeShifts listHkcChangeShifts=new HkcChangeShifts(); private HkcChangeShifts listHkcChangeShifts = new HkcChangeShifts();
private FingerprintUtil _fingerprintUtil; private FingerprintUtil _fingerprintUtil;
@ -117,7 +117,7 @@ namespace DM_Weight.ViewModels
//_chkFunction= chcFunction; //_chkFunction= chcFunction;
_regionManager = regionManager; _regionManager = regionManager;
_eventAggregator = eventAggregator; _eventAggregator = eventAggregator;
_eventAggregator.GetEvent<FingerprintEvent>().Subscribe(LoginEvent); //_eventAggregator.GetEvent<FingerprintEvent>().Subscribe(LoginEvent);
} }
private DelegateCommand? _loginCommand; private DelegateCommand? _loginCommand;
@ -131,7 +131,7 @@ _exitCommand ??= new DelegateCommand(Exit);
public bool KeepAlive => false; public bool KeepAlive => false;
void Login() void Login()
{ {
LoginBtnEnable = false; LoginBtnEnable = false;
if (!string.IsNullOrEmpty(Username) && !string.IsNullOrEmpty(Password)) if (!string.IsNullOrEmpty(Username) && !string.IsNullOrEmpty(Password))
@ -180,7 +180,7 @@ _exitCommand ??= new DelegateCommand(Exit);
Username = ""; Username = "";
Password = ""; Password = "";
} }
else if (userList.Role == null|| userList.Role.Permissions.Count<=0) else if (userList.Role == null || userList.Role.Permissions.Count <= 0)
{ {
AlertMsg alertMsg = new AlertMsg AlertMsg alertMsg = new AlertMsg
{ {
@ -201,7 +201,7 @@ _exitCommand ??= new DelegateCommand(Exit);
.Where(cs => cs.State == "0").First(); .Where(cs => cs.State == "0").First();
if (listHkcChangeShifts != null) if (listHkcChangeShifts != null)
{ {
if(!listHkcChangeShifts.FromOperator.Equals(userList.UserName) && !listHkcChangeShifts.FromRviewer.Equals(userList.UserName)) if (!listHkcChangeShifts.FromOperator.Equals(userList.UserName) && !listHkcChangeShifts.FromRviewer.Equals(userList.UserName))
{ {
AlertMsg alertMsg = new AlertMsg AlertMsg alertMsg = new AlertMsg
{ {
@ -257,7 +257,8 @@ _exitCommand ??= new DelegateCommand(Exit);
keys.Add("operator", user); keys.Add("operator", user);
//System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() => //System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
//{ //{
_regionManager.RequestNavigate("MainRegion", "HomeWindow", keys); logger.Info("跳转home页面");
_regionManager.RequestNavigate("MainRegion", "HomeWindow", keys);
//})); //}));
} }
// 双人登录模式 // 双人登录模式
@ -273,7 +274,7 @@ _exitCommand ??= new DelegateCommand(Exit);
RaisePropertyChanged("Reviewer"); RaisePropertyChanged("Reviewer");
//System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() => //System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
//{ //{
_regionManager.RequestNavigate("MainRegion", "HomeWindow", keys); _regionManager.RequestNavigate("MainRegion", "HomeWindow", keys);
//})); //}));
} }
@ -297,7 +298,7 @@ _exitCommand ??= new DelegateCommand(Exit);
RaisePropertyChanged("Operator"); RaisePropertyChanged("Operator");
//System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() => //System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
//{ //{
_regionManager.RequestNavigate("MainRegion", "HomeWindow", keys); _regionManager.RequestNavigate("MainRegion", "HomeWindow", keys);
//})); //}));
} }
@ -317,9 +318,9 @@ _exitCommand ??= new DelegateCommand(Exit);
//1仅当班人、审核人可登录 //1仅当班人、审核人可登录
if (LoginUserCheck.Equals("1")) if (LoginUserCheck.Equals("1"))
{ {
if(listHkcChangeShifts!=null) if (listHkcChangeShifts != null)
{ {
if(listHkcChangeShifts.FromOperator.Equals(user.UserName)) if (listHkcChangeShifts.FromOperator.Equals(user.UserName))
{ {
keys.Add("operator", user); keys.Add("operator", user);
Operator = user; Operator = user;
@ -349,7 +350,7 @@ _exitCommand ??= new DelegateCommand(Exit);
RaisePropertyChanged("Reviewer"); RaisePropertyChanged("Reviewer");
} }
Username = string.Empty; Username = string.Empty;
Password =string.Empty; Password = string.Empty;
} }
} }
} }
@ -368,8 +369,10 @@ _exitCommand ??= new DelegateCommand(Exit);
{ {
FingerMsg = !msg.Result; FingerMsg = !msg.Result;
} }
logger.Info($"LoginBtnEnable:{LoginBtnEnable}");
if (LoginBtnEnable) if (LoginBtnEnable)
{ {
logger.Info($"msg.Message:{msg.Message};{msg.Message.Equals("LOGIN")}");
if (msg.Message.Equals("LOGIN")) if (msg.Message.Equals("LOGIN"))
{ {
UserList userList = new UserList(); UserList userList = new UserList();
@ -380,7 +383,7 @@ _exitCommand ??= new DelegateCommand(Exit);
//.First(u => u.Id == msg.Id && u.MachineId == ConfigurationManager.AppSettings["machineId"].ToString()); //.First(u => u.Id == msg.Id && u.MachineId == ConfigurationManager.AppSettings["machineId"].ToString());
logger.Info($"userList==null?{userList == null}");
if (userList == null) if (userList == null)
{ {
AlertMsg alertMsg = new AlertMsg AlertMsg alertMsg = new AlertMsg
@ -447,7 +450,7 @@ _exitCommand ??= new DelegateCommand(Exit);
public void OnNavigatedTo(NavigationContext navigationContext) public void OnNavigatedTo(NavigationContext navigationContext)
{ {
//FingerMsg = !_fingerprintUtil.bIsConnected; //FingerMsg = !_fingerprintUtil.bIsConnected;
//_eventAggregator.GetEvent<FingerprintEvent>().Subscribe(LoginEvent); _eventAggregator.GetEvent<FingerprintEvent>().Subscribe(LoginEvent);
} }

View File

@ -73,13 +73,15 @@ namespace DM_Weight.ViewModels
_regionManager = regionManager; _regionManager = regionManager;
_container = container; _container = container;
//_cHKFunction = cHKFunction; //_cHKFunction = cHKFunction;
//System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() => System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
//{ {
_container.RegisterType<object, LoginWindow>("LoginWindow"); //_container.RegisterType<object, LoginWindow>("LoginWindow");
_regionManager.RegisterViewWithRegion("MainRegion", "LoginWindow"); //_regionManager.RegisterViewWithRegion("MainRegion", "LoginWindow");
//})); _regionManager.RequestNavigate("MainRegion", "LoginWindow");
}));
} }
void doMyPrismEvent2(AlertMsg msg) void doMyPrismEvent2(AlertMsg msg)

View File

@ -0,0 +1,12 @@
<UserControl x:Class="DM_Weight.Views.EmptyWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:DM_Weight.Views"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<!--空白页面用于退出登录时先跳转该页面再退出登录ContentRegion先跳转到该页面让上一个页面先进OnNavigatedFrom。-->
</Grid>
</UserControl>

View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace DM_Weight.Views
{
/// <summary>
/// EmptyWindow.xaml 的交互逻辑
/// </summary>
public partial class EmptyWindow : UserControl
{
public EmptyWindow()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,41 @@
using SharpPromise;
using System;
using System.Threading.Tasks;
namespace DM_Weight.util
{
public class PromiseUtil<T>
{
public int _delay { get; set; }
public T? _data { get; set; }
public async Task taskAsyncLoop(int delay, T data, Action<PromiseUtil<T>, Action, Action> action)
{
_data = data;
_delay = 0;
while (_delay >= 0)
{
await new Promise(async (Action onResolve, Action onReject) =>
{
await Task.Delay(_delay);
try
{
await Task.Run(() => action(this, onResolve, onReject));
}
catch (Exception ex)
{
onReject();
}
}).Then(() =>
{
_delay = delay;
}).Catch((Exception e) =>
{
_delay = -1;
});
}
}
}
}