mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-16 17:10:53 +08:00
This commit is contained in:
parent
722fba283f
commit
0bf884ec9e
@ -27,12 +27,13 @@ export const initMessage = () => {
|
||||
|
||||
// type: info/error; timeout: 0 手动关闭;-1 用不关闭
|
||||
export const showMessage = (message: string, timeout = 6000, type = "info", messageId?: string) => {
|
||||
const messageVersion = message + (type === "error" ? " v" + Constants.SIYUAN_VERSION : "");
|
||||
const id = messageId || genUUID();
|
||||
const messagesElement = document.getElementById("message").firstElementChild;
|
||||
const existElement = messagesElement.querySelector(`.b3-snackbar[data-id="${id}"]`);
|
||||
if (existElement) {
|
||||
window.clearTimeout(parseInt(existElement.getAttribute("data-timeoutid")));
|
||||
existElement.innerHTML = `<div class="b3-snackbar__content${timeout === 0 ? " b3-snackbar__content--close" : ""}">${message}</div>${timeout === 0 ? '<svg class="b3-snackbar__close"><use xlink:href="#iconCloseRound"></use></svg>' : ""}`;
|
||||
existElement.innerHTML = `<div class="b3-snackbar__content${timeout === 0 ? " b3-snackbar__content--close" : ""}">${messageVersion}</div>${timeout === 0 ? '<svg class="b3-snackbar__close"><use xlink:href="#iconCloseRound"></use></svg>' : ""}`;
|
||||
if (type === "error") {
|
||||
existElement.classList.add("b3-snackbar--error");
|
||||
} else {
|
||||
@ -46,7 +47,7 @@ export const showMessage = (message: string, timeout = 6000, type = "info", mess
|
||||
}
|
||||
return;
|
||||
}
|
||||
let messageHTML = `<div data-id="${id}" class="b3-snackbar--hide b3-snackbar${type === "error" ? " b3-snackbar--error" : ""}"><div class="b3-snackbar__content${timeout === 0 ? " b3-snackbar__content--close" : ""}">${message}</div>`;
|
||||
let messageHTML = `<div data-id="${id}" class="b3-snackbar--hide b3-snackbar${type === "error" ? " b3-snackbar--error" : ""}"><div class="b3-snackbar__content${timeout === 0 ? " b3-snackbar__content--close" : ""}">${messageVersion}</div>`;
|
||||
if (timeout === 0) {
|
||||
messageHTML += '<svg class="b3-snackbar__close"><use xlink:href="#iconCloseRound"></use></svg>';
|
||||
} else if (timeout !== -1) { // -1 时需等待请求完成后手动关闭
|
||||
|
Loading…
Reference in New Issue
Block a user