wui-components-v2 1.0.13 → 1.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,92 +0,0 @@
1
- /**
2
- * 延迟加载中间件
3
- * 延迟显示加载状态,防止快速请求导致的闪烁
4
- * @param delay 显示加载状态前的延迟时间(毫秒)
5
- * @returns Alova 中间件
6
- */
7
- export function createDelayLoadingMiddleware(delay = 300) {
8
- return async (context: any, next: any) => {
9
- context.controlLoading()
10
-
11
- const { loading } = context.proxyStates
12
-
13
- const timer = setTimeout(() => {
14
- loading.v = true
15
- }, delay)
16
-
17
- await next()
18
-
19
- loading.v = false
20
- clearTimeout(timer)
21
- }
22
- }
23
-
24
- /**
25
- * 全局加载中间件
26
- * 为所有请求显示全局加载指示器,支持延迟显示
27
- *
28
- * 使用示例:
29
- * ```typescript
30
- * // 1. 基本用法
31
- * const { send: submit } = useRequest(method, {
32
- * middleware: createGlobalLoadingMiddleware()
33
- * });
34
- *
35
- * // 2. 自定义延迟时间和加载文本
36
- * const { send: submit } = useRequest(method, {
37
- * middleware: createGlobalLoadingMiddleware({
38
- * delay: 500, // 延迟 500ms 显示加载指示器,防止闪烁
39
- * loadingText: '正在提交...', // 自定义加载文本
40
- * })
41
- * });
42
- * ```
43
- *
44
- * @param options 加载选项
45
- * @param options.delay 显示加载指示器前的延迟时间(毫秒),默认 300ms
46
- * @param options.loadingText 加载指示器显示的文本,默认为 'Loading...'
47
- * @returns Alova 中间件
48
- */
49
- export function createGlobalLoadingMiddleware(options: {
50
- delay?: number
51
- loadingText?: string
52
- } = {}) {
53
- const {
54
- delay = 0,
55
- loadingText = 'Loading...',
56
- } = options
57
-
58
- return async (ctx: any, next: any) => {
59
- // 自行控制loading
60
- ctx.controlLoading()
61
-
62
- const globalLoading = useGlobalLoading()
63
- let timer: ReturnType<typeof setTimeout> | null = null
64
-
65
- // 如果delay为0或未设置,直接显示loading
66
- if (delay <= 0) {
67
- globalLoading.loading(loadingText)
68
- }
69
- else {
70
- // 延迟特定时间显示全局loading
71
- timer = setTimeout(() => {
72
- globalLoading.loading(loadingText)
73
- }, delay)
74
- }
75
-
76
- try {
77
- await next()
78
- }
79
- finally {
80
- // 清除定时器并关闭loading
81
- if (timer) {
82
- clearTimeout(timer)
83
- }
84
- globalLoading.close()
85
- }
86
- }
87
- }
88
-
89
- // 导出延迟加载中间件作为默认中间件
90
- export const defaultMiddleware = createDelayLoadingMiddleware()
91
-
92
- export default defaultMiddleware