Administrator 3 months ago
parent
commit
0a1f94e644
  1. 15
      AppShell.xaml.cs
  2. 9
      Models/AppModels.cs
  3. 4
      SunlightAggregationTerminal.csproj
  4. 21
      View/Loading.xaml
  5. 9
      View/Loading.xaml.cs
  6. 4
      View/LogPage.xaml.cs
  7. 17
      View/LogWindow.xaml
  8. 19
      View/LogWindow.xaml.cs

15
AppShell.xaml.cs

@ -22,17 +22,22 @@ namespace SunlightAggregationTerminal
await Navigation.PushModalAsync(new NavigationPage(logpage));
}
else
{
//发送登录请求
TcpServer.Configuration(App.GlobalData.ServerID,
App.GlobalData.User, App.GlobalData.UserPassword,
Models.AppModels.GetAppUniqueId());
{
var loading = new View.Loading();
await Navigation.PushModalAsync(loading);
if (await AppModels.LogIn())
{//拒绝登陆时打开登录页面
await loading.Navigation.PopModalAsync();
}
else
{
await loading.Navigation.PopModalAsync();
var logpage = new View.LogPage();
await Navigation.PushModalAsync(logpage);
}
}
}
}

9
Models/AppModels.cs

@ -40,7 +40,7 @@ namespace SunlightAggregationTerminal.Models
App.GlobalData.DarkMode = Convert.ToBoolean(dat.Field<object>("DarkMode"));
App.GlobalData.MessageNotificationMode = Convert.ToBoolean(dat.Field<object>("MessageNotificationMode"));
TcpServer.Configuration(App.GlobalData.ServerID, App.GlobalData.User, App.GlobalData.UserPassword, dat.Field<string>("GUID") ?? "Not");
// TcpServer.Configuration(App.GlobalData.ServerID, App.GlobalData.User, App.GlobalData.UserPassword, dat.Field<string>("GUID") ?? "Not");
}
//启动tcp
// TcpServer.CreateCustomService();
@ -76,7 +76,10 @@ namespace SunlightAggregationTerminal.Models
{
App.GlobalData.LogNo = false;
//发生登录请求
//发送登录请求
TcpServer.Configuration(App.GlobalData.ServerID,
App.GlobalData.User, App.GlobalData.UserPassword,
Models.AppModels.GetAppUniqueId());
// 创建一个 15 秒的延时任务
Task delayTask = Task.Delay(15000);
@ -86,7 +89,7 @@ namespace SunlightAggregationTerminal.Models
while (!App.GlobalData.LogNo)
{
// 每隔 100 毫秒检查一次,避免 CPU 占用过高
await Task.Delay(100);
await Task.Delay(1000);
}
});
// 使用 Task.WhenAny 等待任意一个任务完成

4
SunlightAggregationTerminal.csproj

@ -116,10 +116,10 @@
<MauiXaml Update="ScanPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="View\LogPage.xaml">
<MauiXaml Update="View\Loading.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="View\LogWindow.xaml">
<MauiXaml Update="View\LogPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
</ItemGroup>

21
View/Loading.xaml

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="SunlightAggregationTerminal.View.Loading"
Title="Loading">
<Grid x:Name="LoadingIndicator" BackgroundColor="Gray"
IsVisible="True" Opacity="0.9">
<VerticalStackLayout Padding="30" Spacing="10"
VerticalOptions="Center"
HorizontalOptions="Center">
<ActivityIndicator IsRunning="True"
Color="#512BD4"
HorizontalOptions="Center"
VerticalOptions="Center" />
<Label Text="等待中..."
FontAttributes="Bold"
FontSize="24"
TextColor="Black"/>
</VerticalStackLayout>
</Grid>
</ContentPage>

9
View/Loading.xaml.cs

@ -0,0 +1,9 @@
namespace SunlightAggregationTerminal.View;
public partial class Loading : ContentPage
{
public Loading()
{
InitializeComponent();
}
}

4
View/LogPage.xaml.cs

@ -74,8 +74,8 @@ public partial class LogPage : ContentPage
private async void Log_Clicked(object sender, EventArgs e)//登录
{
TcpServer.Configuration(SERVERIP.Text, UsernameEntry.Text, PasswordEntry.Text,
Models.AppModels.GetAppUniqueId());
//TcpServer.Configuration(SERVERIP.Text, UsernameEntry.Text, PasswordEntry.Text,
// Models.AppModels.GetAppUniqueId());
LoadingIndicator.IsVisible = true;

17
View/LogWindow.xaml

@ -1,17 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<Window xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="SunlightAggregationTerminal.View.LogWindow"
Title="LogWindow">
<ContentPage>
<!-- 登录按钮 -->
<Button Text="登 录"
BackgroundColor="#512BD4"
TextColor="White"
HeightRequest="50"
WidthRequest="100"
CornerRadius="10"
Margin="0,10,0,0"/>
</ContentPage>
</Window>

19
View/LogWindow.xaml.cs

@ -1,19 +0,0 @@
namespace SunlightAggregationTerminal.View;
public partial class LogWindow : Window
{
public LogWindow()
{
InitializeComponent();
Page = new ContentPage()
{
Content = new VerticalStackLayout
{
Children = {
new Label { HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, Text = "Welcome to .NET MAUI!"
}
}
}
};
}
}
Loading…
Cancel
Save