diff --git a/BBWYB.Client/GlobalContext.cs b/BBWYB.Client/GlobalContext.cs index eac8ac1..c5f82c4 100644 --- a/BBWYB.Client/GlobalContext.cs +++ b/BBWYB.Client/GlobalContext.cs @@ -1,5 +1,6 @@ using BBWYB.Client.Models; using CommunityToolkit.Mvvm.ComponentModel; +using Newtonsoft.Json; using System.Collections.Generic; namespace BBWYB.Client @@ -27,6 +28,11 @@ namespace BBWYB.Client public string BBWYApiHost { get; set; } public string MDSApiHost { get; set; } + + public string GetUserString() + { + return JsonConvert.SerializeObject(User); + } #endregion } } \ No newline at end of file diff --git a/BBWYB.Client/Views/WebB/WebB.xaml b/BBWYB.Client/Views/WebB/WebB.xaml index d5f413b..9131a20 100644 --- a/BBWYB.Client/Views/WebB/WebB.xaml +++ b/BBWYB.Client/Views/WebB/WebB.xaml @@ -6,9 +6,9 @@ xmlns:local="clr-namespace:BBWYB.Client.Views.WebB" mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800" - Title="WebB" Background="Red"> + Title="WebB"> - + diff --git a/BBWYB.Client/Views/WebB/WebB.xaml.cs b/BBWYB.Client/Views/WebB/WebB.xaml.cs index 09cf5c8..1873c33 100644 --- a/BBWYB.Client/Views/WebB/WebB.xaml.cs +++ b/BBWYB.Client/Views/WebB/WebB.xaml.cs @@ -1,4 +1,8 @@ -using System.Windows.Controls; +using BBWYB.Client.APIServices; +using Microsoft.Extensions.DependencyInjection; +using System.Collections.Generic; +using System.Windows; +using System.Windows.Controls; namespace BBWYB.Client.Views.WebB { @@ -10,9 +14,50 @@ namespace BBWYB.Client.Views.WebB private WebView2Manager w2m; private bool isNavigated; + private IList managerDepartment; + private MdsApiService mdsApiService; + private ShopService shopService; + private GlobalContext globalContext; + public WebB() { InitializeComponent(); + this.Loaded += WebB_Loaded; + } + + private void WebB_Loaded(object sender, System.Windows.RoutedEventArgs e) + { + var sp = (App.Current as App).ServiceProvider; + using (var s = sp.CreateScope()) + { + w2m = s.ServiceProvider.GetRequiredService(); + globalContext = s.ServiceProvider.GetRequiredService(); + mdsApiService = s.ServiceProvider.GetRequiredService(); + shopService = s.ServiceProvider.GetRequiredService(); + } + + var url = "http://qtbbwy.qiyue666.com"; + w2m.CoreWebView2InitializationCompleted = (e) => + { + w2m.wb2.CoreWebView2.AddHostObjectToScript("qtbbwybContext", this.globalContext); + isNavigated = true; + w2m.wb2.CoreWebView2.Navigate(url); + }; + + + w2m.Init(); + w2m.wb2.SetValue(Grid.RowProperty, 1); + w2m.wb2.Margin = new Thickness(1, 0, 1, 0); + grid.Children.Add(w2m.wb2); + + + + if (w2m.IsInitializationCompleted && !isNavigated) + { + w2m.wb2.CoreWebView2.Navigate(url); + //w2m.wb2.CoreWebView2.NavigateToString(content); + isNavigated = true; + } } } }