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

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

parent 2af25aa6
{
"name": "辅助发货易打单1.1.0",
"version": "1.0.0",
"description": "辅助手机壳厂家打印发货易的快递单",
"name": "辅助发货易打单1.1.0",
"version": "1.0.0",
"description": "辅助手机壳厂家打印发货易的快递单",
"manifest_version": 2,
"background": {
"scripts": ["background.js"]
},
"browser_action": {
"default_popup": "popup.html",
"default_icon": "icon.png",
"default_title": "辅助发货易打单"
},
"icons": {
"128": "icon.png"
},
"manifest_version": 2,
"background": {
"scripts": ["background.js"]
},
"browser_action": {
"default_popup": "popup.html",
"default_icon": "icon.png",
"default_title": "辅助发货易打单"
},
"icons": {
"128": "icon.png"
},
"web_accessible_resources": ["icon.png"],
"web_accessible_resources": ["icon.png"],
"content_scripts": [
{
"matches": [
"*://*.fahuoyi.com/*",
"*://admin.rtxmdz.com/*",
"http://localhost:8082/*",
"http://localhost:8083/*",
"*://*.rtxmdz.com/*"
],
"js": ["content.js"],
"run_at": "document_idle"
}
],
"content_scripts": [
{
"matches": [
"*://*.fahuoyi.com/*",
"*://admin.rtxmdz.com/*",
"http://localhost:8082/*",
"http://localhost:8083/*",
"*://*.rtxmdz.com/*"
],
"js": ["content.js"],
"run_at": "document_idle"
}
],
"permissions": [
"background",
"storage",
"contextMenus",
"tabs",
"cookies",
"webRequest",
"management",
"activeTab",
"history",
"notifications",
"webRequestBlocking",
"http://*/*",
"https://*/*",
"downloads"
]
"permissions": [
"background",
"storage",
"contextMenus",
"tabs",
"cookies",
"webRequest",
"management",
"activeTab",
"history",
"notifications",
"webRequestBlocking",
"http://*/*",
"https://*/*",
"downloads"
]
}
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
const PlatfromsMap = new Map([
[0, /.+:\/\/a.*\.fahuoyi.com\/scanPrinting\/index/],
[1, /.+:\/\/pdd.*\.fahuoyi.com\/scanPrinting\/index/],
[2, /.+:\/\/jd.*\.fahuoyi.com\/scanPrinting\/index/]
])
[0, /.+:\/\/a.*\.fahuoyi.com\/scanPrinting\/index/],
[1, /.+:\/\/pdd.*\.fahuoyi.com\/scanPrinting\/index/],
[2, /.+:\/\/jd.*\.fahuoyi.com\/scanPrinting\/index/],
]);
chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
console.log("onMessage", message);
if (message.action === StartPrint) {
// console.log("startPrint")
// 通知fahuoyi的content开始点击
// chrome.tabs.query(
// {
// url: "*://*.fahuoyi.com/scanPrinting/index",
// },
// function (tabs) {
// let exp = new RegExp(PlatfromsMap.get(message.value.platform)!, "i");
if (message.action === StartPrint) {
// console.log("startPrint")
// 通知fahuoyi的content开始点击
chrome.tabs.query({
url: "*://*.fahuoyi.com/scanPrinting/index"
}, function (tabs) {
let exp = new RegExp(PlatfromsMap.get(message.value.platform)!, 'i')
console.log(tabs, 'tabs66')
tabs && tabs.forEach(tab => {
if (exp.test(tab.url!)) {
chrome.tabs.sendMessage(tab.id!, { action: Print, value: message.value })
}
})
// // sendResponse("")
// if (tabs[0]) {
// chrome.tabs.sendMessage(tabs[0].id!, { action: Print, value: message.value })
// }
})
chrome.tabs.query({
url: "*://*.fahuoyi.com/features/scanPrinting"
}, function (tabs) {
console.log(tabs, 'tabs11')
tabs && tabs.forEach(tab => {
chrome.tabs.executeScript(tab.id!, {code: 'console.log(window["scan-printing-form"])'});
})
})
} else if (message.action === "sendNewWaybillNo") {
// console.log(tabs, "tabs66");
// tabs &&
// tabs.forEach((tab) => {
// if (exp.test(tab.url!)) {
// chrome.tabs.sendMessage(tab.id!, {
// action: Print,
// value: message.value,
// });
// }
// });
// // // sendResponse("")
// // if (tabs[0]) {
// // chrome.tabs.sendMessage(tabs[0].id!, { action: Print, value: message.value })
// // }
// }
// );
chrome.tabs.query(
{
url: "*://*.fahuoyi.com/features/scanPrinting",
},
function (tabs) {
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") {
// 从bg页面转发给厂家页面的content.js
chrome.tabs.query(
{
url: factoryContentUrls,
},
function (tabs) {
tabs &&
tabs.forEach((tab) => {
// chrome.tabs.sendMessage(tab.id!, message)
const port = chrome.tabs.connect(tab.id!, {
name: "sendNewWaybillNo",
});
port.onMessage.addListener(function (msg, port) {
if (msg.action === "answer") {
// console.log(msg, port, 'bg')
port.disconnect();
}
});
port.postMessage(message);
});
}
);
// let port = chrome.runtime.connect({ name: "bgSendMessage" })
// port.postMessage(message)
}
});
// chrome.runtime.onConnect.addListener(function (msg) {
// console.log(msg, 'msgbg')
// })
// 从bg页面转发给厂家页面的content.js
chrome.tabs.query({
url: factoryContentUrls
}, function (tabs) {
tabs && tabs.forEach(tab => {
// chrome.tabs.sendMessage(tab.id!, message)
const port = chrome.tabs.connect(tab.id!, { name: "sendNewWaybillNo" })
port.onMessage.addListener(function (msg, port) {
if (msg.action === "answer") {
// console.log(msg, port, 'bg')
port.disconnect()
}
})
port.postMessage(message)
function getPrintJS(param: any): string {
console.log(param);
let _ScanPrintSearchType = ScanPrintSearchType.WAYBILL_NO;
let _GetWaybillNoMethod = GetWaybillNoMethod.OLD;
})
})
// let port = chrome.runtime.connect({ name: "bgSendMessage" })
// port.postMessage(message)
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
}
})
// chrome.runtime.onConnect.addListener(function (msg) {
// console.log(msg, 'msgbg')
// })
\ No newline at end of file
});
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 { Print, StartPrint } from "../types";
import { Print, StartPrint, getFaHuoYiSetting } from "../types";
import { ScanPrintingForm } from "../types/scanPrinting";
export enum PlatformCode {
"淘系及其他平台订单模板" = 0,
"拼多多订单模板" = 1,
"京东订单模板" = 2
"淘系及其他平台订单模板" = 0,
"拼多多订单模板" = 1,
"京东订单模板" = 2,
}
type Params = {
waybillNo: string // 运单号
platform: PlatformCode,
wayCompanyId: string
waybillNo: string; // 运单号
platform: PlatformCode;
wayCompanyId: string;
} & {
orderNo: string// 订单号
wayCompanyId: string// 快递公司的Id
platform: PlatformCode,// 平台编码,淘系及其他平台订单模板的为0,拼多多订单的为1,京东订单的为2
}
orderNo: string; // 订单号
wayCompanyId: string; // 快递公司的Id
platform: PlatformCode; // 平台编码,淘系及其他平台订单模板的为0,拼多多订单的为1,京东订单的为2
};
interface Response {
data: {
action: "StartPrint",
value: Params
}
data: {
action: "StartPrint";
value: Params;
};
}
window.addEventListener("message", function (res: Response) {
if (res.data.action === "StartPrint") {
chrome.storage?.local.get({ list: [] }, function (storage) {
// @ts-ignore
if (storage.list.length == 0 || !storage.list[0].wayCompanyId || !storage.list[0].waybillTemplateList.some(item => item)) {
alert("请选择快递模板")
return;
}
const { wayCompanyId, waybillNo, orderNo, platform } = res.data.value
if (!waybillNo && (!wayCompanyId || !orderNo || ![0, 1, 2].includes(Number(platform)))) {
alert("参数传递错误")
return;
}
chrome.runtime.sendMessage({ action: StartPrint, value: res.data.value }, function (response) {
})
})
}
})
if (res.data.action === "StartPrint") {
chrome.storage?.local.get(
{
list: [],
scanPrintingForm: {
waybillTemplates: [],
shippingAddresses: [],
printers: [],
},
isAutoEmit: false,
},
function (storage) {
// @ts-ignore
if (
storage.list.length == 0 ||
!storage.list[0].wayCompanyId ||
!storage.list[0].waybillTemplateList.some((item: any) => item)
) {
alert("请选择快递模板");
return;
}
// @ts-ignore
if (
storage.scanPrintingForm.waybillTemplates.length == 0 ||
storage.scanPrintingForm.shippingAddresses.length == 0 ||
storage.scanPrintingForm.printers.length == 0
) {
alert("发货易配置信息为空或获取失败");
return;
}
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 {
"waybillNo" = "waybillNo",
"orderOriginalId" = "orderOriginalId"
"waybillNo" = "waybillNo",
"orderOriginalId" = "orderOriginalId",
}
// fahuoyi.com
interface Message {
action: "Print",
value: Params
action: "Print";
value: Params;
}
const printWayBillByOld = function (waybillNo: string, wayCompanyId: string) {
chrome.storage.local.get({ list: [], isAutoEmit: false }, function (res) {
// 选择使用旧单号打印
let oldOptionDom = document.querySelectorAll(".form-group.mr20>.radio-inline")[1] as HTMLLabelElement
let waybillNoBtn = document.querySelector(".form-group>.form-control.original-id-input-label>option[value=waybillNo]") as HTMLOptionElement
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 printId: string
// @ts-ignore
res.list.forEach(item => {
if (item.wayCompanyId === wayCompanyId) {
printId = item.printId === "仅获取电子面单号不打印面单" ? "isGenerateWaybillNoOnly" : item.printId
// printId = item.printId
}
})
// 1.选择旧单号打印
oldOptionDom.click()
// 2.选择打单模板
waybillNoBtn.selected = true
selectDom.value = SelectOptions.waybillNo
// @ts-ignore
selectDom.dispatchEvent(new Event("change", { bubbles: true }))
// 3.选择打印机
printDom.value = printId!
printDom.dispatchEvent(new Event("change", { bubbles: true }))
// 4.自动发货
autoDom.value = "true"
autoDom.dispatchEvent(new Event("change", { bubbles: true }))
// 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
bySelf.value = "OFFLINE"
bySelf.dispatchEvent(new Event("change", { bubbles: true }))
// 6.输入运单号
// selectDom.__reactEventHandlers$8wsw7c8olk.onChange({ target: { value: SelectOptions.waybillNo } })
inputDom.value = waybillNo
// 7.默认参数写死
hiddenInputDom.value = "true"
serachBtn.click()
})
}
const printWayBillByNew = function ({ orderNo, wayCompanyId, platform }: Pick<Params, "orderNo" | "wayCompanyId" | "platform">) {
// console.log(orderNo, wayCompanyId, platform)
// 根据快递公司的companyId选择相应的配置
chrome.storage.local.get({ list: [], isAutoEmit: false }, function (res) {
// console.log(res, 'res') //res:{isAutoEmit:boolean,list:[{waybillCompanyId:"",waybillTemplateList:[x,x,x]}]}
let waybillTemplate: string;
let printId: string;
// @ts-ignore
res.list.forEach(item => {
if (item.wayCompanyId === wayCompanyId) {
waybillTemplate = item.waybillTemplateList[platform]
printId = item.printId === "仅获取电子面单号不打印面单" ? "isGenerateWaybillNoOnly" : item.printId
// printId = item.printId
}
})
let newOrderBtn = document.querySelector(".form-group.mr20>.radio-inline.mr10") as HTMLLabelElement
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 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 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
//1.点击 获取新单号打印
newOrderBtn.click()
//2.选择快递单模板
wayTemplateSelect.value = waybillTemplate! + ""
wayTemplateSelect.dispatchEvent(new Event("change", { bubbles: true }))
//3.点击订单编号
selectDom.value = SelectOptions.orderOriginalId
// @ts-ignore
selectDom.dispatchEvent(new Event("change", { bubbles: true }))
// 4. 选择打印机
printDom!.value = printId!
printDom.dispatchEvent(new Event("change", { bubbles: true }))
// orderBtn.click()
// 5.自动发货
autoDom.value = "true"
autoDom.dispatchEvent(new Event("change", { bubbles: true }))
// 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
bySelf.value = "OFFLINE"
bySelf.dispatchEvent(new Event("change", { bubbles: true }))
//7.输入订单编号
inputDom.value = orderNo
// 8.默认参数写死
hiddenInputDom.value = "true"
//9.点击搜索并打印
searchDom.click()
chrome.storage.local.get({ list: [], isAutoEmit: false }, function (res) {
// 选择使用旧单号打印
let oldOptionDom = document.querySelectorAll(
".form-group.mr20>.radio-inline"
)[1] as HTMLLabelElement;
let waybillNoBtn = document.querySelector(
".form-group>.form-control.original-id-input-label>option[value=waybillNo]"
) as HTMLOptionElement;
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 printId: string;
// @ts-ignore
res.list.forEach((item) => {
if (item.wayCompanyId === wayCompanyId) {
printId =
item.printId === "仅获取电子面单号不打印面单"
? "isGenerateWaybillNoOnly"
: item.printId;
// printId = item.printId
}
});
// 1.选择旧单号打印
oldOptionDom.click();
// 2.选择打单模板
waybillNoBtn.selected = true;
selectDom.value = SelectOptions.waybillNo;
// @ts-ignore
selectDom.dispatchEvent(new Event("change", { bubbles: true }));
// 3.选择打印机
printDom.value = printId!;
printDom.dispatchEvent(new Event("change", { bubbles: true }));
// 4.自动发货
autoDom.value = "true";
autoDom.dispatchEvent(new Event("change", { bubbles: true }));
// 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;
bySelf.value = "OFFLINE";
bySelf.dispatchEvent(new Event("change", { bubbles: true }));
// 6.输入运单号
// selectDom.__reactEventHandlers$8wsw7c8olk.onChange({ target: { value: SelectOptions.waybillNo } })
inputDom.value = waybillNo;
// 7.默认参数写死
hiddenInputDom.value = "true";
serachBtn.click();
});
};
})
}
const printWayBillByNew = function ({
orderNo,
wayCompanyId,
platform,
}: Pick<Params, "orderNo" | "wayCompanyId" | "platform">) {
// console.log(orderNo, wayCompanyId, platform)
// 根据快递公司的companyId选择相应的配置
chrome.storage.local.get({ list: [], isAutoEmit: false }, function (res) {
// console.log(res, 'res') //res:{isAutoEmit:boolean,list:[{waybillCompanyId:"",waybillTemplateList:[x,x,x]}]}
let waybillTemplate: string;
let printId: string;
// @ts-ignore
res.list.forEach((item) => {
if (item.wayCompanyId === wayCompanyId) {
waybillTemplate = item.waybillTemplateList[platform];
printId =
item.printId === "仅获取电子面单号不打印面单"
? "isGenerateWaybillNoOnly"
: item.printId;
// printId = item.printId
}
});
let newOrderBtn = document.querySelector(
".form-group.mr20>.radio-inline.mr10"
) as HTMLLabelElement;
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 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 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;
//1.点击 获取新单号打印
newOrderBtn.click();
//2.选择快递单模板
wayTemplateSelect.value = waybillTemplate! + "";
wayTemplateSelect.dispatchEvent(new Event("change", { bubbles: true }));
//3.点击订单编号
selectDom.value = SelectOptions.orderOriginalId;
// @ts-ignore
selectDom.dispatchEvent(new Event("change", { bubbles: true }));
// 4. 选择打印机
printDom!.value = printId!;
printDom.dispatchEvent(new Event("change", { bubbles: true }));
// orderBtn.click()
// 5.自动发货
autoDom.value = "true";
autoDom.dispatchEvent(new Event("change", { bubbles: true }));
// 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;
bySelf.value = "OFFLINE";
bySelf.dispatchEvent(new Event("change", { bubbles: true }));
//7.输入订单编号
inputDom.value = orderNo;
// 8.默认参数写死
hiddenInputDom.value = "true";
//9.点击搜索并打印
searchDom.click();
});
};
//发货易页面
chrome.runtime.onMessage.addListener(function (message: Message, sender, response) {
if (message.action === Print) {
if (message.value.waybillNo) {
printWayBillByOld(message.value.waybillNo, message.value.wayCompanyId)
} else {
const { orderNo, wayCompanyId, platform } = message.value
printWayBillByNew({ orderNo, wayCompanyId, platform })
}
chrome.runtime.onMessage.addListener(function (
message: Message,
sender,
response
) {
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) {
printWayBillByOld(message.value.waybillNo, message.value.wayCompanyId);
} else {
const { orderNo, wayCompanyId, platform } = message.value;
printWayBillByNew({ orderNo, wayCompanyId, platform });
}
})
}
});
// 拿到打印机
chrome.runtime.onConnect.addListener(function (port) {
if (port.name === "getPrinter") {
port.onMessage.addListener(function (msg) {
if (msg.action === "getPrint") {
// @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")
// console.log(2)
// console.log(options, options[0].value, '3')
let arr = []
for (let i = 0; i < options.length; i++) {
arr.push(options[i].textContent)
// arr.push(options[i].value)
}
port.postMessage(arr)
if (port.name === "getPrinter") {
port.onMessage.addListener(function (msg) {
if (msg.action === "getPrint") {
// @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"
);
// console.log(2)
// console.log(options, options[0].value, '3')
let arr = [];
for (let i = 0; i < options.length; i++) {
arr.push(options[i].textContent);
// arr.push(options[i].value)
}
}
})
}
})
port.postMessage(arr);
}
});
}
});
// 厂家content.js页面
// chrome.runtime.onMessage.addListener(function (message, sender, response) {
......@@ -240,159 +333,230 @@ chrome.runtime.onConnect.addListener(function (port) {
// }
// })
chrome.runtime.onConnect.addListener(function (port) {
if (port.name === "sendNewWaybillNo") {
// console.log(port, 'port')
port.onMessage.addListener(function (msg) {
// console.log(msg, 'msg')
if (msg.action === "sendNewWaybillNo") {
window.postMessage({ action: "newWaybillNo", message: msg?.message, orderNo: msg?.orderNo, waybillNo: msg?.waybillNo, result: msg.result }, '*')
port.postMessage({ action: "answer" })
}
})
}
})
console.log("content chrome onConnect", port);
if (port.name === "sendNewWaybillNo") {
// console.log(port, 'port')
port.onMessage.addListener(function (msg) {
// console.log(msg, 'msg')
console.log("content port onMessage", msg);
if (msg.action === "sendNewWaybillNo") {
window.postMessage(
{
action: "newWaybillNo",
message: msg?.message,
orderNo: msg?.orderNo,
waybillNo: msg?.waybillNo,
result: msg.result,
},
"*"
);
port.postMessage({ action: "answer" });
}
});
}
});
// inject.js
const startPrintWayBill = function (params: Params) {
// 通知content.js触发事件
window.postMessage({ action: "StartPrint", value: params }, "*")
return new Promise(function (resolve, reject) {
// @ts-ignore
window.onmessage = function (res) {
if (res.data.action === "newWaybillNo") {
console.log(res.data, 'res.data')
res.data.result ? resolve(res.data.waybillNo) : reject(res.data);
}
}
})
// 通知content.js触发事件
window.postMessage({ action: "StartPrint", value: params }, "*");
return new Promise(function (resolve, reject) {
// @ts-ignore
window.onmessage = function (res) {
if (res.data.action === "newWaybillNo") {
console.log(res.data, "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
*/
window.addEventListener("message", function (msg) {
if (msg.data.action === "sendNewWaybillNo") {
// chrome.runtime.onConnect.addListener(function (port) {
// console.log(port, 'port')
// port.postMessage(msg.data)
// })
chrome.runtime.sendMessage(msg.data)
}
})
if (msg.data.action === "sendNewWaybillNo") {
// chrome.runtime.onConnect.addListener(function (port) {
// console.log(port, 'port')
// port.postMessage(msg.data)
// })
chrome.runtime.sendMessage(msg.data);
}
if (msg.data.action === getFaHuoYiSetting) {
console.log("content Get Test Message", JSON.parse(msg.data.value));
}
});
function observerDom(): Boolean {
let tbodyDom = document.querySelector(
"#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);
if (!tbodyDom) return false;
if (tbodyDom) {
console.log("observer");
let observe = new MutationObserver(function (mutations, observe) {
console.log(mutations, "mutations");
let td = mutations[mutations.length - 1].addedNodes[0].childNodes[3];
console.log(td, "td");
if (!td) return;
let tdObserve = new MutationObserver(function (mutations, observe) {
console.log(mutations, "mutations");
mutations.forEach((item) => {
item.addedNodes.forEach((node) => {
// @ts-ignore
if (
node.nodeType == 3 &&
node.parentElement?.className.includes("danger")
) {
console.log(node.textContent, "nodeTextContent");
// @ts-ignore
return window.postMessage(
{
action: "sendNewWaybillNo",
//@ts-ignorenpm
message: node?.wholeText,
result: false,
},
"*"
);
}
if (node.nodeName == "DIV") {
let text = node.childNodes[2].textContent;
let orderNo =
item.target.parentElement?.children[0]?.children[0]
?.childNodes[0]?.textContent;
console.log(orderNo, "orderNo");
console.log(text, "text", node);
window.postMessage(
{
action: "sendNewWaybillNo",
waybillNo: text,
orderNo,
result: true,
},
"*"
);
// 从发货易页面发消息给bg
// chrome.runtime.sendMessage({ action: "newWaybillNo", value: text }, function (res) {
// })
// console.log("fahuoyi")
// let fahuoyiPort = chrome.runtime.connect({ name: "sendMessage" })
// fahuoyiPort.postMessage({ action: "newWaybillNo", value: text })
// chrome.runtime.onConnect.addListener(function (port) {
// console.log(port, 'port')
// port.postMessage({ action: "newWaybillNo", value: text })
// })
}
});
});
});
tdObserve.observe(td, {
childList: true,
characterData: true,
subtree: true,
attributes: true,
});
});
observe.observe(tbodyDom, {
childList: true,
});
let bfqxDom = document.querySelector("body");
let observe1 = new MutationObserver(function (mutations, observe) {
// mutations[0].addedNodes[0].className
console.log(mutations, "bfqxDom");
mutations.forEach((item) => {
item.addedNodes.forEach((node) => {
// node.textContent == 'bootbox modal fade sui-modal in' &&
if (
node.textContent ==
"该订单有商品正在退款中或者已取消,是否确认继续打印?取 消确 定"
) {
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!, {
childList: true,
});
}
return true;
}
function injectCustomjs() {
let temp = document.createElement("script");
let temp = document.createElement("script")
temp.innerHTML = `window.startPrintWayBill=${startPrintWayBill}`
document.body.appendChild(temp)
let tbodyDom = document.querySelector("#elContainer>div>table>tbody")
if (tbodyDom) {
let observe = new MutationObserver(function (mutations, observe) {
console.log(mutations, 'mutations')
let td = mutations[0].addedNodes[0].childNodes[3]
console.log(td, 'td')
if (!td) return;
let tdObserve = new MutationObserver(function (mutations, observe) {
console.log(mutations, 'mutations')
mutations.forEach(item => {
item.addedNodes.forEach(node => {
// @ts-ignore
if (node.nodeType == 3 && node.parentElement?.className.includes("text-danger")) {
console.log(node.textContent, 'nodeTextContent')
// @ts-ignore
return window.postMessage({ action: "sendNewWaybillNo", message: node?.wholeText, result: false }, "*")
}
if (node.nodeName == "DIV") {
let text = node.childNodes[2].textContent;
let orderNo = item.target.parentElement?.children[0]?.children[0]?.childNodes[0]?.textContent
console.log(orderNo, 'orderNo')
window.postMessage({ action: "sendNewWaybillNo", waybillNo: text, orderNo, result: true }, "*")
// 从发货易页面发消息给bg
// chrome.runtime.sendMessage({ action: "newWaybillNo", value: text }, function (res) {
// })
// console.log("fahuoyi")
// let fahuoyiPort = chrome.runtime.connect({ name: "sendMessage" })
// fahuoyiPort.postMessage({ action: "newWaybillNo", value: text })
// chrome.runtime.onConnect.addListener(function (port) {
// console.log(port, 'port')
// port.postMessage({ action: "newWaybillNo", value: text })
// })
}
})
})
})
tdObserve.observe(td, {
childList: true,
characterData: true,
subtree: true,
attributes: true
})
})
observe.observe(tbodyDom!, {
childList: true,
})
let bfqxDom = document.querySelector("body")
let observe1 = new MutationObserver(function (mutations, observe) {
// mutations[0].addedNodes[0].className
console.log(mutations, 'bfqxDom')
mutations.forEach(item => {
item.addedNodes.forEach(node => {
// node.textContent == 'bootbox modal fade sui-modal in' &&
if (node.textContent == '× 该订单有商品正在退款中或者已取消,是否确认继续打印?确定取消') {
let bfqxyesbtn = document.querySelector(".btn.btn-primary.bootbox-accept") as HTMLButtonElement
let bfqxnobtn = document.querySelector(".btn.btn-default.bootbox-cancel") as HTMLButtonElement
console.log('bfqxyesbtn', bfqxyesbtn)
bfqxyesbtn.click()
}
})
})
})
observe1.observe(bfqxDom!, {
childList: true,
})
}
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";
import { Select, Button } from "antd";
import "./index.scss";
const { Option } = Select
const { Option } = Select;
export interface IwaybillTemplate {
name: string,
value: string
name: string;
value: string;
}
interface Item {
wayCompanyId: string | undefined,
waybillTemplateList: (string | undefined)[]
printId: string | undefined
wayCompanyId: string | undefined;
waybillTemplateList: (string | undefined)[];
printId: string | undefined;
}
type List = Item[]
type List = Item[];
//
const AllWayCompany = [
{ name: "圆通速递", value: "YTO" }
, { name: "申通快递", value: "STO" }
, { name: "中通快递", value: "ZTO" }
, { name: "韵达快递", value: "YUNDA" }
, { name: "顺丰速运", value: "SF" }
, { name: "百世快递", value: "HTKY" }
, { name: "EMS", value: "EMS" }
, { name: "EMS经济快递", value: "EYB" }
, { name: "邮政标准快递", value: "DISTRIBUTOR_1715055" }
, { name: "邮政快递包裹", value: "POSTB" }
, { name: "中国邮政", value: "POST" }
, { name: "京东快递", value: "EX_JD_EXPRESS" }
, { name: "天天快递", value: "TTKDEX" }
, { name: "国通快递", value: "GTO" }
, { name: "安能快递(小包)", value: "DISTRIBUTOR_12017865" }
, { name: "安能物流", value: "ANE56" }
, { name: "全峰快递", value: "QFKD" }
, { name: "联邦快递", value: "FEDEX" }
, { name: "德邦快递", value: "DBKD" }
, { name: "德邦物流", value: "DBL" }
, { name: "宅急送", value: "ZJS" }
, { name: "优速快递", value: "UC" }
, { name: "龙邦速递", value: "LB" }
, { name: "亚风", value: "AIR" }
, { name: "天地华宇", value: "HOAU" }
, { name: "速尔快运", value: "SURE" }
, { name: "大田", value: "DTW" }
, { name: "保宏物流", value: "BHWL" }
, { name: "发网", value: "UNIPS" }
, { name: "长发", value: "YUD" }
, { name: "长宇", value: "CYEXP" }
, { name: "远长", value: "YC" }
, { name: "东方汇", value: "DFH" }
, { name: "飞远配送 ", value: "GZLT" }
, { name: "派易国际物流77", value: "PKGJWL" }
, { name: "信丰物流", value: "XFWL" }
, { name: "飞远(爱彼西)配送", value: "HZABC" }
, { name: "华强物流", value: "SHQ" }
, { name: "百世物流", value: "BEST" }
, { name: "新邦物流", value: "XB" }
, { name: "美国速递", value: "MGSD" }
, { name: "远成快运", value: "YCKY" }
, { name: "品骏快递", value: "PJBEST" }
, { name: "苏宁物流", value: "DISTRIBUTOR_13452378" }
, { name: "WnDirect", value: "WND" }
, { name: "能达速递", value: "NEDA" }
, { name: "黑猫宅急便", value: "YCT" }
, { name: "D速物流", value: "DISTRIBUTOR_13460212" }
, { name: "联昊通", value: "LTS" }
, { name: "E速宝", value: "ESB" }
, { name: "佳吉快递", value: "CNEX" }
, { name: "广东EMS", value: "GDEMS" }
, { name: "增益速递", value: "QRT" }
, { name: "全一快递", value: "UAPEX" }
, { name: "快捷快递", value: "FAST" }
, { name: "中铁快运", value: "CRE" }
, { name: "速通物流", value: "EX_SUT56" }
, { name: "顺丰快运", value: "EX_SFKY" }
, { name: "速腾快递", value: "EX_STE56" }
, { name: "顺心捷达", value: "DISTRIBUTOR_13484485" }
, { name: "宽昊物流", value: "EX_KHWL" }
, { name: "都市节奏", value: "EX_DSJZ" }
, { name: "众邮快递", value: "EX_ZYKD" }
, { name: "京东快运", value: "EX_JDKY" }
, { name: "DN快递", value: "EX_TOPSPEED_DN" }
, { name: "九曳供应链", value: "DISTRIBUTOR_13323734" }
, { name: "重庆华宇物流", value: "EX_CQHY" }
, { name: "极兔速递", value: "EX_JTSD" }
, { name: "丹鸟", value: "DISTRIBUTOR_13503931" }
, { name: "如风达配送", value: "BJRFD-001" }
, { name: "韵达点通达", value: "EX_YUNDA_DTD" }
, { name: "壹米滴答", value: "YMDD" }
, { name: "百世国际", value: "DISTRIBUTOR_13433751" }
, { name: "安迅物流", value: "DISTRIBUTOR_13365751" }
, { name: "承诺达特快", value: "DISTRIBUTOR_13469985" }
, { name: "沃埃家", value: "EX_WOWVIP" }
, { name: "京广速递", value: "EX_SZKKE" }
, { name: "鸿昌物流", value: "EX_HC" }
, { name: "华企快运", value: "EX_HUAQIEX" }
, { name: "中骅物流", value: "EX_CHUNGHWA56" }
, { name: "百世快运", value: "BESTQJT" }
, { name: "运通速运", value: "WTO" }
, { name: "中通快运", value: "DISTRIBUTOR_13222803" }
, { name: "菜鸟大件-日日顺配", value: "DISTRIBUTOR_13159132" }
, { name: "安世通快递", value: "DISTRIBUTOR_13415300" }
, { name: "百世云配", value: "DISTRIBUTOR_13468073" }
, { name: "韵达快运", value: "DISTRIBUTOR_13421750" }
, { name: "中通国际直邮", value: "DISTRIBUTOR_13196453" }
, { name: "京东大件开放承运商", value: "EX_JD_HPCP" }
, { name: "加运美速递", value: "DISTRIBUTOR_13468074" }
, { name: "中运全速", value: "EX_TOPSPEED" }
, { name: "其他", value: "OTHER" }
, { name: "跨越速运", value: "DISTRIBUTOR_13211725" }
, { name: "菜鸟大件-中铁配", value: "DISTRIBUTOR_13148625" }
]
{ name: "圆通速递", value: "YTO" },
{ name: "申通快递", value: "STO" },
{ name: "中通快递", value: "ZTO" },
{ name: "韵达快递", value: "YUNDA" },
{ name: "顺丰速运", value: "SF" },
{ name: "百世快递", value: "HTKY" },
{ name: "EMS", value: "EMS" },
{ name: "EMS经济快递", value: "EYB" },
{ name: "邮政标准快递", value: "DISTRIBUTOR_1715055" },
{ name: "邮政快递包裹", value: "POSTB" },
{ name: "中国邮政", value: "POST" },
{ name: "京东快递", value: "EX_JD_EXPRESS" },
{ name: "天天快递", value: "TTKDEX" },
{ name: "国通快递", value: "GTO" },
{ name: "安能快递(小包)", value: "DISTRIBUTOR_12017865" },
{ name: "安能物流", value: "ANE56" },
{ name: "全峰快递", value: "QFKD" },
{ name: "联邦快递", value: "FEDEX" },
{ name: "德邦快递", value: "DBKD" },
{ name: "德邦物流", value: "DBL" },
{ name: "宅急送", value: "ZJS" },
{ name: "优速快递", value: "UC" },
{ name: "龙邦速递", value: "LB" },
{ name: "亚风", value: "AIR" },
{ name: "天地华宇", value: "HOAU" },
{ name: "速尔快运", value: "SURE" },
{ name: "大田", value: "DTW" },
{ name: "保宏物流", value: "BHWL" },
{ name: "发网", value: "UNIPS" },
{ name: "长发", value: "YUD" },
{ name: "长宇", value: "CYEXP" },
{ name: "远长", value: "YC" },
{ name: "东方汇", value: "DFH" },
{ name: "飞远配送 ", value: "GZLT" },
{ name: "派易国际物流77", value: "PKGJWL" },
{ name: "信丰物流", value: "XFWL" },
{ name: "飞远(爱彼西)配送", value: "HZABC" },
{ name: "华强物流", value: "SHQ" },
{ name: "百世物流", value: "BEST" },
{ name: "新邦物流", value: "XB" },
{ name: "美国速递", value: "MGSD" },
{ name: "远成快运", value: "YCKY" },
{ name: "品骏快递", value: "PJBEST" },
{ name: "苏宁物流", value: "DISTRIBUTOR_13452378" },
{ name: "WnDirect", value: "WND" },
{ name: "能达速递", value: "NEDA" },
{ name: "黑猫宅急便", value: "YCT" },
{ name: "D速物流", value: "DISTRIBUTOR_13460212" },
{ name: "联昊通", value: "LTS" },
{ name: "E速宝", value: "ESB" },
{ name: "佳吉快递", value: "CNEX" },
{ name: "广东EMS", value: "GDEMS" },
{ name: "增益速递", value: "QRT" },
{ name: "全一快递", value: "UAPEX" },
{ name: "快捷快递", value: "FAST" },
{ name: "中铁快运", value: "CRE" },
{ name: "速通物流", value: "EX_SUT56" },
{ name: "顺丰快运", value: "EX_SFKY" },
{ name: "速腾快递", value: "EX_STE56" },
{ name: "顺心捷达", value: "DISTRIBUTOR_13484485" },
{ name: "宽昊物流", value: "EX_KHWL" },
{ name: "都市节奏", value: "EX_DSJZ" },
{ name: "众邮快递", value: "EX_ZYKD" },
{ name: "京东快运", value: "EX_JDKY" },
{ name: "DN快递", value: "EX_TOPSPEED_DN" },
{ name: "九曳供应链", value: "DISTRIBUTOR_13323734" },
{ name: "重庆华宇物流", value: "EX_CQHY" },
{ name: "极兔速递", value: "EX_JTSD" },
{ name: "丹鸟", value: "DISTRIBUTOR_13503931" },
{ name: "如风达配送", value: "BJRFD-001" },
{ name: "韵达点通达", value: "EX_YUNDA_DTD" },
{ name: "壹米滴答", value: "YMDD" },
{ name: "百世国际", value: "DISTRIBUTOR_13433751" },
{ name: "安迅物流", value: "DISTRIBUTOR_13365751" },
{ name: "承诺达特快", value: "DISTRIBUTOR_13469985" },
{ name: "沃埃家", value: "EX_WOWVIP" },
{ name: "京广速递", value: "EX_SZKKE" },
{ name: "鸿昌物流", value: "EX_HC" },
{ name: "华企快运", value: "EX_HUAQIEX" },
{ name: "中骅物流", value: "EX_CHUNGHWA56" },
{ name: "百世快运", value: "BESTQJT" },
{ name: "运通速运", value: "WTO" },
{ name: "中通快运", value: "DISTRIBUTOR_13222803" },
{ name: "菜鸟大件-日日顺配", value: "DISTRIBUTOR_13159132" },
{ name: "安世通快递", value: "DISTRIBUTOR_13415300" },
{ name: "百世云配", value: "DISTRIBUTOR_13468073" },
{ name: "韵达快运", value: "DISTRIBUTOR_13421750" },
{ name: "中通国际直邮", value: "DISTRIBUTOR_13196453" },
{ name: "京东大件开放承运商", value: "EX_JD_HPCP" },
{ name: "加运美速递", value: "DISTRIBUTOR_13468074" },
{ name: "中运全速", value: "EX_TOPSPEED" },
{ name: "其他", value: "OTHER" },
{ name: "跨越速运", value: "DISTRIBUTOR_13211725" },
{ name: "菜鸟大件-中铁配", value: "DISTRIBUTOR_13148625" },
];
const PlatformsMap = new Map([
[0, /.+:\/\/a.*\.fahuoyi.com\//],
[1, /.+:\/\/pdd.*\.fahuoyi.com\//],
[2, /.+:\/\/jd.*\.fahuoyi.com\//]
])
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[]>([])
[0, /.+:\/\/a.*\.fahuoyi.com\//],
[1, /.+:\/\/pdd.*\.fahuoyi.com\//],
[2, /.+:\/\/jd.*\.fahuoyi.com\//],
]);
/**
* 快递单模板的类型
*/
enum WaybillTemplateType {
CAINIAO = "CAINIAO",
JD = "JD",
const setMap = new Map([
[0, setAWaybillTemplate],
[1, setPDDWaybillTemplate],
[2, setJDWaybillTemplate]
])
const getMap = new Map([
[0, AWaybillTemplate],
[1, PDDWaybillTemplate],
[2, JDWaybillTemplate]
])
// 获取发货易快递模板列表
const getWaybillTemplate = useCallback(async () => {
chrome.tabs.query({
url: "*://*.fahuoyi.com/scanPrinting/index"
}, async function (tabs) {
JDL = "JDL",
NORMAL = "NORMAL",
let platformUrls: string[] = []
for (let value of PlatformsMap.values()) {
let prefixUrl: string;
tabs.forEach(tab => {
console.log(value.test(tab.url!))
if (tab.url && value.test(tab.url!)) {
prefixUrl = tab.url.match(value)![0]
console.log(prefixUrl, 'url')
}
})
OFFICIAL = "OFFICIAL",
platformUrls.push(prefixUrl!)
console.log(platformUrls, 'platformUrls')
}
for (let index in platformUrls) {
let prefix = platformUrls[index]
console.log(prefix, 'prefix')
let data = prefix ? await fetch(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 => {
// @ts-ignore
return data.map(dataItem => ({
name: dataItem.name,
value: dataItem.id
}))
})
}
PDD = "PDD",
JINRITEMAI = "JINRITEMAI",
})
}, [])
const getPrintList = useCallback(async () => {
chrome.tabs.query({
url: "*://*.fahuoyi.com/scanPrinting/index"
}, async function (tabs) {
if (tabs.length >= 1) {
let port = chrome.tabs.connect(tabs[0].id!, { name: "getPrinter" });
port.postMessage({ action: "getPrint" })
port.onMessage.addListener(function (msg) {
setPrintList(msg)
})
}
})
}, [])
useEffect(() => {
getWaybillTemplate()
getPrintList()
chrome.storage.local.get({ list: [{ wayCompanyId: undefined, waybillTemplateList: [undefined, undefined, undefined], printId: undefined }] }, function (res) {
if (res.list.length === 0) {
chrome.storage.local.set({ list: [{ wayCompanyId: undefined, waybillTemplateList: [undefined, undefined, undefined], printId: undefined }] }, function () {
setList([{ wayCompanyId: undefined, waybillTemplateList: [undefined, undefined, undefined], printId: undefined }])
})
} else {
setList(res.list as List)
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([
[0, setAWaybillTemplate],
[1, setPDDWaybillTemplate],
[2, setJDWaybillTemplate],
]);
const getMap = new Map([
[0, AWaybillTemplate],
[1, PDDWaybillTemplate],
[2, JDWaybillTemplate],
]);
// 获取发货易快递模板列表
const getWaybillTemplate_old = useCallback(async () => {
chrome.tabs.query(
{
url: "*://*.fahuoyi.com/scanPrinting/index",
},
async function (tabs) {
let platformUrls: string[] = [];
for (let value of PlatformsMap.values()) {
let prefixUrl: string;
tabs.forEach((tab) => {
console.log(value.test(tab.url!));
if (tab.url && value.test(tab.url!)) {
prefixUrl = tab.url.match(value)![0];
console.log(prefixUrl, "url");
}
})
}, [])
useEffect(() => {
chrome.storage.local.set({ list: list })
}, [list])
const onChangeWayCompany = useCallback((value: string, wayIndex: number) => {
setList(pre => {
const newList = [...pre]
newList[wayIndex].wayCompanyId = value
return newList;
})
}, [])
const onChangeWayTemplate = useCallback((e: string, wayIndex: number, tempIndex: number) => {
setList(pre => {
const newList = [...pre]
newList[wayIndex].waybillTemplateList[tempIndex] = e;
return newList
})
}, [])
const onChangePrint = useCallback((e: string, wayIndex: number) => {
setList(pre => {
const newList = [...pre]
newList[wayIndex].printId = e;
return newList;
})
}, [])
// 新增快递
const handleAddWay = useCallback(() => {
setList(pre => {
const newState = [...pre]
newState.push({ wayCompanyId: undefined, waybillTemplateList: [undefined, undefined, undefined], printId: undefined })
return newState;
})
}, [])
// 删除
const remove = useCallback((index: number) => {
setList(pre => {
const newState = [...pre]
newState.splice(index, 1)
return newState
})
}, [])
return (
<>
<div className="waybill-model">
<span className="waybill-model-title" key="one">选择快递</span>
<span className="waybill-model-title" key="two">选择淘系及其他平台订单模板</span>
<span className="waybill-model-title" key="three">选择拼多多订单模板</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>
});
platformUrls.push(prefixUrl!);
console.log(platformUrls, "platformUrls");
}
for (let index in platformUrls) {
let prefix = platformUrls[index];
console.log(prefix, "prefix");
let data = prefix
? await fetch(
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) => {
// @ts-ignore
return data.map((dataItem) => ({
name: dataItem.name,
value: dataItem.id,
}));
});
}
}
);
}, []);
const getPrintList_old = useCallback(async () => {
chrome.tabs.query(
{
url: "*://*.fahuoyi.com/scanPrinting/index",
},
async function (tabs) {
if (tabs.length >= 1) {
let port = chrome.tabs.connect(tabs[0].id!, {
name: "getPrinter",
});
port.postMessage({ action: "getPrint" });
port.onMessage.addListener(function (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(() => {
getWaybillTemplate();
getPrintList();
chrome.storage.local.get(
{
list: [
{
wayCompanyId: undefined,
waybillTemplateList: [undefined, undefined, undefined],
printId: undefined,
},
],
},
function (res) {
if (res.list.length === 0) {
chrome.storage.local.set(
{
list: [
{
list.map((item, wayIndex) => {
return <>
<Select
showSearch
key={ wayIndex + "wayCompany" }
style={ { width: 150 } }
placeholder="请选择快递"
optionFilterProp="children"
onChange={ (value) => onChangeWayCompany(value, wayIndex) }
value={ item.wayCompanyId }
>
{
AllWayCompany.map((item, index) => {
return <Option key={ index } value={ item.value }>{ item.name }</Option>
})
}
</Select>
{
item.waybillTemplateList.map((item, tempIndex) => {
return <Select
key={ tempIndex + "wayTemplate" }
showSearch
style={ { width: 150 } }
placeholder="选择快递模板"
optionFilterProp="children"
onChange={ (value) => onChangeWayTemplate(value, wayIndex, tempIndex) }
value={ item }
>
{
getMap.get(tempIndex)!.map((item, index) => {
return <Option key={ index } value={ item.value }>{ item.name }</Option>
})
}
</Select>
})
}
<Select
key={ item.printId + 'print' }
showSearch
style={ { width: 150 } }
placeholder="选择打印机"
optionFilterProp="children"
onChange={ (value) => onChangePrint(value, wayIndex) }
value={ item.printId }
>
{
printList.map((item, index) => {
return <Option key={ index } value={ item }>{ item }</Option>
})
}
</Select>
<Button type="default" key={ item.printId + "btn" } style={ { padding: "0 5px" } } onClick={ () => remove(wayIndex) }>删除</Button>
</>
})
}
</div>
<Button type="link" onClick={ handleAddWay }>新增快递</Button>
</>
)
}
export default WayBillModel
\ No newline at end of file
wayCompanyId: undefined,
waybillTemplateList: [undefined, undefined, undefined],
printId: undefined,
},
],
},
function () {
setList([
{
wayCompanyId: undefined,
waybillTemplateList: [undefined, undefined, undefined],
printId: undefined,
},
]);
}
);
} else {
setList(res.list as List);
}
}
);
}, []);
useEffect(() => {
chrome.storage.local.set({ list: list });
}, [list]);
const onChangeWayCompany = useCallback((value: string, wayIndex: number) => {
setList((pre) => {
const newList = [...pre];
newList[wayIndex].wayCompanyId = value;
return newList;
});
}, []);
const onChangeWayTemplate = useCallback(
(e: string, wayIndex: number, tempIndex: number) => {
setList((pre) => {
const newList = [...pre];
newList[wayIndex].waybillTemplateList[tempIndex] = e;
return newList;
});
},
[]
);
const onChangePrint = useCallback((e: string, wayIndex: number) => {
setList((pre) => {
const newList = [...pre];
newList[wayIndex].printId = e;
return newList;
});
}, []);
// 新增快递
const handleAddWay = useCallback(() => {
setList((pre) => {
const newState = [...pre];
newState.push({
wayCompanyId: undefined,
waybillTemplateList: [undefined, undefined, undefined],
printId: undefined,
});
return newState;
});
}, []);
// 删除
const remove = useCallback((index: number) => {
setList((pre) => {
const newState = [...pre];
newState.splice(index, 1);
return newState;
});
}, []);
return (
<>
<div className="waybill-model">
<span className="waybill-model-title" key="one">
选择快递
</span>
<span className="waybill-model-title" key="two">
选择淘系及其他平台订单模板
</span>
<span className="waybill-model-title" key="three">
选择拼多多订单模板
</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
showSearch
key={wayIndex + "wayCompany"}
style={{ width: 150 }}
placeholder="请选择快递"
optionFilterProp="children"
onChange={(value) => onChangeWayCompany(value, wayIndex)}
value={item.wayCompanyId}
>
{AllWayCompany.map((item, index) => {
return (
<Option key={index} value={item.value}>
{item.name}
</Option>
);
})}
</Select>
{item.waybillTemplateList.map((item, tempIndex) => {
return (
<Select
key={tempIndex + "wayTemplate"}
showSearch
style={{ width: 150 }}
placeholder="选择快递模板"
optionFilterProp="children"
onChange={(value) =>
onChangeWayTemplate(value, wayIndex, tempIndex)
}
value={item}
>
{getMap.get(tempIndex)!.map((item, index) => {
return (
<Option key={index} value={item.value}>
{item.name}
</Option>
);
})}
</Select>
);
})}
<Select
key={item.printId + "print"}
showSearch
style={{ width: 150 }}
placeholder="选择打印机"
optionFilterProp="children"
onChange={(value) => onChangePrint(value, wayIndex)}
value={item.printId}
>
{printList.map((item, index) => {
return (
<Option key={index} value={item}>
{item}
</Option>
);
})}
</Select>
<Button
type="default"
key={item.printId + "btn"}
style={{ padding: "0 5px" }}
onClick={() => remove(wayIndex)}
>
删除
</Button>
</>
);
})}
</div>
<Button type="link" onClick={handleAddWay}>
新增快递
</Button>
</>
);
};
export default WayBillModel;
......@@ -4,6 +4,8 @@
// // 让popup获取waybillTemplate
// export const GetWaybillTemplate = "getWaybillTemplate"
export const StartPrint = "StartPrint"
export const StartPrint = "StartPrint";
export const Print = "Print"
\ No newline at end of file
export const Print = "Print";
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