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;
}
This diff is collapsed.
This diff is collapsed.
......@@ -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