Commit 24015d63 authored by 十三's avatar 十三

使用发货易scan-printing-form新接口

parent 2af25aa6
import { factoryContentUrls } from "../config"; import { factoryContentUrls } from "../config";
import { StartPrint, Print } from "../types"; import { StartPrint, Print } from "../types/index";
import { ScanPrintSearchType, GetWaybillNoMethod } from "../types/scanPrinting";
// platform: PlatformCode,// 平台编码,淘系及其他平台订单模板的为0,拼多多订单的为1,京东订单的为2 // platform: PlatformCode,// 平台编码,淘系及其他平台订单模板的为0,拼多多订单的为1,京东订单的为2
const PlatfromsMap = new Map([ const PlatfromsMap = new Map([
[0, /.+:\/\/a.*\.fahuoyi.com\/scanPrinting\/index/], [0, /.+:\/\/a.*\.fahuoyi.com\/scanPrinting\/index/],
[1, /.+:\/\/pdd.*\.fahuoyi.com\/scanPrinting\/index/], [1, /.+:\/\/pdd.*\.fahuoyi.com\/scanPrinting\/index/],
[2, /.+:\/\/jd.*\.fahuoyi.com\/scanPrinting\/index/] [2, /.+:\/\/jd.*\.fahuoyi.com\/scanPrinting\/index/],
]) ]);
chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) { chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
console.log("onMessage", message);
if (message.action === StartPrint) { if (message.action === StartPrint) {
// console.log("startPrint") // console.log("startPrint")
// 通知fahuoyi的content开始点击 // 通知fahuoyi的content开始点击
chrome.tabs.query({ // chrome.tabs.query(
url: "*://*.fahuoyi.com/scanPrinting/index" // {
}, function (tabs) { // url: "*://*.fahuoyi.com/scanPrinting/index",
let exp = new RegExp(PlatfromsMap.get(message.value.platform)!, 'i') // },
// function (tabs) {
// let exp = new RegExp(PlatfromsMap.get(message.value.platform)!, "i");
console.log(tabs, 'tabs66') // console.log(tabs, "tabs66");
tabs && tabs.forEach(tab => { // tabs &&
if (exp.test(tab.url!)) { // tabs.forEach((tab) => {
chrome.tabs.sendMessage(tab.id!, { action: Print, value: message.value }) // if (exp.test(tab.url!)) {
} // chrome.tabs.sendMessage(tab.id!, {
}) // action: Print,
// // sendResponse("") // value: message.value,
// if (tabs[0]) { // });
// chrome.tabs.sendMessage(tabs[0].id!, { action: Print, value: message.value }) // }
// });
// // // sendResponse("")
// // if (tabs[0]) {
// // chrome.tabs.sendMessage(tabs[0].id!, { action: Print, value: message.value })
// // }
// } // }
}) // );
chrome.tabs.query({ chrome.tabs.query(
url: "*://*.fahuoyi.com/features/scanPrinting" {
}, function (tabs) { url: "*://*.fahuoyi.com/features/scanPrinting",
console.log(tabs, 'tabs11') },
tabs && tabs.forEach(tab => { function (tabs) {
chrome.tabs.executeScript(tab.id!, {code: 'console.log(window["scan-printing-form"])'}); console.log(tabs, "tabs11");
}) tabs &&
}) tabs.forEach((tab) => {
chrome.tabs.sendMessage(tab.id!, {
action: Print,
value: message.value,
js: `console.log(window["scan-printing-form"]);window["scan-printing-form"].config(${getPrintJS(
message.value
)});window["scan-printing-form"].searchAndPrint("${
message.value?.waybillNo
? message.value?.waybillNo
: message.value?.orderNo
}")`,
});
// chrome.tabs.executeScript(tab.id!, {
// code: `console.log(window["scan-printing-form"]);window["scan-printing-form"].config(${getPrintJS(
// message.value
// )});`,
// });
// console.log(getPrintJS(message.value));
});
}
);
} else if (message.action === "sendNewWaybillNo") { } else if (message.action === "sendNewWaybillNo") {
// 从bg页面转发给厂家页面的content.js // 从bg页面转发给厂家页面的content.js
chrome.tabs.query({ chrome.tabs.query(
url: factoryContentUrls {
}, function (tabs) { url: factoryContentUrls,
tabs && tabs.forEach(tab => { },
function (tabs) {
tabs &&
tabs.forEach((tab) => {
// chrome.tabs.sendMessage(tab.id!, message) // chrome.tabs.sendMessage(tab.id!, message)
const port = chrome.tabs.connect(tab.id!, { name: "sendNewWaybillNo" }) const port = chrome.tabs.connect(tab.id!, {
name: "sendNewWaybillNo",
});
port.onMessage.addListener(function (msg, port) { port.onMessage.addListener(function (msg, port) {
if (msg.action === "answer") { if (msg.action === "answer") {
// console.log(msg, port, 'bg') // console.log(msg, port, 'bg')
port.disconnect() port.disconnect();
} }
}) });
port.postMessage(message) port.postMessage(message);
});
}) }
}) );
// let port = chrome.runtime.connect({ name: "bgSendMessage" }) // let port = chrome.runtime.connect({ name: "bgSendMessage" })
// port.postMessage(message) // port.postMessage(message)
} }
}) });
// chrome.runtime.onConnect.addListener(function (msg) { // chrome.runtime.onConnect.addListener(function (msg) {
// console.log(msg, 'msgbg') // console.log(msg, 'msgbg')
// }) // })
function getPrintJS(param: any): string {
console.log(param);
let _ScanPrintSearchType = ScanPrintSearchType.WAYBILL_NO;
let _GetWaybillNoMethod = GetWaybillNoMethod.OLD;
let _printId: string = param.list[0].printId;
let _waybillTemplate: string = "0";
// @ts-ignore
param.list.forEach((item) => {
if (item.wayCompanyId === param.wayCompanyId) {
(_waybillTemplate = item.waybillTemplateList[param?.platform ?? 0]),
(_printId =
item.printId === "仅获取电子面单号不打印面单"
? "isGenerateWaybillNoOnly"
: item.printId);
// printId = item.printId
}
});
if (param.waybillNo) {
//旧单号
} else {
//新单号
_ScanPrintSearchType = ScanPrintSearchType.ORDER_ORIGINAL_ID;
_GetWaybillNoMethod = GetWaybillNoMethod.NEW;
}
let ConfigParams = `{
/**
* 扫描类型
*/
searchType: "${_ScanPrintSearchType}",
/**
* 是否避免重复扫描打印
*/
checkRepeatPrint: true,
/**
* 快递单模板id
*/
waybillTemplateId: ${_waybillTemplate},
/**
* 打印机名称
*/
printer: "${_printId}",
/**
* 发货人id
*/
shippingAddressId: ${param.scanPrintingForm.shippingAddresses[0].id},
/**
* 是否打印成功后自动发货
*/
autoShippingAfterPrint: ${param.isAutoEmit ? "true" : "false"},
/**
* 获取面单方式
*/
getWaybillNoMethod: "${_GetWaybillNoMethod}",
/**
* 发货方式
*/
shippingWay: "OFFLINE"
}`;
return ConfigParams;
}
import { message } from "antd"; import { message } from "antd";
import { Print, StartPrint } from "../types"; import { Print, StartPrint, getFaHuoYiSetting } from "../types";
import { ScanPrintingForm } from "../types/scanPrinting";
export enum PlatformCode { export enum PlatformCode {
"淘系及其他平台订单模板" = 0, "淘系及其他平台订单模板" = 0,
"拼多多订单模板" = 1, "拼多多订单模板" = 1,
"京东订单模板" = 2 "京东订单模板" = 2,
} }
type Params = { type Params = {
waybillNo: string // 运单号 waybillNo: string; // 运单号
platform: PlatformCode, platform: PlatformCode;
wayCompanyId: string wayCompanyId: string;
} & { } & {
orderNo: string// 订单号 orderNo: string; // 订单号
wayCompanyId: string// 快递公司的Id wayCompanyId: string; // 快递公司的Id
platform: PlatformCode,// 平台编码,淘系及其他平台订单模板的为0,拼多多订单的为1,京东订单的为2 platform: PlatformCode; // 平台编码,淘系及其他平台订单模板的为0,拼多多订单的为1,京东订单的为2
} };
interface Response { interface Response {
data: { data: {
action: "StartPrint", action: "StartPrint";
value: Params value: Params;
} };
} }
window.addEventListener("message", function (res: Response) { window.addEventListener("message", function (res: Response) {
if (res.data.action === "StartPrint") { if (res.data.action === "StartPrint") {
chrome.storage?.local.get({ list: [] }, function (storage) { chrome.storage?.local.get(
{
list: [],
scanPrintingForm: {
waybillTemplates: [],
shippingAddresses: [],
printers: [],
},
isAutoEmit: false,
},
function (storage) {
// @ts-ignore // @ts-ignore
if (storage.list.length == 0 || !storage.list[0].wayCompanyId || !storage.list[0].waybillTemplateList.some(item => item)) { if (
alert("请选择快递模板") storage.list.length == 0 ||
!storage.list[0].wayCompanyId ||
!storage.list[0].waybillTemplateList.some((item: any) => item)
) {
alert("请选择快递模板");
return; return;
} }
const { wayCompanyId, waybillNo, orderNo, platform } = res.data.value // @ts-ignore
if (!waybillNo && (!wayCompanyId || !orderNo || ![0, 1, 2].includes(Number(platform)))) { if (
alert("参数传递错误") storage.scanPrintingForm.waybillTemplates.length == 0 ||
storage.scanPrintingForm.shippingAddresses.length == 0 ||
storage.scanPrintingForm.printers.length == 0
) {
alert("发货易配置信息为空或获取失败");
return; return;
} }
chrome.runtime.sendMessage({ action: StartPrint, value: res.data.value }, function (response) { const { wayCompanyId, waybillNo, orderNo, platform } = res.data.value;
if (
}) !waybillNo &&
}) (!wayCompanyId || !orderNo || ![0, 1, 2].includes(Number(platform)))
) {
alert("参数传递错误");
return;
}
console.log(storage.scanPrintingForm);
let newValue = {
...res.data.value,
scanPrintingForm: storage.scanPrintingForm,
list: storage.list,
isAutoEmit: storage.isAutoEmit,
};
chrome.runtime.sendMessage(
{ action: StartPrint, value: newValue },
function (response) {}
);
}
);
} else if (res.data.action === getFaHuoYiSetting) {
//console.log("content recive:", JSON.parse(res.data.value));
chrome.storage.local.set(
{
// @ts-ignore
scanPrintingForm: JSON.parse(res.data.value),
},
() => {}
);
chrome.runtime.sendMessage(
{ action: getFaHuoYiSetting, value: res.data },
function (response) {}
);
} }
}) });
enum SelectOptions { enum SelectOptions {
"waybillNo" = "waybillNo", "waybillNo" = "waybillNo",
"orderOriginalId" = "orderOriginalId" "orderOriginalId" = "orderOriginalId",
} }
// fahuoyi.com // fahuoyi.com
interface Message { interface Message {
action: "Print", action: "Print";
value: Params value: Params;
} }
const printWayBillByOld = function (waybillNo: string, wayCompanyId: string) { const printWayBillByOld = function (waybillNo: string, wayCompanyId: string) {
chrome.storage.local.get({ list: [], isAutoEmit: false }, function (res) { chrome.storage.local.get({ list: [], isAutoEmit: false }, function (res) {
// 选择使用旧单号打印 // 选择使用旧单号打印
let oldOptionDom = document.querySelectorAll(".form-group.mr20>.radio-inline")[1] as HTMLLabelElement let oldOptionDom = document.querySelectorAll(
let waybillNoBtn = document.querySelector(".form-group>.form-control.original-id-input-label>option[value=waybillNo]") as HTMLOptionElement ".form-group.mr20>.radio-inline"
let selectDom = document.querySelector("select.form-control.original-id-input-label") as HTMLSelectElement )[1] as HTMLLabelElement;
let inputDom = document.querySelector(".form-group>.form-control.original-id-input") as HTMLInputElement let waybillNoBtn = document.querySelector(
let serachBtn = document.querySelector(".form-group>.btn.btn-primary[type=button]") as HTMLButtonElement ".form-group>.form-control.original-id-input-label>option[value=waybillNo]"
let printDom = document.querySelector("#elContainer>div>.form-inline.panel-border.p15.search-panel>div[class]>.form-group.mr20[style]>select.form-control") as HTMLSelectElement ) as HTMLOptionElement;
let autoDom = document.querySelectorAll("#elContainer>div>.form-inline.panel-border.p15.search-panel>div.mt10>div.form-group.mr20>select.form-control")[1] as HTMLSelectElement let selectDom = document.querySelector(
"select.form-control.original-id-input-label"
) as HTMLSelectElement;
let inputDom = document.querySelector(
".form-group>.form-control.original-id-input"
) as HTMLInputElement;
let serachBtn = document.querySelector(
".form-group>.btn.btn-primary[type=button]"
) as HTMLButtonElement;
let printDom = document.querySelector(
"#elContainer>div>.form-inline.panel-border.p15.search-panel>div[class]>.form-group.mr20[style]>select.form-control"
) as HTMLSelectElement;
let autoDom = document.querySelectorAll(
"#elContainer>div>.form-inline.panel-border.p15.search-panel>div.mt10>div.form-group.mr20>select.form-control"
)[1] as HTMLSelectElement;
// 默认参数写死 // 默认参数写死
let hiddenInputDom = document.querySelector("#forcePrintMergerOrderInput") as HTMLInputElement let hiddenInputDom = document.querySelector(
"#forcePrintMergerOrderInput"
) as HTMLInputElement;
let printId: string let printId: string;
// @ts-ignore // @ts-ignore
res.list.forEach(item => { res.list.forEach((item) => {
if (item.wayCompanyId === wayCompanyId) { if (item.wayCompanyId === wayCompanyId) {
printId = item.printId === "仅获取电子面单号不打印面单" ? "isGenerateWaybillNoOnly" : item.printId printId =
item.printId === "仅获取电子面单号不打印面单"
? "isGenerateWaybillNoOnly"
: item.printId;
// printId = item.printId // printId = item.printId
} }
});
})
// 1.选择旧单号打印 // 1.选择旧单号打印
oldOptionDom.click() oldOptionDom.click();
// 2.选择打单模板 // 2.选择打单模板
waybillNoBtn.selected = true waybillNoBtn.selected = true;
selectDom.value = SelectOptions.waybillNo selectDom.value = SelectOptions.waybillNo;
// @ts-ignore // @ts-ignore
selectDom.dispatchEvent(new Event("change", { bubbles: true })) selectDom.dispatchEvent(new Event("change", { bubbles: true }));
// 3.选择打印机 // 3.选择打印机
printDom.value = printId! printDom.value = printId!;
printDom.dispatchEvent(new Event("change", { bubbles: true })) printDom.dispatchEvent(new Event("change", { bubbles: true }));
// 4.自动发货 // 4.自动发货
autoDom.value = "true" autoDom.value = "true";
autoDom.dispatchEvent(new Event("change", { bubbles: true })) autoDom.dispatchEvent(new Event("change", { bubbles: true }));
// 5.自己联系快递公司 // 5.自己联系快递公司
let bySelf = document.querySelectorAll("#elContainer>div>.form-inline.panel-border.p15.search-panel>div.mt10>div.form-group.mr20>select.form-control")[2] as HTMLSelectElement let bySelf = document.querySelectorAll(
bySelf.value = "OFFLINE" "#elContainer>div>.form-inline.panel-border.p15.search-panel>div.mt10>div.form-group.mr20>select.form-control"
bySelf.dispatchEvent(new Event("change", { bubbles: true })) )[2] as HTMLSelectElement;
bySelf.value = "OFFLINE";
bySelf.dispatchEvent(new Event("change", { bubbles: true }));
// 6.输入运单号 // 6.输入运单号
// selectDom.__reactEventHandlers$8wsw7c8olk.onChange({ target: { value: SelectOptions.waybillNo } }) // selectDom.__reactEventHandlers$8wsw7c8olk.onChange({ target: { value: SelectOptions.waybillNo } })
inputDom.value = waybillNo inputDom.value = waybillNo;
// 7.默认参数写死 // 7.默认参数写死
hiddenInputDom.value = "true" hiddenInputDom.value = "true";
serachBtn.click()
})
} serachBtn.click();
});
};
const printWayBillByNew = function ({ orderNo, wayCompanyId, platform }: Pick<Params, "orderNo" | "wayCompanyId" | "platform">) { const printWayBillByNew = function ({
orderNo,
wayCompanyId,
platform,
}: Pick<Params, "orderNo" | "wayCompanyId" | "platform">) {
// console.log(orderNo, wayCompanyId, platform) // console.log(orderNo, wayCompanyId, platform)
// 根据快递公司的companyId选择相应的配置 // 根据快递公司的companyId选择相应的配置
chrome.storage.local.get({ list: [], isAutoEmit: false }, function (res) { chrome.storage.local.get({ list: [], isAutoEmit: false }, function (res) {
...@@ -121,111 +187,138 @@ const printWayBillByNew = function ({ orderNo, wayCompanyId, platform }: Pick<Pa ...@@ -121,111 +187,138 @@ const printWayBillByNew = function ({ orderNo, wayCompanyId, platform }: Pick<Pa
let printId: string; let printId: string;
// @ts-ignore // @ts-ignore
res.list.forEach(item => { res.list.forEach((item) => {
if (item.wayCompanyId === wayCompanyId) { if (item.wayCompanyId === wayCompanyId) {
waybillTemplate = item.waybillTemplateList[platform] waybillTemplate = item.waybillTemplateList[platform];
printId = item.printId === "仅获取电子面单号不打印面单" ? "isGenerateWaybillNoOnly" : item.printId printId =
item.printId === "仅获取电子面单号不打印面单"
? "isGenerateWaybillNoOnly"
: item.printId;
// printId = item.printId // printId = item.printId
} }
});
}) let newOrderBtn = document.querySelector(
".form-group.mr20>.radio-inline.mr10"
let newOrderBtn = document.querySelector(".form-group.mr20>.radio-inline.mr10") as HTMLLabelElement ) as HTMLLabelElement;
let wayTemplateSelect = document.querySelector(".form-group.mr20>.form-control.waybill-template-select") as HTMLSelectElement let wayTemplateSelect = document.querySelector(
".form-group.mr20>.form-control.waybill-template-select"
) as HTMLSelectElement;
// let orderBtn = document.querySelector(".form-group>.form-control.original-id-input-label>option[value=orderOriginalId]") as HTMLOptionElement // let orderBtn = document.querySelector(".form-group>.form-control.original-id-input-label>option[value=orderOriginalId]") as HTMLOptionElement
let selectDom = document.querySelector("select.form-control.original-id-input-label") as HTMLSelectElement let selectDom = document.querySelector(
let inputDom = document.querySelector(".form-group>.form-control.original-id-input") as HTMLInputElement "select.form-control.original-id-input-label"
) as HTMLSelectElement;
let searchDom = document.querySelector(".form-group>.btn.btn-primary") as HTMLButtonElement let inputDom = document.querySelector(
".form-group>.form-control.original-id-input"
let printDom = document.querySelector("#elContainer>div>.form-inline.panel-border.p15.search-panel>div[class]>.form-group.mr20[style]>select.form-control") as HTMLSelectElement ) as HTMLInputElement;
let autoDom = document.querySelectorAll("#elContainer>div>.form-inline.panel-border.p15.search-panel>div.mt10>div.form-group.mr20>select.form-control")[1] as HTMLSelectElement
let searchDom = document.querySelector(
".form-group>.btn.btn-primary"
) as HTMLButtonElement;
let printDom = document.querySelector(
"#elContainer>div>.form-inline.panel-border.p15.search-panel>div[class]>.form-group.mr20[style]>select.form-control"
) as HTMLSelectElement;
let autoDom = document.querySelectorAll(
"#elContainer>div>.form-inline.panel-border.p15.search-panel>div.mt10>div.form-group.mr20>select.form-control"
)[1] as HTMLSelectElement;
// 默认参数写死 // 默认参数写死
let hiddenInputDom = document.querySelector("#forcePrintMergerOrderInput") as HTMLInputElement let hiddenInputDom = document.querySelector(
"#forcePrintMergerOrderInput"
) as HTMLInputElement;
//1.点击 获取新单号打印 //1.点击 获取新单号打印
newOrderBtn.click() newOrderBtn.click();
//2.选择快递单模板 //2.选择快递单模板
wayTemplateSelect.value = waybillTemplate! + "" wayTemplateSelect.value = waybillTemplate! + "";
wayTemplateSelect.dispatchEvent(new Event("change", { bubbles: true })) wayTemplateSelect.dispatchEvent(new Event("change", { bubbles: true }));
//3.点击订单编号 //3.点击订单编号
selectDom.value = SelectOptions.orderOriginalId selectDom.value = SelectOptions.orderOriginalId;
// @ts-ignore // @ts-ignore
selectDom.dispatchEvent(new Event("change", { bubbles: true })) selectDom.dispatchEvent(new Event("change", { bubbles: true }));
// 4. 选择打印机 // 4. 选择打印机
printDom!.value = printId! printDom!.value = printId!;
printDom.dispatchEvent(new Event("change", { bubbles: true })) printDom.dispatchEvent(new Event("change", { bubbles: true }));
// orderBtn.click() // orderBtn.click()
// 5.自动发货 // 5.自动发货
autoDom.value = "true" autoDom.value = "true";
autoDom.dispatchEvent(new Event("change", { bubbles: true })) autoDom.dispatchEvent(new Event("change", { bubbles: true }));
// 6.自己联系快递公司 // 6.自己联系快递公司
let bySelf = document.querySelectorAll("#elContainer>div>.form-inline.panel-border.p15.search-panel>div.mt10>div.form-group.mr20>select.form-control")[2] as HTMLSelectElement let bySelf = document.querySelectorAll(
bySelf.value = "OFFLINE" "#elContainer>div>.form-inline.panel-border.p15.search-panel>div.mt10>div.form-group.mr20>select.form-control"
bySelf.dispatchEvent(new Event("change", { bubbles: true })) )[2] as HTMLSelectElement;
bySelf.value = "OFFLINE";
bySelf.dispatchEvent(new Event("change", { bubbles: true }));
//7.输入订单编号 //7.输入订单编号
inputDom.value = orderNo inputDom.value = orderNo;
// 8.默认参数写死 // 8.默认参数写死
hiddenInputDom.value = "true" hiddenInputDom.value = "true";
//9.点击搜索并打印 //9.点击搜索并打印
searchDom.click() searchDom.click();
});
}) };
}
//发货易页面 //发货易页面
chrome.runtime.onMessage.addListener(function (message: Message, sender, response) { chrome.runtime.onMessage.addListener(function (
message: Message,
sender,
response
) {
if (message.action === Print) { if (message.action === Print) {
//console.log(message.js);
let btn_js: HTMLButtonElement = document.createElement("button");
btn_js.style.cssText = "width:0;heigth:0";
document.body.appendChild(btn_js);
// @ts-ignore
btn_js.setAttribute("onclick", message.js);
btn_js.click();
btn_js.setAttribute("onclick", "");
btn_js.remove();
return;
if (message.value.waybillNo) { if (message.value.waybillNo) {
printWayBillByOld(message.value.waybillNo, message.value.wayCompanyId) printWayBillByOld(message.value.waybillNo, message.value.wayCompanyId);
} else { } else {
const { orderNo, wayCompanyId, platform } = message.value const { orderNo, wayCompanyId, platform } = message.value;
printWayBillByNew({ orderNo, wayCompanyId, platform }) printWayBillByNew({ orderNo, wayCompanyId, platform });
} }
} }
});
})
// 拿到打印机 // 拿到打印机
chrome.runtime.onConnect.addListener(function (port) { chrome.runtime.onConnect.addListener(function (port) {
if (port.name === "getPrinter") { if (port.name === "getPrinter") {
port.onMessage.addListener(function (msg) { port.onMessage.addListener(function (msg) {
if (msg.action === "getPrint") { if (msg.action === "getPrint") {
// @ts-ignore // @ts-ignore
let options: HTMLOptionElement[] = document.querySelectorAll("#elContainer>div>.form-inline.panel-border.p15.search-panel>div[class]>.form-group.mr20[style]>select.form-control>option") let options: HTMLOptionElement[] = document.querySelectorAll(
"#elContainer>div>.form-inline.panel-border.p15.search-panel>div[class]>.form-group.mr20[style]>select.form-control>option"
);
// console.log(2) // console.log(2)
// console.log(options, options[0].value, '3') // console.log(options, options[0].value, '3')
let arr = [] let arr = [];
for (let i = 0; i < options.length; i++) { for (let i = 0; i < options.length; i++) {
arr.push(options[i].textContent);
arr.push(options[i].textContent)
// arr.push(options[i].value) // arr.push(options[i].value)
} }
port.postMessage(arr) port.postMessage(arr);
} }
}) });
} }
}) });
// 厂家content.js页面 // 厂家content.js页面
// chrome.runtime.onMessage.addListener(function (message, sender, response) { // chrome.runtime.onMessage.addListener(function (message, sender, response) {
...@@ -240,100 +333,164 @@ chrome.runtime.onConnect.addListener(function (port) { ...@@ -240,100 +333,164 @@ chrome.runtime.onConnect.addListener(function (port) {
// } // }
// }) // })
chrome.runtime.onConnect.addListener(function (port) { chrome.runtime.onConnect.addListener(function (port) {
console.log("content chrome onConnect", port);
if (port.name === "sendNewWaybillNo") { if (port.name === "sendNewWaybillNo") {
// console.log(port, 'port') // console.log(port, 'port')
port.onMessage.addListener(function (msg) { port.onMessage.addListener(function (msg) {
// console.log(msg, 'msg') // console.log(msg, 'msg')
console.log("content port onMessage", msg);
if (msg.action === "sendNewWaybillNo") { if (msg.action === "sendNewWaybillNo") {
window.postMessage(
{
window.postMessage({ action: "newWaybillNo", message: msg?.message, orderNo: msg?.orderNo, waybillNo: msg?.waybillNo, result: msg.result }, '*') action: "newWaybillNo",
message: msg?.message,
port.postMessage({ action: "answer" }) orderNo: msg?.orderNo,
waybillNo: msg?.waybillNo,
result: msg.result,
},
"*"
);
port.postMessage({ action: "answer" });
} }
}) });
} }
});
})
// inject.js // inject.js
const startPrintWayBill = function (params: Params) { const startPrintWayBill = function (params: Params) {
// 通知content.js触发事件 // 通知content.js触发事件
window.postMessage({ action: "StartPrint", value: params }, "*") window.postMessage({ action: "StartPrint", value: params }, "*");
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
// @ts-ignore // @ts-ignore
window.onmessage = function (res) { window.onmessage = function (res) {
if (res.data.action === "newWaybillNo") { if (res.data.action === "newWaybillNo") {
console.log(res.data, 'res.data') console.log(res.data, "res.data");
res.data.result ? resolve(res.data.waybillNo) : reject(res.data); res.data.result ? resolve(res.data.waybillNo) : reject(res.data);
}
};
});
};
const injectGetFaHuoYiSetting = function (params: Params) {
// 通知content.js触发事件
window.addEventListener("onSEScanPrintingFormLoad", () => {
// scanPrintingForm.onLoad((data: OnLoadData) => {
// //const { waybillTemplates, shippingAddresses, printers } = data;
// console.log("init", data);
// // window.postMessage(
// // { action: getFaHuoYiSetting, value: JSON.stringify(data) },
// // "*"
// // );
// });
//@ts-ignore
var scanPrintingForm: ScanPrintingForm = window["scan-printing-form"];
var timer: number = window.setInterval(function () {
if (scanPrintingForm === undefined) {
//@ts-ignore
scanPrintingForm = window["scan-printing-form"];
} }
if (
//@ts-ignore
scanPrintingForm.waybillTemplates.length > 0 ||
//@ts-ignore
scanPrintingForm.shippingAddresses.length > 0 ||
//@ts-ignore
scanPrintingForm.printers.length > 0
) {
console.log(scanPrintingForm);
window.postMessage(
{
action: "getFaHuoYiSetting",
value: JSON.stringify(scanPrintingForm),
},
"*"
);
clearInterval(timer);
} }
}) }, 1000);
// return new Promise(function (resolve, reject) {
// // @ts-ignore
// window.onmessage = function (res) {
// if (res.data.action === getFaHuoYiSetting) {
// console.log(res.data, getFaHuoYiSetting);
// res.data.result ? resolve(res.data) : reject(res.data);
// }
// };
// });
});
}; };
/** /**
* 发货易content * 发货易content
*/ */
window.addEventListener("message", function (msg) { window.addEventListener("message", function (msg) {
if (msg.data.action === "sendNewWaybillNo") { if (msg.data.action === "sendNewWaybillNo") {
// chrome.runtime.onConnect.addListener(function (port) { // chrome.runtime.onConnect.addListener(function (port) {
// console.log(port, 'port') // console.log(port, 'port')
// port.postMessage(msg.data) // port.postMessage(msg.data)
// }) // })
chrome.runtime.sendMessage(msg.data) chrome.runtime.sendMessage(msg.data);
} }
if (msg.data.action === getFaHuoYiSetting) {
}) console.log("content Get Test Message", JSON.parse(msg.data.value));
}
function injectCustomjs() { });
let temp = document.createElement("script") function observerDom(): Boolean {
temp.innerHTML = `window.startPrintWayBill=${startPrintWayBill}` let tbodyDom = document.querySelector(
document.body.appendChild(temp) "#root > section > main > div > div.content-right.background-white.h > div > div > div > div.ant-table-wrapper > div > div > div > div > div > table > tbody"
);
console.log("observer", tbodyDom);
let tbodyDom = document.querySelector("#elContainer>div>table>tbody") if (!tbodyDom) return false;
if (tbodyDom) { if (tbodyDom) {
console.log("observer");
let observe = new MutationObserver(function (mutations, observe) { let observe = new MutationObserver(function (mutations, observe) {
console.log(mutations, 'mutations') console.log(mutations, "mutations");
let td = mutations[0].addedNodes[0].childNodes[3]
console.log(td, 'td')
let td = mutations[mutations.length - 1].addedNodes[0].childNodes[3];
console.log(td, "td");
if (!td) return; if (!td) return;
let tdObserve = new MutationObserver(function (mutations, observe) { let tdObserve = new MutationObserver(function (mutations, observe) {
console.log(mutations, 'mutations') console.log(mutations, "mutations");
mutations.forEach(item => { mutations.forEach((item) => {
item.addedNodes.forEach((node) => {
item.addedNodes.forEach(node => {
// @ts-ignore // @ts-ignore
if (node.nodeType == 3 && node.parentElement?.className.includes("text-danger")) { if (
node.nodeType == 3 &&
console.log(node.textContent, 'nodeTextContent') node.parentElement?.className.includes("danger")
) {
console.log(node.textContent, "nodeTextContent");
// @ts-ignore // @ts-ignore
return window.postMessage({ action: "sendNewWaybillNo", message: node?.wholeText, result: false }, "*") return window.postMessage(
{
action: "sendNewWaybillNo",
//@ts-ignorenpm
message: node?.wholeText,
result: false,
},
"*"
);
} }
if (node.nodeName == "DIV") { if (node.nodeName == "DIV") {
let text = node.childNodes[2].textContent; let text = node.childNodes[2].textContent;
let orderNo = item.target.parentElement?.children[0]?.children[0]?.childNodes[0]?.textContent let orderNo =
console.log(orderNo, 'orderNo') item.target.parentElement?.children[0]?.children[0]
window.postMessage({ action: "sendNewWaybillNo", waybillNo: text, orderNo, result: true }, "*") ?.childNodes[0]?.textContent;
console.log(orderNo, "orderNo");
console.log(text, "text", node);
window.postMessage(
{
action: "sendNewWaybillNo",
waybillNo: text,
orderNo,
result: true,
},
"*"
);
// 从发货易页面发消息给bg // 从发货易页面发消息给bg
// chrome.runtime.sendMessage({ action: "newWaybillNo", value: text }, function (res) { // chrome.runtime.sendMessage({ action: "newWaybillNo", value: text }, function (res) {
...@@ -345,54 +502,61 @@ function injectCustomjs() { ...@@ -345,54 +502,61 @@ function injectCustomjs() {
// console.log(port, 'port') // console.log(port, 'port')
// port.postMessage({ action: "newWaybillNo", value: text }) // port.postMessage({ action: "newWaybillNo", value: text })
// }) // })
} }
}) });
}) });
}) });
tdObserve.observe(td, { tdObserve.observe(td, {
childList: true, childList: true,
characterData: true, characterData: true,
subtree: true, subtree: true,
attributes: true attributes: true,
}) });
});
observe.observe(tbodyDom, {
})
observe.observe(tbodyDom!, {
childList: true, childList: true,
});
}) let bfqxDom = document.querySelector("body");
let bfqxDom = document.querySelector("body")
let observe1 = new MutationObserver(function (mutations, observe) { let observe1 = new MutationObserver(function (mutations, observe) {
// mutations[0].addedNodes[0].className // mutations[0].addedNodes[0].className
console.log(mutations, 'bfqxDom') console.log(mutations, "bfqxDom");
mutations.forEach(item => { mutations.forEach((item) => {
item.addedNodes.forEach(node => { item.addedNodes.forEach((node) => {
// node.textContent == 'bootbox modal fade sui-modal in' && // node.textContent == 'bootbox modal fade sui-modal in' &&
if (node.textContent == '× 该订单有商品正在退款中或者已取消,是否确认继续打印?确定取消') { if (
let bfqxyesbtn = document.querySelector(".btn.btn-primary.bootbox-accept") as HTMLButtonElement node.textContent ==
let bfqxnobtn = document.querySelector(".btn.btn-default.bootbox-cancel") as HTMLButtonElement "该订单有商品正在退款中或者已取消,是否确认继续打印?取 消确 定"
console.log('bfqxyesbtn', bfqxyesbtn) ) {
bfqxyesbtn.click() let bfqxyesbtn = document.querySelector(
"body > div:nth-child(19) > div > div.ant-modal-wrap > div > div.ant-modal-content > div > div > div.ant-modal-confirm-btns > button.ant-btn.ant-btn-primary"
) as HTMLButtonElement;
let bfqxnobtn = document.querySelector(
"body > div:nth-child(19) > div > div.ant-modal-wrap > div > div.ant-modal-content > div > div > div.ant-modal-confirm-btns > button:nth-child(1)"
) as HTMLButtonElement;
console.log("bfqxyesbtn", bfqxyesbtn);
bfqxyesbtn.click();
} }
}) });
}) });
}) });
observe1.observe(bfqxDom!, { observe1.observe(bfqxDom!, {
childList: true, childList: true,
});
})
} }
return true;
} }
function injectCustomjs() {
let temp = document.createElement("script");
temp.innerHTML = `window.startPrintWayBill=${startPrintWayBill};window.getFaHuoYiSetting=${injectGetFaHuoYiSetting};window.getFaHuoYiSetting();`;
document.body.appendChild(temp);
var timer: number = window.setInterval(function () {
if (observerDom()) clearInterval(timer);
}, 1000);
}
injectCustomjs() injectCustomjs();
...@@ -2,337 +2,453 @@ import React, { useState, useCallback, useEffect } from "react"; ...@@ -2,337 +2,453 @@ import React, { useState, useCallback, useEffect } from "react";
import { Select, Button } from "antd"; import { Select, Button } from "antd";
import "./index.scss"; import "./index.scss";
const { Option } = Select const { Option } = Select;
export interface IwaybillTemplate { export interface IwaybillTemplate {
name: string, name: string;
value: string value: string;
} }
interface Item { interface Item {
wayCompanyId: string | undefined, wayCompanyId: string | undefined;
waybillTemplateList: (string | undefined)[] waybillTemplateList: (string | undefined)[];
printId: string | undefined printId: string | undefined;
} }
type List = Item[] type List = Item[];
// //
const AllWayCompany = [ const AllWayCompany = [
{ name: "圆通速递", value: "YTO" } { name: "圆通速递", value: "YTO" },
, { name: "申通快递", value: "STO" } { name: "申通快递", value: "STO" },
, { name: "中通快递", value: "ZTO" } { name: "中通快递", value: "ZTO" },
, { name: "韵达快递", value: "YUNDA" } { name: "韵达快递", value: "YUNDA" },
, { name: "顺丰速运", value: "SF" } { name: "顺丰速运", value: "SF" },
, { name: "百世快递", value: "HTKY" } { name: "百世快递", value: "HTKY" },
, { name: "EMS", value: "EMS" } { name: "EMS", value: "EMS" },
, { name: "EMS经济快递", value: "EYB" } { name: "EMS经济快递", value: "EYB" },
, { name: "邮政标准快递", value: "DISTRIBUTOR_1715055" } { name: "邮政标准快递", value: "DISTRIBUTOR_1715055" },
, { name: "邮政快递包裹", value: "POSTB" } { name: "邮政快递包裹", value: "POSTB" },
, { name: "中国邮政", value: "POST" } { name: "中国邮政", value: "POST" },
, { name: "京东快递", value: "EX_JD_EXPRESS" } { name: "京东快递", value: "EX_JD_EXPRESS" },
, { name: "天天快递", value: "TTKDEX" } { name: "天天快递", value: "TTKDEX" },
, { name: "国通快递", value: "GTO" } { name: "国通快递", value: "GTO" },
, { name: "安能快递(小包)", value: "DISTRIBUTOR_12017865" } { name: "安能快递(小包)", value: "DISTRIBUTOR_12017865" },
, { name: "安能物流", value: "ANE56" } { name: "安能物流", value: "ANE56" },
, { name: "全峰快递", value: "QFKD" } { name: "全峰快递", value: "QFKD" },
, { name: "联邦快递", value: "FEDEX" } { name: "联邦快递", value: "FEDEX" },
, { name: "德邦快递", value: "DBKD" } { name: "德邦快递", value: "DBKD" },
, { name: "德邦物流", value: "DBL" } { name: "德邦物流", value: "DBL" },
, { name: "宅急送", value: "ZJS" } { name: "宅急送", value: "ZJS" },
, { name: "优速快递", value: "UC" } { name: "优速快递", value: "UC" },
, { name: "龙邦速递", value: "LB" } { name: "龙邦速递", value: "LB" },
, { name: "亚风", value: "AIR" } { name: "亚风", value: "AIR" },
, { name: "天地华宇", value: "HOAU" } { name: "天地华宇", value: "HOAU" },
, { name: "速尔快运", value: "SURE" } { name: "速尔快运", value: "SURE" },
, { name: "大田", value: "DTW" } { name: "大田", value: "DTW" },
, { name: "保宏物流", value: "BHWL" } { name: "保宏物流", value: "BHWL" },
, { name: "发网", value: "UNIPS" } { name: "发网", value: "UNIPS" },
, { name: "长发", value: "YUD" } { name: "长发", value: "YUD" },
, { name: "长宇", value: "CYEXP" } { name: "长宇", value: "CYEXP" },
, { name: "远长", value: "YC" } { name: "远长", value: "YC" },
, { name: "东方汇", value: "DFH" } { name: "东方汇", value: "DFH" },
, { name: "飞远配送 ", value: "GZLT" } { name: "飞远配送 ", value: "GZLT" },
, { name: "派易国际物流77", value: "PKGJWL" } { name: "派易国际物流77", value: "PKGJWL" },
, { name: "信丰物流", value: "XFWL" } { name: "信丰物流", value: "XFWL" },
, { name: "飞远(爱彼西)配送", value: "HZABC" } { name: "飞远(爱彼西)配送", value: "HZABC" },
, { name: "华强物流", value: "SHQ" } { name: "华强物流", value: "SHQ" },
, { name: "百世物流", value: "BEST" } { name: "百世物流", value: "BEST" },
, { name: "新邦物流", value: "XB" } { name: "新邦物流", value: "XB" },
, { name: "美国速递", value: "MGSD" } { name: "美国速递", value: "MGSD" },
, { name: "远成快运", value: "YCKY" } { name: "远成快运", value: "YCKY" },
, { name: "品骏快递", value: "PJBEST" } { name: "品骏快递", value: "PJBEST" },
, { name: "苏宁物流", value: "DISTRIBUTOR_13452378" } { name: "苏宁物流", value: "DISTRIBUTOR_13452378" },
, { name: "WnDirect", value: "WND" } { name: "WnDirect", value: "WND" },
, { name: "能达速递", value: "NEDA" } { name: "能达速递", value: "NEDA" },
, { name: "黑猫宅急便", value: "YCT" } { name: "黑猫宅急便", value: "YCT" },
, { name: "D速物流", value: "DISTRIBUTOR_13460212" } { name: "D速物流", value: "DISTRIBUTOR_13460212" },
, { name: "联昊通", value: "LTS" } { name: "联昊通", value: "LTS" },
, { name: "E速宝", value: "ESB" } { name: "E速宝", value: "ESB" },
, { name: "佳吉快递", value: "CNEX" } { name: "佳吉快递", value: "CNEX" },
, { name: "广东EMS", value: "GDEMS" } { name: "广东EMS", value: "GDEMS" },
, { name: "增益速递", value: "QRT" } { name: "增益速递", value: "QRT" },
, { name: "全一快递", value: "UAPEX" } { name: "全一快递", value: "UAPEX" },
, { name: "快捷快递", value: "FAST" } { name: "快捷快递", value: "FAST" },
, { name: "中铁快运", value: "CRE" } { name: "中铁快运", value: "CRE" },
, { name: "速通物流", value: "EX_SUT56" } { name: "速通物流", value: "EX_SUT56" },
, { name: "顺丰快运", value: "EX_SFKY" } { name: "顺丰快运", value: "EX_SFKY" },
, { name: "速腾快递", value: "EX_STE56" } { name: "速腾快递", value: "EX_STE56" },
, { name: "顺心捷达", value: "DISTRIBUTOR_13484485" } { name: "顺心捷达", value: "DISTRIBUTOR_13484485" },
, { name: "宽昊物流", value: "EX_KHWL" } { name: "宽昊物流", value: "EX_KHWL" },
, { name: "都市节奏", value: "EX_DSJZ" } { name: "都市节奏", value: "EX_DSJZ" },
, { name: "众邮快递", value: "EX_ZYKD" } { name: "众邮快递", value: "EX_ZYKD" },
, { name: "京东快运", value: "EX_JDKY" } { name: "京东快运", value: "EX_JDKY" },
, { name: "DN快递", value: "EX_TOPSPEED_DN" } { name: "DN快递", value: "EX_TOPSPEED_DN" },
, { name: "九曳供应链", value: "DISTRIBUTOR_13323734" } { name: "九曳供应链", value: "DISTRIBUTOR_13323734" },
, { name: "重庆华宇物流", value: "EX_CQHY" } { name: "重庆华宇物流", value: "EX_CQHY" },
, { name: "极兔速递", value: "EX_JTSD" } { name: "极兔速递", value: "EX_JTSD" },
, { name: "丹鸟", value: "DISTRIBUTOR_13503931" } { name: "丹鸟", value: "DISTRIBUTOR_13503931" },
, { name: "如风达配送", value: "BJRFD-001" } { name: "如风达配送", value: "BJRFD-001" },
, { name: "韵达点通达", value: "EX_YUNDA_DTD" } { name: "韵达点通达", value: "EX_YUNDA_DTD" },
, { name: "壹米滴答", value: "YMDD" } { name: "壹米滴答", value: "YMDD" },
, { name: "百世国际", value: "DISTRIBUTOR_13433751" } { name: "百世国际", value: "DISTRIBUTOR_13433751" },
, { name: "安迅物流", value: "DISTRIBUTOR_13365751" } { name: "安迅物流", value: "DISTRIBUTOR_13365751" },
, { name: "承诺达特快", value: "DISTRIBUTOR_13469985" } { name: "承诺达特快", value: "DISTRIBUTOR_13469985" },
, { name: "沃埃家", value: "EX_WOWVIP" } { name: "沃埃家", value: "EX_WOWVIP" },
, { name: "京广速递", value: "EX_SZKKE" } { name: "京广速递", value: "EX_SZKKE" },
, { name: "鸿昌物流", value: "EX_HC" } { name: "鸿昌物流", value: "EX_HC" },
, { name: "华企快运", value: "EX_HUAQIEX" } { name: "华企快运", value: "EX_HUAQIEX" },
, { name: "中骅物流", value: "EX_CHUNGHWA56" } { name: "中骅物流", value: "EX_CHUNGHWA56" },
, { name: "百世快运", value: "BESTQJT" } { name: "百世快运", value: "BESTQJT" },
, { name: "运通速运", value: "WTO" } { name: "运通速运", value: "WTO" },
, { name: "中通快运", value: "DISTRIBUTOR_13222803" } { name: "中通快运", value: "DISTRIBUTOR_13222803" },
, { name: "菜鸟大件-日日顺配", value: "DISTRIBUTOR_13159132" } { name: "菜鸟大件-日日顺配", value: "DISTRIBUTOR_13159132" },
, { name: "安世通快递", value: "DISTRIBUTOR_13415300" } { name: "安世通快递", value: "DISTRIBUTOR_13415300" },
, { name: "百世云配", value: "DISTRIBUTOR_13468073" } { name: "百世云配", value: "DISTRIBUTOR_13468073" },
, { name: "韵达快运", value: "DISTRIBUTOR_13421750" } { name: "韵达快运", value: "DISTRIBUTOR_13421750" },
, { name: "中通国际直邮", value: "DISTRIBUTOR_13196453" } { name: "中通国际直邮", value: "DISTRIBUTOR_13196453" },
, { name: "京东大件开放承运商", value: "EX_JD_HPCP" } { name: "京东大件开放承运商", value: "EX_JD_HPCP" },
, { name: "加运美速递", value: "DISTRIBUTOR_13468074" } { name: "加运美速递", value: "DISTRIBUTOR_13468074" },
, { name: "中运全速", value: "EX_TOPSPEED" } { name: "中运全速", value: "EX_TOPSPEED" },
, { name: "其他", value: "OTHER" } { name: "其他", value: "OTHER" },
, { name: "跨越速运", value: "DISTRIBUTOR_13211725" } { name: "跨越速运", value: "DISTRIBUTOR_13211725" },
, { name: "菜鸟大件-中铁配", value: "DISTRIBUTOR_13148625" } { name: "菜鸟大件-中铁配", value: "DISTRIBUTOR_13148625" },
] ];
const PlatformsMap = new Map([ const PlatformsMap = new Map([
[0, /.+:\/\/a.*\.fahuoyi.com\//], [0, /.+:\/\/a.*\.fahuoyi.com\//],
[1, /.+:\/\/pdd.*\.fahuoyi.com\//], [1, /.+:\/\/pdd.*\.fahuoyi.com\//],
[2, /.+:\/\/jd.*\.fahuoyi.com\//] [2, /.+:\/\/jd.*\.fahuoyi.com\//],
]) ]);
const WayBillModel = function () { /**
* 快递单模板的类型
*/
enum WaybillTemplateType {
CAINIAO = "CAINIAO",
JD = "JD",
JDL = "JDL",
NORMAL = "NORMAL",
OFFICIAL = "OFFICIAL",
const [list, setList] = useState<List>([]) PDD = "PDD",
const [AWaybillTemplate, setAWaybillTemplate] = useState<IwaybillTemplate[]>([])
const [PDDWaybillTemplate, setPDDWaybillTemplate] = useState<IwaybillTemplate[]>([])
const [JDWaybillTemplate, setJDWaybillTemplate] = useState<IwaybillTemplate[]>([])
const [printList, setPrintList] = useState<string[]>([]) JINRITEMAI = "JINRITEMAI",
TAOBAO_CAINIAO = "TAOBAO_CAINIAO",
}
const PlatformsList = [
{ index: 0, value: WaybillTemplateType.CAINIAO },
{ index: 1, value: WaybillTemplateType.PDD },
{ index: 2, value: WaybillTemplateType.JD },
];
const WayBillModel = function () {
const [list, setList] = useState<List>([]);
const [AWaybillTemplate, setAWaybillTemplate] = useState<IwaybillTemplate[]>(
[]
);
const [PDDWaybillTemplate, setPDDWaybillTemplate] = useState<
IwaybillTemplate[]
>([]);
const [JDWaybillTemplate, setJDWaybillTemplate] = useState<
IwaybillTemplate[]
>([]);
const [printList, setPrintList] = useState<string[]>([]);
const setMap = new Map([ const setMap = new Map([
[0, setAWaybillTemplate], [0, setAWaybillTemplate],
[1, setPDDWaybillTemplate], [1, setPDDWaybillTemplate],
[2, setJDWaybillTemplate] [2, setJDWaybillTemplate],
]) ]);
const getMap = new Map([ const getMap = new Map([
[0, AWaybillTemplate], [0, AWaybillTemplate],
[1, PDDWaybillTemplate], [1, PDDWaybillTemplate],
[2, JDWaybillTemplate] [2, JDWaybillTemplate],
]) ]);
// 获取发货易快递模板列表 // 获取发货易快递模板列表
const getWaybillTemplate = useCallback(async () => { const getWaybillTemplate_old = useCallback(async () => {
chrome.tabs.query({ chrome.tabs.query(
url: "*://*.fahuoyi.com/scanPrinting/index" {
}, async function (tabs) { url: "*://*.fahuoyi.com/scanPrinting/index",
},
async function (tabs) {
let platformUrls: string[] = [] let platformUrls: string[] = [];
for (let value of PlatformsMap.values()) { for (let value of PlatformsMap.values()) {
let prefixUrl: string; let prefixUrl: string;
tabs.forEach(tab => { tabs.forEach((tab) => {
console.log(value.test(tab.url!)) console.log(value.test(tab.url!));
if (tab.url && value.test(tab.url!)) { if (tab.url && value.test(tab.url!)) {
prefixUrl = tab.url.match(value)![0] prefixUrl = tab.url.match(value)![0];
console.log(prefixUrl, 'url') console.log(prefixUrl, "url");
} }
}) });
platformUrls.push(prefixUrl!) platformUrls.push(prefixUrl!);
console.log(platformUrls, 'platformUrls') console.log(platformUrls, "platformUrls");
} }
for (let index in platformUrls) { for (let index in platformUrls) {
let prefix = platformUrls[index] let prefix = platformUrls[index];
console.log(prefix, 'prefix') console.log(prefix, "prefix");
let data = prefix ? await fetch(prefix + "waybillTemplate/listRest?_=" + new Date().getTime(), { method: "GET" }).then(res => { let data = prefix
console.log("2") ? await fetch(
return res.json() prefix + "waybillTemplate/listRest?_=" + new Date().getTime(),
{ method: "GET" }
).then((res) => {
console.log("2");
return res.json();
})
: [];
console.log("3");
console.log(data, "data");
}) : [] setMap.get(Number(index))!((pre) => {
console.log("3")
console.log(data, 'data')
setMap.get(Number(index))!(pre => {
// @ts-ignore // @ts-ignore
return data.map(dataItem => ({ return data.map((dataItem) => ({
name: dataItem.name, name: dataItem.name,
value: dataItem.id value: dataItem.id,
})) }));
}) });
} }
}
);
}, []);
}) const getPrintList_old = useCallback(async () => {
chrome.tabs.query(
}, []) {
url: "*://*.fahuoyi.com/scanPrinting/index",
const getPrintList = useCallback(async () => { },
chrome.tabs.query({ async function (tabs) {
url: "*://*.fahuoyi.com/scanPrinting/index"
}, async function (tabs) {
if (tabs.length >= 1) { if (tabs.length >= 1) {
let port = chrome.tabs.connect(tabs[0].id!, { name: "getPrinter" }); let port = chrome.tabs.connect(tabs[0].id!, {
port.postMessage({ action: "getPrint" }) name: "getPrinter",
});
port.postMessage({ action: "getPrint" });
port.onMessage.addListener(function (msg) { port.onMessage.addListener(function (msg) {
setPrintList(msg) setPrintList(msg);
}) });
} }
}
}) );
}, []);
}, []) // 获取发货易快递模板列表
const getWaybillTemplate = useCallback(async () => {
chrome.storage.local.get(["scanPrintingForm"], function (result) {
for (let platform of PlatformsList) {
let filiterList = result.scanPrintingForm.waybillTemplates.filter(
(dataItem: any) => dataItem.printType === platform.value
);
setMap.get(Number(platform.index))!((pre) => {
// @ts-ignore
return filiterList.map((dataItem: any) => ({
name: dataItem.name,
value: dataItem.id,
}));
});
}
});
}, []);
const getPrintList = useCallback(async () => {
chrome.storage.local.get(["scanPrintingForm"], function (result) {
setPrintList(
result.scanPrintingForm.printers.map((dataItem: any) => dataItem.name)
);
});
}, []);
useEffect(() => { useEffect(() => {
getWaybillTemplate() getWaybillTemplate();
getPrintList() getPrintList();
chrome.storage.local.get({ list: [{ wayCompanyId: undefined, waybillTemplateList: [undefined, undefined, undefined], printId: undefined }] }, function (res) { chrome.storage.local.get(
{
list: [
{
wayCompanyId: undefined,
waybillTemplateList: [undefined, undefined, undefined],
printId: undefined,
},
],
},
function (res) {
if (res.list.length === 0) { if (res.list.length === 0) {
chrome.storage.local.set({ list: [{ wayCompanyId: undefined, waybillTemplateList: [undefined, undefined, undefined], printId: undefined }] }, function () { chrome.storage.local.set(
setList([{ wayCompanyId: undefined, waybillTemplateList: [undefined, undefined, undefined], printId: undefined }]) {
}) list: [
{
wayCompanyId: undefined,
waybillTemplateList: [undefined, undefined, undefined],
printId: undefined,
},
],
},
function () {
setList([
{
wayCompanyId: undefined,
waybillTemplateList: [undefined, undefined, undefined],
printId: undefined,
},
]);
}
);
} else { } else {
setList(res.list as List) setList(res.list as List);
} }
}
}) );
}, []) }, []);
useEffect(() => { useEffect(() => {
chrome.storage.local.set({ list: list }) chrome.storage.local.set({ list: list });
}, [list]) }, [list]);
const onChangeWayCompany = useCallback((value: string, wayIndex: number) => { const onChangeWayCompany = useCallback((value: string, wayIndex: number) => {
setList(pre => { setList((pre) => {
const newList = [...pre] const newList = [...pre];
newList[wayIndex].wayCompanyId = value newList[wayIndex].wayCompanyId = value;
return newList; return newList;
}) });
}, []) }, []);
const onChangeWayTemplate = useCallback((e: string, wayIndex: number, tempIndex: number) => { const onChangeWayTemplate = useCallback(
setList(pre => { (e: string, wayIndex: number, tempIndex: number) => {
const newList = [...pre] setList((pre) => {
const newList = [...pre];
newList[wayIndex].waybillTemplateList[tempIndex] = e; newList[wayIndex].waybillTemplateList[tempIndex] = e;
return newList return newList;
}) });
}, []) },
[]
);
const onChangePrint = useCallback((e: string, wayIndex: number) => { const onChangePrint = useCallback((e: string, wayIndex: number) => {
setList(pre => { setList((pre) => {
const newList = [...pre] const newList = [...pre];
newList[wayIndex].printId = e; newList[wayIndex].printId = e;
return newList; return newList;
}) });
}, []) }, []);
// 新增快递 // 新增快递
const handleAddWay = useCallback(() => { const handleAddWay = useCallback(() => {
setList(pre => { setList((pre) => {
const newState = [...pre] const newState = [...pre];
newState.push({ wayCompanyId: undefined, waybillTemplateList: [undefined, undefined, undefined], printId: undefined }) newState.push({
wayCompanyId: undefined,
waybillTemplateList: [undefined, undefined, undefined],
printId: undefined,
});
return newState; return newState;
}) });
}, []) }, []);
// 删除 // 删除
const remove = useCallback((index: number) => { const remove = useCallback((index: number) => {
setList(pre => { setList((pre) => {
const newState = [...pre] const newState = [...pre];
newState.splice(index, 1) newState.splice(index, 1);
return newState return newState;
}) });
}, []) }, []);
return ( return (
<> <>
<div className="waybill-model"> <div className="waybill-model">
<span className="waybill-model-title" key="one">选择快递</span> <span className="waybill-model-title" key="one">
<span className="waybill-model-title" key="two">选择淘系及其他平台订单模板</span> 选择快递
<span className="waybill-model-title" key="three">选择拼多多订单模板</span> </span>
<span className="waybill-model-title" key="four">选择京东订单模板</span> <span className="waybill-model-title" key="two">
<span className="waybill-model-print" key="seven">打印机</span> 选择淘系及其他平台订单模板
<span className="waybill-model-title" key="five">操作</span> </span>
{ <span className="waybill-model-title" key="three">
list.map((item, wayIndex) => { 选择拼多多订单模板
return <> </span>
<span className="waybill-model-title" key="four">
选择京东订单模板
</span>
<span className="waybill-model-print" key="seven">
打印机
</span>
<span className="waybill-model-title" key="five">
操作
</span>
{list.map((item, wayIndex) => {
return (
<>
<Select <Select
showSearch showSearch
key={ wayIndex + "wayCompany" } key={wayIndex + "wayCompany"}
style={ { width: 150 } } style={{ width: 150 }}
placeholder="请选择快递" placeholder="请选择快递"
optionFilterProp="children" optionFilterProp="children"
onChange={ (value) => onChangeWayCompany(value, wayIndex) } onChange={(value) => onChangeWayCompany(value, wayIndex)}
value={ item.wayCompanyId } value={item.wayCompanyId}
> >
{ {AllWayCompany.map((item, index) => {
AllWayCompany.map((item, index) => { return (
return <Option key={ index } value={ item.value }>{ item.name }</Option> <Option key={index} value={item.value}>
}) {item.name}
} </Option>
);
})}
</Select> </Select>
{ {item.waybillTemplateList.map((item, tempIndex) => {
item.waybillTemplateList.map((item, tempIndex) => { return (
return <Select <Select
key={ tempIndex + "wayTemplate" } key={tempIndex + "wayTemplate"}
showSearch showSearch
style={ { width: 150 } } style={{ width: 150 }}
placeholder="选择快递模板" placeholder="选择快递模板"
optionFilterProp="children" optionFilterProp="children"
onChange={ (value) => onChangeWayTemplate(value, wayIndex, tempIndex) } onChange={(value) =>
value={ item } onChangeWayTemplate(value, wayIndex, tempIndex)
>
{
getMap.get(tempIndex)!.map((item, index) => {
return <Option key={ index } value={ item.value }>{ item.name }</Option>
})
} }
value={item}
>
{getMap.get(tempIndex)!.map((item, index) => {
return (
<Option key={index} value={item.value}>
{item.name}
</Option>
);
})}
</Select> </Select>
}) );
} })}
<Select <Select
key={ item.printId + 'print' } key={item.printId + "print"}
showSearch showSearch
style={ { width: 150 } } style={{ width: 150 }}
placeholder="选择打印机" placeholder="选择打印机"
optionFilterProp="children" optionFilterProp="children"
onChange={ (value) => onChangePrint(value, wayIndex) } onChange={(value) => onChangePrint(value, wayIndex)}
value={ item.printId } value={item.printId}
> >
{ {printList.map((item, index) => {
printList.map((item, index) => { return (
return <Option key={ index } value={ item }>{ item }</Option> <Option key={index} value={item}>
}) {item}
} </Option>
);
})}
</Select> </Select>
<Button type="default" key={ item.printId + "btn" } style={ { padding: "0 5px" } } onClick={ () => remove(wayIndex) }>删除</Button> <Button
type="default"
key={item.printId + "btn"}
style={{ padding: "0 5px" }}
onClick={() => remove(wayIndex)}
>
删除
</Button>
</> </>
}) );
} })}
</div> </div>
<Button type="link" onClick={ handleAddWay }>新增快递</Button> <Button type="link" onClick={handleAddWay}>
新增快递
</Button>
</> </>
) );
} };
export default WayBillModel export default WayBillModel;
\ No newline at end of file
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
// // 让popup获取waybillTemplate // // 让popup获取waybillTemplate
// export const GetWaybillTemplate = "getWaybillTemplate" // export const GetWaybillTemplate = "getWaybillTemplate"
export const StartPrint = "StartPrint" export const StartPrint = "StartPrint";
export const Print = "Print" export const Print = "Print";
\ No newline at end of file
export const getFaHuoYiSetting = "getFaHuoYiSetting";
// ScanPrintingForm对象默认绑定在 window["scan-printing-form"]
// 可以在发货易js加载之前增加事件回调,可以保证获取到ScanPrintingForm对象
// window.addEventListener("onSEScanPrintingFormLoad", () => {
// const scanPrintingForm = window["scan-printing-form"];
// });
/**
* 扫描打印数据加载完成回调函数
*/
export type OnLoadCallbackFunction = (data: OnLoadData) => void;
/**
* 扫描打印数据加载完成回调数据
*/
export interface OnLoadData {
waybillTemplates: WaybillTemplate[];
shippingAddresses: ShippingAddress[];
printers: Printer[];
}
export interface ScanPrintingForm {
/**
* 增加数据加载成功回调方法
* 使用示例
* ```
* scanPrintingForm.onLoad((data)=>{
* const { waybillTemplates, shippingAddresses, printers } = data;
*
* })
* ```
*/
onLoad(callbackFn: OnLoadCallbackFunction): void;
/**
* 配置表单
*/
config(params: ConfigParams): Result;
/**
* 发送扫描打印任务
*/
searchAndPrint(value: string): Result;
}
export interface Result {
successful: boolean;
message: string;
}
/**
* 扫描打印类型
*/
export enum ScanPrintSearchType {
/**
* 使用订单编号
*/
ORDER_ORIGINAL_ID = "ORDER_ORIGINAL_ID",
/**
* 使用运单号
*/
WAYBILL_NO = "WAYBILL_NO",
}
/**
* 获取运单号方式
*/
export enum GetWaybillNoMethod {
/**
* 使用新单号
*/
NEW = "NEW",
/**
* 使用旧单号
*/
OLD = "OLD",
}
/**
* 发货方式
*/
export enum ShippingWay {
/**
* 自己联系物流
*/
OFFLINE = "OFFLINE",
/**
* 在线下单
*/
ONLINE = "ONLINE",
}
/**
* 快递单模板打印类型
*/
export interface ConfigParams {
/**
* 扫描类型
*/
searchType: ScanPrintSearchType;
/**
* 是否避免重复扫描打印
*/
checkRepeatPrint: boolean;
/**
* 快递单模板id
*/
waybillTemplateId: number;
/**
* 打印机名称
*/
printer: string;
/**
* 发货人id
*/
shippingAddressId: number;
/**
* 是否打印成功后自动发货
*/
autoShippingAfterPrint: boolean;
/**
* 获取面单方式
*/
getWaybillNoMethod: GetWaybillNoMethod;
/**
* 发货方式
*/
shippingWay?: ShippingWay;
}
/**
* 快递单模板的类型
*/
export enum WaybillTemplateType {
CAINIAO = "CAINIAO",
JD = "JD",
JDL = "JDL",
NORMAL = "NORMAL",
OFFICIAL = "OFFICIAL",
PDD = "PDD",
JINRITEMAI = "JINRITEMAI",
TAOBAO_CAINIAO = "TAOBAO_CAINIAO",
}
/**
* 快递单模板
*/
export interface WaybillTemplate {
allowedShopIds?: string;
allowedShopIdsArray?: string[];
bindingPrinter: string;
bindingShopIds: string;
companyId: number;
customAreaHeight?: number;
customAreaLeft: number;
customAreaPrintTemplateUrl: string;
customAreaTop: number;
customAreaWidth?: number;
defaultShippingAddressId: number;
deleted: boolean;
enableEmptyShortAddressCheck: boolean;
/**
* 只有电子面单才有此字段
* 申请地址id
*/
ewaybillShippingAddressId: number;
forceNoPageMargins: boolean;
height: number;
id: number;
index: number;
is3PartsWaybill: boolean;
isPrintBottomLogo: boolean;
isPrintTopLogo: boolean;
isSystemTemplate: boolean;
logisticsCompany: LogisticsCompany;
name: string;
offsetLeft: number;
offsetTop: number;
picture: string;
printTemplateId: string;
printTemplateUrl: string;
printType: WaybillTemplatePrintType;
serviceOptions: string;
shopId: number;
supportsChildWaybillNoMode: boolean;
systemTemplateId: number;
thumbnail: string;
type: WaybillTemplateType;
width: number;
}
/**
* 快递单模板打印类型
*/
export enum WaybillTemplatePrintType {
CAINIAO = "CAINIAO",
JDL = "JDL",
PDD = "PDD",
/**蓝牙打印 */
PRINT_CMD = "PRINT_CMD",
JINRITEMAI = "JINRITEMAI",
}
/**
* 快递公司类型
*/
export enum LogisticsCompany {
/**中通快递 */
ZTO = "ZTO",
/**中通快运 */
ZTO56 = "ZTO56",
/**圆通速递 */
YTO = "YTO",
/**申通快递 */
STO = "STO",
/**韵达速递 */
YUNDA = "YUNDA",
/**韵达快运 */
YUNDA56 = "YUNDA56",
/**中国邮政 */
POST = "POST",
/**邮政快递包裹 */
POSTB = "POSTB",
/**邮政标准快递 */
POSTS = "POSTS",
/**EMS */
EMS = "EMS",
/**顺丰速运 */
SF = "SF",
/**顺丰快运 */
SFKY = "SFKY",
/**极兔速递 */
JT = "JT",
/**天天快递 */
TTKDEX = "TTKDEX",
/**宅急送 */
ZJS = "ZJS",
/**百世快递 */
HTKY = "HTKY",
/**百世快运 */
BESTQJT = "BESTQJT",
/**百世物流 */
BEST = "BEST",
/**众邮快递 */
ZY = "ZY",
/**京东快运 */
JDKY = "JDKY",
/**丰网速运 */
FENGWANG = "FENGWANG",
/**安能快递 */
ANE66 = "ANE66",
/**安能物流 */
ANE56 = "ANE56",
/**京东快递 */
JD_EXPRESS = "JD_EXPRESS",
/**京东大件物流 */
JD_HPCP = "JD_HPCP",
/**德邦物流 */
DBL = "DBL",
/**德邦快递 */
DBKD = "DBKD",
/**韵达国际 */
YUNDAGJ = "YUNDAGJ",
/**韵达同城 */
YUNDA_TC = "YUNDA_TC",
/**申通快运 */
STO56 = "STO56",
/**申通国际 */
STOGJ = "STOGJ",
/**中通国际 */
ZTOGJ = "ZTOGJ",
/**国通快递 */
GTO = "GTO",
/**EMS经济快递 */
EYB = "EYB",
/**跨越速运 */
KUAYUE = "KUAYUE",
/**安鲜达 */
EXFRESH = "EXFRESH",
/**九曳供应链 */
JIUYESCM = "JIUYESCM",
/**优速快递 */
UC = "UC",
/**万象物流 */
WXWL = "WXWL",
/**全锋快递 */
QFKD = "QFKD",
/**龙邦快递 */
LB = "LB",
/**全一快递 */
UAPEX = "UAPEX",
/**快捷快递 */
FAST = "FAST",
/**天地华宇 */
HOAU = "HOAU",
/**品骏快递 */
PJBEST = "PJBEST",
/**如风达快递 */
RFD = "RFD",
/**远成快运 */
YCKY = "YCKY",
/**壹米滴答 */
YMDD = "YMDD",
/**速尔快递 */
SURE = "SURE",
/**速通物流 */
SUT56 = "SUT56",
/**中铁快运 */
CRE = "CRE",
/**亚风 */
AIR = "AIR",
/**佳吉快递 */
CNEX = "CNEX",
/**联邦快递 */
FEDEX = "FEDEX",
/**增益速递 */
QRT = "QRT",
/**加运美速递 */
JYMWL = "JYMWL",
/**信丰物流 */
XFWL = "XFWL",
/**大田物流 */
DTW = "DTW",
/**D速物流 */
DSWL = "DSWL",
/**承诺达特快 */
CNDTK = "CNDTK",
/**运通物流 */
YTWL = "YTWL",
/**长宇物流 */
CYWL = "CYWL",
/**新邦物流 */
XBWL = "XBWL",
/**联昊通 */
LWT = "LWT",
/**苏宁物流 */
SNWL = "SNWL",
/**能达速递 */
NDSD = "NDSD",
/**保宏物流 */
BHWL = "BHWL",
/**发网 */
FW = "FW",
/**长发 */
CF = "CF",
/**远长 */
YC = "YC",
/**东方汇 */
DFH = "DFH",
/**飞远配送 */
FYPS = "FYPS",
/**黑猫宅急便 */
HMZJB = "HMZJB",
/**E速宝 */
ESB = "ESB",
/**华强物流 */
HQWL = "HQWL",
/**安迅物流 */
AXWL = "AXWL",
/**中运全速 */
TOPSPEED = "TOPSPEED",
/**华企快运 */
HUAQIEX = "HUAQIEX",
/**丹鸟 */
DN = "DN",
/**都市节奏 */
DSJZ = "DSJZ",
/**宽昊物流 */
KHWL = "KHWL",
/**顺心捷达 */
SXJD = "SXJD",
/**京广速递 */
SZKKE = "SZKKE",
/**韵达点通达 */
YUNDA_DTD = "YUNDA_DTD",
/**百世云配 */
BSYP = "BSYP",
/**运通速运 */
WTO = "WTO",
/**沃埃家 */
WOWVIP = "WOWVIP",
/**菜鸟裹裹 */
CN_GUOGUO = "CN_GUOGUO",
/**淘特物流快递 */
TTWLKD = "TTWLKD",
/**速腾快递 */
STE56 = "STE56",
/**安得物流 */
ANDE = "ANDE",
/**百世国际 */
BESTGJ = "BESTGJ",
/**当当网 */
DANGDANG = "DANGDANG",
/**EWE全球快递 */
EWE = "EWE",
/**丰云配 */
FYP = "FYP",
/**高捷物流 */
GJWL = "GJWL",
/**空港宏远电商物流 */
HYWL = "HYWL",
/**卡行天下快运 */
KXTX = "KXTX",
/**日日顺 */
RRS = "RRS",
/**威盛快递 */
WSKD = "WSKD",
/**威时沛运 */
WSPY = "WSPY",
/**贝海国际速递 */
XLOBO = "XLOBO",
/**中远e环球 */
ZYEHQ = "ZYEHQ",
/**转运四方物流 */
ZYSF = "ZYSF",
/**卓志速运 */
ZZSY = "ZZSY",
/**其他 */
OTHER = "OTHER",
}
/**
* 发货人对象
*/
export interface ShippingAddress {
id: number;
/**绑定的店铺列表 用,分割 */
bindingShopIds: string;
city: string;
cityCode: number;
district: string;
districtCode: number;
mobile: string;
/**发货地址名称 */
name: string;
province: string;
provinceCode: number;
/**发货人姓名 */
shipperName: string;
street: string;
telephone: string;
zipCode: string;
/**排序 */
index: number;
}
/**
* 打印机对象
*/
export interface Printer {
name: string;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment