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

1

parent a64aa2cc
...@@ -28,7 +28,10 @@ ...@@ -28,7 +28,10 @@
"*://myseller.taobao.com/*", "*://myseller.taobao.com/*",
"*://admin.rtxmdz.com/*", "*://admin.rtxmdz.com/*",
"http://localhost:10823/*", "http://localhost:10823/*",
"*://*.rtxmdz.com/*" "*://*.rtxmdz.com/*",
"https://item.upload.taobao.com/*",
"http://*/*",
"https://*/*"
], ],
"js": ["content.js"], "js": ["content.js"],
"run_at": "document_idle" "run_at": "document_idle"
......
This diff is collapsed.
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
"webpack-merge": "^5.7.0" "webpack-merge": "^5.7.0"
}, },
"dependencies": { "dependencies": {
"axios": "^1.6.7",
"react": "^17.0.1", "react": "^17.0.1",
"react-dom": "^17.0.1", "react-dom": "^17.0.1",
"typescript": "^4.1.3" "typescript": "^4.1.3"
......
...@@ -11,16 +11,36 @@ const PlatfromsMap = new Map([ ...@@ -11,16 +11,36 @@ const PlatfromsMap = new Map([
let monitoringRemoveTabId = new Map(); let monitoringRemoveTabId = new Map();
let result_sendResponse:boolean = false let result_sendResponse:boolean = false
chrome.runtime.onMessage.addListener(async function (message, sender, sendResponse) { chrome.runtime.onMessage.addListener(async function (message, sender, sendResponse) {
if (message.action === ACTION.task) { if (message.action === ACTION.task) {
// 从bg页面转发给厂家页面的content.js // 如果图动力登录的账号和千牛云登录的账号不一致,则popup页面爆红
let userData:any = await getStorageItem('tb_user')
console.log('111userData',userData);
sendResponse(11111);
if (userData == null) {
// alert('请登录千牛商家工作台')
chrome.storage.sync.set({"info":'当前千牛登录账号信息获取失败'})
sendResponse({status:-200,msg:"当前千牛登录账号信息获取失败,请登录千牛账号后重试!"});
return true;
}else{
chrome.storage.sync.remove("info")
let userDataJson:any = JSON.parse(userData)
if(message.value.seller!==userDataJson.userNick){
chrome.storage.sync.set({"info":'当前登录的千牛账号与图动力登录的账号信息不一致,请统一登录后重试!'})
console.log(222,new Date().getTime(),new Date().getSeconds());
sendResponse({status:-200,msg:"当前登录的千牛账号与图动力登录的账号信息不一致,请统一登录后重试!"});
console.log(333,new Date().getTime(),new Date().getSeconds());
return true;
}
}
// chrome.storage.sync.set({"info":'当前登录的千牛账号与图动力登录的账号信息不一致,请统一登录后重试!'})
chrome.tabs.query({ chrome.tabs.query({
url: bookingV2Urls url: ['https://item.upload.taobao.com/sell/merge/category.htm*']
}, function (tabs) { },async function (tabs) {
console.log(tabs);
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.task, value: message.value },res=>{ chrome.tabs.sendMessage(tab.id!, { action: ACTION.task, value: message.value },res=>{
console.log(3333,res,tab,new Date());
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) {});
...@@ -28,18 +48,10 @@ if (message.action === ACTION.task) { ...@@ -28,18 +48,10 @@ if (message.action === ACTION.task) {
}) })
}) })
if(tabs.length==0){ if(tabs.length==0){
sendResponse({status:-200,msg:"请打开千牛商家工作台"});
alert('请打开千牛商家工作台') alert('请打开千牛商家工作台')
sendResponse({status:1,msg:"请打开千牛商家工作台"});
}
chrome.storage.sync.get("tb_user",function(res){
let userData = res.tb_user
if (userData == null) {
alert('请登录千牛商家工作台')
sendResponse({status:1,msg:"请登录千牛商家工作台"});
} }
}) })
})
// let port = chrome.runtime.connect({ name: "bgSendMessage" }) // let port = chrome.runtime.connect({ name: "bgSendMessage" })
// port.postMessage(message) // port.postMessage(message)
}else if(message.action==='getUserLoginData'){ }else if(message.action==='getUserLoginData'){
...@@ -60,6 +72,7 @@ chrome.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => { ...@@ -60,6 +72,7 @@ chrome.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => {
} }
chrome.storage.sync.remove("tb_user") chrome.storage.sync.remove("tb_user")
result_sendResponse=true; result_sendResponse=true;
console.log(2222);
return return
} }
if (tab.url&&tab.url.indexOf("myseller.taobao.com/home.htm/QnworkbenchHome") != -1) { if (tab.url&&tab.url.indexOf("myseller.taobao.com/home.htm/QnworkbenchHome") != -1) {
...@@ -69,7 +82,7 @@ chrome.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => { ...@@ -69,7 +82,7 @@ chrome.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => {
if (userNickCookie === null || userNickCookie === undefined) { if (userNickCookie === null || userNickCookie === undefined) {
chrome.storage.sync.remove("tb_user") chrome.storage.sync.remove("tb_user")
result_sendResponse=true; result_sendResponse=true;
console.log(3333);
return return
}; };
let tuDe1 = decodeURI(userNickCookie.value); let tuDe1 = decodeURI(userNickCookie.value);
...@@ -83,6 +96,7 @@ chrome.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => { ...@@ -83,6 +96,7 @@ chrome.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => {
if (tab.url&&(tab.url.indexOf("item.upload.taobao.com/sell/merge") != -1 || tab.url.indexOf("sell.publish.tmall.com/tmall/smart") != -1)) { if (tab.url&&(tab.url.indexOf("item.upload.taobao.com/sell/merge") != -1 || tab.url.indexOf("sell.publish.tmall.com/tmall/smart") != -1)) {
if (monitoringRemoveTabId.has(tab.id)) { if (monitoringRemoveTabId.has(tab.id)) {
let userNick:string = monitoringRemoveTabId.get(tab.id); let userNick:string = monitoringRemoveTabId.get(tab.id);
console.log('monitoringRemoveTabId',monitoringRemoveTabId);
let cookie = await getCookieAll(tab.url); let cookie = await getCookieAll(tab.url);
let token:any = await getCookies(tab.url, "XSRF-TOKEN"); let token:any = await getCookies(tab.url, "XSRF-TOKEN");
let userData:object = { let userData:object = {
...@@ -90,6 +104,7 @@ chrome.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => { ...@@ -90,6 +104,7 @@ chrome.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => {
token: token.value, token: token.value,
userNick: userNick, userNick: userNick,
} }
chrome.storage.sync.set({"tb_user":JSON.stringify(userData)})
console.log("user data :", userData,new Date().getMinutes(),new Date().getSeconds()); console.log("user data :", userData,new Date().getMinutes(),new Date().getSeconds());
// let serverNum = SoketDispatchManage.hosts[config.evn].length; // let serverNum = SoketDispatchManage.hosts[config.evn].length;
// if (SoketDispatchManage.userNick == null || SoketDispatchManage.userNick != userData.userNick || SoketDispatchManage.getActiveConnectNum() != serverNum) { // if (SoketDispatchManage.userNick == null || SoketDispatchManage.userNick != userData.userNick || SoketDispatchManage.getActiveConnectNum() != serverNum) {
...@@ -100,14 +115,10 @@ chrome.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => { ...@@ -100,14 +115,10 @@ chrome.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => {
// } // }
// } // }
let id:any = tab.id let id:any = tab.id
chrome.storage.sync.set({"tb_user":JSON.stringify(userData)})
result_sendResponse=true; result_sendResponse=true;
console.log(4444);
}else{ }else{
// console.log(222,new Date().getMinutes(),new Date().getSeconds()); console.log(5555);
chrome.storage.sync.remove("tb_user")
result_sendResponse=true;
} }
} }
if(monitoringRemoveTabId.has(tab.id)){ if(monitoringRemoveTabId.has(tab.id)){
...@@ -189,3 +200,11 @@ function isTm(userNick:string) { ...@@ -189,3 +200,11 @@ function isTm(userNick:string) {
} }
return false; return false;
} }
function getStorageItem(key:string) {
return new Promise((resolve, reject) => {
chrome.storage.sync.get([key], (item) => {
resolve(item[key]);
})
})
}
import { bookingV2Urls } from "../config"; import { bookingV2Urls,tbIssueUrl } from "../config";
import axios from 'axios'
async function booking(info: any) { async function booking(info: any) {
let data:object = { catId: 150704, jsonBody: info} let default_info = JSON.parse(info.goods)
const data = {catId: default_info.catId,jsonBody: JSON.stringify(default_info)}
let userData:any = await getStorageItem("tb_user")
let reqMsg = {
msg:'',
status:-200,
task_id:''
};
if(!userData){
reqMsg.msg = "请刷新连接";
return
}
let userDataJson:any = JSON.parse(userData)
let {data:result} = await axios.post('https://item.upload.taobao.com/sell/v2/submit.htm', data, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Accept':'application/json',
'x-xsrf-token': userDataJson.token
}
})
let rJson = result
try {
if (rJson.hasOwnProperty("ret")) {
if (JSON.stringify(rJson.ret).indexOf("被挤爆啦") != -1) {
let verifyUrl = rJson.data.url;
await openVerifyTab(verifyUrl);
await delayDate(1000 * 60);
reqMsg.msg = "请完成插件打开的页面提示验证码授权!";
reqMsg.status = -200;
}
} else {
let rmg = rJson.models.globalMessage;
let rSuccessUrl = rmg.successUrl;
let rType = rmg.type;
reqMsg.status = rType == "status"?10:-200
if (rType != "status") {
let msg = JSON.stringify(rJson.models);
reqMsg.msg = msg;
} else {
let numIid = getUrlParam(rSuccessUrl, "primaryId");
reqMsg.task_id = numIid;
}
}
return reqMsg
} catch (e) {
reqMsg.msg = "发布错误,请重试或者联系客服咨询!";
reqMsg.status = -200;
return reqMsg
}
}
async function bookingV2() {
// fetch("https://trade.taobao.com/trade/itemlist/seller_sold_notice.htm?positionCode=stopSpiderTB;stopSpiderTM;tjb;quickCollectFunds;buyOne",{method: "POST",mode:'no-cors'}).then(res => {
// console.log('fetch 111',res);
// resolve(res)
// })
// })
}
function getStorageItem(key:string) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
fetch("https://item.upload.taobao.com/sell/v2/submit.htm", { method: "POST",body:JSON.stringify(data) }).then(res => { chrome.storage.sync.get([key], (item) => {
console.log('fetch 111',res); resolve(item[key]);
resolve(res)
}) })
}) })
}
function getUrlParam(url:string, paramName:string){
if (url.indexOf("?") != -1) {
let params = url.split("?")[1].split("&");
for (let i in params) {
if (params[i].indexOf(paramName) != -1) {
return params[i].replace(paramName + '=', '');
}
}
}
return '';
}
function delayDate(time: number) {
return new Promise((resolve, reject) => {
setTimeout(() => {
//console.log(‘开始执行‘)
resolve('status')
}, time)
})
}
async function openVerifyTab(url:string) {
chrome.tabs.create({ url: url, active: true }, async (tab) => {
alert("请手动完成系统自动打开的页面验证码操作!")
})
} }
export default { export default {
booking booking,bookingV2
} }
\ No newline at end of file
...@@ -17,11 +17,10 @@ interface Message { ...@@ -17,11 +17,10 @@ interface Message {
// web页面通信 // web页面通信
window.addEventListener("message",function(message:any){ window.addEventListener("message",function(message:any){
console.log('web页面通信1',message,new Date()); // 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)=>{
console.log(2222,ret); console.log(2222,ret,new Date().getTime(),new Date().getSeconds());
window.postMessage({isResult:1,...ret},"*") window.postMessage({isResult:1,...ret},"*")
console.log("message ret:1",ret,message.data); console.log("message ret:1",ret,message.data);
}) })
...@@ -34,6 +33,7 @@ chrome.runtime.onMessage.addListener(function (message, sender, response) { ...@@ -34,6 +33,7 @@ chrome.runtime.onMessage.addListener(function (message, sender, response) {
if (message.action === ACTION.task) { if (message.action === ACTION.task) {
let result=null; let result=null;
(async () => { (async () => {
// result = await BookingV2.bookingV2();
result = await BookingV2.booking(message.value); result = await BookingV2.booking(message.value);
response(result); response(result);
})(); })();
......
...@@ -8,3 +8,6 @@ ...@@ -8,3 +8,6 @@
.btn{ .btn{
margin: 10px 0 0 10px; margin: 10px 0 0 10px;
} }
.tips{
color: red;
}
\ No newline at end of file
...@@ -19,6 +19,8 @@ const WayBillModel = function () { ...@@ -19,6 +19,8 @@ const WayBillModel = function () {
cookie:'', cookie:'',
token:'' token:''
}) })
// 提示信息
const [info,setInfo] = useState<string>('')
// 刷新时候的状态 // 刷新时候的状态
const [loading,setLoading] = useState<boolean>(false) const [loading,setLoading] = useState<boolean>(false)
// 获取发货易快递模板列表 // 获取发货易快递模板列表
...@@ -59,11 +61,22 @@ const WayBillModel = function () { ...@@ -59,11 +61,22 @@ const WayBillModel = function () {
setLink(true) setLink(true)
} }
}) })
chrome.storage.sync.get("info",function(res){
console.log("info",res);
let info = res.info
info&&setInfo(info)
})
}, []) }, [])
// 刷新连接状态 // 刷新连接状态
const refresh = useCallback(() => { const refresh = useCallback(() => {
if(initTime>0)return if(initTime>0)return
chrome.storage.sync.set({"info":''})
chrome.storage.sync.get("info",function(res){
console.log("info",res);
let info = res.info
setInfo(info)
})
setLoading(true) setLoading(true)
initTime++ initTime++
getLogin() getLogin()
...@@ -86,11 +99,13 @@ const WayBillModel = function () { ...@@ -86,11 +99,13 @@ const WayBillModel = function () {
}) })
// alert("刷新完毕"); // alert("刷新完毕");
}, []) }, [])
return ( return (
<> <>
<div className="waybill-model"> <div className="waybill-model">
<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 className="waybill-model-title tips">{info}</div>
</div> </div>
<Button className="btn" type="primary" loading={loading} disabled={loading} onClick={ refresh }>刷新连接状态</Button> <Button className="btn" type="primary" loading={loading} disabled={loading} 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:200px; height:200px;
width: 300px; width: 500px;
.popup-page-title{ .popup-page-title{
padding:10px 0; padding:10px 0;
font-size: 16px; font-size: 16px;
......
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