Browse Source

web页面

yijia
shanji 2 years ago
parent
commit
c97986fe5e
  1. 2
      BBWYB.Client/App.xaml
  2. 3
      BBWYB.Client/GlobalContext.cs
  3. 9
      BBWYB.Client/ViewModels/ViewModelLocator.cs
  4. 96
      BBWYB.Client/ViewModels/WebVM.cs
  5. 25
      BBWYB.Client/Views/Web.xaml
  6. 83
      BBWYB.Client/Views/Web.xaml.cs
  7. 96
      WebTest/MainWindow.xaml.cs

2
BBWYB.Client/App.xaml

@ -4,7 +4,7 @@
xmlns:local="clr-namespace:BBWYB.Client"
xmlns:vm="clr-namespace:BBWYB.Client.ViewModels"
xmlns:ctr="clr-namespace:BBWYB.Client.Converters"
StartupUri="/Views/MainWindow.xaml"
StartupUri="/Views/Web.xaml"
ShutdownMode="OnExplicitShutdown">
<!--StartupUri="/Views/MainWindow.xaml"-->
<Application.Resources>

3
BBWYB.Client/GlobalContext.cs

@ -1,7 +1,6 @@
using BBWYB.Client.APIServices;
using BBWYB.Client.Helpers;
using BBWYB.Client.Models;
using BBWYB.Client.ViewModels;
using BBWYB.Client.Views.PackPurchaseTaska;
using BBWYB.Client.Views.WebB;
using CommunityToolkit.Mvvm.ComponentModel;
@ -22,7 +21,7 @@ namespace BBWYB.Client
{
public GlobalContext()
{
BBWYBApiVersion = "10037";
BBWYBApiVersion = "10038";
}
private User user;

9
BBWYB.Client/ViewModels/ViewModelLocator.cs

@ -118,5 +118,14 @@ namespace BBWYB.Client.ViewModels
return s.ServiceProvider.GetRequiredService<UpdatePurchaseTaskViewModel>();
}
}
public WebVM WebVM
{
get
{
using var s = sp.CreateScope();
return s.ServiceProvider.GetRequiredService<WebVM>();
}
}
}
}

96
BBWYB.Client/ViewModels/WebVM.cs

@ -0,0 +1,96 @@
using BBWYB.Client.APIServices;
using BBWYB.Client.Models;
using BBWYB.Client.Views;
using BBWYB.Common.Extensions;
using BBWYB.Common.Models;
using CommunityToolkit.Mvvm.Messaging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace BBWYB.Client.ViewModels
{
public class WebVM : BaseVM, IDenpendency
{
private MdsApiService mdsApiService;
private MenuModel selectedMenuModel;
private bool isLoading;
ShopService shopService;
public GlobalContext GlobalContext { get; set; }
public bool IsLoading { get => isLoading; set { SetProperty(ref isLoading, value); } }
public WebVM(GlobalContext globalContext,
MdsApiService mdsApiService,
ShopService shopService)
{
this.mdsApiService = mdsApiService;
this.GlobalContext = globalContext;
this.shopService = shopService;
Task.Factory.StartNew(Login);
}
private void Login()
{
IsLoading = true;
try
{
var mdsUserResponse = mdsApiService.GetUserInfo(GlobalContext.UserToken);
if (!mdsUserResponse.Success)
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));
var res = shopService.GetDepartmentList();
if (!res.Success)
throw new Exception(res.Msg);
var allDepartmentList = res.Data.Map<IList<Department>>();
var shopList = new List<Shop>();
foreach (var d in allDepartmentList)
shopList.AddRange(d.ShopList);
GlobalContext.User.ShopList = shopList;
IList<Department> departmentList = null;
var response = mdsApiService.GetShopDetailList();
if (!response.Success)
throw new Exception(response.Msg);
departmentList = response.Data?.Where(d => d.Name.Contains("供应链")).ToList();
if (departmentList.Count == 0)
throw new Exception("缺少有效的部门数据");
var shopIds = new List<string>();
foreach (var d in departmentList)
{
if (d.ShopList != null && d.ShopList.Count > 0)
{
foreach (var s in d.ShopList)
shopIds.Add(s.ShopId.ToString());
}
}
GlobalContext.User.DepartmentList = departmentList;
WeakReferenceMessenger.Default.Send(new Message_WebB_LoginCompleted(null));
IsLoading = false;
}
catch (Exception ex)
{
IsLoading = false;
App.Current.Dispatcher.Invoke(() =>
{
MessageBox.Show(ex.Message, "登录失败");
});
Environment.Exit(Environment.ExitCode);
}
}
}
}

