xn-fe-tools 1.0.0

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.
Files changed (50) hide show
  1. package/README.md +112 -0
  2. package/dist/hooks/toAwaitFetch/toAwaitFetch.api.d.ts +469 -0
  3. package/dist/hooks/toAwaitFetch/toAwaitFetch.api.d.ts.map +1 -0
  4. package/dist/hooks/toAwaitFetch/toAwaitFetch.d.ts +95 -0
  5. package/dist/hooks/toAwaitFetch/toAwaitFetch.d.ts.map +1 -0
  6. package/dist/hooks/useCounter.d.ts +21 -0
  7. package/dist/hooks/useCounter.d.ts.map +1 -0
  8. package/dist/hooks/useFetch/axiosFetch.d.ts +111 -0
  9. package/dist/hooks/useFetch/axiosFetch.d.ts.map +1 -0
  10. package/dist/hooks/useFetch/cacheManager.d.ts +75 -0
  11. package/dist/hooks/useFetch/cacheManager.d.ts.map +1 -0
  12. package/dist/hooks/useFetch/fetch.d.ts +99 -0
  13. package/dist/hooks/useFetch/fetch.d.ts.map +1 -0
  14. package/dist/hooks/useFetch/fetch.types.d.ts +510 -0
  15. package/dist/hooks/useFetch/fetch.types.d.ts.map +1 -0
  16. package/dist/hooks/useFetch/fetchUtils.d.ts +171 -0
  17. package/dist/hooks/useFetch/fetchUtils.d.ts.map +1 -0
  18. package/dist/hooks/useFetch/index.d.ts +7 -0
  19. package/dist/hooks/useFetch/index.d.ts.map +1 -0
  20. package/dist/hooks/useFetch/requestQueue.d.ts +45 -0
  21. package/dist/hooks/useFetch/requestQueue.d.ts.map +1 -0
  22. package/dist/hooks/useLocalStorage.d.ts +18 -0
  23. package/dist/hooks/useLocalStorage.d.ts.map +1 -0
  24. package/dist/hooks/useTable/defaultConfig.d.ts +47 -0
  25. package/dist/hooks/useTable/defaultConfig.d.ts.map +1 -0
  26. package/dist/hooks/useTable/index.d.ts +13 -0
  27. package/dist/hooks/useTable/index.d.ts.map +1 -0
  28. package/dist/hooks/useTable/types.d.ts +217 -0
  29. package/dist/hooks/useTable/types.d.ts.map +1 -0
  30. package/dist/hooks/useTable/useTableRequest.d.ts +26 -0
  31. package/dist/hooks/useTable/useTableRequest.d.ts.map +1 -0
  32. package/dist/hooks/useTable/useTableStatic.d.ts +19 -0
  33. package/dist/hooks/useTable/useTableStatic.d.ts.map +1 -0
  34. package/dist/hooks/useTable/utils.d.ts +8 -0
  35. package/dist/hooks/useTable/utils.d.ts.map +1 -0
  36. package/dist/hooks/useToggle.d.ts +21 -0
  37. package/dist/hooks/useToggle.d.ts.map +1 -0
  38. package/dist/hooks/utils/utils.d.ts +20 -0
  39. package/dist/hooks/utils/utils.d.ts.map +1 -0
  40. package/dist/index.cjs.js +1 -0
  41. package/dist/index.d.ts +3 -0
  42. package/dist/index.d.ts.map +1 -0
  43. package/dist/index.es.js +1 -0
  44. package/dist/toAwaitFetch/toAwaitFetch.cjs.js +1 -0
  45. package/dist/toAwaitFetch/toAwaitFetch.es.js +1 -0
  46. package/dist/version.cjs.js +1 -0
  47. package/dist/version.d.ts +11 -0
  48. package/dist/version.d.ts.map +1 -0
  49. package/dist/version.es.js +1 -0
  50. package/package.json +81 -0
