Vanessa 2023-06-09 22:43:50 +08:00
parent 182eb26b47
commit 0c33bb16d9
2 changed files with 35 additions and 26 deletions

View file

@ -89,6 +89,7 @@ export abstract class Constants {
public static readonly TIMEOUT_INPUT = 256;
public static readonly TIMEOUT_LOAD = 300;
public static readonly TIMEOUT_TRANSITION = 300;
public static readonly TIMEOUT_COUNT = 1000;
// id
public static readonly HELP_PATH = {

View file

@ -149,23 +149,27 @@ export const initStatus = (isWindow = false) => {
};
let countRootId: string;
let countTimeout: number;
export const countSelectWord = (range: Range, rootID?: string) => {
/// #if !MOBILE
if (document.getElementById("status").classList.contains("fn__none")) {
return;
}
const selectText = range.toString();
if (selectText) {
fetchPost("/api/block/getContentWordCount", {"content": range.toString()}, (response) => {
renderStatusbarCounter(response.data);
});
countRootId = "";
} else if (rootID && rootID !== countRootId) {
countRootId = rootID;
fetchPost("/api/block/getTreeStat", {id: rootID}, (response) => {
renderStatusbarCounter(response.data);
});
}
clearTimeout(countTimeout);
countTimeout = window.setTimeout(() => {
const selectText = range.toString();
if (selectText) {
fetchPost("/api/block/getContentWordCount", {"content": range.toString()}, (response) => {
renderStatusbarCounter(response.data);
});
countRootId = "";
} else if (rootID && rootID !== countRootId) {
countRootId = rootID;
fetchPost("/api/block/getTreeStat", {id: rootID}, (response) => {
renderStatusbarCounter(response.data);
});
}
}, Constants.TIMEOUT_COUNT);
/// #endif
};
@ -174,26 +178,30 @@ export const countBlockWord = (ids: string[], rootID?: string, clearCache = fals
if (document.getElementById("status").classList.contains("fn__none")) {
return;
}
if (clearCache) {
countRootId = "";
}
if (ids.length > 0) {
fetchPost("/api/block/getBlocksWordCount", {ids}, (response) => {
renderStatusbarCounter(response.data);
});
countRootId = "";
} else if (rootID && rootID !== countRootId) {
countRootId = rootID;
fetchPost("/api/block/getTreeStat", {id: rootID}, (response) => {
renderStatusbarCounter(response.data);
});
}
clearTimeout(countTimeout);
countTimeout = window.setTimeout(() => {
if (clearCache) {
countRootId = "";
}
if (ids.length > 0) {
fetchPost("/api/block/getBlocksWordCount", {ids}, (response) => {
renderStatusbarCounter(response.data);
});
countRootId = "";
} else if (rootID && rootID !== countRootId) {
countRootId = rootID;
fetchPost("/api/block/getTreeStat", {id: rootID}, (response) => {
renderStatusbarCounter(response.data);
});
}
}, Constants.TIMEOUT_COUNT);
/// #endif
};
export const clearCounter = () => {
countRootId = "";
document.querySelector("#status .status__counter").innerHTML = "";
clearTimeout(countTimeout);
};
export const renderStatusbarCounter = (stat: {