25
BBWYB.Client/Views/Web.xaml

@ -0,0 +1,25 @@
<c:BWindow x:Class="BBWYB.Client.Views.Web"
xmlns:c="clr-namespace:SJ.Controls;assembly=SJ.Controls"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:BBWYB.Client.Views"
mc:Ignorable="d"
Style="{StaticResource bwstyle}"
DataContext="{Binding WebVM,Source={StaticResource Locator}}"
Title="Web" Height="450" Width="800">
<Grid x:Name="grid">
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Border BorderThickness="0,0,0,1" BorderBrush="{StaticResource MainMenu.BorderBrush}">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="10,0,0,0">
<TextBlock Text="{Binding GlobalContext.User.Name}"/>
<TextBlock Text="{Binding GlobalContext.BBWYBApiVersion}" Margin="5,0,0,0"/>
</StackPanel>
</Border>
<c:RoundWaitProgress Play="{Binding IsLoading}" Panel.ZIndex="999" Grid.RowSpan="2"/>
</Grid>
</c:BWindow>

83
BBWYB.Client/Views/Web.xaml.cs

@ -0,0 +1,83 @@
using CommunityToolkit.Mvvm.Messaging;
using CommunityToolkit.Mvvm.Messaging.Messages;
using Microsoft.Extensions.DependencyInjection;
using SJ.Controls;
using System.Windows;
using System.Windows.Controls;
namespace BBWYB.Client.Views
{
/// <summary>
/// Web.xaml 的交互逻辑
/// </summary>
public partial class Web : BWindow
{
private WebView2Manager w2m;
private bool isNavigated;
private GlobalContext globalContext;
public Web()
{
InitializeComponent();
this.Width = SystemParameters.WorkArea.Size.Width * 0.8;
this.Height = SystemParameters.WorkArea.Size.Height * 0.7;
var sp = (App.Current as App).ServiceProvider;
using (var s = sp.CreateScope())
{
w2m = s.ServiceProvider.GetRequiredService<WebView2Manager>();
globalContext = s.ServiceProvider.GetRequiredService<GlobalContext>();
}
WeakReferenceMessenger.Default.Register<Message_WebB_LoginCompleted>(this, (o, x) =>
{
this.Dispatcher.BeginInvoke(initWebView);
});
}
private void Web_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
}
private void initWebView()
{
#if DEBUG
var url = "http://qtbbwy.qiyue666.com";//"http://192.168.1.2:8080";
var registerName = "webTestContext";
//var url = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "s.html");
#else
var url = "http://qtbbwy.qiyue666.com";
var registerName = "webContext";
#endif
//var url = "http://qtbbwy.qiyue666.com";
w2m.CoreWebView2InitializationCompleted = (e) =>
{
w2m.wb2.CoreWebView2.AddHostObjectToScript(registerName, this.globalContext);
isNavigated = true;
w2m.wb2.CoreWebView2.Navigate(url);
};
w2m.Init("bbwyb_web");
w2m.wb2.SetValue(Grid.RowProperty, 1);
w2m.wb2.Margin = new Thickness(1, 0, 1, 0);
//grid.Children.Clear();
grid.Children.Add(w2m.wb2);
if (w2m.IsInitializationCompleted && !isNavigated)
{
w2m.wb2.CoreWebView2.Navigate(url);
//w2m.wb2.CoreWebView2.NavigateToString(content);
isNavigated = true;
}
}
}
public class Message_WebB_LoginCompleted : ValueChangedMessage<object>
{
public Message_WebB_LoginCompleted(object value) : base(value)
{
}
}
}

