Commit 6a06bcb2 by 庄欣

ok

parent 69c75ee4
chrome.runtime.onMessage.addListener( chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) { function(request, sender, sendResponse) {
chrome.cookies.get({ switch (request.action) {
url: "https://www.mepai.me/", case "getAccessToken":
name: "auth" chrome.cookies.get({
}, function(cookies) { url: "https://www.mepai.me/",
var token = {access_token: cookies.value}; name: "auth"
console.log(token) }, function(cookies) {
sendResponse(token); var token = {value: cookies.value};
return true; sendResponse(token);
} return true;
); }
);
break;
case "setCookie":
chrome.cookies.set({
url: "https://www.mepai.me/",
name: request['key'],
value: request["value"],
}, function(cookies) {
return true;
}
);
break;
case "getCookie":
chrome.cookies.get({
url: "https://www.mepai.me/",
name: request['key']
}, function(cookies) {
var token = {value: cookies.value};
sendResponse(token);
return true;
}
);
break;
}
return true; return true;
} }
); );
\ No newline at end of file
...@@ -100,9 +100,8 @@ var getData = (api, data, callback) => { ...@@ -100,9 +100,8 @@ var getData = (api, data, callback) => {
return res.json() return res.json()
}).then(final => { }).then(final => {
if (final.code.toString() === "100002") { if (final.code.toString() === "100002") {
// $this.err = "请先登录,若登录账号没有操作权限,请向公司管理员申请"; alert("请先登录,若登录账号没有操作权限,请向公司管理员申请");
} else if (final.code.toString() === "100001") { return
// $this.err = "";
} }
return callback(final); return callback(final);
}).catch(e => { }).catch(e => {
...@@ -144,8 +143,10 @@ var getToday = () => { ...@@ -144,8 +143,10 @@ var getToday = () => {
} }
window.onload = function () { window.onload = function () {
chrome.runtime.sendMessage({}, function(response) { chrome.runtime.sendMessage({
ACCESS_TOKEN = response.access_token; "action": "getAccessToken"
}, function(response) {
ACCESS_TOKEN = response.value;
goNext() goNext()
}); });
} }
...@@ -198,6 +199,17 @@ function goNext() { ...@@ -198,6 +199,17 @@ function goNext() {
}); });
todayInput.value = getToday(); todayInput.value = getToday();
worksDom.value = getWorksId(); worksDom.value = getWorksId();
getCookie("default_admin", function (res) {
if (res.value != null) {
adminDom.value = res.value;
}
});
getCookie("default_status", function (res) {
if (res.value != null) {
statusDom.value = res.value;
}
});
var sendBtn = document.getElementById("send") var sendBtn = document.getElementById("send")
sendBtn.onclick = function () { sendBtn.onclick = function () {
loading(); loading();
...@@ -222,9 +234,28 @@ function goNext() { ...@@ -222,9 +234,28 @@ function goNext() {
} }
alert("操作成功"); alert("操作成功");
removeLoading(); removeLoading();
setCookie("default_admin", postData['admin_id']);
setCookie("default_status", postData['status']);
prop(); prop();
return ; return ;
}); });
} }
} }
function setCookie(key, value) {
chrome.runtime.sendMessage({
"action": "setCookie",
"value": value,
"key": key,
}, function(response) {
});
}
function getCookie(key, callback) {
chrome.runtime.sendMessage({
"action": "getCookie",
"key": key,
}, function(response) {
callback(response);
});
}
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