Commit 8fdf6f3e authored by 刘燕芳's avatar 刘燕芳

通信

parent 4e86efe9
...@@ -27,8 +27,7 @@ ...@@ -27,8 +27,7 @@
"matches": [ "matches": [
"*://myseller.taobao.com/*", "*://myseller.taobao.com/*",
"*://admin.rtxmdz.com/*", "*://admin.rtxmdz.com/*",
"http://localhost:8082/*", "http://localhost:10823/*",
"http://localhost:8083/*",
"*://*.rtxmdz.com/*" "*://*.rtxmdz.com/*"
], ],
"js": ["content.js"], "js": ["content.js"],
......
This diff is collapsed.
import { bookingV2Urls } from "../config";
let domEle = {
divNav:document.getElementsByClassName("nav-link") as HTMLCollection,
inputOrderId: "#originalIds",
btnSearch: "#root > section > main > div > div > div > div.order-main > div.order-table-container > div.order-search-pane > div > div > div:nth-child(2) > button:nth-child(2)",
checkBoxSelectAll: "div.bottom-operation-bar > span input.ant-checkbox-input",
btnPrint: ".ec-print-waybill-button",
modalTips:"ant-modal-confirm-title",
btnTipsConfirm:"div.ant-modal-confirm-body-wrapper > div > button.ant-btn-primary",
spanWaybillTemplate: ():any=>document.getElementsByClassName("ant-modal-body")[0].getElementsByClassName("ant-select-selector")[0] ,
divWaybillTemplateList: ():any=>document.getElementsByClassName("rc-virtual-list-holder-inner")[0] ,
radioGetNewWaybill: ():any=>document.querySelector(".ant-modal-body input.ant-radio-input") ,
inputWaybillNoOnly: ():any=>document.querySelector("#isGenerateWaybillNoOnly") ,
btnDialogPrint: ():any=>document.querySelector("div.ant-modal-footer button"),
modalResult: "#printEwaybillResultDialog",
tableResult: ():any=>document.querySelector("#ewaybill-result-table > div > div.ant-table-body > table"),
btnClose: ():any=>document.querySelector("div.ant-modal-footer button:nth-child(3)") ,
btnDeliver: ():any=>document.querySelector("div.ant-modal-footer button:nth-child(2)") ,
deliverResult:():any=>document.querySelector(".ant-modal-body>div.ant-table-wrapper .ant-table-tbody"),
deliverClose: ():any=>document.querySelector("div.ant-modal-footer button") ,
}
async function booking(info: any) { async function booking(info: any) {
return ; console.log(2222);
let data:object = { catId: 150704, jsonBody: info}
}
async function waitOrder() {
let result = {
status: 4,
msg: "获取订单超时",
data: [],
}
for (let i = 0; i < 10; i++) {
await delayDate(1000);
let loadingMask = document.querySelector("#root > section > main > div > div > div > div.order-main > div.order-table-container > div.loading-mark-container > div") as any;
if (loadingMask.style.display=="none" ) {
if (document.querySelector("#root > section > main > div > div > div > div.order-main > div.order-table-container > div.loading-mark-container > table > tbody > tr > td > div > div.mb10 > p")) {
//无订单
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 (document.getElementsByClassName("ant-modal-content").length) {
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.tableResult()) {
result.status = 0;
result.msg = ""
return result;
}
}
return result;
}
function delayDate(time: number) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
setTimeout(() => { fetch("https://item.upload.taobao.com/sell/v2/submit.htm", { method: "POST",body:JSON.stringify(data) }).then(res => {
//console.log(‘开始执行‘) console.log('fetch 111',res);
resolve("success"); resolve(res)
}, time);
});
}
function changeReactInputValue(inputDom:any,newText:string){
let lastValue = inputDom.value;
inputDom.value = newText;
let event = new Event('input', { bubbles: true });
// @ts-ignore
event.simulated = true;
let tracker = inputDom._valueTracker;
if (tracker) {
tracker.setValue(lastValue);
}
inputDom.dispatchEvent(event);
}
const mouseClickEvents = ['mousedown', 'click', 'mouseup'];
function simulateMouseClick(element:any){
mouseClickEvents.forEach(mouseEventType =>
element.dispatchEvent(
new MouseEvent(mouseEventType, {
view: window,
bubbles: true,
cancelable: true,
buttons: 1
}) })
) })
);
} }
export default { export default {
booking booking
} }
\ No newline at end of file
...@@ -6,16 +6,24 @@ import { message } from "antd"; ...@@ -6,16 +6,24 @@ import { message } from "antd";
import { ACTION, Print, StartPrint } from "../types"; import { ACTION, Print, StartPrint } from "../types";
import BookingV2 from "./bookingV2" import BookingV2 from "./bookingV2"
type Params = {
a: number // 运单号
b: number
}
interface Message {
action: "Print",
value: Params
}
// web页面通信 // web页面通信
window.addEventListener("message",function(message:any){ window.addEventListener("message",function(message:any){
console.log('web页面通信',message); console.log('web页面通信1',message,new Date());
if(message.data.action == ACTION.task){ if(message.data.action == ACTION.task){
chrome.runtime.sendMessage(message.data,(ret)=>{ chrome.runtime.sendMessage(message.data,(ret)=>{
// window.postMessage({isResult:1,...ret},"*") console.log(2222,ret);
console.log("message ret:",ret,message.data); window.postMessage({isResult:1,...ret},"*")
console.log("message ret:1",ret,message.data);
}) })
} }
}) })
...@@ -37,10 +45,10 @@ chrome.runtime.onMessage.addListener(function (message, sender, response) { ...@@ -37,10 +45,10 @@ chrome.runtime.onMessage.addListener(function (message, sender, response) {
* 发货易content * 发货易content
*/ */
window.addEventListener("message", function (msg) { // window.addEventListener("message", function (msg) {
console.log('发货易content',msg); // console.log('发货易content',msg,new Date());
}) // })
This diff is collapsed.
...@@ -4,4 +4,7 @@ ...@@ -4,4 +4,7 @@
overflow-y: auto; overflow-y: auto;
overflow-x: hidden; overflow-x: hidden;
margin-left: 10px; margin-left: 10px;
}
.btn{
margin: 10px 0 0 10px;
} }
\ No newline at end of file
...@@ -7,6 +7,7 @@ interface User { ...@@ -7,6 +7,7 @@ interface User {
cookie:string, cookie:string,
token:string token:string
} }
let initTime = 0
const WayBillModel = function () { const WayBillModel = function () {
// 当前是否连接成功 // 当前是否连接成功
const [link,setLink] = useState<boolean>(false) const [link,setLink] = useState<boolean>(false)
...@@ -18,6 +19,8 @@ const WayBillModel = function () { ...@@ -18,6 +19,8 @@ const WayBillModel = function () {
cookie:'', cookie:'',
token:'' token:''
}) })
// 刷新时候的状态
const [loading,setLoading] = useState<boolean>(false)
// 获取发货易快递模板列表 // 获取发货易快递模板列表
const getLogin = useCallback(async () => { const getLogin = useCallback(async () => {
chrome.tabs.query({ chrome.tabs.query({
...@@ -43,7 +46,6 @@ const WayBillModel = function () { ...@@ -43,7 +46,6 @@ const WayBillModel = function () {
// 获取用户信息 // 获取用户信息
chrome.storage.sync.get("tb_user",function(res){ chrome.storage.sync.get("tb_user",function(res){
console.log(res); console.log(res);
let userData = res.tb_user let userData = res.tb_user
if (userData == null) { if (userData == null) {
setIsLogin(false) setIsLogin(false)
...@@ -61,6 +63,9 @@ const WayBillModel = function () { ...@@ -61,6 +63,9 @@ const WayBillModel = function () {
// 刷新连接状态 // 刷新连接状态
const refresh = useCallback(() => { const refresh = useCallback(() => {
if(initTime>0)return
setLoading(true)
initTime++
getLogin() getLogin()
chrome.runtime.sendMessage({ action: 'getUserLoginData' },async()=>{ chrome.runtime.sendMessage({ action: 'getUserLoginData' },async()=>{
let userData:any = await getStorageItem("tb_user") let userData:any = await getStorageItem("tb_user")
...@@ -76,6 +81,8 @@ const WayBillModel = function () { ...@@ -76,6 +81,8 @@ const WayBillModel = function () {
setUser(userDataJson) setUser(userDataJson)
setLink(true) setLink(true)
} }
initTime = 0
setLoading(false)
}) })
// alert("刷新完毕"); // alert("刷新完毕");
}, []) }, [])
...@@ -85,7 +92,7 @@ const WayBillModel = function () { ...@@ -85,7 +92,7 @@ const WayBillModel = function () {
<div className="waybill-model-title" key="one">千牛登录账号:{is_login?user.userNick:'未登录'}</div> <div className="waybill-model-title" key="one">千牛登录账号:{is_login?user.userNick:'未登录'}</div>
<div className="waybill-model-title" key="two">通信状态:{link?'连接成功':'连接中断'}</div> <div className="waybill-model-title" key="two">通信状态:{link?'连接成功':'连接中断'}</div>
</div> </div>
<Button type="link" onClick={ refresh }>刷新连接状态</Button> <Button className="btn" type="primary" loading={loading} disabled={loading} onClick={ refresh }>刷新连接状态</Button>
</> </>
) )
} }
......
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