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_INPUT = 256;
public static readonly TIMEOUT_LOAD = 300; public static readonly TIMEOUT_LOAD = 300;
public static readonly TIMEOUT_TRANSITION = 300; public static readonly TIMEOUT_TRANSITION = 300;
public static readonly TIMEOUT_COUNT = 1000;
// id // id
public static readonly HELP_PATH = { public static readonly HELP_PATH = {

View file

@ -149,11 +149,14 @@ export const initStatus = (isWindow = false) => {
}; };
let countRootId: string; let countRootId: string;
let countTimeout: number;
export const countSelectWord = (range: Range, rootID?: string) => { export const countSelectWord = (range: Range, rootID?: string) => {
/// #if !MOBILE /// #if !MOBILE
if (document.getElementById("status").classList.contains("fn__none")) { if (document.getElementById("status").classList.contains("fn__none")) {
return; return;
} }
clearTimeout(countTimeout);
countTimeout = window.setTimeout(() => {
const selectText = range.toString(); const selectText = range.toString();
if (selectText) { if (selectText) {
fetchPost("/api/block/getContentWordCount", {"content": range.toString()}, (response) => { fetchPost("/api/block/getContentWordCount", {"content": range.toString()}, (response) => {
@ -166,6 +169,7 @@ export const countSelectWord = (range: Range, rootID?: string) => {
renderStatusbarCounter(response.data); renderStatusbarCounter(response.data);
}); });
} }
}, Constants.TIMEOUT_COUNT);
/// #endif /// #endif
}; };
@ -174,6 +178,8 @@ export const countBlockWord = (ids: string[], rootID?: string, clearCache = fals
if (document.getElementById("status").classList.contains("fn__none")) { if (document.getElementById("status").classList.contains("fn__none")) {
return; return;
} }
clearTimeout(countTimeout);
countTimeout = window.setTimeout(() => {
if (clearCache) { if (clearCache) {
countRootId = ""; countRootId = "";
} }
@ -188,12 +194,14 @@ export const countBlockWord = (ids: string[], rootID?: string, clearCache = fals
renderStatusbarCounter(response.data); renderStatusbarCounter(response.data);
}); });
} }
}, Constants.TIMEOUT_COUNT);
/// #endif /// #endif
}; };
export const clearCounter = () => { export const clearCounter = () => {
countRootId = ""; countRootId = "";
document.querySelector("#status .status__counter").innerHTML = ""; document.querySelector("#status .status__counter").innerHTML = "";
clearTimeout(countTimeout);
}; };
export const renderStatusbarCounter = (stat: { export const renderStatusbarCounter = (stat: {