mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-10 22:23:28 +08:00
This commit is contained in:
parent
d06ebab62f
commit
f46c3bfd5d
@ -60,6 +60,7 @@ export abstract class Constants {
|
|||||||
public static readonly LOCAL_CODELANG = "local-codelang";
|
public static readonly LOCAL_CODELANG = "local-codelang";
|
||||||
public static readonly LOCAL_FONTSTYLES = "local-fontstyles";
|
public static readonly LOCAL_FONTSTYLES = "local-fontstyles";
|
||||||
public static readonly LOCAL_EXPORTPDF = "local-exportpdf";
|
public static readonly LOCAL_EXPORTPDF = "local-exportpdf";
|
||||||
|
public static readonly LOCAL_EXPORTWORD = "local-exportword";
|
||||||
public static readonly LOCAL_BAZAAR = "local-bazaar";
|
public static readonly LOCAL_BAZAAR = "local-bazaar";
|
||||||
|
|
||||||
// timeout
|
// timeout
|
||||||
|
@ -105,9 +105,38 @@ export const saveExport = (option: { type: string, id: string }) => {
|
|||||||
pdfDialog.destroy();
|
pdfDialog.destroy();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return;
|
} else if (option.type === "word") {
|
||||||
|
const localData = localStorage.getItem(Constants.LOCAL_EXPORTWORD);
|
||||||
|
const wordDialog = new Dialog({
|
||||||
|
title: "Word " + window.siyuan.languages.config,
|
||||||
|
content: `<div class="b3-dialog__content">
|
||||||
|
<label class="fn__flex b3-label">
|
||||||
|
<div class="fn__flex-1">
|
||||||
|
${window.siyuan.languages.exportPDF4}
|
||||||
|
</div>
|
||||||
|
<span class="fn__space"></span>
|
||||||
|
<input id="removeAssets" class="b3-switch" type="checkbox" ${localData === "true" ? "checked" : ""}>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="b3-dialog__action">
|
||||||
|
<button class="b3-button b3-button--cancel">${window.siyuan.languages.cancel}</button><div class="fn__space"></div>
|
||||||
|
<button class="b3-button b3-button--text">${window.siyuan.languages.confirm}</button>
|
||||||
|
</div>`,
|
||||||
|
width: "520px",
|
||||||
|
});
|
||||||
|
const btnsElement = wordDialog.element.querySelectorAll(".b3-button");
|
||||||
|
btnsElement[0].addEventListener("click", () => {
|
||||||
|
wordDialog.destroy();
|
||||||
|
});
|
||||||
|
btnsElement[1].addEventListener("click", () => {
|
||||||
|
const removeAssets = (wordDialog.element.querySelector("#removeAssets") as HTMLInputElement).checked;
|
||||||
|
localStorage.setItem(Constants.LOCAL_EXPORTWORD, removeAssets.toString());
|
||||||
|
getExportPath(option, undefined, removeAssets);
|
||||||
|
wordDialog.destroy();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
getExportPath(option);
|
||||||
}
|
}
|
||||||
getExportPath(option);
|
|
||||||
/// #endif
|
/// #endif
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -151,6 +180,7 @@ const getExportPath = (option: { type: string, id: string }, pdfOption?: PrintTo
|
|||||||
fetchPost(url, {
|
fetchPost(url, {
|
||||||
id: option.id,
|
id: option.id,
|
||||||
pdf: option.type === "pdf",
|
pdf: option.type === "pdf",
|
||||||
|
removeAssets,
|
||||||
savePath
|
savePath
|
||||||
}, exportResponse => {
|
}, exportResponse => {
|
||||||
if (option.type === "word") {
|
if (option.type === "word") {
|
||||||
@ -339,26 +369,6 @@ pre code {
|
|||||||
path: pdfFilePath
|
path: pdfFilePath
|
||||||
}, () => {
|
}, () => {
|
||||||
afterExport(pdfFilePath, msgId);
|
afterExport(pdfFilePath, msgId);
|
||||||
if (removeAssets) {
|
|
||||||
const removePromise = (dir: string) => {
|
|
||||||
return new Promise(function (resolve) {
|
|
||||||
//先读文件夹
|
|
||||||
fs.stat(dir, function (err, stat) {
|
|
||||||
if (stat.isDirectory()) {
|
|
||||||
fs.readdir(dir, function (err, files) {
|
|
||||||
files = files.map(file => path.join(dir, file)); // a/b a/m
|
|
||||||
Promise.all(files.map(file => removePromise(file))).then(function () {
|
|
||||||
fs.rmdir(dir, resolve);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
fs.unlink(dir, resolve);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
removePromise(path.join(filePath, "assets"));
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
win.destroy();
|
win.destroy();
|
||||||
}).catch((error: string) => {
|
}).catch((error: string) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user