Commit 6a06bcb2 by 庄欣

ok

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