Browse Source

增加快捷登录

master
С·æ 4 years ago
parent
commit
d9b9f76566
  1. 2
      .gitignore
  2. 12
      JdShopListener/JdShopListener.sln
  3. 126
      JdShopListener/JdShopListener/ApiHelper.cs
  4. 16
      JdShopListener/JdShopListener/JdShopListener.csproj
  5. 2
      JdShopListener/JdShopListener/JdShopListener.csproj.user
  6. 10
      JdShopListener/JdShopListener/MainWindow.xaml
  7. 2
      JdShopListener/JdShopListener/MainWindow.xaml.cs
  8. 256
      JdShopListener/JdShopListener/MainWindowViewModel.cs
  9. 88
      JdShopListener/JdShopListener/MemoryHelper.cs
  10. 80
      JdShopListener/JdShopListener/Models/ItemlabelInfoDto.cs
  11. 2
      JdShopListener/JdShopListener/Properties/PublishProfiles/FolderProfile.pubxml
  12. 3
      JdShopListener/JdShopListener/Properties/PublishProfiles/FolderProfile.pubxml.user
  13. 1
      JdShopListener/JdShopListener/SqlHelpers/DbHelper.cs
  14. 92
      JdShopListener/WpfNoticeMsg/NoticeMessage.xaml
  15. 63
      JdShopListener/WpfNoticeMsg/NoticeMessage.xaml.cs
  16. 23
      JdShopListener/WpfNoticeMsg/WpfNoticeMsg.csproj
  17. 14
      JdShopListener/WpfNoticeMsg/WpfNoticeMsg.csproj.user

2
.gitignore

@ -1,3 +1,5 @@
/JdShopListener/JdShopListener/obj
/JdShopListener/JdShopListener/bin
/JdShopListener/.vs
/JdShopListener/WpfNoticeMsg/bin
/JdShopListener/WpfNoticeMsg/obj

12
JdShopListener/JdShopListener.sln

