mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 23:20:13 +01:00
🐛 export msg
This commit is contained in:
parent
23ad748535
commit
432fe6be1e
5 changed files with 23 additions and 20 deletions
|
|
@ -166,8 +166,7 @@ export const exportConfig = {
|
|||
fetchPost("/api/export/exportDataInFolder", {
|
||||
folder: result.filePath
|
||||
}, () => {
|
||||
hideMessage(id);
|
||||
afterExport(result.filePath);
|
||||
afterExport(result.filePath, id);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -33,15 +33,23 @@ export const showMessage = (message: string, timeout = 6000, type = "info", mess
|
|||
const existElement = messagesElement.querySelector(`.b3-snackbar[data-id="${id}"]`)
|
||||
if (existElement) {
|
||||
existElement.firstElementChild.innerHTML = message;
|
||||
window.clearTimeout(parseInt(existElement.getAttribute("data-timeoutid")));
|
||||
if (timeout > 0) {
|
||||
const timeoutId = window.setTimeout(() => {
|
||||
hideMessage(id);
|
||||
}, timeout);
|
||||
existElement.setAttribute("data-timeoutid", timeoutId.toString());
|
||||
}
|
||||
return;
|
||||
}
|
||||
let messageHTML = `<div data-id="${id}" class="b3-snackbar--hide b3-snackbar${type === "error" ? " b3-snackbar--error" : ""}"><div class="b3-snackbar__content">${message}</div>`;
|
||||
if (timeout === 0) {
|
||||
messageHTML += '<svg class="b3-snackbar__close"><use xlink:href="#iconClose"></use></svg>';
|
||||
} else if (timeout !== -1) { // -1 时需等待请求完成后手动关闭
|
||||
window.setTimeout(() => {
|
||||
const timeoutId = window.setTimeout(() => {
|
||||
hideMessage(id);
|
||||
}, timeout);
|
||||
messageHTML.replace("<div data-id", `<div data-timeoutid="${timeoutId}" data-id`);
|
||||
}
|
||||
if (messagesElement.childElementCount === 0) {
|
||||
messagesElement.parentElement.classList.add("b3-snackbars--show");
|
||||
|
|
|
|||
|
|
@ -84,8 +84,8 @@ export const kernelError = () => {
|
|||
export const exitSiYuan = () => {
|
||||
fetchPost("/api/system/exit", {force: false}, (response) => {
|
||||
if (response.code === 1) {
|
||||
showMessage(response.msg, response.data.closeTimeout, "error");
|
||||
const buttonElement = document.querySelector("#message button");
|
||||
const msgId = showMessage(response.msg, response.data.closeTimeout, "error");
|
||||
const buttonElement = document.querySelector(`#message [data-id="${msgId}"] button`);
|
||||
if (buttonElement) {
|
||||
buttonElement.addEventListener("click", () => {
|
||||
fetchPost("/api/system/exit", {force: true}, () => {
|
||||
|
|
|
|||
|
|
@ -138,11 +138,10 @@ const getExportPath = (option: { type: string, id: string }, pdfOption?: PrintTo
|
|||
pdf: option.type === "pdf",
|
||||
savePath: result.filePath
|
||||
}, exportResponse => {
|
||||
hideMessage(id);
|
||||
if (option.type === "word") {
|
||||
afterExport(result.filePath);
|
||||
afterExport(result.filePath, id);
|
||||
} else {
|
||||
onExport(exportResponse, result.filePath, option.type, pdfOption, removeAssets);
|
||||
onExport(exportResponse, result.filePath, option.type, pdfOption, removeAssets, id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -150,7 +149,7 @@ const getExportPath = (option: { type: string, id: string }, pdfOption?: PrintTo
|
|||
});
|
||||
};
|
||||
|
||||
const onExport = (data: IWebSocketData, filePath: string, type: string, pdfOptions?: PrintToPDFOptions, removeAssets?: boolean) => {
|
||||
const onExport = (data: IWebSocketData, filePath: string, type: string, pdfOptions?: PrintToPDFOptions, removeAssets?: boolean, msgId?:string) => {
|
||||
let themeName = window.siyuan.config.appearance.themeLight;
|
||||
let mode = 0;
|
||||
if (["html", "htmlmd"].includes(type) && window.siyuan.config.appearance.mode === 1) {
|
||||
|
|
@ -319,7 +318,7 @@ pre code {
|
|||
id: data.data.id,
|
||||
path: pdfFilePath
|
||||
}, () => {
|
||||
afterExport(pdfFilePath);
|
||||
afterExport(pdfFilePath, msgId);
|
||||
if (removeAssets) {
|
||||
const removePromise = (dir: string) => {
|
||||
return new Promise(function (resolve) {
|
||||
|
|
@ -354,7 +353,7 @@ pre code {
|
|||
} else {
|
||||
const htmlPath = path.join(filePath, "index.html");
|
||||
fs.writeFileSync(htmlPath, html);
|
||||
afterExport(htmlPath);
|
||||
afterExport(htmlPath, msgId);
|
||||
}
|
||||
};
|
||||
/// #endif
|
||||
|
|
|
|||
|
|
@ -4,16 +4,13 @@ import {escapeHtml} from "../../util/escape";
|
|||
import {shell} from "electron";
|
||||
import * as path from "path";
|
||||
|
||||
export const afterExport = (exportPath: string) => {
|
||||
const id = showMessage(`<div class="fn__flex">
|
||||
<div class="fn__flex-center">${window.siyuan.languages.exported}${escapeHtml(exportPath)}</div>
|
||||
<div class="fn__space"></div>
|
||||
<div class="fn__space"></div>
|
||||
<button class="b3-button b3-button--white">${window.siyuan.languages.showInFolder}</button>
|
||||
</div>`, 6000);
|
||||
document.querySelector("#message button").addEventListener("click", () => {
|
||||
export const afterExport = (exportPath: string, msgId: string) => {
|
||||
showMessage(`${window.siyuan.languages.exported}${escapeHtml(exportPath)}
|
||||
<div class="fn__space"></div>
|
||||
<button class="b3-button b3-button--white">${window.siyuan.languages.showInFolder}</button>`, 6000, "info", msgId);
|
||||
document.querySelector(`#message [data-id="${msgId}"] button`).addEventListener("click", () => {
|
||||
shell.showItemInFolder(path.join(exportPath));
|
||||
hideMessage(id);
|
||||
hideMessage(msgId);
|
||||
});
|
||||
};
|
||||
/// #endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue