This commit is contained in:
Vanessa 2023-03-27 15:30:13 +08:00
parent b7b8ae998f
commit 44ca060440
5 changed files with 16 additions and 17 deletions

View file

@ -46,7 +46,7 @@ export abstract class Constants {
public static readonly SIZE_ZOOM = [0.25, 0.33, 0.5, 0.67, 0.75, 0.8, 0.9, 1, 1.1, 1.25, 1.5, 1.75, 2, 2.5, 3]; public static readonly SIZE_ZOOM = [0.25, 0.33, 0.5, 0.67, 0.75, 0.8, 0.9, 1, 1.1, 1.25, 1.5, 1.75, 2, 2.5, 3];
// ws callback // ws callback
public static readonly CB_MOUNT_HELP = "cb-mount-help"; public static readonly CB_MOVE_NOLIST = "cb-move-nolist";
public static readonly CB_MOUNT_REMOVE = "cb-mount-remove"; public static readonly CB_MOUNT_REMOVE = "cb-mount-remove";
public static readonly CB_GET_APPEND = "cb-get-append"; // 向下滚动加载 public static readonly CB_GET_APPEND = "cb-get-append"; // 向下滚动加载
public static readonly CB_GET_BEFORE = "cb-get-before"; // 向上滚动加载 public static readonly CB_GET_BEFORE = "cb-get-before"; // 向上滚动加载

View file

@ -32,7 +32,7 @@ export class Files extends Model {
if (data) { if (data) {
switch (data.cmd) { switch (data.cmd) {
case "moveDoc": case "moveDoc":
this.onMove(data.data); this.onMove(data);
break; break;
case "mount": case "mount":
this.onMount(data); this.onMount(data);
@ -466,8 +466,8 @@ export class Files extends Model {
selectRootElements.push(item); selectRootElements.push(item);
} else { } else {
const dataPath = item.getAttribute("data-path"); const dataPath = item.getAttribute("data-path");
const isChild = fromPaths.find(item => { const isChild = fromPaths.find(itemPath => {
if (dataPath.startsWith(item.replace(".sy", ""))) { if (dataPath.startsWith(itemPath.replace(".sy", ""))) {
return true; return true;
} }
}); });
@ -478,11 +478,13 @@ export class Files extends Model {
} }
}); });
if (newElement.classList.contains("dragover")) { if (newElement.classList.contains("dragover")) {
await fetchPost("/api/filetree/moveDocs", { fetchPost("/api/filetree/moveDocs", {
toNotebook: toURL, toNotebook: toURL,
fromPaths, fromPaths,
toPath, toPath,
}); });
newElement.classList.remove("dragover", "dragover__bottom", "dragover__top");
return;
} }
const ulSort = newUlElement.getAttribute("data-sortmode"); const ulSort = newUlElement.getAttribute("data-sortmode");
if ((newElement.classList.contains("dragover__bottom") || newElement.classList.contains("dragover__top")) && if ((newElement.classList.contains("dragover__bottom") || newElement.classList.contains("dragover__top")) &&
@ -513,6 +515,7 @@ export class Files extends Model {
toNotebook: toURL, toNotebook: toURL,
fromPaths, fromPaths,
toPath: toDir === "/" ? "/" : toDir + ".sy", toPath: toDir === "/" ? "/" : toDir + ".sy",
callback: Constants.CB_MOVE_NOLIST,
}); });
selectFileElements.forEach(item => { selectFileElements.forEach(item => {
item.setAttribute("data-path", pathPosix().join(toDir, item.getAttribute("data-node-id") + ".sy")); item.setAttribute("data-path", pathPosix().join(toDir, item.getAttribute("data-node-id") + ".sy"));
@ -775,13 +778,8 @@ export class Files extends Model {
fileItemElement.querySelector(".b3-list-item__text").innerHTML = escapeHtml(data.title); fileItemElement.querySelector(".b3-list-item__text").innerHTML = escapeHtml(data.title);
} }
private onMove(data: { private onMove(response: IWebSocketData) {
fromNotebook: string, const sourceElement = this.element.querySelector(`ul[data-url="${response.data.fromNotebook}"] li[data-path="${response.data.fromPath}"]`) as HTMLElement;
toNotebook: string,
fromPath: string
toPath: string
}) {
const sourceElement = this.element.querySelector(`ul[data-url="${data.fromNotebook}"] li[data-path="${data.fromPath}"]`) as HTMLElement;
if (sourceElement) { if (sourceElement) {
if (sourceElement.nextElementSibling && sourceElement.nextElementSibling.tagName === "UL") { if (sourceElement.nextElementSibling && sourceElement.nextElementSibling.tagName === "UL") {
sourceElement.nextElementSibling.remove(); sourceElement.nextElementSibling.remove();
@ -800,7 +798,7 @@ export class Files extends Model {
sourceElement.remove(); sourceElement.remove();
} }
} }
const newElement = this.element.querySelector(`[data-url="${data.toNotebook}"] li[data-path="${data.toPath}"]`) as HTMLElement; const newElement = this.element.querySelector(`[data-url="${response.data.toNotebook}"] li[data-path="${response.data.toPath}"]`) as HTMLElement;
// 更新移动到的新文件夹 // 更新移动到的新文件夹
if (newElement) { if (newElement) {
newElement.querySelector(".b3-list-item__toggle").classList.remove("fn__hidden"); newElement.querySelector(".b3-list-item__toggle").classList.remove("fn__hidden");
@ -814,7 +812,9 @@ export class Files extends Model {
if (newElement.nextElementSibling && newElement.nextElementSibling.tagName === "UL") { if (newElement.nextElementSibling && newElement.nextElementSibling.tagName === "UL") {
newElement.nextElementSibling.remove(); newElement.nextElementSibling.remove();
} }
this.getLeaf(newElement, data.toNotebook); if (response.callback !== Constants.CB_MOVE_NOLIST) {
this.getLeaf(newElement, response.data.toNotebook);
}
} }
} }
} }

View file

@ -38,7 +38,7 @@ export const onMessage = (data: IWebSocketData) => {
openMobileFileById(data.data.id, [Constants.CB_GET_FOCUS]); openMobileFileById(data.data.id, [Constants.CB_GET_FOCUS]);
break; break;
case"txerr": case"txerr":
transactionError(data); transactionError();
break; break;
case"statusbar": case"statusbar":
progressStatus(data); progressStatus(data);

View file

@ -82,7 +82,6 @@ export const mountHelp = () => {
const notebookId = Constants.HELP_PATH[window.siyuan.config.appearance.lang as "zh_CN" | "en_US"]; const notebookId = Constants.HELP_PATH[window.siyuan.config.appearance.lang as "zh_CN" | "en_US"];
fetchPost("/api/notebook/removeNotebook", {notebook: notebookId, callback: Constants.CB_MOUNT_REMOVE}, () => { fetchPost("/api/notebook/removeNotebook", {notebook: notebookId, callback: Constants.CB_MOUNT_REMOVE}, () => {
fetchPost("/api/notebook/openNotebook", { fetchPost("/api/notebook/openNotebook", {
callback: Constants.CB_MOUNT_HELP,
notebook: notebookId notebook: notebookId
}); });
}); });

View file

@ -90,7 +90,7 @@ class App {
progressStatus(data); progressStatus(data);
break; break;
case "txerr": case "txerr":
transactionError(data); transactionError();
break; break;
case "syncing": case "syncing":
processSync(data); processSync(data);