From c1eb5404b69addf80423af0e390a42749dfee293 Mon Sep 17 00:00:00 2001 From: shanji <18996038927@163.com> Date: Fri, 16 Jun 2023 22:41:54 +0800 Subject: [PATCH] 10128 --- BBWY.Client/GlobalContext.cs | 18 +++++++++++++++++- BBWY.Client/Models/User/User.cs | 2 ++ BBWY.Client/ViewModels/MainViewModel.cs | 1 + BBWY.Client/Views/Order/GrabJDMibole.xaml.cs | 8 ++++++++ BBWY.Client/Views/Web/Web.xaml.cs | 1 + 5 files changed, 29 insertions(+), 1 deletion(-) diff --git a/BBWY.Client/GlobalContext.cs b/BBWY.Client/GlobalContext.cs index b665bde4..a6a1baae 100644 --- a/BBWY.Client/GlobalContext.cs +++ b/BBWY.Client/GlobalContext.cs @@ -1,15 +1,19 @@ using BBWY.Client.Models; +using Newtonsoft.Json; using System.Collections.Generic; +using System.Runtime.InteropServices; namespace BBWY.Client { + [ClassInterface(ClassInterfaceType.AutoDual)] + [ComVisible(true)] public class GlobalContext : NotifyObject { public GlobalContext() { ShopServiceGroupList = new List(); ShopServiceGroupLowerList = new List(); - ClientVersion = "10127"; + ClientVersion = "10128"; } private User user; @@ -42,5 +46,17 @@ namespace BBWY.Client public string QKApiHost { get; set; } #endregion + + #region Web + public string GetUserString() + { + return JsonConvert.SerializeObject(User); + } + + public string GetClientApiVersion() + { + return ClientVersion; + } + #endregion } } \ No newline at end of file diff --git a/BBWY.Client/Models/User/User.cs b/BBWY.Client/Models/User/User.cs index 6561e164..6f4f8fea 100644 --- a/BBWY.Client/Models/User/User.cs +++ b/BBWY.Client/Models/User/User.cs @@ -28,5 +28,7 @@ namespace BBWY.Client.Models /// public IList ShopList { get; set; } + public string Token { get; set; } + } } diff --git a/BBWY.Client/ViewModels/MainViewModel.cs b/BBWY.Client/ViewModels/MainViewModel.cs index 3250a6c1..5f8615e2 100644 --- a/BBWY.Client/ViewModels/MainViewModel.cs +++ b/BBWY.Client/ViewModels/MainViewModel.cs @@ -268,6 +268,7 @@ namespace BBWY.Client.ViewModels throw new Exception($"获取磨刀石用户信息失败 {mdsUserResponse.Msg}"); GlobalContext.User = mdsUserResponse.Data.Map(); + GlobalContext.User.Token = GlobalContext.UserToken; GlobalContext.User.SonDepartmentNames = string.Empty; if (mdsUserResponse.Data.SonDepartmentList != null && mdsUserResponse.Data.SonDepartmentList.Count > 0) GlobalContext.User.SonDepartmentNames = string.Join(',', mdsUserResponse.Data.SonDepartmentList.Select(sd => sd.DepartmentName)); diff --git a/BBWY.Client/Views/Order/GrabJDMibole.xaml.cs b/BBWY.Client/Views/Order/GrabJDMibole.xaml.cs index 22ff3f2f..09f557f5 100644 --- a/BBWY.Client/Views/Order/GrabJDMibole.xaml.cs +++ b/BBWY.Client/Views/Order/GrabJDMibole.xaml.cs @@ -40,10 +40,17 @@ namespace BBWY.Client.Views.Order private void GrabJDMibole_Loaded(object sender, RoutedEventArgs e) { var sp = (App.Current as App).ServiceProvider; + using (var s = sp.CreateScope()) { w2m = s.ServiceProvider.GetRequiredService(); } + GlobalContext globalContext = null; + using (var s = sp.CreateScope()) + { + globalContext = s.ServiceProvider.GetRequiredService(); + } + w2m.Init(shopId); grid.Children.Add(w2m.wb2); @@ -53,6 +60,7 @@ namespace BBWY.Client.Views.Order w2m.CoreWebView2InitializationCompleted = (e) => { isNavigated = true; + w2m.wb2.CoreWebView2.AddHostObjectToScript("webContext", globalContext); w2m.wb2.CoreWebView2.Navigate($"https://neworder.shop.jd.com/order/orderDetail?orderId={orderId}"); }; w2m.OnNavigationCompleted = async (e) => diff --git a/BBWY.Client/Views/Web/Web.xaml.cs b/BBWY.Client/Views/Web/Web.xaml.cs index 5c35e579..714d4f4f 100644 --- a/BBWY.Client/Views/Web/Web.xaml.cs +++ b/BBWY.Client/Views/Web/Web.xaml.cs @@ -41,6 +41,7 @@ namespace BBWY.Client.Views.Web w2m.CoreWebView2InitializationCompleted = (e) => { isNavigated = true; + w2m.wb2.CoreWebView2.AddHostObjectToScript("webContext", this.globalContext); // w2m.wb2.CoreWebView2.Navigate($"https://neworder.shop.jd.com/order/orderDetail?orderId={orderId}"); w2m.wb2.CoreWebView2.Navigate(url); };