96
WebTest/MainWindow.xaml.cs

@ -126,78 +126,42 @@ private string registerName = "webContext";
if (mdsUserResponse.Data.SonDepartmentList != null && mdsUserResponse.Data.SonDepartmentList.Count > 0)
globalContext.User.SonDepartmentNames = string.Join(',', mdsUserResponse.Data.SonDepartmentList.Select(sd => sd.DepartmentName));
//if (GlobalContext.User.TeamName == "刷单组")
// return;
var res = shopService.GetDepartmentList();
if (!res.Success)
throw new Exception(res.Msg);
var allDepartmentList = res.Data.Map<IList<Department>>();
//if (GlobalContext.User.TeamName == "刷单组")
//{
//var shopList = new List<Shop>();
//foreach (var d in allDepartmentList)
// shopList.AddRange(d.ShopList);
//globalContext.User.ShopList = shopList;
IList<Department> departmentList = null;
if (globalContext.User.TeamName == "刷单组" ||
managerDepartment.Contains(globalContext.User.TeamName) ||
managerDepartment.Any(m => globalContext.User.SonDepartmentNames.Contains(m)))
{
var response = shopService.GetDepartmentList();
if (!response.Success)
throw new Exception(response.Msg);
departmentList = response.Data.Map<List<Department>>();
}
else
{
var response = mdsApiService.GetShopDetailList();
if (!response.Success)
throw new Exception(response.Msg);
departmentList = response.Data;
if (departmentList.Count == 0)
throw new Exception("缺少有效的部门数据");
var shopIds = new List<string>();
foreach (var d in departmentList)
{
if (d.ShopList != null && d.ShopList.Count > 0)
{
foreach (var s in d.ShopList)
shopIds.Add(s.ShopId.ToString());
}
}
var shopList2Res = shopService.GetShopListByIds(shopIds);
if (shopList2Res.Success && shopList2Res.Data != null && shopList2Res.Data.Count() > 0)
{
foreach (var d in departmentList)
{
foreach (var shop in d.ShopList)
{
var s2 = shopList2Res.Data.FirstOrDefault(s => s.ShopId == shop.ShopId);
if (s2 != null)
{
shop.DingDingKey = s2.DingDingKey;
shop.DingDingWebHook = s2.DingDingWebHook;
shop.SkuSafeTurnoverDays = s2.SkuSafeTurnoverDays;
shop.SiNanPolicyLevel = s2.SiNanPolicyLevel;
shop.SiNanDingDingKey = s2.SiNanDingDingKey;
shop.SiNanDingDingWebHook = s2.SiNanDingDingWebHook;
shop.AppKey2 = s2.AppKey2;
shop.AppSecret2 = s2.AppSecret2;
shop.AppToken2 = s2.AppToken2;
}
}
}
}
}
for (var i = 0; i < departmentList.Count(); i++)
var response = mdsApiService.GetShopDetailList();
if (!response.Success)
throw new Exception(response.Msg);
departmentList = response.Data?.Where(d => d.Name.Contains("供应链")).ToList();
if (departmentList.Count == 0)
throw new Exception("缺少有效的部门数据");
var shopIds = new List<string>();
foreach (var d in departmentList)
{
var d = departmentList[i];
for (var j = 0; j < d.ShopList.Count(); j++)
if (d.ShopList != null && d.ShopList.Count > 0)
{
var shop = d.ShopList[j];
if (string.IsNullOrEmpty(shop.AppToken2))
{
d.ShopList.RemoveAt(j);
j--;
}
foreach (var s in d.ShopList)
shopIds.Add(s.ShopId.ToString());
}
if (d.ShopList == null || d.ShopList.Count() == 0)
{
departmentList.RemoveAt(i);
i--;
}
}
globalContext.User.DepartmentList = departmentList;
}

Loading…
Cancel
Save