Commit 2e9e01f8 authored by 刘燕芳's avatar 刘燕芳

save

parent d4411315
import { factoryContentUrls,bookingV2Urls,homeUrl,tmIssueUrl,tbIssueUrl } from "../config"; import { Tabs } from "antd";
import { factoryContentUrls,bookingV2Urls,homeUrl,tmIssueUrl,tbIssueUrl,tbIssueUrls } from "../config";
import { StartPrint, Print, ACTION } from "../types"; import { StartPrint, Print, ACTION } from "../types";
const tmNameSiffix = ['旗舰店', '专卖店', '专营店'] const tmNameSiffix = ['旗舰店', '专卖店', '专营店']
// platform: PlatformCode,// 平台编码,淘系及其他平台订单模板的为0,拼多多订单的为1,京东订单的为2 // platform: PlatformCode,// 平台编码,淘系及其他平台订单模板的为0,拼多多订单的为1,京东订单的为2
...@@ -10,37 +11,33 @@ const PlatfromsMap = new Map([ ...@@ -10,37 +11,33 @@ const PlatfromsMap = new Map([
]) ])
let monitoringRemoveTabId = new Map(); let monitoringRemoveTabId = new Map();
let result_sendResponse:boolean = false let result_sendResponse:boolean = false
let tb_user:any = {}
let taIssueId:any = null
chrome.runtime.onMessage.addListener(async function (message, sender, sendResponse) { chrome.runtime.onMessage.addListener(async function (message, sender, sendResponse) {
console.log('message',message);
if (message.action === ACTION.task) { if (message.action === ACTION.task) {
// 如果图动力登录的账号和千牛云登录的账号不一致,则popup页面爆红 if (JSON.stringify(tb_user) === "{}") {
let userData:any = await getStorageItem('tb_user')
console.log('111userData',userData);
sendResponse(11111);
if (userData == null) {
// alert('请登录千牛商家工作台')
chrome.storage.sync.set({"info":'当前千牛登录账号信息获取失败'}) chrome.storage.sync.set({"info":'当前千牛登录账号信息获取失败'})
sendResponse({status:-200,msg:"当前千牛登录账号信息获取失败,请登录千牛账号后重试!"}); sendResponse({status:-200,task_id:message.value.task_id,msg:"当前千牛登录账号信息获取失败,请登录千牛账号后重试!"});
return true; return true
}else{ }else{
chrome.storage.sync.remove("info") chrome.storage.sync.remove("info")
let userDataJson:any = JSON.parse(userData) if(message.value.seller.seller_name!==tb_user.userNick){
if(message.value.seller!==userDataJson.userNick){ chrome.storage.sync.set({"info":'当前登录的千牛账号与图动力授权的账号信息不一致,请统一登录后重试!'})
chrome.storage.sync.set({"info":'当前登录的千牛账号与图动力登录的账号信息不一致,请统一登录后重试!'}) sendResponse({status:-200,task_id:message.value.task_id,msg:"当前登录的千牛账号与图动力授权的账号信息不一致,请统一登录后重试!"});
console.log(222,new Date().getTime(),new Date().getSeconds()); return true
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: ['https://item.upload.taobao.com/sell/merge/category.htm*'] url:tbIssueUrls
},async function (tabs) { },async function (tabs) {
console.log(tabs); // 如果图动力登录的账号和千牛云登录的账号不一致,则popup页面爆红
console.log('tabs',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('res',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) {});
...@@ -48,13 +45,13 @@ chrome.runtime.onMessage.addListener(async function (message, sender, sendRespon ...@@ -48,13 +45,13 @@ chrome.runtime.onMessage.addListener(async function (message, sender, sendRespon
}) })
}) })
if(tabs.length==0){ if(tabs.length==0){
sendResponse({status:-200,msg:"请打开千牛商家工作台"}); sendResponse({status:-200,task_id:message.value.task_id,msg:"请打开千牛商家工作台"});
alert('请打开千牛商家工作台') alert('请打开千牛商家工作台')
} }
}) })
// let port = chrome.runtime.connect({ name: "bgSendMessage" })
// port.postMessage(message)
}else if(message.action==='getUserLoginData'){ }else if(message.action==='getUserLoginData'){
console.log(2222);
await getUserLoginData() await getUserLoginData()
sendResponse() sendResponse()
} }
...@@ -72,7 +69,6 @@ chrome.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => { ...@@ -72,7 +69,6 @@ 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) {
...@@ -82,15 +78,23 @@ chrome.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => { ...@@ -82,15 +78,23 @@ 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
}; };
chrome.tabs.query({
url:[tbIssueUrl]
},async function (tabs) {
console.log(tabs);
if(!tabs.length||(tabs.length&&!monitoringRemoveTabId.has(tabs[0].id))){
taIssueId = await createTab(tbIssueUrl);
}
})
let tuDe1 = decodeURI(userNickCookie.value); let tuDe1 = decodeURI(userNickCookie.value);
let tuDe2 = unescape(tuDe1.replace(/\\(u[0-9a-fA-F]{4})/gm, '%$1')); let tuDe2 = unescape(tuDe1.replace(/\\(u[0-9a-fA-F]{4})/gm, '%$1'));
if (tuDe2.indexOf(":") != -1) tuDe2 = tuDe2.split(":")[0]; if (tuDe2.indexOf(":") != -1) tuDe2 = tuDe2.split(":")[0];
let createUrl = isTm(tuDe2) ? tmIssueUrl : tbIssueUrl; let createUrl = isTm(tuDe2) ? tmIssueUrl : tbIssueUrl;
let tabId = await createTab(createUrl); let tabId = await createTab(createUrl);
monitoringRemoveTabId.set(tabId, tuDe2); monitoringRemoveTabId.set(tabId, tuDe2);
} }
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)) {
...@@ -104,6 +108,7 @@ chrome.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => { ...@@ -104,6 +108,7 @@ chrome.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => {
token: token.value, token: token.value,
userNick: userNick, userNick: userNick,
} }
tb_user = userData
chrome.storage.sync.set({"tb_user":JSON.stringify(userData)}) 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;
...@@ -131,6 +136,10 @@ chrome.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => { ...@@ -131,6 +136,10 @@ chrome.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => {
async function getUserLoginData(){ async function getUserLoginData(){
result_sendResponse = false result_sendResponse = false
monitoringRemoveTabId.clear()
console.log('taIssueId',taIssueId);
taIssueId&&chrome.tabs.remove(taIssueId);
let tabId = await createTab(homeUrl); let tabId = await createTab(homeUrl);
monitoringRemoveTabId.set(tabId, ""); monitoringRemoveTabId.set(tabId, "");
await newTab() await newTab()
...@@ -200,11 +209,13 @@ function isTm(userNick:string) { ...@@ -200,11 +209,13 @@ function isTm(userNick:string) {
} }
return false; return false;
} }
function getStorageItem(key:string) { function getLocalStronges(url:string, name:string){
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
chrome.storage.sync.get([key], (item) => { chrome.storage.local.get({
resolve(item[key]); url: url,
name: name
}, (cookies) => {
resolve(cookies);
}) })
}) })
} }
export const factoryContentUrls = ["http://localhost:10823/*", "*://*.rtxmdz.com/*"] export const factoryContentUrls = ["http://localhost:10823/*", "*://*.rtxmdz.com/*"]
export const bookingV2Urls=["https://myseller.taobao.com/*","https://loginmyseller.taobao.com/*"] export const bookingV2Urls=["https://myseller.taobao.com/*","https://loginmyseller.taobao.com/*"]
export const tbIssueUrls=["https://item.upload.taobao.com/sell/merge/category.htm*"]
export const homeUrl = "https://myseller.taobao.com/home.htm/QnworkbenchHome"; export const homeUrl = "https://myseller.taobao.com/home.htm/QnworkbenchHome";
export const tbIssueUrl = "https://item.upload.taobao.com/sell/merge/category.htm" export const tbIssueUrl = "https://item.upload.taobao.com/sell/merge/category.htm"
export const tmIssueUrl = "https://sell.publish.tmall.com/tmall/smart/category.htm" export const tmIssueUrl = "https://sell.publish.tmall.com/tmall/smart/category.htm"
\ No newline at end of file
...@@ -8,11 +8,11 @@ async function booking(info: any) { ...@@ -8,11 +8,11 @@ async function booking(info: any) {
let reqMsg = { let reqMsg = {
msg:'', msg:'',
status:-200, status:-200,
task_id:'' task_id:info.task_id
}; };
if(!userData){ if(!userData){
reqMsg.msg = "请刷新连接"; reqMsg.msg = "请刷新连接";
return return reqMsg
} }
let userDataJson:any = JSON.parse(userData) let userDataJson:any = JSON.parse(userData)
let {data:result} = await axios.post('https://item.upload.taobao.com/sell/v2/submit.htm', data, { let {data:result} = await axios.post('https://item.upload.taobao.com/sell/v2/submit.htm', data, {
...@@ -40,10 +40,11 @@ async function booking(info: any) { ...@@ -40,10 +40,11 @@ async function booking(info: any) {
if (rType != "status") { if (rType != "status") {
let msg = JSON.stringify(rJson.models); let msg = JSON.stringify(rJson.models);
reqMsg.msg = msg; reqMsg.msg = msg;
} else {
let numIid = getUrlParam(rSuccessUrl, "primaryId");
reqMsg.task_id = numIid;
} }
// else {
// let numIid = getUrlParam(rSuccessUrl, "primaryId");
// reqMsg.goods_id = numIid;
// }
} }
return reqMsg return reqMsg
} catch (e) { } catch (e) {
...@@ -52,13 +53,6 @@ async function booking(info: any) { ...@@ -52,13 +53,6 @@ async function booking(info: any) {
return reqMsg 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) { function getStorageItem(key:string) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
chrome.storage.sync.get([key], (item) => { chrome.storage.sync.get([key], (item) => {
...@@ -94,5 +88,5 @@ function delayDate(time: number) { ...@@ -94,5 +88,5 @@ function delayDate(time: number) {
} }
export default { export default {
booking,bookingV2 booking
} }
\ No newline at end of file
...@@ -33,8 +33,8 @@ chrome.runtime.onMessage.addListener(function (message, sender, response) { ...@@ -33,8 +33,8 @@ 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);
console.log(2222,result,new Date().getTime(),new Date().getSeconds());
response(result); response(result);
})(); })();
} }
......
...@@ -51,6 +51,7 @@ const WayBillModel = function () { ...@@ -51,6 +51,7 @@ const WayBillModel = function () {
let userData = res.tb_user let userData = res.tb_user
if (userData == null) { if (userData == null) {
setIsLogin(false) setIsLogin(false)
setLink(false)
setUser({userNick: '', setUser({userNick: '',
cookie:'', cookie:'',
token:''}) token:''})
...@@ -85,6 +86,7 @@ const WayBillModel = function () { ...@@ -85,6 +86,7 @@ const WayBillModel = function () {
console.log('userData',userData,new Date().getMinutes(),new Date().getSeconds()); console.log('userData',userData,new Date().getMinutes(),new Date().getSeconds());
if (userData == null) { if (userData == null) {
setIsLogin(false) setIsLogin(false)
setLink(false)
setUser({userNick: '', setUser({userNick: '',
cookie:'', cookie:'',
token:''}) token:''})
......
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