Skip to content

Commit

Permalink
增加Inner Notification
Browse files Browse the repository at this point in the history
  • Loading branch information
adlered committed Nov 7, 2019
1 parent eb110a4 commit 37344ad
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 26 deletions.
37 changes: 30 additions & 7 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/main/java/pers/adlered/picuang/prop/Prop.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Prop {
properties.load(new BufferedInputStream(new FileInputStream("config.ini")));
} catch (FileNotFoundException e) {
properties.put("imageUploadedCount", "0");
properties.put("version", "V2.0");
properties.put("version", "V2.1");
try {
properties.store(new BufferedOutputStream(new FileOutputStream("config.ini")), "Save Configs File.");
} catch (FileNotFoundException FNFE) {
Expand All @@ -39,7 +39,7 @@ public static String get(String key) {
public static void set(String key, String value) {
try {
properties.setProperty(key, value);
System.out.println("[Prop] set key '" + key + "' to value '" + value + "'");
System.out.println("[Prop] Set key '" + key + "' to value '" + value + "'");
PrintWriter printWriter = new PrintWriter(new FileWriter("config.ini"), true);
Set set = properties.keySet();
for (Object object : set) {
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/static/js/d-toast.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 12 additions & 11 deletions src/main/resources/static/js/user/common-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sourceAll = undefined;

function stopUploadThreads() {
sourceAll.cancel('Operation canceled by the user.');
$("#status").html("");
sendStatus("");
change(0);
tempCount = 0;
queue = 0;
Expand All @@ -18,11 +18,11 @@ function clone() {
axios.post('/clone', param, {})
.then(function (response) {
if (response.data.code == 200) {
$("#status").html("克隆成功!");
sendStatus("克隆成功!");
sendNotify("图片克隆已完成。");
responseHandler(response);
} else {
$("#status").html("克隆失败!原因:" + response.data.msg);
sendStatus("克隆失败!原因:" + response.data.msg);
sendNotify("图片克隆失败。");
}
}
Expand All @@ -42,7 +42,7 @@ function upload() {
if (suffixName == "jpeg" || suffixName == "jpg" || suffixName == "png" || suffixName == "gif" || suffixName == "svg") {
uploadToServer(file);
} else {
alert(file.name + " 格式不受支持,将跳过该图片的上传。(其它图片不受影响)");
sendInnerNotify(file.name + " 格式不受支持,将跳过该图片的上传。(其它图片不受影响)");
}
}
}
Expand All @@ -63,7 +63,7 @@ function uploadToServer(file) {
onUploadProgress: function (progressEvent) {
if (progressEvent.lengthComputable) {
progress = progressEvent.loaded / progressEvent.total * 100 | 0;
$("#status").html('<button onclick="stopUploadThreads()" class="btn btn-info">终止上传</button><br><br>多线程传输中<br><strong>队列:' + queue + '</strong><br>' + file.name + ':' + progress + '%');
sendStatus('<button onclick="stopUploadThreads()" class="btn btn-info">终止上传</button><br><br>多线程传输中<br><strong>队列:' + queue + '</strong><br>' + file.name + ':' + progress + '%');
change(progress);
}
},
Expand All @@ -75,10 +75,11 @@ function uploadToServer(file) {
.then(function (response) {
change(0);
responseHandler(response);
sendStatus('<button onclick="stopUploadThreads()" class="btn btn-info">终止上传</button><br><br>多线程传输中<br><strong>队列:' + queue + '</strong><br>' + file.name + ':' + progress + '%');
--queue;
if (queue == 0) {
sendNotify(tempCount + "张图片已上传成功。");
$("#status").html("<strong>" + tempCount + "张</strong> 图片已全部传输完毕。");
sendStatus("<strong>" + tempCount + "张</strong> 图片已全部传输完毕。");
tempCount = 0;
}
sourceAll = undefined;
Expand All @@ -88,18 +89,18 @@ function uploadToServer(file) {
console.log('Request canceled', reason.message);
} else {
change(0);
$("#status").html("您的图片大小超过限制:(");
sendStatus("您的图片大小超过限制:(");
--queue;
if (queue == 0) {
sendNotify(tempCount + "张图片已上传成功,部分图片超出大小限制。");
$("#status").html("<strong>" + tempCount + "张</strong> 图片部分传输成功。(部分图片大小超过限制)");
sendStatus("<strong>" + tempCount + "张</strong> 图片部分传输成功。(部分图片大小超过限制)");
tempCount = 0;
}
}
sourceAll = undefined;
});
} else {
alert(file.name + " 文件大小为" + size + "MB,超过限制的" + picLimit + "MB,将跳过传输!(其它图片不受影响)");
sendInnerNotify(file.name + " 文件大小为" + size + "MB,超过限制的" + picLimit + "MB,将跳过传输!(其它图片不受影响)");
}
}

Expand All @@ -114,10 +115,10 @@ function responseHandler(response) {
$("#links").css("display", "block");
break;
case 406:
$("#status").html("未选择图片,请重试。");
sendStatus("未选择图片,请重试。");
break;
case 500:
$("#status").html("图片错误,服务器拒绝解析!请检查图片格式。");
sendStatus("图片错误,服务器拒绝解析!请检查图片格式。");
break;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/static/js/user/drag-and-drop.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
$(function () {
var oDiv = $("html").get(0);
oDiv.ondragenter = function () {
$("#dragToUploadInformation").css("display", "block");
$("#dragToUploadInformation").show(1000);
setTimeout(function () {
$("#dragToUploadInformation").css("display", "none");
$("#dragToUploadInformation").hide(1000);
}, 2000);
};
oDiv.ondragover = function (e) {
Expand All @@ -22,7 +22,7 @@ $(function () {
if (suffixName == "jpeg" || suffixName == "jpg" || suffixName == "png" || suffixName == "gif" || suffixName == "svg") {
uploadToServer(fs[i]);
} else {
alert(fs[i].name + " 格式不受支持,将跳过该图片的上传。(其它图片不受影响)");
sendInnerNotify(fs[i].name + " 格式不受支持,将跳过该图片的上传。(其它图片不受影响)");
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions src/main/resources/static/js/user/notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ $(function () {

function sendNotify(str) {
if (window.Notification.permission === "granted") {
// Chrome提醒
var title = "Picuang图床 - 提醒";
var option = {
body: str,
Expand All @@ -15,3 +16,19 @@ function sendNotify(str) {
};
}
}

function sendInnerNotify(str) {
// 页内提醒
var config = {
title: "Picuang图床 - 提醒",
body: str,
inner: true,
icon: "/favicon.png",
onclick: function (data) {}
};
new dToast(config);
}

function sendStatus(str) {
$("#status").html(str);
}
4 changes: 2 additions & 2 deletions src/main/resources/static/js/user/on-paste.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ document.getElementsByTagName('html')[0].addEventListener('paste', function (e)
file = new File([file], filename, {type: file.type});
} catch (e) {
if (file.name != null) {
alert(file.name + " 格式不受支持将跳过该图片的上传");
sendInnerNotify(file.name + " 格式不受支持将跳过该图片的上传");
} else {
alert(filename + " 格式不受支持将跳过该图片的上传。");
sendInnerNotify(filename + " 格式不受支持将跳过该图片的上传。");
}
}
}
Expand Down
Loading

0 comments on commit 37344ad

Please sign in to comment.