第三方库存上传功能

This commit is contained in:
wule committed 2025-07-22 16:57:02 +08:00
1 parent 0740da277c
commit 7e71b08863
29 files changed
+5391 -178

No files matched your search

@@ -24,6 +24,7 @@ using System.Web.Hosting;
using System.Windows.Forms;
using Work;
using Work.BLL.Tools;
using TemuKJD.KJDForms.AdminForms;
namespace TemuKJD.KJDForms.ShopForms
{
@@ -46,6 +47,7 @@ namespace TemuKJD.KJDForms.ShopForms
private ShopLoginInfo shop = null;
private List<ShopCompany> lstShopCompany = new List<ShopCompany>();
private string currentUrl = "";
private long currentSupplierId = 0;
public ShopLoginForm(ShopLoginInfo shopInfo)
{
@@ -279,6 +281,18 @@ namespace TemuKJD.KJDForms.ShopForms
cefWebBrowser.LoadError += CefWebBrowser_LoadError;
cefWebBrowser.Dock = DockStyle.Fill;
//js绑定C#对象
ShopBrowserObject shopObj = new ShopBrowserObject();
shopObj.OnInfoReceived += ShopObj_OnInfoReceived;
CefSharpSettings.WcfEnabled = true;
cefWebBrowser.JavascriptObjectRepository.Register(
name: "shopObj",
objectToBind: shopObj,
isAsync: false,
options: new BindingOptions { Binder = BindingOptions.DefaultBinder.Binder /*CamelCaseJavascriptNames = false*/ /*cef79*/ }
);
if (shop.Cookies == null)
shop.Cookies = "";
@@ -340,6 +354,12 @@ namespace TemuKJD.KJDForms.ShopForms
});
}
}
private void ShopObj_OnInfoReceived(string information)
{
//BaseMsgForm.ShowInfo(information);
if (!string.IsNullOrEmpty(information))
cefWebBrowser.GetBrowser().MainFrame.EvaluateScriptAsync("alert('" + information + "');");
}
private void CefWebBrowser_LoadError(object sender, CefSharp.LoadErrorEventArgs e)
{
@@ -371,10 +391,31 @@ namespace TemuKJD.KJDForms.ShopForms
//
// });
//}
//js绑定C#对象 html页面内声明绑定的C#对象
StringBuilder sb = new StringBuilder();
sb.Append("(function(){");
sb.Append("CefSharp.BindObjectAsync('shopObj');");
sb.Append("})();");
cefWebBrowser.GetBrowser().MainFrame.EvaluateScriptAsync(sb.ToString());
}
private void RequestHandler_ResourceLoadComplete(object sender, string url, string postData, string responseData, IRequest request)
{
Task.Run(() =>
{
var data = responseData;
if (data.Contains("supplierId") && data.Contains("\"success\":true"))
{
var supplierIds = BaseRegex.GetMatchRegex(ref data, "\"supplierId\":\\d{5,20}");
if (supplierIds.Count > 0 && supplierIds[0].Groups.Count > 0)
{
var supplierId = supplierIds[0].Groups[0].Value.Replace("\"supplierId\":", "").ParseToLong();
if (supplierId > 0)
this.currentSupplierId = supplierId;
}
}
});
if (url.StartsWith("https://seller.kuajingmaihuo.com/settle/site-main"))
{
cefWebBrowser.Load(shopMainUrl);
@@ -434,6 +475,44 @@ namespace TemuKJD.KJDForms.ShopForms
// }
// });
//}
// 库存上传按钮
if (currentUrl.StartsWith("https://seller.kuajingmaihuo.com/goods/product/list"))
{
Task.Run(() => {
string sAddInputJs = @"
document.addEventListener('wheel', function(event) {
// 检查滚动方向
//if (event.deltaY < 0) {
// console.log('向上滚动');
//} else {
// console.log('向下滚动');
//}
// 或者使用 event.deltaX 来检查水平滚动
//if (event.deltaX < 0) {
// console.log('向左滚动');
//} else if (event.deltaX > 0) {
// console.log('向右滚动');
//}
// 阻止默认的滚动行为(如果有需要)
//event.preventDefault();
addGetProdButton();
});
addGetProdButton();
function addGetProdButton() {
var productLst = document.getElementsByClassName('product-info_idContent__iDukx');
for(i=0; i<productLst.length; i++) {
if (productLst[i].innerHTML.indexOf('库存上传') < 0 && productLst[i].innerHTML.indexOf('SPU ID') >= 0) {
var sSpuId = productLst[i].innerText.replace('\r','').replace('\n','').replace('SPU ID:', '');
productLst[i].innerHTML = productLst[i].innerHTML.replace(""></div>"", ""><input type=\""button\"" style=\""margin-left: 50px; width:60px; text-align:center\"" value=\""库存上传\"" onclick=\""shopObj.getThirdProduct('"" + sSpuId + ""'," + this.currentSupplierId + @")\""></div>"");
}
}
}";
cefWebBrowser.GetBrowser().MainFrame.EvaluateScriptAsync(sAddInputJs);
});
}
}
/// <summary>