@ -1,9 +1,11 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30804.86
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JdShopListener", "JdShopListener\JdShopListener.csproj", "{ED16D55D-BE5B-4206-8A0D-6C91A7A583B1}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JdShopListener", "JdShopListener\JdShopListener.csproj", "{ED16D55D-BE5B-4206-8A0D-6C91A7A583B1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WpfNoticeMsg", "WpfNoticeMsg\WpfNoticeMsg.csproj", "{67CEC78B-30B2-43EC-B254-C9CA133C3C55}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -15,6 +17,10 @@ Global
{ED16D55D-BE5B-4206-8A0D-6C91A7A583B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ED16D55D-BE5B-4206-8A0D-6C91A7A583B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ED16D55D-BE5B-4206-8A0D-6C91A7A583B1}.Release|Any CPU.Build.0 = Release|Any CPU
{67CEC78B-30B2-43EC-B254-C9CA133C3C55}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{67CEC78B-30B2-43EC-B254-C9CA133C3C55}.Debug|Any CPU.Build.0 = Debug|Any CPU
{67CEC78B-30B2-43EC-B254-C9CA133C3C55}.Release|Any CPU.ActiveCfg = Release|Any CPU
{67CEC78B-30B2-43EC-B254-C9CA133C3C55}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

126
JdShopListener/JdShopListener/ApiHelper.cs

@ -0,0 +1,126 @@
using JdShopListener.Models;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Windows;
namespace Utils
{
public class ApiHelper
{
public static string ApiBase { get; set; } = "http://localhost:5000";
//public static string ApiBase { get; set; } = "http://hyapi.qiyue666.com";
static string jwtToken;
public static string JwtToken
{
get
{
if (string.IsNullOrEmpty(jwtToken))
{
jwtToken = Utils.MemoryHelper.GetMemoryToken();
}
return jwtToken;
}
}
/// <summary>
/// 获取标签信息
/// </summary>
/// <param name="ids"></param>
/// <param name="platform"></param>
/// <returns></returns>
public static (bool isOk,List<ItemlabelInfoDto> datas) GetLabelByItemIds(int type=1)
{
try
{
var result = Http($"http://hyapi.qiyue666.com/HuiYan/itemlabels/GetItemsByJpLabels?type={type}");
var data = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(result);
string json = data.Data.ToString();
var datas = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ItemlabelInfoDto>>(json);
bool isSuccess = data.Success;
return (isSuccess, datas ?? new List<ItemlabelInfoDto>());
}
catch
{
return (false, new List<ItemlabelInfoDto>());
}
}
/// <summary>
/// http接口调用
/// </summary>
/// <param name="api"></param>
/// <param name="postData"></param>
/// <returns></returns>
private static string Http(string api, string postData = null, bool isAgain = false)
{
try
{
string url = api;
if (!url.StartsWith("http"))
{
url = ApiBase + api;
}
HttpClient http = new HttpClient();
http.Timeout = new TimeSpan(0, 0, 35);
http.DefaultRequestHeaders.Add("Authorization", "Bearer " + JwtToken);
if (postData!=null)
{
StringContent content = new StringContent(postData);
content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
var result = http.PostAsync(url, content).Result.Content.ReadAsStringAsync().Result;
return result;
}
var request = new HttpRequestMessage() { Method = HttpMethod.Get, RequestUri = new Uri(url) };
var res = http.SendAsync(request).Result;
if (res.StatusCode == System.Net.HttpStatusCode.Unauthorized)
{
return string.Empty;
}
else
{
//服务器挂掉
if (res.StatusCode != System.Net.HttpStatusCode.OK)
{
if (isAgain)
return null;
Thread.Sleep(60000);
return Http(api, postData, true);
}
return res.Content.ReadAsStringAsync().Result;
}
}
catch (HttpRequestException ex)
{
if (isAgain)
return null;
Thread.Sleep(60000);
return Http(api, postData, true);
}
catch (Exception ex)
{
return null;
}
}
}
}

16
JdShopListener/JdShopListener/JdShopListener.csproj

@ -5,9 +5,19 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
<UseWPF>true</UseWPF>
<AssemblyName>跟屁虫</AssemblyName>
<Platforms>AnyCPU;x86</Platforms>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>
<ItemGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x86'">
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.5">
<PrivateAssets>all</PrivateAssets>
@ -29,6 +39,10 @@
<Folder Include="db\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\WpfNoticeMsg\WpfNoticeMsg.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>

2
JdShopListener/JdShopListener/JdShopListener.csproj.user

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<_LastSelectedProfileId>D:\2019\齐论项目\京东竞品监控\JdShopListener\JdShopListener\Properties\PublishProfiles\FolderProfile.pubxml</_LastSelectedProfileId>
<_LastSelectedProfileId>D:\2019\齐论项目\跟屁虫\JdShopListener\JdShopListener\Properties\PublishProfiles\FolderProfile.pubxml</_LastSelectedProfileId>
</PropertyGroup>
<ItemGroup>
<ApplicationDefinition Update="App.xaml">

10
JdShopListener/JdShopListener/MainWindow.xaml

@ -200,7 +200,7 @@
</Setter>
</Style>
</Window.Resources>
<Grid>
<Grid >
<TabControl>
<TabItem Header="单品监控">
@ -332,5 +332,13 @@
<TextBox Text="{Binding LogText}" AcceptsReturn="True" IsReadOnly="True"></TextBox>
</TabItem>
</TabControl>
<Border Visibility="{Binding IsInitLoding,Converter={StaticResource toString},ConverterParameter=true----Visible|false----Collapsed}">
<Border.Background>
<SolidColorBrush Color="Gray" Opacity="0.3"></SolidColorBrush>
</Border.Background>
<TextBlock Text="{Binding InitText}" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="25"></TextBlock>
</Border>
</Grid>
</Window>

2
JdShopListener/JdShopListener/MainWindow.xaml.cs

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
@ -12,6 +13,7 @@ using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Utils;
namespace JdShopListener
{

256
JdShopListener/JdShopListener/MainWindowViewModel.cs

@ -12,6 +12,7 @@ using System.Linq;
using System.Threading;
using Newtonsoft.Json.Linq;
using PuppeteerSharp;
using Utils;
namespace JdShopListener
{
@ -29,6 +30,17 @@ namespace JdShopListener
}
}
private bool _IsInitLoding;
/// <summary>
/// 是否正在初始化
/// </summary>
public bool IsInitLoding
{
get { return _IsInitLoding; }
set { Set(ref _IsInitLoding, value); }
}
DingApiHelper dingApi=null;
public string JDCookie { get; set; }
@ -57,6 +69,7 @@ namespace JdShopListener
SkuList = new System.Collections.ObjectModel.ObservableCollection<SkuModel>();
SelectDate = DateList.FirstOrDefault();
SelectPro = ProList.FirstOrDefault();
Init();
if (System.IO.File.Exists(ddFileName))
@ -74,8 +87,59 @@ namespace JdShopListener
dingApi = new DingApiHelper(DDSecret, Webhook);
}
LoadHYItems();
}
private string _InitText= "正在加载慧眼竞品商品数据, 请稍后...";
public string InitText
{
get { return _InitText; }
set { Set(ref _InitText, value); }
}
public void LoadHYItems()
{
Thread t = new Thread(() =>
{
try
{
IsInitLoding = true;
var result = ApiHelper.GetLabelByItemIds();
result.datas.ForEach(item => {
var last = skuList.FirstOrDefault(c => c.SkuId == item.GoodsId);
if (last != null)
{
if (last.IsShow != 1)
{
last.IsShow = 1;
DbHelper.Db.UpdateSkuModel(last);
}
}
//新增
else {
Application.Current.Dispatcher.Invoke(() => {
InitText = $"正在添加【{item.GoodsId}】...";
});
AddSku(item.GoodsId);
}
//
});
}
finally {
IsInitLoding = false;
}
});
t.IsBackground = true;
t.Start();
}
List<SkuModel> skuList;
/// <summary>
/// 初始化
/// </summary>
@ -83,6 +147,9 @@ namespace JdShopListener
{
SkuList.Clear();
var list= DbHelper.Db.GetSkuList();
skuList = list;
list.ForEach(c => {
if (c.IsShow == 1)
{
@ -272,7 +339,7 @@ namespace JdShopListener
if (IsStart !=false)
{
MessageBox.Show("采集中不可操作!");
WpfNoticeMsg.NoticeMessage.Show("采集中不可操作!");
return;
}
@ -284,134 +351,137 @@ namespace JdShopListener
{
try
{
AddSku(Sku);
IsAdd = false;
}
catch(Exception ex)
{
WpfNoticeMsg.NoticeMessage.Show("添加失败,异常信息:"+ex.Message);
}
});
addThread.Start();
}
if (string.IsNullOrEmpty(JDCookie))
{
AddLog("开始获取Cookie!");
InitLoginCookie();
}
var detail = GetItemDetail(Sku);
JArray list = detail.product.colorSize as JArray;
//spuId
string spuId = detail.product.mainSkuId;
private void AddSku(string newSku)
{
if (string.IsNullOrEmpty(JDCookie))
{
AddLog("开始获取Cookie!");
InitLoginCookie();
}
if (list==null||list.Count == 0)
{
list = new JArray();
list.Add(JToken.FromObject(new { skuId=Sku }));
}
var detail = GetItemDetail(newSku);
JArray list = detail.product.colorSize as JArray;
List<SkuModel> skus = new List<SkuModel>();
//spuId
string spuId = detail.product.mainSkuId;
if (list == null || list.Count == 0)
{
list = new JArray();
list.Add(JToken.FromObject(new { skuId = newSku }));
}
foreach (JObject sku in list)
{
SkuModel model = new SkuModel()
{
Desc = Desc,
SkuId = sku["skuId"].ToString(),
SpuId = spuId
};
if (model.SkuId == Sku)
{
model.IsShow = 1;
}
List<SkuModel> skus = new List<SkuModel>();
foreach (JObject sku in list)
{
SkuModel model = new SkuModel()
{
Desc = Desc,
SkuId = sku["skuId"].ToString(),
SpuId = spuId
};
//去除重复
if (SkuList.Count(c => c.SkuId == model.SkuId) > 0)
{
if (model.SkuId == newSku)
{
model.IsShow = 1;
}
if (model.IsShow == 1)
{
var osku = SkuList.FirstOrDefault(c => c.SkuId == model.SkuId);
if (osku.IsShow != 1)
{
osku.IsShow = 1;
DbHelper.Db.UpdateSkuModel(osku);
}
//去除重复
if (SkuList.Count(c => c.SkuId == model.SkuId) > 0)
{
}
if (model.IsShow == 1)
{
var osku = SkuList.FirstOrDefault(c => c.SkuId == model.SkuId);
if (osku.IsShow != 1)
{
continue;
osku.IsShow = 1;
DbHelper.Db.UpdateSkuModel(osku);
}
//加入本地数据库
skus.Add(model);
Application.Current.Dispatcher.Invoke(() =>
{
SkuList.Add(model);
});
}
//加载sku详情
skus.ForEach(sku =>
{
var detail = GetItemDetail(sku.SkuId);
//主图
string src = detail.product.src;
var catIds = detail.product.cat;
continue;
}
List<int> cats = new List<int>();
foreach (var catId in catIds)
{
cats.Add((int)catId);
}
//加入本地数据库
skus.Add(model);
string cat = string.Join(",", cats);
Application.Current.Dispatcher.Invoke(() =>
{
SkuList.Add(model);
});
}
//标题
string title = detail.product.name;
//加载sku详情
skus.ForEach(sku =>
{
var detail = GetItemDetail(sku.SkuId);
//主图
string src = detail.product.src;
var catIds = detail.product.cat;
string shopId = detail.product.shopId;
List<int> cats = new List<int>();
string vid = detail.product.venderId;
foreach (var catId in catIds)
{
cats.Add((int)catId);
}
sku.ImgUrl = "http://img11.360buyimg.com/n1/" + src;
sku.Title = title;
sku.Cat = cat;
sku.ShopId = shopId;
sku.VenderId = vid;
string cat = string.Join(",", cats);
if (DbHelper.Db.AddSkuModel(sku))
{
AddLog($"{sku.SkuId}添加监控成功!");
}
else {
AddLog($"{sku.SkuId}添加监控列表失败!");
}
//标题
string title = detail.product.name;
Thread.Sleep(3000);
});
string shopId = detail.product.shopId;
//if (DbHelper.Db.AddSkuModel(skus))
//{
MessageBox.Show("添加成功", "提示");
AddLog("全部相关sku添加成功!");
//}
string vid = detail.product.venderId;
sku.ImgUrl = "http://img11.360buyimg.com/n1/" + src;
sku.Title = title;
sku.Cat = cat;
sku.ShopId = shopId;
sku.VenderId = vid;
IsAdd = false;
if (DbHelper.Db.AddSkuModel(sku))
{
AddLog($"{sku.SkuId}添加监控成功!");
}
catch(Exception ex)
else
{
MessageBox.Show("添加失败,异常信息:"+ex.Message);
AddLog($"{sku.SkuId}添加监控列表失败!");
}
Thread.Sleep(3000);
});
addThread.Start();
//if (DbHelper.Db.AddSkuModel(skus))
//{
WpfNoticeMsg.NoticeMessage.Show($"{newSku}添加成功", "提示");
AddLog("全部相关sku添加成功!");
}
/// <summary>
@ -431,7 +501,7 @@ namespace JdShopListener
{
if (IsAdd)
{
MessageBox.Show("请等待添加完成之后操作!");
WpfNoticeMsg.NoticeMessage.Show("请等待添加完成之后操作!");
return;
}
@ -699,7 +769,7 @@ namespace JdShopListener
dingApi = new DingApiHelper(DDSecret, Webhook);
MessageBox.Show("保存成功!", "提示");
WpfNoticeMsg.NoticeMessage.Show("保存成功!", "提示");
}

88
JdShopListener/JdShopListener/MemoryHelper.cs

@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using System.IO.MemoryMappedFiles;
using System.Text;
namespace Utils
{
public class MemoryHelper
{
public static string GetMemoryToken()
{
string memoryName = string.Empty;
string[] args = Environment.GetCommandLineArgs();
foreach (var arg in args)
{
if (arg.StartsWith("uid:"))
{
memoryName = arg;
}
}
var result = MemoryHelper.ReadMMF(memoryName);
if (result.isOk)
{
return result.content;
}
else
{
System.Environment.Exit(0);
return string.Empty;
}
}
/// <summary>
/// 写入映射文件
/// </summary>
/// <param name="mapname"></param>
/// <param name="content"></param>
public static bool WriteMMF(string mapname, string content)
{
MemoryMappedFile mmf = MemoryMappedFile.CreateOrOpen(mapname, 1000, MemoryMappedFileAccess.ReadWrite);
if (!string.IsNullOrEmpty(content))
{
using (var mmfStream = mmf.CreateViewStream())
{
using (var sw = new System.IO.StreamWriter(mmfStream))
{
sw.Write(content.Trim());
}
}
return true;
}
return false;
}
/// <summary>
/// 读取映射文件
/// </summary>
/// <param name="mapname"></param>
public static (bool isOk,string content) ReadMMF(string mapname)
{
try
{
MemoryMappedFile mmf = MemoryMappedFile.OpenExisting(mapname);
using (var mmfStream = mmf.CreateViewStream(0, 1000, MemoryMappedFileAccess.ReadWrite))
{
byte[] buffer = new byte[128];
int nLength = 0;
StringBuilder sb = new StringBuilder();
do
{
nLength = mmfStream.Read(buffer, 0, 128);
sb.AppendLine(System.Text.ASCIIEncoding.Default.GetString(buffer));
} while (nLength > 0);
return (true, sb.ToString().Replace("\0", null).TrimEnd());
}
}
catch (Exception ex)
{
return (false, null);
}
}
}
}

80
JdShopListener/JdShopListener/Models/ItemlabelInfoDto.cs

@ -0,0 +1,80 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace JdShopListener.Models
{
public class ItemlabelInfoDto: itemlabels
{
/// <summary>
/// 平台
/// </summary>
public int Platform { get; set; }
/// <summary>
/// 是否集团过滤
/// </summary>
public bool HasFilter { get; set; }
/// <summary>
/// 宝贝ID
/// </summary>
public string GoodsId { get; set; }
}
public class itemlabels
{
public String Id { get; set; }
/// <summary>
/// 创建时间
/// </summary>
public DateTime CreateTime { get; set; }
/// <summary>
/// 创建人Id
/// </summary>
public String CreatorId { get; set; }
/// <summary>
/// 否已删除
/// </summary>
public Boolean Deleted { get; set; }
/// <summary>
/// 宝贝ID
/// </summary>
public String ItemsId { get; set; }
/// <summary>
/// 是否筛选
/// </summary>
public Boolean IsScreening { get; set; }
/// <summary>
/// 是否过滤
/// </summary>
public Boolean IsFilter { get; set; }
/// <summary>
/// 是否竞品
/// </summary>
public Boolean IsCompeting { get; set; }
/// <summary>
/// 是否加入产品库
/// </summary>
public Boolean IsAdded { get; set; }
/// <summary>
/// 添加人
/// </summary>
public String UserId { get; set; }
/// <summary>
/// 团队ID
/// </summary>
public String TeamId { get; set; }
}
}

2
JdShopListener/JdShopListener/Properties/PublishProfiles/FolderProfile.pubxml

@ -11,7 +11,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<TargetFramework>netcoreapp3.1</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishSingleFile>True</PublishSingleFile>
<PublishSingleFile>False</PublishSingleFile>
<PublishReadyToRun>False</PublishReadyToRun>
<PublishTrimmed>False</PublishTrimmed>
</PropertyGroup>

3
JdShopListener/JdShopListener/Properties/PublishProfiles/FolderProfile.pubxml.user

@ -3,4 +3,7 @@
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<History>True|2021-11-11T10:06:38.5161322Z;True|2021-11-11T17:53:13.2835443+08:00;True|2021-11-11T17:52:00.9170918+08:00;True|2021-11-11T17:51:37.4852682+08:00;True|2021-11-11T17:49:30.9386192+08:00;True|2021-11-11T17:44:28.5146341+08:00;True|2021-11-11T17:42:26.8480671+08:00;True|2021-11-11T17:37:14.4108790+08:00;True|2021-11-11T17:30:25.4460722+08:00;</History>
</PropertyGroup>
</Project>

1
JdShopListener/JdShopListener/SqlHelpers/DbHelper.cs

@ -83,7 +83,6 @@ namespace JdShopListener.SqlHelpers
{
using (var db = new JdDBContext())
{
db.SkuItems.Remove(model);
return db.SaveChanges()>0;
}

92
JdShopListener/WpfNoticeMsg/NoticeMessage.xaml

@ -0,0 +1,92 @@
<Window x:Class="WpfNoticeMsg.NoticeMessage"
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:WpfNoticeMsg"
mc:Ignorable="d"
AllowsTransparency="True"
WindowStyle="None"
ResizeMode="NoResize"
WindowStartupLocation="CenterOwner"
Background="Transparent"
Foreground="White"
Title="NoticeMessage" MinHeight="75" MinWidth="350">
<WindowChrome.WindowChrome>
<WindowChrome GlassFrameThickness="-1" CaptionHeight="2"/>
</WindowChrome.WindowChrome>
<Window.Style>
<Style TargetType="{x:Type Window}">
<Setter Property="Background" Value="Transparent"></Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Window}">
<Border BorderBrush="#D7D7D7"
BorderThickness="1"
CornerRadius="6"
x:Name="WindowBorder">
<Border.Background>
<SolidColorBrush Opacity="0.6" Color="Black"></SolidColorBrush>
</Border.Background>
<Grid x:Name="LayoutRoot"
Background="{TemplateBinding Background}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid x:Name="WindowTitlePanel"
Background="{TemplateBinding BorderBrush}"
Margin="0,-1,0,0">
<ContentPresenter Content="{TemplateBinding Tag}"></ContentPresenter>
</Grid>
<AdornerDecorator Grid.Row="1"
KeyboardNavigation.IsTabStop="False">
<ContentPresenter Content="{TemplateBinding Content}"
x:Name="MainContentPresenter"
KeyboardNavigation.TabNavigation="Cycle" />
</AdornerDecorator>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Style>
<Window.Tag>
<Border Padding="5">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Text="提示" FontSize="14" Padding="20 5" x:Name="txt_Title"></TextBlock>
<Button Padding="10" Grid.Column="1" HorizontalAlignment="Right" Name="close" Click="close_Click">
<Button.Template>
<ControlTemplate TargetType="Button">
<Border Padding="{TemplateBinding Padding}">
<Border.Background>
<SolidColorBrush Color="White" Opacity="0.01"></SolidColorBrush>
</Border.Background>
<Path Data="M0 0 10 10 M5 5 10 0 M5 5 0 10" Stroke="White" ></Path>
</Border>
</ControlTemplate>
</Button.Template>
</Button>
</Grid>
</Border>
</Window.Tag>
<Grid x:Name="grid" >
<TextBlock Margin="20 0 20 15" VerticalAlignment="Center" HorizontalAlignment="Center" x:Name="txtMsg"></TextBlock>
</Grid>
</Window>

63
JdShopListener/WpfNoticeMsg/NoticeMessage.xaml.cs

@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace WpfNoticeMsg
{
/// <summary>
/// NoticeMessage.xaml 的交互逻辑
/// </summary>
public partial class NoticeMessage : Window
{
public NoticeMessage()
{
InitializeComponent();
}
/// <summary>
/// 显示消息
/// </summary>
/// <param name="msg"></param>
/// <param name="title"></param>
/// <param name="sleep"></param>
public static void Show(string msg, string title = "提示", int sleep = 2000)
{
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
NoticeMessage noticeMessage = new NoticeMessage();
noticeMessage.Owner = Application.Current.MainWindow;
noticeMessage.txt_Title.Text = title;
noticeMessage.txtMsg.Text = msg;
noticeMessage.Height= noticeMessage.grid.ActualHeight;
noticeMessage.Width = noticeMessage.grid.ActualWidth + 30;
noticeMessage.Show();
Task.Factory.StartNew(() =>
{
Thread.Sleep(sleep);
Application.Current.Dispatcher.Invoke(() =>
{
noticeMessage.Close();
});
});
}));
}
private void close_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
}

23
JdShopListener/WpfNoticeMsg/WpfNoticeMsg.csproj

@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<UseWPF>true</UseWPF>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="5.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="MvvmLightLibsStd10" Version="5.4.1.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>
</Project>

14
JdShopListener/WpfNoticeMsg/WpfNoticeMsg.csproj.user

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
<ItemGroup>
<Compile Update="NoticeMessage.xaml.cs">
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<Page Update="NoticeMessage.xaml">
<SubType>Designer</SubType>
</Page>
</ItemGroup>
</Project>
Loading…
Cancel
Save