- {Object.keys(result).map((key, i) => {
- const item = result[key]
- return (
-
-
{key}
-
- {item.map((it, index) => (
-
handlePage(it.routePath, it)}
- >
-
-
-
+ {loading && (
+
+
+
+ )}
+ {!loading && searchWords && Object.keys(result).length === 0 && (
+
+
+
+ 未找到关于 “{searchWords} “{' '}
+ 的搜索结果
+
+
+ )}
+ {!!Object.keys(result).length && !loading && (
+
+ {Object.keys(result).map((key, i) => {
+ const item = result[key]
+ return (
+
+
{key}
+
+ {item.map((it, index) => (
+
handlePage(it.routePath, it)}
+ >
+
+
+
-
-
- ))}
+ ))}
+
-
- )
- })}
-
+ )
+ })}
+
+ )}
>
)}
diff --git a/packages/doc/src/hooks/index.ts b/packages/doc/src/hooks/index.ts
index c41a284b..81ac1d2c 100644
--- a/packages/doc/src/hooks/index.ts
+++ b/packages/doc/src/hooks/index.ts
@@ -1,3 +1,37 @@
+import { useRef, useEffect, useCallback } from 'react'
+
+export function useDebounce(fn, delay, dep: any[]) {
+ const { current } = useRef
({ fn, timer: null });
+ useEffect(function () {
+ current.fn = fn;
+ }, [fn]);
+
+ return useCallback(function f(...args) {
+ if (current.timer) {
+ clearTimeout(current.timer);
+ }
+ current.timer = setTimeout(() => {
+ current.fn( ...args);
+ }, delay);
+ }, dep || [])
+}
+
+export function useThrottle(fn, delay, dep: any[]) {
+ const { current } = useRef({ fn, timer: null });
+ useEffect(function () {
+ current.fn = fn;
+ }, [fn]);
+
+ return useCallback(function f(...args) {
+ if (!current.timer) {
+ current.timer = setTimeout(() => {
+ delete current.timer;
+ }, delay);
+ current.fn(...args);
+ }
+ }, dep || []);
+}
+
export * from './usePersistFn'
export * from './useTimeout'
export * from './useDepsTimeout'
diff --git a/packages/doc/src/utils/common.ts b/packages/doc/src/utils/common.ts
index fe2745e5..1d877927 100644
--- a/packages/doc/src/utils/common.ts
+++ b/packages/doc/src/utils/common.ts
@@ -54,8 +54,6 @@ export function getSimulatorUrl(simulator: IDocSimulator, currentUrl: string) {
path = simulator.transform(currentUrl)
}
- console.info(`${domain}${path}`)
-
return `${domain}${path}`
}
@@ -79,7 +77,6 @@ function sandBox(value) {
}
export function JSONparse(target) {
- console.info(target, 'target')
return JSON.parse(JSON.stringify(target), function (_, val) {
if (
/^function\s*\(.*\)\s*{/.test(val) ||