This commit is contained in:
Vanessa 2023-05-18 10:23:19 +08:00
parent 4e3fb4bbf5
commit 0d9fcf8245

View file

@ -9,9 +9,7 @@ import {needSubscribe} from "../../util/needSubscribe";
import {MenuItem} from "../../menus/Menu"; import {MenuItem} from "../../menus/Menu";
import {confirmDialog} from "../../dialog/confirmDialog"; import {confirmDialog} from "../../dialog/confirmDialog";
import {replaceFileName} from "../../editor/rename"; import {replaceFileName} from "../../editor/rename";
import {escapeHtml} from "../../util/escape"; import {getDisplayName, movePathTo, pathPosix} from "../../util/pathName";
import {unicode2Emoji} from "../../emoji";
import {Constants} from "../../constants";
export class Inbox extends Model { export class Inbox extends Model {
private element: Element; private element: Element;
@ -89,7 +87,6 @@ export class Inbox extends Model {
const type = target.getAttribute("data-type"); const type = target.getAttribute("data-type");
if (type === "min") { if (type === "min") {
getDockByType("inbox").toggleModel("inbox"); getDockByType("inbox").toggleModel("inbox");
event.stopPropagation();
event.preventDefault(); event.preventDefault();
break; break;
} else if (type === "selectall") { } else if (type === "selectall") {
@ -106,6 +103,7 @@ export class Inbox extends Model {
}); });
} }
countElement.innerHTML = `${this.selectIds.length.toString()}/${this.pageCount.toString()}`; countElement.innerHTML = `${this.selectIds.length.toString()}/${this.pageCount.toString()}`;
window.siyuan.menus.menu.remove();
event.stopPropagation(); event.stopPropagation();
break; break;
} else if (type === "select") { } else if (type === "select") {
@ -117,6 +115,7 @@ export class Inbox extends Model {
} }
countElement.innerHTML = `${this.selectIds.length.toString()}/${this.pageCount.toString()}`; countElement.innerHTML = `${this.selectIds.length.toString()}/${this.pageCount.toString()}`;
selectAllElement.checked = this.element.lastElementChild.querySelectorAll("input:checked").length === this.element.lastElementChild.querySelectorAll(".b3-list-item").length; selectAllElement.checked = this.element.lastElementChild.querySelectorAll("input:checked").length === this.element.lastElementChild.querySelectorAll(".b3-list-item").length;
window.siyuan.menus.menu.remove();
event.stopPropagation(); event.stopPropagation();
break; break;
} else if (type === "previous") { } else if (type === "previous") {
@ -124,7 +123,6 @@ export class Inbox extends Model {
this.currentPage--; this.currentPage--;
this.update(); this.update();
} }
event.stopPropagation();
event.preventDefault(); event.preventDefault();
break; break;
} else if (type === "next") { } else if (type === "next") {
@ -132,12 +130,10 @@ export class Inbox extends Model {
this.currentPage++; this.currentPage++;
this.update(); this.update();
} }
event.stopPropagation();
event.preventDefault(); event.preventDefault();
break; break;
} else if (type === "back") { } else if (type === "back") {
this.back(); this.back();
event.stopPropagation();
event.preventDefault(); event.preventDefault();
break; break;
} else if (type === "more") { } else if (type === "more") {
@ -155,7 +151,6 @@ export class Inbox extends Model {
detailsElement.classList.remove("fn__none"); detailsElement.classList.remove("fn__none");
detailsElement.scrollTop = 0; detailsElement.scrollTop = 0;
this.element.lastElementChild.classList.add("fn__none"); this.element.lastElementChild.classList.add("fn__none");
event.stopPropagation();
event.preventDefault(); event.preventDefault();
break; break;
} }
@ -173,7 +168,7 @@ export class Inbox extends Model {
this.element.lastElementChild.classList.remove("fn__none"); this.element.lastElementChild.classList.remove("fn__none");
} }
private genDetail(data:IInbox) { private genDetail(data: IInbox) {
let linkHTML = ""; let linkHTML = "";
/// #if MOBILE /// #if MOBILE
if (data.shorthandURL) { if (data.shorthandURL) {
@ -227,41 +222,36 @@ ${(Lute.New()).MarkdownStr("", data.shorthandContent)}
} }
} }
}).element); }).element);
const submenu: IMenu[] = []; let ids: string[] = [];
window.siyuan.notebooks.forEach((item) => { if (detailsElement.classList.contains("fn__none")) {
if (!item.closed) { ids = this.selectIds;
submenu.push({ } else {
iconHTML: `${unicode2Emoji(item.icon || Constants.SIYUAN_IMAGE_NOTE, false, "b3-menu__icon", true)}`, ids = [detailsElement.getAttribute("data-id")];
label: escapeHtml(item.name), }
click: () => { if (ids.length > 0) {
window.siyuan.menus.menu.append(new MenuItem({
label: window.siyuan.languages.move,
icon: "iconMove",
click: () => {
this.move(ids);
}
}).element);
window.siyuan.menus.menu.append(new MenuItem({
label: window.siyuan.languages.remove,
icon: "iconTrashcan",
click: () => {
confirmDialog(window.siyuan.languages.deleteOpConfirm, window.siyuan.languages.confirmDelete + "?", () => {
if (detailsElement.classList.contains("fn__none")) { if (detailsElement.classList.contains("fn__none")) {
this.move(item.id); this.remove();
} else { } else {
this.move(item.id, detailsElement.getAttribute("data-id")); this.remove(detailsElement.getAttribute("data-id"));
} }
} });
}); }
} }).element);
}); }
window.siyuan.menus.menu.append(new MenuItem({
label: window.siyuan.languages.move, window.siyuan.menus.menu.popup({x: event.clientX, y: event.clientY + 16});
icon: "iconMove",
submenu
}).element);
window.siyuan.menus.menu.append(new MenuItem({
label: window.siyuan.languages.remove,
icon: "iconTrashcan",
click: () => {
confirmDialog(window.siyuan.languages.deleteOpConfirm, window.siyuan.languages.confirmDelete + "?", () => {
if (detailsElement.classList.contains("fn__none")) {
this.remove();
} else {
this.remove(detailsElement.getAttribute("data-id"));
}
});
}
}).element);
window.siyuan.menus.menu.popup({x: event.clientX, y: event.clientY});
window.siyuan.menus.menu.element.style.zIndex = "221"; // 移动端被右侧栏遮挡 window.siyuan.menus.menu.element.style.zIndex = "221"; // 移动端被右侧栏遮挡
} }
@ -289,22 +279,17 @@ ${(Lute.New()).MarkdownStr("", data.shorthandContent)}
}); });
} }
private move(notebookId: string, id?: string) { private move(ids: string[]) {
let ids: string[]; movePathTo((toPath, toNotebook) => {
if (id) { ids.forEach(item => {
ids = [id]; fetchPost("/api/filetree/createDoc", {
} else { notebook: toNotebook[0],
ids = this.selectIds; path: pathPosix().join(getDisplayName(toPath[0], false, true), Lute.NewNodeID() + ".sy"),
} title: replaceFileName(this.data[item].shorthandTitle),
md: this.data[item].shorthandContent,
ids.forEach(item => { }, () => {
fetchPost("/api/filetree/createDoc", { this.remove(item);
notebook: notebookId, });
path: `/${Lute.NewNodeID()}.sy`,
title: replaceFileName(this.data[item].shorthandTitle),
md: this.data[item].shorthandContent,
}, () => {
this.remove(item);
}); });
}); });
} }