Vanessa 2024-01-26 19:49:35 +08:00
parent 8ce0d2487c
commit 045b7a6739
2 changed files with 14 additions and 3 deletions

View file

@ -78,4 +78,10 @@
} }
} }
} }
.export-img__space {
flex: auto;
height: 8px;
width: 100%;
}
} }

View file

@ -46,7 +46,7 @@ export const exportImage = (id: string) => {
<span class="fn__space"></span> <span class="fn__space"></span>
<input id="watermark" class="b3-switch fn__flex-center" type="checkbox" ${window.siyuan.storage[Constants.LOCAL_EXPORTIMG].watermark ? "checked" : ""}> <input id="watermark" class="b3-switch fn__flex-center" type="checkbox" ${window.siyuan.storage[Constants.LOCAL_EXPORTIMG].watermark ? "checked" : ""}>
</label> </label>
<span class="fn__flex-1"></span> <span class="fn__flex-1 export-img__space"></span>
<button disabled class="b3-button b3-button--cancel">${window.siyuan.languages.cancel}</button><div class="fn__space"></div> <button disabled class="b3-button b3-button--cancel">${window.siyuan.languages.cancel}</button><div class="fn__space"></div>
<button disabled class="b3-button b3-button--text">${window.siyuan.languages.confirm}</button> <button disabled class="b3-button b3-button--text">${window.siyuan.languages.confirm}</button>
</div> </div>
@ -65,7 +65,9 @@ export const exportImage = (id: string) => {
setStorageVal(Constants.LOCAL_EXPORTIMG, window.siyuan.storage[Constants.LOCAL_EXPORTIMG]); setStorageVal(Constants.LOCAL_EXPORTIMG, window.siyuan.storage[Constants.LOCAL_EXPORTIMG]);
setTimeout(() => { setTimeout(() => {
addScript("/stage/protyle/js/html2canvas.min.js?v=1.4.1", "protyleHtml2canvas").then(() => { addScript("/stage/protyle/js/html2canvas.min.js?v=1.4.1", "protyleHtml2canvas").then(() => {
window.html2canvas(exportDialog.element.querySelector(".b3-dialog__content"), {useCORS: true}).then((canvas) => { window.html2canvas(exportDialog.element.querySelector(".b3-dialog__content"), {
useCORS: true,
}).then((canvas) => {
canvas.toBlob((blob: Blob) => { canvas.toBlob((blob: Blob) => {
const formData = new FormData(); const formData = new FormData();
formData.append("file", blob, btnsElement[1].getAttribute("data-title")); formData.append("file", blob, btnsElement[1].getAttribute("data-title"));
@ -186,10 +188,13 @@ export const exportImage = (id: string) => {
item.innerHTML = symbolElements[symbolElements.length - 1].innerHTML; item.innerHTML = symbolElements[symbolElements.length - 1].innerHTML;
}); });
previewElement.querySelectorAll(".img img").forEach((item: HTMLImageElement) => { previewElement.querySelectorAll(".img img").forEach((item: HTMLImageElement) => {
if (item.src.endsWith(".svg")) { const imgSrc = item.getAttribute("src")
if (imgSrc.endsWith(".svg")) {
fetchGet(item.src, (response: string) => { fetchGet(item.src, (response: string) => {
item.src = `data:image/svg+xml;base64,${btoa(unescape(encodeURIComponent(response)))}`; item.src = `data:image/svg+xml;base64,${btoa(unescape(encodeURIComponent(response)))}`;
}); });
} else if (imgSrc.startsWith("assets/")) {
item.src = location.origin + "/" + imgSrc;
} }
}); });
updateWatermark(); updateWatermark();