Commit 57a0ea77 by 庄欣

ok

parent 6a06bcb2
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
switch (request.action) {
switch (request['action']) {
case "getAccessToken":
chrome.cookies.get({
url: "https://www.mepai.me/",
name: "auth"
}, function(cookies) {
if (cookies == null) {
sendResponse({value: null});
return true;
}
var token = {value: cookies.value};
sendResponse(token);
return true;
......
......@@ -98,4 +98,18 @@
border-radius: 4px;
color: #ffffff;
margin-bottom: 20px;
}
\ No newline at end of file
}
#__extend_fast_quote #__extend_fastquote_container #_____mp_fastquote .error {
color: #ff2e2e;
font-size: 20px;
padding-left: 10px;
margin-bottom: 20px;
}
#__extend_fast_quote #__extend_fastquote_container #_____mp_fastquote .success {
color: #004cbc;
font-size: 20px;
padding-left: 10px;
}
......@@ -4,10 +4,13 @@
<img id="closeBtn" style="width: 48px;height: 48px;" >
</div>
<div class="col-12" style="padding-left: 10px">
<h4>添加有米使用记录</h4>
<h6>(有中台的请在中台标注)</h6>
</div>
<div class="error" id="error"></div>
<div class="success" id="success"></div>
<div id="main-ui">
<div class="col-12" style="padding-left: 10px">
<h4>添加有米使用记录</h4>
<h6>(有中台的请在中台标注)</h6>
</div>
<div class="form-group">
<label>作品id</label>
<input type="text" disabled id="worksId" class="form-control"/>
......@@ -34,7 +37,8 @@
<label>过审情况</label>
<select class="form-control" id="status">
<option value="0">待审核</option>
<option value="1" selected>已审核</option>
<option value="1" selected>已过审</option>
<option value="2" selected>被拒绝</option>
</select>
</div>
<div class="form-group">
......@@ -46,5 +50,5 @@
<div class="buttons form-group">
<button class="btn btn-primary" id="send">提交</button>
</div>
</div>
</div>
......@@ -74,17 +74,31 @@ function base64Decode(data) {
}
var getChannels = (callback) => {
this.getData(host + "/works/channels", {}, (res) => {
getData(host + "/works/channels", {}, (res) => {
callback(res.data);
});
}
var getManagers = (callback) => {
this.getData(host + "/user/managers", {}, (res) => {
getData(host + "/user/managers", {}, (res) => {
callback(res.data);
})
}
var addError = function(error, showUi) {
var errorDom = document.getElementById("error");
errorDom.innerHTML = error;
if (!showUi) {
var main = document.getElementById("main-ui");
main.style.display = "none";
}
}
var addSuccess = function (msg) {
var okDom = document.getElementById("success");
okDom.innerHTML = msg;
}
var getData = (api, data, callback) => {
api = api + "?";
for (var i in data) {
......@@ -100,7 +114,7 @@ var getData = (api, data, callback) => {
return res.json()
}).then(final => {
if (final.code.toString() === "100002") {
alert("请先登录,若登录账号没有操作权限,请向公司管理员申请");
addError("请先登录,若登录账号没有操作权限,请向公司管理员申请", false);
return
}
return callback(final);
......@@ -109,7 +123,6 @@ var getData = (api, data, callback) => {
});
}
var sendData = (api, data, callback) => {
var $this = this;
var header = {
method: "POST",
headers: {
......@@ -121,14 +134,12 @@ var sendData = (api, data, callback) => {
body: JSON.stringify(data)
};
fetch(api, header).then(res => {
$this.loading = false;
return res.json()
}).then(final => {
return callback(final);
})
}
var getToday = () => {
var dt = new Date();
var month = dt.getMonth() + 1;
......@@ -146,6 +157,10 @@ window.onload = function () {
chrome.runtime.sendMessage({
"action": "getAccessToken"
}, function(response) {
if (response == null || response.value == null) {
addError("请先登录,若登录账号没有操作权限,请向公司管理员申请", false);
return
}
ACCESS_TOKEN = response.value;
goNext()
});
......@@ -171,7 +186,6 @@ function removeLoading() {
}
function goNext() {
var todayInput = document.getElementById("today");
var channelDom = document.getElementById("channelId");
var adminDom = document.getElementById("admins");
......@@ -186,6 +200,11 @@ function goNext() {
d.value = channels[i].channel_id;
d.innerHTML = channels[i].name;
channelDom.appendChild(d)
getCookie("default_channel", function (res) {
if (res.value != null) {
channelDom.value = res.value;
}
});
}
});
getManagers(function(res) {
......@@ -195,16 +214,15 @@ function goNext() {
d.value = managers[i].id;
d.innerHTML = managers[i].name;
adminDom.appendChild(d)
getCookie("default_admin", function (res) {
if (res.value != null) {
adminDom.value = res.value;
}
});
}
});
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;
......@@ -223,20 +241,20 @@ function goNext() {
"works_id": worksDom.value,
};
if (isNaN(postData['works_id']) || postData['works_id'] <= 0) {
alert("作品id解析失败")
addError("作品id解析失败", true)
return
}
sendData(host + "/works/pushrecord", postData, (res) => {
if (res.code.toString() !== "100001") {
alert(res.message);
addError(res.message, true);
removeLoading();
return;
}
alert("操作成功");
addSuccess("操作成功,已添加到后台推送记录");
removeLoading();
setCookie("default_admin", postData['admin_id']);
setCookie("default_status", postData['status']);
prop();
setCookie("default_channel", postData['channel_id']);
return ;
});
}
......
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