瀏覽代碼

:bug: export msg

Vanessa 3 年之前
父節點
當前提交
432fe6be1e

+ 1 - 2
app/src/config/exportConfig.ts

@@ -166,8 +166,7 @@ export const exportConfig = {
                     fetchPost("/api/export/exportDataInFolder", {
                     fetchPost("/api/export/exportDataInFolder", {
                         folder: result.filePath
                         folder: result.filePath
                     }, () => {
                     }, () => {
-                        hideMessage(id);
-                        afterExport(result.filePath);
+                        afterExport(result.filePath, id);
                     });
                     });
                 }
                 }
             });
             });

+ 9 - 1
app/src/dialog/message.ts

@@ -33,15 +33,23 @@ export const showMessage = (message: string, timeout = 6000, type = "info", mess
     const existElement = messagesElement.querySelector(`.b3-snackbar[data-id="${id}"]`)
     const existElement = messagesElement.querySelector(`.b3-snackbar[data-id="${id}"]`)
     if (existElement) {
     if (existElement) {
         existElement.firstElementChild.innerHTML = message;
         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;
         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>`;
     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) {
     if (timeout === 0) {
         messageHTML += '<svg class="b3-snackbar__close"><use xlink:href="#iconClose"></use></svg>';
         messageHTML += '<svg class="b3-snackbar__close"><use xlink:href="#iconClose"></use></svg>';
     } else if (timeout !== -1) { // -1 时需等待请求完成后手动关闭
     } else if (timeout !== -1) { // -1 时需等待请求完成后手动关闭
-        window.setTimeout(() => {
+        const timeoutId = window.setTimeout(() => {
             hideMessage(id);
             hideMessage(id);
         }, timeout);
         }, timeout);
+        messageHTML.replace("<div data-id", `<div data-timeoutid="${timeoutId}" data-id`);
     }
     }
     if (messagesElement.childElementCount === 0) {
     if (messagesElement.childElementCount === 0) {
         messagesElement.parentElement.classList.add("b3-snackbars--show");
         messagesElement.parentElement.classList.add("b3-snackbars--show");

+ 2 - 2
app/src/dialog/processSystem.ts

@@ -84,8 +84,8 @@ export const kernelError = () => {
 export const exitSiYuan = () => {
 export const exitSiYuan = () => {
     fetchPost("/api/system/exit", {force: false}, (response) => {
     fetchPost("/api/system/exit", {force: false}, (response) => {
         if (response.code === 1) {
         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) {
             if (buttonElement) {
                 buttonElement.addEventListener("click", () => {
                 buttonElement.addEventListener("click", () => {
                     fetchPost("/api/system/exit", {force: true}, () => {
                     fetchPost("/api/system/exit", {force: true}, () => {

+ 5 - 6
app/src/protyle/export/index.ts

@@ -138,11 +138,10 @@ const getExportPath = (option: { type: string, id: string }, pdfOption?: PrintTo
                     pdf: option.type === "pdf",
                     pdf: option.type === "pdf",
                     savePath: result.filePath
                     savePath: result.filePath
                 }, exportResponse => {
                 }, exportResponse => {
-                    hideMessage(id);
                     if (option.type === "word") {
                     if (option.type === "word") {
-                        afterExport(result.filePath);
+                        afterExport(result.filePath, id);
                     } else {
                     } 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 themeName = window.siyuan.config.appearance.themeLight;
     let mode = 0;
     let mode = 0;
     if (["html", "htmlmd"].includes(type) && window.siyuan.config.appearance.mode === 1) {
     if (["html", "htmlmd"].includes(type) && window.siyuan.config.appearance.mode === 1) {
@@ -319,7 +318,7 @@ pre code {
                             id: data.data.id,
                             id: data.data.id,
                             path: pdfFilePath
                             path: pdfFilePath
                         }, () => {
                         }, () => {
-                            afterExport(pdfFilePath);
+                            afterExport(pdfFilePath, msgId);
                             if (removeAssets) {
                             if (removeAssets) {
                                 const removePromise = (dir: string) => {
                                 const removePromise = (dir: string) => {
                                     return new Promise(function (resolve) {
                                     return new Promise(function (resolve) {
@@ -354,7 +353,7 @@ pre code {
     } else {
     } else {
         const htmlPath = path.join(filePath, "index.html");
         const htmlPath = path.join(filePath, "index.html");
         fs.writeFileSync(htmlPath, html);
         fs.writeFileSync(htmlPath, html);
-        afterExport(htmlPath);
+        afterExport(htmlPath, msgId);
     }
     }
 };
 };
 /// #endif
 /// #endif

+ 6 - 9
app/src/protyle/export/util.ts

@@ -4,16 +4,13 @@ import {escapeHtml} from "../../util/escape";
 import {shell} from "electron";
 import {shell} from "electron";
 import * as path from "path";
 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));
         shell.showItemInFolder(path.join(exportPath));
-        hideMessage(id);
+        hideMessage(msgId);
     });
     });
 };
 };
 /// #endif
 /// #endif