@@ -0,0 +1,7 @@
1
+ export { useAxiosFetch, useAxiosGet, useAxiosPost, useGetPromise, usePostPromise, setDefaultFetchOptions as setDefaultAxiosFetchOptions, getDefaultFetchOptions as getDefaultAxiosFetchOptions, resetDefaultFetchOptions as resetDefaultAxiosFetchOptions, } from './axiosFetch';
2
+ export { useFetch, useFetchGet, useFetchPost, useFetchGetPromise, useFetchPostPromise, setDefaultFetchOptions as setDefaultFetchOptions, getDefaultFetchOptions as getDefaultFetchOptions, resetDefaultFetchOptions as resetDefaultFetchOptions, } from './fetch';
3
+ export { toValue, deepMerge, createDefaultOptionsManager, getRetryDelay, mergeUrlParams, isTimeoutError, isNetworkError, isServerError, shouldRetry, type ErrorInfo, } from './fetchUtils';
4
+ export type { UseAxiosFetchOptions, UseAxiosFetchReturn, UseFetchReturn, DefaultFetchOptions, FetchResponse, BeforeFetch, AfterFetch, OnFetchError, BeforeFetchContext, BeforeFetchResult, AfterFetchContext, AfterFetchResult, AfterFetchReturn, OnFetchErrorContext, OnFetchErrorResultContext, OnFetchErrorResult, } from './fetch.types';
5
+ export { globalCacheManager, CacheManager, defaultCacheKeyGenerator, type CacheKeyGenerator, } from './cacheManager';
6
+ export { globalRequestQueue, RequestQueue, } from './requestQueue';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/useFetch/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,aAAa,EACb,WAAW,EACX,YAAY,EACZ,aAAa,EACb,cAAc,EACd,sBAAsB,IAAI,2BAA2B,EACrD,sBAAsB,IAAI,2BAA2B,EACrD,wBAAwB,IAAI,6BAA6B,GAC1D,MAAM,cAAc,CAAA;AAGrB,OAAO,EACL,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,kBAAkB,EAClB,mBAAmB,EACnB,sBAAsB,IAAI,sBAAsB,EAChD,sBAAsB,IAAI,sBAAsB,EAChD,wBAAwB,IAAI,wBAAwB,GACrD,MAAM,SAAS,CAAA;AAGhB,OAAO,EACL,OAAO,EACP,SAAS,EACT,2BAA2B,EAC3B,aAAa,EACb,cAAc,EACd,cAAc,EACd,cAAc,EACd,aAAa,EACb,WAAW,EACX,KAAK,SAAS,GACf,MAAM,cAAc,CAAA;AAGrB,YAAY,EACV,oBAAoB,EACpB,mBAAmB,EACnB,cAAc,EACd,mBAAmB,EACnB,aAAa,EACb,WAAW,EACX,UAAU,EACV,YAAY,EACZ,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,EACnB,yBAAyB,EACzB,kBAAkB,GACnB,MAAM,eAAe,CAAA;AAGtB,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,wBAAwB,EACxB,KAAK,iBAAiB,GACvB,MAAM,gBAAgB,CAAA;AAGvB,OAAO,EACL,kBAAkB,EAClB,YAAY,GACb,MAAM,gBAAgB,CAAA"}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * 请求队列管理器
3
+ */
4
+ declare class RequestQueue {
5
+ private queues;
6
+ private pendingRequests;
7
+ /**
8
+ * 生成队列键(用于标识相同的请求)
9
+ */
10
+ generateKey(config: {
11
+ url: string;
12
+ method: string;
13
+ params?: any;
14
+ data?: any;
15
+ headers?: Record<string, string>;
16
+ }): string;
17
+ /**
18
+ * 加入队列或执行请求
19
+ */
20
+ enqueue<T>(key: string, requestFn: () => Promise<{
21
+ data: T | undefined;
22
+ error: Error | undefined;
23
+ }>): Promise<{
24
+ data: T | undefined;
25
+ error: Error | undefined;
26
+ }>;
27
+ /**
28
+ * 取消队列中的请求(可选功能)
29
+ */
30
+ cancel(key: string): void;
31
+ /**
32
+ * 清空所有队列
33
+ */
34
+ clear(): void;
35
+ /**
36
+ * 获取队列统计信息
37
+ */
38
+ getStats(): {
39
+ pendingRequests: number;
40
+ queuedRequests: number;
41
+ };
42
+ }
43
+ export declare const globalRequestQueue: RequestQueue;
44
+ export { RequestQueue };
45
+ //# sourceMappingURL=requestQueue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"requestQueue.d.ts","sourceRoot":"","sources":["../../../src/hooks/useFetch/requestQueue.ts"],"names":[],"mappings":"AASA;;GAEG;AACH,cAAM,YAAY;IAChB,OAAO,CAAC,MAAM,CAAiC;IAC/C,OAAO,CAAC,eAAe,CAAsE;IAE7F;;OAEG;IACH,WAAW,CAAC,MAAM,EAAE;QAClB,GAAG,EAAE,MAAM,CAAA;QACX,MAAM,EAAE,MAAM,CAAA;QACd,MAAM,CAAC,EAAE,GAAG,CAAA;QACZ,IAAI,CAAC,EAAE,GAAG,CAAA;QACV,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KACjC,GAAG,MAAM;IAQV;;OAEG;IACG,OAAO,CAAC,CAAC,EACb,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,MAAM,OAAO,CAAC;QAAE,IAAI,EAAE,CAAC,GAAG,SAAS,CAAC;QAAC,KAAK,EAAE,KAAK,GAAG,SAAS,CAAA;KAAE,CAAC,GAC1E,OAAO,CAAC;QAAE,IAAI,EAAE,CAAC,GAAG,SAAS,CAAC;QAAC,KAAK,EAAE,KAAK,GAAG,SAAS,CAAA;KAAE,CAAC;IAgD7D;;OAEG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAWzB;;OAEG;IACH,KAAK,IAAI,IAAI;IAKb;;OAEG;IACH,QAAQ;;;;CAUT;AAGD,eAAO,MAAM,kBAAkB,cAAqB,CAAA;AAGpD,OAAO,EAAE,YAAY,EAAE,CAAA"}
@@ -0,0 +1,18 @@
1
+ import { type Ref } from 'vue';
2
+ export interface UseLocalStorageOptions<T> {
3
+ defaultValue?: T;
4
+ serializer?: {
5
+ read: (value: string) => T;
6
+ write: (value: T) => string;
7
+ };
8
+ onError?: (error: Error) => void;
9
+ }
10
+ /**
11
+ * 响应式 localStorage
12
+ * @param key - localStorage 键名
13
+ * @param initialValue - 初始值
14
+ * @param options - 配置选项
15
+ * @returns 响应式值
16
+ */
17
+ export declare function useLocalStorage<T>(key: string, initialValue: T, options?: UseLocalStorageOptions<T>): Ref<T>;
18
+ //# sourceMappingURL=useLocalStorage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLocalStorage.d.ts","sourceRoot":"","sources":["../../src/hooks/useLocalStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,KAAK,GAAG,EAAE,MAAM,KAAK,CAAA;AAErD,MAAM,WAAW,sBAAsB,CAAC,CAAC;IACvC,YAAY,CAAC,EAAE,CAAC,CAAA;IAChB,UAAU,CAAC,EAAE;QACX,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,CAAC,CAAA;QAC1B,KAAK,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,MAAM,CAAA;KAC5B,CAAA;IACD,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAA;CACjC;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAC/B,GAAG,EAAE,MAAM,EACX,YAAY,EAAE,CAAC,EACf,OAAO,GAAE,sBAAsB,CAAC,CAAC,CAAM,GACtC,GAAG,CAAC,CAAC,CAAC,CAoER"}
@@ -0,0 +1,47 @@
1
+ import type { UseTableRequestDefaultOptions, UseTableRequestOptions, UseTableStaticOptions } from './types';
2
+ /**
3
+ * 设置全局默认配置
4
+ * 可以设置除 fetcher 和 params 外的所有属性
5
+ *
6
+ * @param options 默认配置选项
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * setUseTableRequestDefaults({
11
+ * autoFetch: false,
12
+ * pagination: {
13
+ * pageSize: 20
14
+ * },
15
+ * requestKeyConfig: {
16
+ * pageIndexKey: 'page',
17
+ * pageSizeKey: 'size'
18
+ * },
19
+ * responseKeyConfig: {
20
+ * dataKey: 'data.list',
21
+ * totalKey: 'data.total'
22
+ * },
23
+ * onError: (error) => {
24
+ * console.error('Request failed:', error)
25
+ * }
26
+ * })
27
+ * ```
28
+ */
29
+ export declare function setUseTableRequestDefaults(options: Partial<UseTableRequestDefaultOptions>): void;
30
+ /**
31
+ * 获取全局默认配置
32
+ * @returns 全局默认配置
33
+ */
34
+ export declare function getUseTableRequestDefaults(): Partial<UseTableRequestDefaultOptions>;
35
+ /**
36
+ * 重置全局默认配置
37
+ */
38
+ export declare function resetUseTableRequestDefaults(): void;
39
+ /**
40
+ * 合并默认配置和用户配置
41
+ * @param userOptions 用户配置
42
+ * @returns 合并后的配置
43
+ */
44
+ export declare function mergeUseTableRequestOptions<T = any, P = any>(userOptions: UseTableRequestOptions<T, P>): UseTableRequestOptions<T, P>;
45
+ export declare const setUseTableStaticDefaults: (options: Partial<UseTableStaticOptions>) => void;
46
+ export declare function mergeUseTableStaticOptions(userOptions: UseTableStaticOptions): UseTableStaticOptions;
47
+ //# sourceMappingURL=defaultConfig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaultConfig.d.ts","sourceRoot":"","sources":["../../../src/hooks/useTable/defaultConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,6BAA6B,EAAE,sBAAsB,EAAE,qBAAqB,EAAoB,MAAM,SAAS,CAAA;AAOjH;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,OAAO,CAAC,6BAA6B,CAAC,GAAG,IAAI,CAEhG;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,IAAI,OAAO,CAAC,6BAA6B,CAAC,CAEnF;AAED;;GAEG;AACH,wBAAgB,4BAA4B,IAAI,IAAI,CAEnD;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG,EAC1D,WAAW,EAAE,sBAAsB,CAAC,CAAC,EAAE,CAAC,CAAC,GACxC,sBAAsB,CAAC,CAAC,EAAE,CAAC,CAAC,CA+B9B;AAUD,eAAO,MAAM,yBAAyB,GAAI,SAAS,OAAO,CAAC,qBAAqB,CAAC,KAAG,IAiBnF,CAAA;AACD,wBAAgB,0BAA0B,CACxC,WAAW,EAAE,qBAAqB,GACjC,qBAAqB,CAkBvB"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * useTable - Vue 3 Composition API 表格管理 Hook
3
+ *
4
+ * 提供两个主要方法:
5
+ * - useTableRequest: 处理 API 请求的表格
6
+ * - useTableStatic: 处理静态数据的表格
7
+ */
8
+ export { useTableRequest } from './useTableRequest';
9
+ export { useTableStatic } from './useTableStatic';
10
+ export { createPaginationState } from './utils';
11
+ export { setUseTableRequestDefaults, getUseTableRequestDefaults, resetUseTableRequestDefaults } from './defaultConfig';
12
+ export * from './types';
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/useTable/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAGnD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAGjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAG/C,OAAO,EACL,0BAA0B,EAC1B,0BAA0B,EAC1B,4BAA4B,EAC7B,MAAM,iBAAiB,CAAA;AAGxB,cAAc,SAAS,CAAA"}
@@ -0,0 +1,217 @@
1
+ import type { Ref, UnwrapRef } from 'vue';
2
+ /**
3
+ * 分页配置
4
+ */
5
+ export interface PaginationConfig {
6
+ /**
7
+ * 当前页码
8
+ */
9
+ currentPage?: number;
10
+ /**
11
+ * 每页显示条数
12
+ */
13
+ pageSize?: number;
14
+ /**
15
+ * 每页显示条数选项
16
+ */
17
+ pageSizesList?: number[];
18
+ }
19
+ /**
20
+ * 请求参数映射配置
21
+ */
22
+ export interface RequestKeyConfig {
23
+ /**
24
+ * 请求参数中页码的字段名
25
+ * @default 'pageIndex'
26
+ */
27
+ pageIndexKey?: string;
28
+ /**
29
+ * 请求参数中每页条数的字段名
30
+ * @default 'pageSize'
31
+ */
32
+ pageSizeKey?: string;
33
+ }
34
+ /**
35
+ * 响应数据映射配置
36
+ */
37
+ export interface ResponseKeyConfig {
38
+ /**
39
+ * 响应数据中数据列表的字段名(支持点号分隔的路径)
40
+ * @default 'data'
41
+ */
42
+ dataKey?: string;
43
+ /**
44
+ * 响应数据中总数的字段名(支持点号分隔的路径)
45
+ * @default 'total'
46
+ */
47
+ totalKey?: string;
48
+ /**
49
+ * 响应数据中页码的字段名(支持点号分隔的路径)
50
+ * 如果提供,将从响应中同步页码到分页状态
51
+ * @default undefined
52
+ */
53
+ pageIndexKey?: string;
54
+ }
55
+ /**
56
+ * 请求配置选项(排除 fetcher 和 params,用于全局默认配置)
57
+ */
58
+ export type UseTableRequestDefaultOptions = Omit<UseTableRequestOptions<any, any>, 'fetcher' | 'params'>;
59
+ /**
60
+ * 请求配置选项
61
+ */
62
+ export interface UseTableRequestOptions<T = any, P = any> {
63
+ /**
64
+ * 请求函数(必需)
65
+ */
66
+ fetcher: (params: any) => Promise<any>;
67
+ /**
68
+ * 请求参数
69
+ */
70
+ params?: P;
71
+ /**
72
+ * 是否自动发起请求
73
+ * @default true
74
+ */
75
+ autoFetch?: boolean;
76
+ /**
77
+ * 请求参数变化时是否自动重新请求
78
+ * @default true
79
+ */
80
+ autoFetchOnParamsChange?: boolean;
81
+ /**
82
+ * 分页配置。设置为 false 时不进行分页处理
83
+ */
84
+ pagination?: PaginationConfig | false;
85
+ /**
86
+ * 请求参数映射配置
87
+ */
88
+ requestKeyConfig?: RequestKeyConfig;
89
+ /**
90
+ * 响应数据映射配置
91
+ */
92
+ responseKeyConfig?: ResponseKeyConfig;
93
+ /**
94
+ * 请求前的处理函数
95
+ */
96
+ beforeFetch?: (params: any) => any | Promise<any>;
97
+ /**
98
+ * 请求成功后的处理函数
99
+ */
100
+ afterFetch?: (data: any) => T[] | Promise<T[]>;
101
+ /**
102
+ * 请求失败后的处理函数
103
+ */
104
+ onError?: (error: any) => void;
105
+ }
106
+ /**
107
+ * 静态数据配置选项
108
+ * @template T 数据项类型,必须是对象类型
109
+ */
110
+ export interface UseTableStaticOptions<T extends Record<string, any> = Record<string, any>> {
111
+ /**
112
+ * 静态数据
113
+ */
114
+ data: T[] | Ref<T[]>;
115
+ /**
116
+ * 数据过滤函数
117
+ */
118
+ filterFn?: (item: T) => boolean;
119
+ /**
120
+ * 分页配置。设置为 false 时不进行分页处理
121
+ */
122
+ pagination?: PaginationConfig | false;
123
+ }
124
+ /**
125
+ * 分页状态
126
+ */
127
+ export interface PaginationState {
128
+ /**
129
+ * 当前页码
130
+ */
131
+ currentPage: number;
132
+ /**
133
+ * 每页显示条数
134
+ */
135
+ pageSize: number;
136
+ /**
137
+ * 总条数
138
+ */
139
+ total: number;
140
+ /**
141
+ * 每页显示条数选项
142
+ */
143
+ pageSizesList: number[];
144
+ }
145
+ /**
146
+ * 表格状态
147
+ */
148
+ export interface TableState<T = any> {
149
+ /**
150
+ * 表格数据
151
+ */
152
+ data: T[];
153
+ /**
154
+ * 加载状态
155
+ */
156
+ loading: boolean;
157
+ /**
158
+ * 分页状态
159
+ */
160
+ pagination: PaginationState;
161
+ /**
162
+ * 总条数
163
+ */
164
+ total: number;
165
+ }
166
+ /**
167
+ * 表格操作方法
168
+ */
169
+ export interface TableActions {
170
+ /**
171
+ * 刷新表格数据
172
+ */
173
+ refresh: () => Promise<void>;
174
+ /**
175
+ * 重置并刷新(回到第一页)
176
+ */
177
+ reset: () => Promise<void>;
178
+ /**
179
+ * 切换页码
180
+ */
181
+ changePage: (page: number) => Promise<void>;
182
+ /**
183
+ * 切换每页条数
184
+ */
185
+ changePageSize: (size: number) => Promise<void>;
186
+ /**
187
+ * 更新请求参数(仅用于请求模式)
188
+ */
189
+ updateParams?: (params: any) => void;
190
+ }
191
+ /**
192
+ * 将对象类型转换为 Ref 类型(用于 toRefs 的返回值)
193
+ * toRefs 会使用 UnwrapRef 处理嵌套的响应式对象
194
+ */
195
+ type ToRefs<T> = {
196
+ [K in keyof T]: Ref<UnwrapRef<T[K]>>;
197
+ };
198
+ /**
199
+ * useTable 返回值
200
+ * 使用 toRefs 转换后,响应式属性都是 Ref 类型,确保解构时也能保持响应性
201
+ *
202
+ * @example
203
+ * ```ts
204
+ * // 解构使用,响应性保持
205
+ * const { data, pagination, refresh } = useTableStatic({ data: sourceData })
206
+ *
207
+ * // 在模板中使用(自动解包)
208
+ * // <div v-for="item in data">{{ item.name }}</div>
209
+ *
210
+ * // 在 script 中使用(需要 .value)
211
+ * watch(() => data.value, (newData) => { ... })
212
+ * ```
213
+ */
214
+ export interface UseTableReturn<T = any> extends ToRefs<TableState<T>>, TableActions {
215
+ }
216
+ export {};
217
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/hooks/useTable/types.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,26 @@
1
+ import type { UseTableRequestOptions, UseTableReturn } from './types';
2
+ /**
3
+ * 处理请求接口的表格 Hook
4
+ * @param options 请求配置选项
5
+ * @returns 表格状态和操作方法
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * const { data, loading, pagination, refresh, changePage } = useTableRequest({
10
+ * fetcher: async (params) => {
11
+ * return await axios.post('/api/users', params)
12
+ * },
13
+ * params: { status: 'active' },
14
+ * requestKeyConfig: {
15
+ * pageIndexKey: 'page',
16
+ * pageSizeKey: 'size'
17
+ * },
18
+ * responseKeyConfig: {
19
+ * dataKey: 'list',
20
+ * totalKey: 'total'
21
+ * }
22
+ * })
23
+ * ```
24
+ */
25
+ export declare function useTableRequest<T = any, P = any>(options: UseTableRequestOptions<T, P>): UseTableReturn<T>;
26
+ //# sourceMappingURL=useTableRequest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTableRequest.d.ts","sourceRoot":"","sources":["../../../src/hooks/useTable/useTableRequest.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,sBAAsB,EACtB,cAAc,EAGf,MAAM,SAAS,CAAA;AAEhB;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,eAAe,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG,EAC9C,OAAO,EAAE,sBAAsB,CAAC,CAAC,EAAE,CAAC,CAAC,GACpC,cAAc,CAAC,CAAC,CAAC,CA6LnB"}
@@ -0,0 +1,19 @@
1
+ import type { UseTableStaticOptions, UseTableReturn } from './types';
2
+ /**
3
+ * 处理静态数据的表格 Hook
4
+ * @param options 静态数据配置选项
5
+ * @returns 表格状态和操作方法
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * const allData = ref([...])
10
+ * const { data, pagination, changePage } = useTableStatic({
11
+ * data: allData,
12
+ * filterFn: (item) => {
13
+ * return item.status === 'active'
14
+ * }
15
+ * })
16
+ * ```
17
+ */
18
+ export declare function useTableStatic<T extends Record<string, any> = Record<string, any>>(options: UseTableStaticOptions<T>): UseTableReturn<T>;
19
+ //# sourceMappingURL=useTableStatic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTableStatic.d.ts","sourceRoot":"","sources":["../../../src/hooks/useTable/useTableStatic.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,qBAAqB,EACrB,cAAc,EACf,MAAM,SAAS,CAAA;AAEhB;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,cAAc,CAC5B,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAEnD,OAAO,EAAE,qBAAqB,CAAC,CAAC,CAAC,GAChC,cAAc,CAAC,CAAC,CAAC,CAmInB"}
@@ -0,0 +1,8 @@
1
+ import type { PaginationConfig, PaginationState } from './types';
2
+ /**
3
+ * 创建分页状态
4
+ * @param config 分页配置,false 表示不启用分页
5
+ * @returns 分页状态对象
6
+ */
7
+ export declare function createPaginationState(config?: PaginationConfig | false): PaginationState;
8
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/hooks/useTable/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAEhE;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,CAAC,EAAE,gBAAgB,GAAG,KAAK,GAAG,eAAe,CAkBxF"}
@@ -0,0 +1,21 @@
1
+ import { type Ref } from 'vue';
2
+ export type ToggleValue = boolean | string | number;
3
+ export interface UseToggleOptions<T extends ToggleValue> {
4
+ truthyValue?: T;
5
+ falsyValue?: T;
6
+ }
7
+ export interface UseToggleReturn<T extends ToggleValue> {
8
+ value: Ref<T>;
9
+ toggle: () => void;
10
+ setTrue: () => void;
11
+ setFalse: () => void;
12
+ set: (value: T) => void;
13
+ }
14
+ /**
15
+ * 切换布尔值或两个值之间的切换
16
+ * @param initialValue - 初始值
17
+ * @param options - 配置选项
18
+ * @returns 切换对象
19
+ */
20
+ export declare function useToggle<T extends ToggleValue = boolean>(initialValue?: T, options?: UseToggleOptions<T>): UseToggleReturn<T>;
21
+ //# sourceMappingURL=useToggle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useToggle.d.ts","sourceRoot":"","sources":["../../src/hooks/useToggle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,KAAK,GAAG,EAAE,MAAM,KAAK,CAAA;AAEnC,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,CAAA;AAEnD,MAAM,WAAW,gBAAgB,CAAC,CAAC,SAAS,WAAW;IACrD,WAAW,CAAC,EAAE,CAAC,CAAA;IACf,UAAU,CAAC,EAAE,CAAC,CAAA;CACf;AAED,MAAM,WAAW,eAAe,CAAC,CAAC,SAAS,WAAW;IACpD,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,CAAA;IACb,MAAM,EAAE,MAAM,IAAI,CAAA;IAClB,OAAO,EAAE,MAAM,IAAI,CAAA;IACnB,QAAQ,EAAE,MAAM,IAAI,CAAA;IACpB,GAAG,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAA;CACxB;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,WAAW,GAAG,OAAO,EACvD,YAAY,GAAE,CAAc,EAC5B,OAAO,GAAE,gBAAgB,CAAC,CAAC,CAAM,GAChC,eAAe,CAAC,CAAC,CAAC,CA4BpB"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * 工具函数集合
3
+ */
4
+ /**
5
+ * 从对象中根据路径字符串获取值
6
+ * 支持点号分隔的路径,如 'data.list' 或 'data.items[0].name'
7
+ *
8
+ * @param obj - 目标对象
9
+ * @param path - 路径字符串,支持点号和数组索引
10
+ * @returns 获取到的值,如果路径不存在则返回 undefined
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * const obj = { data: { list: [1, 2, 3] } }
15
+ * getPropValue(obj, 'data.list') // [1, 2, 3]
16
+ * getPropValue(obj, 'data.list[0]') // 1
17
+ * ```
18
+ */
19
+ export declare function getPropValue(obj: any, path: string): any;
20
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/hooks/utils/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,GAAG,GAAG,CAoBxD"}
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./toAwaitFetch/toAwaitFetch.cjs.js"),t=require("./version.cjs.js");exports.FetchInstanceImpl=e.FetchInstanceImpl,exports.cancel=e.cancel,exports.createInstance=e.createInstance,exports.sendGet=e.sendGet,exports.sendGetBlob=e.sendGetBlob,exports.sendPost=e.sendPost,exports.sendPostBlob=e.sendPostBlob,exports.sendPostForm=e.sendPostForm,exports.setGlobalConfig=e.setGlobalConfig,exports.toAwaitFetch=e.default,exports.VERSION=t.VERSION,exports.getVersion=t.getVersion;
@@ -0,0 +1,3 @@
1
+ export { default as toAwaitFetch, sendGet, sendPost, sendPostForm, sendPostBlob, sendGetBlob, setGlobalConfig, cancel, createInstance, FetchInstanceImpl, } from './hooks/toAwaitFetch/toAwaitFetch';
2
+ export { VERSION, getVersion } from './version';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,OAAO,IAAI,YAAY,EACvB,OAAO,EACP,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,eAAe,EACf,MAAM,EACN,cAAc,EACd,iBAAiB,GAClB,MAAM,mCAAmC,CAAA;AAG1C,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA"}
@@ -0,0 +1 @@
1
+ import{FetchInstanceImpl as t,cancel as o,createInstance as e,sendGet as s,sendGetBlob as a,sendPost as i,sendPostBlob as r,sendPostForm as m,setGlobalConfig as c,default as f}from"./toAwaitFetch/toAwaitFetch.es.js";import{VERSION as h,getVersion as p}from"./version.es.js";export{t as FetchInstanceImpl,h as VERSION,o as cancel,e as createInstance,p as getVersion,s as sendGet,a as sendGetBlob,i as sendPost,r as sendPostBlob,m as sendPostForm,c as setGlobalConfig,f as toAwaitFetch};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=e=>!("object"!=typeof e||null===e||Array.isArray(e)||e instanceof Date||e instanceof RegExp||e instanceof File||e instanceof Blob||"undefined"!=typeof FormData&&e instanceof FormData),t=(r,o)=>{const s={...r};for(const n in o){if(!Object.prototype.hasOwnProperty.call(o,n))continue;const r=o[n];if(void 0===r)continue;const a=s[n];e(r)&&e(a)?s[n]=t(a,r):s[n]=r}return s},r=e=>e>=200&&e<300,o=()=>!0,s=e=>new Promise(t=>setTimeout(t,e)),n=(e,t,r,o,s)=>({message:e,type:t,status:r,response:o,error:s}),a=e=>{if(e instanceof Error){const t=new Error(e.message);return e.name&&(t.name=e.name),e.stack&&(t.stack=e.stack),t}return new Error(String(e))},i=async(e,t,r)=>!!e?.enabled&&(!(t>(e.maxRetryCount??3))&&(e.shouldRetry?await e.shouldRetry(t,r):"network"===r.type||"timeout"===r.type)),u=(e,t)=>{const r=Object.create(e);let o=!1,s=!1,n=!1;const a=e.then.bind(e),i=e.catch.bind(e),c=a(e=>{n=!0===e.__errorSuppressed,delete e.__errorSuppressed;const t=new Proxy(e,{get(e,t){if(("1"===t||"number"==typeof t&&1===t)&&(s=!0),t===Symbol.iterator){const t=e[Symbol.iterator]();return function*(){let e=0;for(const r of t)1===e&&(s=!0),yield r,e++}}return e[t]}}),r=e[1];return e[2]||!r||n||o||queueMicrotask(()=>{queueMicrotask(()=>{if(!(s||s||o||n)){const e=new Error(`Unhandled fetch error: ${r.message} (type: ${r.type})`);throw e.fetchError=r,e}})}),t});r.cancel=()=>{t&&t()};const l=c.then.bind(c);return r.then=function(e,r){return e&&"function"==typeof e&&!r&&1===e.length?u(l(t=>{const r=t[2],o=t[0];return r&&void 0!==o&&e(o),t}),t):l(e,r)},r.catchHttp=function(e){o=!0;const r=l(t=>{const r=t[2],o=t[1];return!r&&o&&"http"===o.type&&e(o),!r&&o&&(t.__errorSuppressed=!0),t});return u(r,t)},r.catchBusiness=function(e){o=!0;const r=l(t=>{const r=t[1],o=t[2];return!o&&r&&"business"===r.type&&e(r),!o&&r&&(t.__errorSuppressed=!0),t});return u(r,t)},r.catchNetwork=function(e){if(o=!0,e&&"function"==typeof e){const r=l(t=>{const r=t[1],o=t[2];return!o&&r&&e(r),!o&&r&&(t.__errorSuppressed=!0),t});return u(r,t)}return i(e)},r};class c{globalConfig={};constructor(e){e&&(this.globalConfig={...e}),this.request=this.request.bind(this),this.sendGet=this.sendGet.bind(this),this.sendPost=this.sendPost.bind(this),this.sendPostForm=this.sendPostForm.bind(this),this.sendPostBlob=this.sendPostBlob.bind(this),this.sendGetBlob=this.sendGetBlob.bind(this),this.setGlobalConfig=this.setGlobalConfig.bind(this)}async executeRequest(t,u,c=1){try{const y=t,m=y.signal;m&&(m.aborted?u.abort():m.addEventListener("abort",()=>u.abort(),{once:!0}));const w=(l=y.headers,d=y.url,f=y.method,l?"function"==typeof l?l({url:d,method:f}):l:{}),{body:g,urlParams:E}=((t,r,o)=>{if(!t)return{};if("GET"===r||"HEAD"===r||"OPTIONS"===r){if(e(t)){const e=new URLSearchParams;for(const r in t)if(Object.prototype.hasOwnProperty.call(t,r)){const o=t[r];null!=o&&e.append(r,String(o))}return{urlParams:e.toString()}}return{}}if("form"===o&&e(t)){const e=new FormData;for(const r in t)if(Object.prototype.hasOwnProperty.call(t,r)){const o=t[r];null!=o&&(o instanceof File||o instanceof Blob?e.append(r,o):e.append(r,String(o)))}return{body:e}}return"json"===o?{body:JSON.stringify(t)}:"text"===o?{body:String(t)}:"blob"===o&&t instanceof Blob||"arraybuffer"===o&&t instanceof ArrayBuffer?{body:t}:{body:String(t)}})(y.data,y.method||"GET",y.requestType||"json"),P=((e,t,r)=>{if(t.startsWith("http://")||t.startsWith("https://")){if(r){const e=t.includes("?")?"&":"?";return`${t}${e}${r}`}return t}let o=t;e&&(o=`${e.endsWith("/")?e.slice(0,-1):e}${t.startsWith("/")?t:`/${t}`}`);if(r){const e=o.includes("?")?"&":"?";o=`${o}${e}${r}`}return o})(y.baseURL,y.url,E),S=y.timeout;let G,q=!1,T=w;g&&"string"==typeof g&&"json"===y.requestType?T={"Content-Type":"application/json",...w}:g instanceof FormData&&(T=w);const x=fetch(P,{method:y.method||"GET",headers:T,body:g,mode:("websocket"===y.mode?"cors":y.mode)||"cors",credentials:y.credentials||"include",signal:u.signal});let B;if(S){const e=new Promise((e,t)=>{G=setTimeout(()=>{q=!0,u.abort(),t(n("Request timeout","timeout"))},S)});try{B=await Promise.race([x,e]),G&&clearTimeout(G)}catch(b){if(G&&clearTimeout(G),q){const e=n("Request timeout","timeout");let t=!1;if(y.onNetworkError){const r=()=>{t=!0};await y.onNetworkError(a(new Error(e.message)),r)}if(await i(y.retry,c,e))return await s(y.retry?.delay||1e3),this.executeRequest(y,u,c+1);const r=[void 0,e,!1];return r.__errorSuppressed=t,r}throw b}}else B=await x;const _=y.responseType||"json";let R;try{R=await(async(e,t)=>{switch(t){case"json":default:return await e.json();case"text":return await e.text();case"blob":return await e.blob();case"arraybuffer":return await e.arrayBuffer();case"formData":return await e.formData()}})(B,_)}catch(p){const e=n("Failed to parse response","network",B.status,void 0,p instanceof Error?p:new Error(String(p)));let t=!1;if(y.onNetworkError){const r=()=>{t=!0};await y.onNetworkError(a(e.error||new Error(e.message)),r)}if(await i(y.retry,c,e))return await s(y.retry?.delay||1e3),this.executeRequest(y,u,c+1);const r=[void 0,e,!1];return r.__errorSuppressed=t,r}if(!(y.validateStatus||r)(B.status)){const e=n(`HTTP Error: ${B.status} ${B.statusText}`,"http",B.status,R);let t=!1;if(y.onHttpError){const r=()=>{t=!0},o=new Error(e.message);await y.onHttpError(o,B.status,R,r)}if(await i(y.retry,c,e))return await s(y.retry?.delay||1e3),this.executeRequest(y,u,c+1);const r=[void 0,e,!1];return r.__errorSuppressed=t,r}if(!(y.validateResponse||o)(R)){const e=n("Business validation failed","business",B.status,R);let t=!1;if(y.onBusinessError){const r=()=>{t=!0},o=new Error(e.message);await y.onBusinessError(o,R,r)}if(await i(y.retry,c,e))return await s(y.retry?.delay||1e3),this.executeRequest(y,u,c+1);const r=[void 0,e,!1];return r.__errorSuppressed=t,r}let C=R;if(y.transformResponse)try{C=y.transformResponse(R)}catch(h){console.warn("[toAwaitFetch] transformResponse error:",h)}return[C,void 0,!0]}catch(b){const e=(e=>e instanceof DOMException&&"AbortError"===e.name)(b),r=n(e?"Request aborted":b instanceof Error?b.message:"Network error","network",void 0,void 0,b instanceof Error?b:new Error(String(b)));let o=!1;if(t.onNetworkError){const e=()=>{o=!0};await t.onNetworkError(a(r.error||new Error(r.message)),e)}if(!e&&await i(t.retry,c,r))return await s(t.retry?.delay||1e3),this.executeRequest(t,u,c+1);const l=[void 0,r,!1];return l.__errorSuppressed=o,l}var l,d,f}request(e){const r=t({...this.globalConfig},e),o=new AbortController,s=this.executeRequest(r,o);return u(s,()=>o.abort())}setGlobalConfig(e){this.globalConfig={...e}}getGlobalConfig(){return{...this.globalConfig}}mergeGlobalConfig(e){this.globalConfig=t(this.globalConfig,e)}sendGet(e,t,r){return this.request({...r,url:e,method:"GET",data:t})}sendPost(e,t,r){return this.request({...r,url:e,method:"POST",data:t,requestType:"json"})}sendPostForm(e,t,r){return this.request({...r,url:e,method:"POST",data:t,requestType:"form"})}sendPostBlob(e,t,r){return this.request({...r,url:e,method:"POST",data:t,requestType:"json",responseType:"blob"})}sendGetBlob(e,t,r){return this.request({...r,url:e,method:"GET",data:t,responseType:"blob"})}}const l=e=>new c(e),d=new c,f=e=>{e?.cancel?.()},b=Object.assign(e=>e&&"object"==typeof e&&"url"in e?d.request(e):l(e),{create:l,sendGet:d.sendGet.bind(d),sendPost:d.sendPost.bind(d),sendPostForm:d.sendPostForm.bind(d),sendPostBlob:d.sendPostBlob.bind(d),sendGetBlob:d.sendGetBlob.bind(d),setGlobalConfig:d.setGlobalConfig.bind(d),cancel:f});exports.FetchInstanceImpl=c,exports.cancel=f,exports.createInstance=l,exports.default=b,exports.sendGet=(e,t,r)=>d.request({...r,url:e,method:"GET",data:t}),exports.sendGetBlob=(e,t,r)=>d.sendGetBlob(e,t,r),exports.sendPost=(e,t,r)=>d.sendPost(e,t,r),exports.sendPostBlob=(e,t,r)=>d.sendPostBlob(e,t,r),exports.sendPostForm=(e,t,r)=>d.sendPostForm(e,t,r),exports.setGlobalConfig=e=>{d.setGlobalConfig(e)};
@@ -0,0 +1 @@
1
+ const t=t=>!("object"!=typeof t||null===t||Array.isArray(t)||t instanceof Date||t instanceof RegExp||t instanceof File||t instanceof Blob||"undefined"!=typeof FormData&&t instanceof FormData),e=(r,o)=>{const s={...r};for(const n in o){if(!Object.prototype.hasOwnProperty.call(o,n))continue;const r=o[n];if(void 0===r)continue;const a=s[n];t(r)&&t(a)?s[n]=e(a,r):s[n]=r}return s},r=t=>t>=200&&t<300,o=()=>!0,s=t=>new Promise(e=>setTimeout(e,t)),n=(t,e,r,o,s)=>({message:t,type:e,status:r,response:o,error:s}),a=t=>{if(t instanceof Error){const e=new Error(t.message);return t.name&&(e.name=t.name),t.stack&&(e.stack=t.stack),e}return new Error(String(t))},i=async(t,e,r)=>!!t?.enabled&&(!(e>(t.maxRetryCount??3))&&(t.shouldRetry?await t.shouldRetry(e,r):"network"===r.type||"timeout"===r.type)),u=(t,e)=>{const r=Object.create(t);let o=!1,s=!1,n=!1;const a=t.then.bind(t),i=t.catch.bind(t),c=a(t=>{n=!0===t.__errorSuppressed,delete t.__errorSuppressed;const e=new Proxy(t,{get(t,e){if(("1"===e||"number"==typeof e&&1===e)&&(s=!0),e===Symbol.iterator){const e=t[Symbol.iterator]();return function*(){let t=0;for(const r of e)1===t&&(s=!0),yield r,t++}}return t[e]}}),r=t[1];return t[2]||!r||n||o||queueMicrotask(()=>{queueMicrotask(()=>{if(!(s||s||o||n)){const t=new Error(`Unhandled fetch error: ${r.message} (type: ${r.type})`);throw t.fetchError=r,t}})}),e});r.cancel=()=>{e&&e()};const d=c.then.bind(c);return r.then=function(t,r){return t&&"function"==typeof t&&!r&&1===t.length?u(d(e=>{const r=e[2],o=e[0];return r&&void 0!==o&&t(o),e}),e):d(t,r)},r.catchHttp=function(t){o=!0;const r=d(e=>{const r=e[2],o=e[1];return!r&&o&&"http"===o.type&&t(o),!r&&o&&(e.__errorSuppressed=!0),e});return u(r,e)},r.catchBusiness=function(t){o=!0;const r=d(e=>{const r=e[1],o=e[2];return!o&&r&&"business"===r.type&&t(r),!o&&r&&(e.__errorSuppressed=!0),e});return u(r,e)},r.catchNetwork=function(t){if(o=!0,t&&"function"==typeof t){const r=d(e=>{const r=e[1],o=e[2];return!o&&r&&t(r),!o&&r&&(e.__errorSuppressed=!0),e});return u(r,e)}return i(t)},r};class c{globalConfig={};constructor(t){t&&(this.globalConfig={...t}),this.request=this.request.bind(this),this.sendGet=this.sendGet.bind(this),this.sendPost=this.sendPost.bind(this),this.sendPostForm=this.sendPostForm.bind(this),this.sendPostBlob=this.sendPostBlob.bind(this),this.sendGetBlob=this.sendGetBlob.bind(this),this.setGlobalConfig=this.setGlobalConfig.bind(this)}async executeRequest(e,u,c=1){try{const y=e,m=y.signal;m&&(m.aborted?u.abort():m.addEventListener("abort",()=>u.abort(),{once:!0}));const w=(d=y.headers,l=y.url,f=y.method,d?"function"==typeof d?d({url:l,method:f}):d:{}),{body:g,urlParams:E}=((e,r,o)=>{if(!e)return{};if("GET"===r||"HEAD"===r||"OPTIONS"===r){if(t(e)){const t=new URLSearchParams;for(const r in e)if(Object.prototype.hasOwnProperty.call(e,r)){const o=e[r];null!=o&&t.append(r,String(o))}return{urlParams:t.toString()}}return{}}if("form"===o&&t(e)){const t=new FormData;for(const r in e)if(Object.prototype.hasOwnProperty.call(e,r)){const o=e[r];null!=o&&(o instanceof File||o instanceof Blob?t.append(r,o):t.append(r,String(o)))}return{body:t}}return"json"===o?{body:JSON.stringify(e)}:"text"===o?{body:String(e)}:"blob"===o&&e instanceof Blob||"arraybuffer"===o&&e instanceof ArrayBuffer?{body:e}:{body:String(e)}})(y.data,y.method||"GET",y.requestType||"json"),P=((t,e,r)=>{if(e.startsWith("http://")||e.startsWith("https://")){if(r){const t=e.includes("?")?"&":"?";return`${e}${t}${r}`}return e}let o=e;t&&(o=`${t.endsWith("/")?t.slice(0,-1):t}${e.startsWith("/")?e:`/${e}`}`);if(r){const t=o.includes("?")?"&":"?";o=`${o}${t}${r}`}return o})(y.baseURL,y.url,E),q=y.timeout;let S,T=!1,G=w;g&&"string"==typeof g&&"json"===y.requestType?G={"Content-Type":"application/json",...w}:g instanceof FormData&&(G=w);const B=fetch(P,{method:y.method||"GET",headers:G,body:g,mode:("websocket"===y.mode?"cors":y.mode)||"cors",credentials:y.credentials||"include",signal:u.signal});let R;if(q){const t=new Promise((t,e)=>{S=setTimeout(()=>{T=!0,u.abort(),e(n("Request timeout","timeout"))},q)});try{R=await Promise.race([B,t]),S&&clearTimeout(S)}catch(b){if(S&&clearTimeout(S),T){const t=n("Request timeout","timeout");let e=!1;if(y.onNetworkError){const r=()=>{e=!0};await y.onNetworkError(a(new Error(t.message)),r)}if(await i(y.retry,c,t))return await s(y.retry?.delay||1e3),this.executeRequest(y,u,c+1);const r=[void 0,t,!1];return r.__errorSuppressed=e,r}throw b}}else R=await B;const _=y.responseType||"json";let C;try{C=await(async(t,e)=>{switch(e){case"json":default:return await t.json();case"text":return await t.text();case"blob":return await t.blob();case"arraybuffer":return await t.arrayBuffer();case"formData":return await t.formData()}})(R,_)}catch(h){const t=n("Failed to parse response","network",R.status,void 0,h instanceof Error?h:new Error(String(h)));let e=!1;if(y.onNetworkError){const r=()=>{e=!0};await y.onNetworkError(a(t.error||new Error(t.message)),r)}if(await i(y.retry,c,t))return await s(y.retry?.delay||1e3),this.executeRequest(y,u,c+1);const r=[void 0,t,!1];return r.__errorSuppressed=e,r}if(!(y.validateStatus||r)(R.status)){const t=n(`HTTP Error: ${R.status} ${R.statusText}`,"http",R.status,C);let e=!1;if(y.onHttpError){const r=()=>{e=!0},o=new Error(t.message);await y.onHttpError(o,R.status,C,r)}if(await i(y.retry,c,t))return await s(y.retry?.delay||1e3),this.executeRequest(y,u,c+1);const r=[void 0,t,!1];return r.__errorSuppressed=e,r}if(!(y.validateResponse||o)(C)){const t=n("Business validation failed","business",R.status,C);let e=!1;if(y.onBusinessError){const r=()=>{e=!0},o=new Error(t.message);await y.onBusinessError(o,C,r)}if(await i(y.retry,c,t))return await s(y.retry?.delay||1e3),this.executeRequest(y,u,c+1);const r=[void 0,t,!1];return r.__errorSuppressed=e,r}let k=C;if(y.transformResponse)try{k=y.transformResponse(C)}catch(p){console.warn("[toAwaitFetch] transformResponse error:",p)}return[k,void 0,!0]}catch(b){const t=(t=>t instanceof DOMException&&"AbortError"===t.name)(b),r=n(t?"Request aborted":b instanceof Error?b.message:"Network error","network",void 0,void 0,b instanceof Error?b:new Error(String(b)));let o=!1;if(e.onNetworkError){const t=()=>{o=!0};await e.onNetworkError(a(r.error||new Error(r.message)),t)}if(!t&&await i(e.retry,c,r))return await s(e.retry?.delay||1e3),this.executeRequest(e,u,c+1);const d=[void 0,r,!1];return d.__errorSuppressed=o,d}var d,l,f}request(t){const r=e({...this.globalConfig},t),o=new AbortController,s=this.executeRequest(r,o);return u(s,()=>o.abort())}setGlobalConfig(t){this.globalConfig={...t}}getGlobalConfig(){return{...this.globalConfig}}mergeGlobalConfig(t){this.globalConfig=e(this.globalConfig,t)}sendGet(t,e,r){return this.request({...r,url:t,method:"GET",data:e})}sendPost(t,e,r){return this.request({...r,url:t,method:"POST",data:e,requestType:"json"})}sendPostForm(t,e,r){return this.request({...r,url:t,method:"POST",data:e,requestType:"form"})}sendPostBlob(t,e,r){return this.request({...r,url:t,method:"POST",data:e,requestType:"json",responseType:"blob"})}sendGetBlob(t,e,r){return this.request({...r,url:t,method:"GET",data:e,responseType:"blob"})}}const d=t=>new c(t),l=new c,f=(t,e,r)=>l.request({...r,url:t,method:"GET",data:e}),b=(t,e,r)=>l.sendPost(t,e,r),h=(t,e,r)=>l.sendPostForm(t,e,r),p=(t,e,r)=>l.sendPostBlob(t,e,r),y=(t,e,r)=>l.sendGetBlob(t,e,r),m=t=>{l.setGlobalConfig(t)},w=t=>{t?.cancel?.()},g=Object.assign(t=>t&&"object"==typeof t&&"url"in t?l.request(t):d(t),{create:d,sendGet:l.sendGet.bind(l),sendPost:l.sendPost.bind(l),sendPostForm:l.sendPostForm.bind(l),sendPostBlob:l.sendPostBlob.bind(l),sendGetBlob:l.sendGetBlob.bind(l),setGlobalConfig:l.setGlobalConfig.bind(l),cancel:w});export{c as FetchInstanceImpl,w as cancel,d as createInstance,g as default,f as sendGet,y as sendGetBlob,b as sendPost,p as sendPostBlob,h as sendPostForm,m as setGlobalConfig};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e="1.0.0";exports.VERSION=e,exports.getVersion=function(){return e};
@@ -0,0 +1,11 @@
1
+ /**
2
+ * 版本信息
3
+ * 在构建时由 Vite 注入
4
+ */
5
+ export declare const VERSION: string;
6
+ /**
7
+ * 获取当前 SDK 版本号
8
+ * @returns 版本号字符串
9
+ */
10
+ export declare function getVersion(): string;
11
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,OAAO,QAA6D,CAAA;AAEjF;;;GAGG;AACH,wBAAgB,UAAU,IAAI,MAAM,CAEnC"}
@@ -0,0 +1 @@
1
+ const n="1.0.0";function t(){return n}export{n as VERSION,t as getVersion};