506583276@qq.com 2 years ago
parent
commit
0971947e2a
  1. 10
      BBWYB.Client/GlobalContext.cs
  2. 4
      BBWYB.Client/Models/User/User.cs
  3. 2
      BBWYB.Client/ViewModels/MainViewModel.cs
  4. 4
      BBWYB.Client/Views/WebB/WebB.xaml
  5. 45
      BBWYB.Client/Views/WebB/WebB.xaml.cs

10
BBWYB.Client/GlobalContext.cs

@ -1,9 +1,14 @@
using BBWYB.Client.Models;
using CommunityToolkit.Mvvm.ComponentModel;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace BBWYB.Client
{
[ClassInterface(ClassInterfaceType.AutoDual)]
[ComVisible(true)]
public class GlobalContext : ObservableObject
{
public GlobalContext()
@ -29,6 +34,11 @@ namespace BBWYB.Client
public string MDSApiHost { get; set; }
public string BBWYCApiHost { get; set; }
public string QKApiHost { get; set; }
public string GetUserString()
{
return JsonConvert.SerializeObject(User);
}
#endregion
}
}

4
BBWYB.Client/Models/User/User.cs

@ -24,9 +24,11 @@ namespace BBWYB.Client.Models
public IList<Department> DepartmentList { get; set; }
/// <summary>
/// 店铺列表 (暂时只有刷单组才需要)
/// 店铺列表
/// </summary>
public IList<Shop> ShopList { get; set; }
public string Token { get; set; }
}
}

2
BBWYB.Client/ViewModels/MainViewModel.cs

@ -4,6 +4,7 @@ using BBWYB.Client.Views.SelectShop;
using BBWYB.Common.Extensions;
using BBWYB.Common.Models;
using CommunityToolkit.Mvvm.Input;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
@ -139,6 +140,7 @@ namespace BBWYB.Client.ViewModels
throw new Exception($"获取磨刀石用户信息失败 {mdsUserResponse.Msg}");
GlobalContext.User = mdsUserResponse.Data.Map<User>();
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));

4
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">
<Grid>
<Grid x:Name="grid">
</Grid>
</Page>

45
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,48 @@ namespace BBWYB.Client.Views.WebB
private WebView2Manager w2m;
private bool isNavigated;
private IList<string> 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<WebView2Manager>();
globalContext = s.ServiceProvider.GetRequiredService<GlobalContext>();
mdsApiService = s.ServiceProvider.GetRequiredService<MdsApiService>();
shopService = s.ServiceProvider.GetRequiredService<ShopService>();
}
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;
}
}
}
}

Loading…
Cancel
Save