Commit edf02d3b authored by 刘燕芳's avatar 刘燕芳

图动力

parent c32bb894
{ {
"name": "辅助发货易打单1.1.0", "name": "图动力",
"version": "1.0.0", "version": "1.0.0",
"description": "辅助手机壳厂家打印发货易的快递单", "description": "辅助手机壳厂家打印发货易的快递单",
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
"browser_action": { "browser_action": {
"default_popup": "popup.html", "default_popup": "popup.html",
"default_icon": "icon.png", "default_icon": "icon.png",
"default_title": "辅助发货易打单" "default_title": "辅助图动力"
}, },
"icons": { "icons": {
"128": "icon.png" "128": "icon.png"
......
...@@ -58,7 +58,7 @@ chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) { ...@@ -58,7 +58,7 @@ chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
}) })
// let port = chrome.runtime.connect({ name: "bgSendMessage" }) // let port = chrome.runtime.connect({ name: "bgSendMessage" })
// port.postMessage(message) // port.postMessage(message)
}else if (message.action === ACTION.BookingV2) { }else if (message.action === ACTION.task) {
// 从bg页面转发给厂家页面的content.js // 从bg页面转发给厂家页面的content.js
chrome.tabs.query({ chrome.tabs.query({
...@@ -68,7 +68,7 @@ chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) { ...@@ -68,7 +68,7 @@ chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
tabs && tabs.forEach(tab => { tabs && tabs.forEach(tab => {
// chrome.tabs.sendMessage(tab.id!, message) // chrome.tabs.sendMessage(tab.id!, message)
chrome.tabs.update(tab.id!, { active: true}, function(tab1) {}); chrome.tabs.update(tab.id!, { active: true}, function(tab1) {});
chrome.tabs.sendMessage(tab.id!, { action: ACTION.BookingV2, value: message.value },res=>{ chrome.tabs.sendMessage(tab.id!, { action: ACTION.task, value: message.value },res=>{
if(res){ if(res){
sendResponse(res); sendResponse(res);
chrome.tabs.update(sender.tab!.id!, { active: true}, function(tab1) {}); chrome.tabs.update(sender.tab!.id!, { active: true}, function(tab1) {});
...@@ -81,26 +81,6 @@ chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) { ...@@ -81,26 +81,6 @@ chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
}) })
// let port = chrome.runtime.connect({ name: "bgSendMessage" }) // let port = chrome.runtime.connect({ name: "bgSendMessage" })
// port.postMessage(message) // port.postMessage(message)
}else if (message.action === ACTION.BookingApp) {
// 从bg页面转发给厂家页面的content.js
chrome.tabs.query({
url: `https://${message.value.platform}.fahuoyi.com/order/index*` //淘宝:app 拼多多:pdd5
}, function (tabs) {
tabs && tabs.forEach(tab => {
// chrome.tabs.sendMessage(tab.id!, message)
chrome.tabs.sendMessage(tab.id!, { action: ACTION.BookingApp, value: message.value },res=>{
if(res)sendResponse(res);
})
})
if(tabs.length==0){
sendResponse({status:1,msg:"请打开旧版发货易发货页面"});
}
})
// let port = chrome.runtime.connect({ name: "bgSendMessage" })
// port.postMessage(message)
} }
return true; return true;
......
let domEle = {
inputOrderId: document.querySelector("#orderFilterPane > div > form > ul > li:nth-child(4) > input") as HTMLInputElement,
btnSearch: document.querySelector("#searchOrderButton") as HTMLButtonElement,
checkBoxSelectAll: document.querySelector("#orderTable > thead > tr > th:nth-child(1) > input[type=checkbox]") as HTMLInputElement,
btnPrint: document.querySelector("#printWaybillButton") as HTMLButtonElement,
selectWaybillTemplate: document.querySelector("#printWaybillDialog > div > div > div.modal-body > form > div:nth-child(2) > div > select") as HTMLSelectElement,
radioGetNewWaybill: document.querySelector("#printWaybillDialog > div > div > div.modal-body > form > div.form-group.get-waybill-no-method-radios > div > label:nth-child(1) > input[type=radio]") as HTMLInputElement,
inputWaybillNoOnly: document.querySelector("#printWaybillDialog > div > div > div.modal-body > form > div:nth-child(4) > div > div > label > input[type=checkbox]") as HTMLInputElement,
btnDialogPrint: document.querySelector("#printWaybillDialog > div > div > div.modal-footer > button.btn.btn-primary.print-button") as HTMLButtonElement,
btnDialogCancel:document.querySelector("#printWaybillDialog > div > div > div.modal-footer > button.btn.btn-default") as HTMLButtonElement,
modalResult: document.querySelector("#printEwaybillResultDialog") as HTMLDivElement,
tableResult: document.querySelector("#printEwaybillResultDialog > div > div > div.modal-body > div.result-table-container > table") as HTMLTableElement,
btnClose: document.querySelector("#printEwaybillResultDialog > div > div > div.modal-footer > button.btn.btn-default") as HTMLButtonElement,
btnDeliver: document.querySelector("#printEwaybillResultDialog > div > div > div.modal-footer > button.btn.ship-now-btn") as HTMLButtonElement,
unReachModal:()=>document.querySelector(".bootbox-message") as HTMLDivElement,
unReachAccept:()=>document.querySelector(".bootbox-accept") as HTMLButtonElement,
printErrorModal:()=>document.querySelector(".bootbox-message") as HTMLDivElement,
printErrorConfirm:()=>document.querySelector(".bootbox-accept") as HTMLButtonElement,
}
async function booking(wayCompanyId: string, orderNo: string) {
domEle.inputOrderId.value = orderNo;
domEle.checkBoxSelectAll.checked = true;
domEle.btnSearch.click();
let result = {
status: 0,
msg: "",
data: [],
}
result = await waitOrder();
if (result.status > 0) {
return result;
}
domEle.checkBoxSelectAll.click();
domEle.btnPrint.click();
await delayDate(500);
console.log(domEle.unReachModal);
if(domEle.unReachModal() && domEle.unReachModal().innerText==' 所选订单中部分订单地址不可达,是否继续打印?'){
domEle.unReachAccept().click();
}
result = await waitDialog();
if (result.status > 0) {
return result;
}
for (let i = 0; i < domEle.selectWaybillTemplate.options.length; i++) {
if (domEle.selectWaybillTemplate.options[i].value == wayCompanyId) {
domEle.selectWaybillTemplate.selectedIndex = i;
domEle.radioGetNewWaybill.click();
if (domEle.inputWaybillNoOnly.checked == false) domEle.inputWaybillNoOnly.click();
domEle.btnDialogPrint.click();
result = await waitPrintResult();
if (result.status == 0) {
let printReslut: any = {
success: 0,
count: domEle.tableResult.rows.length,
fail: 0,
list: []
}
let chooseIndex = 0
let rowResultList:any = []
for (let rowIter = 0; rowIter < domEle.tableResult.rows.length; rowIter++) {
let rowResult = domEle.tableResult.rows[rowIter].cells[2].innerText;
let rowInfo = domEle.tableResult.rows[rowIter].cells[1].innerText;
let rowObject = {
info: rowInfo,
msg: rowResult,
success: 1,
}
rowResultList.push(rowResult)
if (rowResult.indexOf("打印失败") > -1) {
printReslut.fail++;
rowObject.success = 0;
} else {
printReslut.success++;
}
printReslut.list.push(rowObject)
}
result.data = printReslut;
// 如果所有的订单都打印失败则,等会再发货,关闭弹窗
if(rowResultList.every((item:any)=>item.includes('打印失败'))){
chooseIndex = -1
}
console.log(result);
// 等会再发货
if(chooseIndex===-1){
console.log('等会再发货');
domEle.btnClose.click();
}else{
// 马上发货
console.log('马上发货');
domEle.btnDeliver.click()
}
return result;
}else{
//取消打印
await delayDate(1000);
domEle.btnDialogCancel.click();
return result;
}
break;
}
}
result.msg = "未匹配快递单模板";
result.status = 3;
return result;
}
async function waitOrder() {
let result = {
status: 4,
msg: "获取订单超时",
data: [],
}
for (let i = 0; i < 10; i++) {
await delayDate(1000);
if (domEle.checkBoxSelectAll.checked != true) {
if (document.getElementsByClassName("not-order-found").length > 0) {
//无订单
result.status = 2;
result.msg = "无相关订单"
return result;
} else {
result.status = 0;
result.msg = ""
return result;
}
}
}
return result;
}
async function waitDialog() {
let result = {
status: 4,
msg: "获取打印按钮超时",
data: [],
}
for (let i = 0; i < 10; i++) {
await delayDate(1000);
if (domEle.btnDialogPrint.disabled == false) {
result.status = 0;
result.msg = ""
return result;
}
}
return result;
}
async function waitPrintResult() {
let result = {
status: 4,
msg: "获取打印结果超时",
data: [],
}
for (let i = 0; i < 10; i++) {
await delayDate(1000);
if (domEle.modalResult.className == 'modal fade sui-modal none in') {
result.status = 0;
result.msg = ""
return result;
}
if(domEle.printErrorModal() && domEle.printErrorModal().innerText==' 获取电子面单失败,从9月1日起淘宝平台开启付费解密虚拟号方案(查看详情),因此不支持非菜鸟电子面单打印,请尽量使用菜鸟电子面单打印,如需付费解密虚拟号打印非菜鸟电子面单请联系发货易客服咨询'){
result.msg="获取电子面单失败";
domEle.printErrorConfirm().click();
return result;
}
}
return result;
}
function delayDate(time: number) {
return new Promise((resolve, reject) => {
setTimeout(() => {
//console.log(‘开始执行‘)
resolve("success");
}, time);
});
}
export default {
booking
}
\ No newline at end of file
...@@ -5,14 +5,12 @@ import { message } from "antd"; ...@@ -5,14 +5,12 @@ import { message } from "antd";
import { ACTION, Print, StartPrint } from "../types"; import { ACTION, Print, StartPrint } from "../types";
import BookingApp from "./bookingApp"
import BookingV2 from "./bookingV2" import BookingV2 from "./bookingV2"
export enum PlatformCode { export enum PlatformCode {
"淘系及其他平台订单模板" = 0, "淘系及其他平台订单模板" = 0,
"拼多多订单模板" = 1, "拼多多订单模板" = 1,
"京东订单模板" = 2 "京东订单模板" = 2
} }
console.log("inject");
type Params = { type Params = {
waybillNo: string // 运单号 waybillNo: string // 运单号
platform: PlatformCode, platform: PlatformCode,
...@@ -192,14 +190,9 @@ const printWayBillByNew = function ({ orderNo, wayCompanyId, platform }: Pick<Pa ...@@ -192,14 +190,9 @@ const printWayBillByNew = function ({ orderNo, wayCompanyId, platform }: Pick<Pa
// web页面通信 // web页面通信
window.addEventListener("message",function(message:any){ window.addEventListener("message",function(message:any){
console.log(1111,message);
if(message.data.action == ACTION.BookingApp){
chrome.runtime.sendMessage(message.data,(ret)=>{ if(message.data.action == ACTION.task){
window.postMessage({isResult:1,...ret},"*")
console.log("message ret:",ret,message.data);
})
}
if(message.data.action == ACTION.BookingV2){
chrome.runtime.sendMessage(message.data,(ret)=>{ chrome.runtime.sendMessage(message.data,(ret)=>{
window.postMessage({isResult:1,...ret},"*") window.postMessage({isResult:1,...ret},"*")
console.log("message ret:",ret,message.data); console.log("message ret:",ret,message.data);
...@@ -219,26 +212,14 @@ chrome.runtime.onMessage.addListener(function (message: Message, sender, respons ...@@ -219,26 +212,14 @@ chrome.runtime.onMessage.addListener(function (message: Message, sender, respons
printWayBillByNew({ orderNo, wayCompanyId, platform }) printWayBillByNew({ orderNo, wayCompanyId, platform })
} }
} }
else if (message.action === ACTION.BookingV2) { else if (message.action === ACTION.task) {
console.log("recive BookingV2",message); console.log("task",message);
let result=null; let result=null;
(async () => { (async () => {
result = await BookingV2.booking(message.value.waybillTemplateTitle,message.value.orderNo,message.value.shopId); result = await BookingV2.booking(message.value.waybillTemplateTitle,message.value.orderNo,message.value.shopId);
response(result); response(result);
})(); })();
} }
else if (message.action === ACTION.BookingApp) {
console.log("recive BookingApp",message);
hookConfirm();
let result=null;
(async () => {
result = await BookingApp.booking(message.value.wayCompanyId,message.value.orderNo);
response(result);
})();
}
return true; return true;
}) })
...@@ -268,18 +249,6 @@ chrome.runtime.onConnect.addListener(function (port) { ...@@ -268,18 +249,6 @@ chrome.runtime.onConnect.addListener(function (port) {
} }
}) })
// 厂家content.js页面
// chrome.runtime.onMessage.addListener(function (message, sender, response) {
// if (message.action === "newWaybillNo") {
// window.postMessage(message, "*")
// }
// })
// let FactoryPost = chrome.runtime.connect({ name: "getMessage" })
// FactoryPost.onMessage.addListener(function (msg) {
// if (msg.action === "newWaybillNo") {
// window.postMessage(msg, "*")
// }
// })
chrome.runtime.onConnect.addListener(function (port) { chrome.runtime.onConnect.addListener(function (port) {
if (port.name === "sendNewWaybillNo") { if (port.name === "sendNewWaybillNo") {
...@@ -326,7 +295,8 @@ const startPrintWayBill = function (params: Params) { ...@@ -326,7 +295,8 @@ const startPrintWayBill = function (params: Params) {
*/ */
window.addEventListener("message", function (msg) { window.addEventListener("message", function (msg) {
console.log('发货易content',msg);
if (msg.data.action === "sendNewWaybillNo") { if (msg.data.action === "sendNewWaybillNo") {
// chrome.runtime.onConnect.addListener(function (port) { // chrome.runtime.onConnect.addListener(function (port) {
......
import React,{ useCallback, useContext, useEffect, useState } from "react";
import { Checkbox } from "antd";
const IsAutoEmit = function () {
const [checked, setChecked] = useState<boolean>(true)
const changeRadio = useCallback((e) => {
setChecked(e.target.checked)
}, [])
useEffect(() => {
chrome.storage.local.get({ isAutoEmit: false }, function (res) {
setChecked(res.isAutoEmit)
})
}, [])
useEffect(() => {
chrome.storage.local.set({isAutoEmit:checked})
},[checked])
return <>
<span className="waybill-panel-title">自动发货</span>
<Checkbox checked={ checked } onChange={ changeRadio } style={ { marginLeft: "13px" } }>打印成功后自动发货</Checkbox>
</>
}
export default IsAutoEmit
\ No newline at end of file
import React, { useState, useCallback, useEffect } from "react";
import { Select, Button } from "antd";
import "./index.scss";
const { Option } = Select
export interface IwaybillTemplate {
name: string,
value: string
}
interface Item {
wayCompanyId: string | undefined,
waybillTemplateList: (string | undefined)[]
printId: string | undefined
}
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" }
]
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[]>([])
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) {
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')
}
})
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 = 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)
}
})
}, [])
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
\ No newline at end of file
...@@ -2,10 +2,6 @@ ...@@ -2,10 +2,6 @@
width: 809px; width: 809px;
max-height: 200px; max-height: 200px;
overflow-y: auto; overflow-y: auto;
overflow-x: hidden; overflow-x: hidden;
display: grid; margin-left: 10px;
justify-items: center;
align-items: center;
grid-template-columns: 1fr 1.1fr repeat(3,1fr) 44px;
grid-auto-rows: 40px;
} }
\ No newline at end of file
...@@ -14,7 +14,6 @@ interface Item { ...@@ -14,7 +14,6 @@ interface Item {
} }
type List = Item[] type List = Item[]
//
const AllWayCompany = [ const AllWayCompany = [
{ name: "圆通速递", value: "YTO" } { name: "圆通速递", value: "YTO" }
, { name: "申通快递", value: "STO" } , { name: "申通快递", value: "STO" }
...@@ -118,7 +117,14 @@ const PlatformsMap = new Map([ ...@@ -118,7 +117,14 @@ const PlatformsMap = new Map([
[2, /.+:\/\/jd.*\.fahuoyi.com\//] [2, /.+:\/\/jd.*\.fahuoyi.com\//]
]) ])
const WayBillModel = function () { const WayBillModel = function () {
// 当前是否连接成功
const [link,setLink] = useState<string>('')
// 当前的登录状态
const [is_login,setIsLogin] = useState<boolean>(false)
// 用户信息
const [user,setUser] = useState<object>({
name: '',
})
const [list, setList] = useState<List>([]) const [list, setList] = useState<List>([])
const [AWaybillTemplate, setAWaybillTemplate] = useState<IwaybillTemplate[]>([]) const [AWaybillTemplate, setAWaybillTemplate] = useState<IwaybillTemplate[]>([])
const [PDDWaybillTemplate, setPDDWaybillTemplate] = useState<IwaybillTemplate[]>([]) const [PDDWaybillTemplate, setPDDWaybillTemplate] = useState<IwaybillTemplate[]>([])
...@@ -138,28 +144,15 @@ const WayBillModel = function () { ...@@ -138,28 +144,15 @@ const WayBillModel = function () {
[2, JDWaybillTemplate] [2, JDWaybillTemplate]
]) ])
// 获取发货易快递模板列表 // 获取发货易快递模板列表
const getWaybillTemplate = useCallback(async () => { const getLogin = useCallback(async () => {
chrome.tabs.query({ chrome.tabs.query({
url: "*://*.fahuoyi.com/scanPrinting/index" url: "*://myseller.taobao.com/home.htm/shop-manage/shop-center"
}, async function (tabs) { }, async function (tabs) {
console.log(1111,tabs);
let platformUrls: string[] = [] let platformUrls = tabs.filter(item=>item.url)
for (let value of PlatformsMap.values()) { // platformUrls = tabs.filter(item=>item.url)
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')
}
})
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')
...@@ -205,8 +198,8 @@ const WayBillModel = function () { ...@@ -205,8 +198,8 @@ const WayBillModel = function () {
}, []) }, [])
useEffect(() => { useEffect(() => {
getWaybillTemplate() getLogin()
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({ list: [{ wayCompanyId: undefined, waybillTemplateList: [undefined, undefined, undefined], printId: undefined }] }, function () {
...@@ -222,6 +215,8 @@ const WayBillModel = function () { ...@@ -222,6 +215,8 @@ const WayBillModel = function () {
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]
...@@ -246,8 +241,8 @@ const WayBillModel = function () { ...@@ -246,8 +241,8 @@ const WayBillModel = function () {
}) })
}, []) }, [])
// 新增快递 // 刷新连接状态
const handleAddWay = useCallback(() => { const refresh = 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 })
...@@ -256,81 +251,20 @@ const WayBillModel = function () { ...@@ -256,81 +251,20 @@ const WayBillModel = function () {
}, []) }, [])
// 删除 // 删除
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> <div className="waybill-model-title" key="one">千牛登录账号:{is_login?user:'未登录'}</div>
<span className="waybill-model-title" key="two">选择淘系及其他平台订单模板</span> <div className="waybill-model-title" key="two">通信状态:{link?'连接成功':'连接中断'}</div>
<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> </div>
<Button type="link" onClick={ handleAddWay }>新增快递</Button> <Button type="link" onClick={ refresh }>刷新连接状态</Button>
</> </>
) )
} }
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
justify-content: flex-start; justify-content: flex-start;
align-items: stretch; align-items: stretch;
height:400px; height:400px;
width: 800px; width: 400px;
.popup-page-title{ .popup-page-title{
padding:10px 0; padding:10px 0;
font-size: 16px; font-size: 16px;
......
import React from "react"; import React from "react";
import WayBillModel from "./components/WayBillModel"; import WayBillModel from "./components/WayBillModel";
import IsAutoEmit from "./components/IsAutoEmit";
import "./popup.scss" import "./popup.scss"
const Popup = function () { const Popup = function () {
return ( return (
<div className="popup-page"> <div className="popup-page">
{/* <span className="popup-page-title">打单设置</span> <span className="popup-page-title">打单设置</span>
<div className="waybill-panel"> <div className="waybill-panel">
<span className="waybill-panel-title">电子面单模板</span> <span className="waybill-panel-title">插件状态</span>
<div className="waybill-model-wrap"> <div className="waybill-model-wrap">
<WayBillModel /> <WayBillModel />
</div> </div>
</div> </div>
<div className="waybill-panel">
<IsAutoEmit />
</div> */}
</div> </div>
) )
} }
export default Popup; export default Popup;
\ No newline at end of file
...@@ -5,8 +5,7 @@ ...@@ -5,8 +5,7 @@
// export const GetWaybillTemplate = "getWaybillTemplate" // export const GetWaybillTemplate = "getWaybillTemplate"
export enum ACTION{ export enum ACTION{
BookingV2="BookingV2", task="task",
BookingApp="BookingApp"
} }
......
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