sun-biz 0.0.1-beta.1

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 (84) hide show
  1. package/README.md +23 -0
  2. package/dist/components/index.d.ts +3 -0
  3. package/dist/components/index.js +7 -0
  4. package/dist/components/patient-access/api.d.ts +18 -0
  5. package/dist/components/patient-access/api.js +12 -0
  6. package/dist/components/patient-access/index.d.ts +5 -0
  7. package/dist/components/patient-access/index.js +691 -0
  8. package/dist/components/patient-access/types.d.js +1 -0
  9. package/dist/components/pro-table/composables/TableColumn.d.ts +14 -0
  10. package/dist/components/pro-table/index.d.ts +2 -0
  11. package/dist/components/pro-table/index.js +610 -0
  12. package/dist/components/pro-table/interface/index.d.ts +79 -0
  13. package/dist/components/pro-table/interface/index.js +2 -0
  14. package/dist/components/pro-table/utils.d.ts +39 -0
  15. package/dist/components/pro-table/utils.js +61 -0
  16. package/dist/components/title/index.d.ts +1 -0
  17. package/dist/components/title/index.js +24 -0
  18. package/dist/env.d.js +2 -0
  19. package/dist/hooks/index.d.ts +5 -0
  20. package/dist/hooks/index.js +12 -0
  21. package/dist/hooks/use-app-config/index.d.ts +25 -0
  22. package/dist/hooks/use-app-config/index.js +28 -0
  23. package/dist/hooks/use-app-config/types.d.ts +31 -0
  24. package/dist/hooks/use-app-config/types.js +1 -0
  25. package/dist/hooks/use-column&form-config/index.d.ts +13 -0
  26. package/dist/hooks/use-column&form-config/index.js +21 -0
  27. package/dist/hooks/use-direction-select/index.d.ts +63 -0
  28. package/dist/hooks/use-direction-select/index.js +87 -0
  29. package/dist/hooks/use-fetch-dataset/index.d.ts +12 -0
  30. package/dist/hooks/use-fetch-dataset/index.js +26 -0
  31. package/dist/hooks/use-fetch-dataset/types.d.js +1 -0
  32. package/dist/hooks/use-request/Fetch.d.ts +41 -0
  33. package/dist/hooks/use-request/Fetch.js +184 -0
  34. package/dist/hooks/use-request/config.d.ts +6 -0
  35. package/dist/hooks/use-request/config.js +14 -0
  36. package/dist/hooks/use-request/index.d.ts +5 -0
  37. package/dist/hooks/use-request/index.js +7 -0
  38. package/dist/hooks/use-request/plugins/useAutoRunPlugin.d.ts +3 -0
  39. package/dist/hooks/use-request/plugins/useAutoRunPlugin.js +40 -0
  40. package/dist/hooks/use-request/plugins/useCachePlugin.d.ts +3 -0
  41. package/dist/hooks/use-request/plugins/useCachePlugin.js +103 -0
  42. package/dist/hooks/use-request/plugins/useDebouncePlugin.d.ts +3 -0
  43. package/dist/hooks/use-request/plugins/useDebouncePlugin.js +41 -0
  44. package/dist/hooks/use-request/plugins/useLoadingDelayPlugin.d.ts +3 -0
  45. package/dist/hooks/use-request/plugins/useLoadingDelayPlugin.js +38 -0
  46. package/dist/hooks/use-request/plugins/usePollingPlugin.d.ts +3 -0
  47. package/dist/hooks/use-request/plugins/usePollingPlugin.js +44 -0
  48. package/dist/hooks/use-request/plugins/useRefreshOnWindowFocusPlugin.d.ts +3 -0
  49. package/dist/hooks/use-request/plugins/useRefreshOnWindowFocusPlugin.js +28 -0
  50. package/dist/hooks/use-request/plugins/useRetryPlugin.d.ts +3 -0
  51. package/dist/hooks/use-request/plugins/useRetryPlugin.js +35 -0
  52. package/dist/hooks/use-request/types.d.ts +267 -0
  53. package/dist/hooks/use-request/types.js +2 -0
  54. package/dist/hooks/use-request/useRequest.d.ts +7 -0
  55. package/dist/hooks/use-request/useRequest.js +28 -0
  56. package/dist/hooks/use-request/useRequestImplement.d.ts +3 -0
  57. package/dist/hooks/use-request/useRequestImplement.js +83 -0
  58. package/dist/hooks/use-request/useRequestProvider.d.ts +2 -0
  59. package/dist/hooks/use-request/useRequestProvider.js +6 -0
  60. package/dist/hooks/use-request/utils/cache.d.ts +17 -0
  61. package/dist/hooks/use-request/utils/cache.js +24 -0
  62. package/dist/hooks/use-request/utils/cachePromise.d.ts +4 -0
  63. package/dist/hooks/use-request/utils/cachePromise.js +15 -0
  64. package/dist/hooks/use-request/utils/cacheSubscribe.d.ts +5 -0
  65. package/dist/hooks/use-request/utils/cacheSubscribe.js +23 -0
  66. package/dist/hooks/use-request/utils/index.d.ts +6 -0
  67. package/dist/hooks/use-request/utils/index.js +8 -0
  68. package/dist/hooks/use-request/utils/isDocumentVisible.d.ts +1 -0
  69. package/dist/hooks/use-request/utils/isDocumentVisible.js +6 -0
  70. package/dist/hooks/use-request/utils/isOnline.d.ts +1 -0
  71. package/dist/hooks/use-request/utils/isOnline.js +6 -0
  72. package/dist/hooks/use-request/utils/limit.d.ts +1 -0
  73. package/dist/hooks/use-request/utils/limit.js +12 -0
  74. package/dist/hooks/use-request/utils/resolve-args.d.ts +2 -0
  75. package/dist/hooks/use-request/utils/resolve-args.js +7 -0
  76. package/dist/hooks/use-request/utils/subscribeFocus.d.ts +3 -0
  77. package/dist/hooks/use-request/utils/subscribeFocus.js +25 -0
  78. package/dist/hooks/use-request/utils/subscribeReVisible.d.ts +2 -0
  79. package/dist/hooks/use-request/utils/subscribeReVisible.js +22 -0
  80. package/dist/hooks/use-request/utils/utils.d.ts +3 -0
  81. package/dist/hooks/use-request/utils/utils.js +6 -0
  82. package/dist/index.d.ts +2 -0
  83. package/dist/index.js +5 -0
  84. package/package.json +67 -0
@@ -0,0 +1,267 @@
1
+ import { Ref, watch } from 'vue';
2
+ import { CachedData } from './utils/cache';
3
+ import UseRequestFetch from './Fetch';
4
+ export interface Result {
5
+ errorCode: string;
6
+ errorDetail: string;
7
+ errorMessage: string;
8
+ success: boolean;
9
+ traceId: string;
10
+ warningFlag: number;
11
+ }
12
+ export interface ResPage<T> extends Result {
13
+ data: T[];
14
+ total: number;
15
+ pageNum: number;
16
+ pageSize: number;
17
+ count: string;
18
+ }
19
+ export interface ResultData<T> extends Result {
20
+ data: T;
21
+ }
22
+ export type UseRequestService<TData, TParams extends unknown[]> = (...args: TParams) => Promise<[
23
+ Error | undefined,
24
+ TParams[0] extends {
25
+ pageSize: number;
26
+ pageNumber: number;
27
+ } ? ResPage<TData> : ResultData<TData> | undefined
28
+ ]>;
29
+ export type UseRequestSubscribe = () => void;
30
+ export interface UseRequestFetchState<TData, TParams extends unknown[]> {
31
+ loading: boolean;
32
+ total: any;
33
+ params?: TParams;
34
+ data?: TData;
35
+ restData?: any;
36
+ error?: Error | unknown;
37
+ }
38
+ export interface UseRequestPluginReturn<TData, TParams extends unknown[]> {
39
+ name?: string;
40
+ onBefore?: (params: TParams) => ({
41
+ stopNow?: boolean;
42
+ returnNow?: boolean;
43
+ } & Partial<UseRequestFetchState<TData, TParams>>) | void;
44
+ onRequest?: (service: UseRequestService<TData, TParams>, params: TParams) => {
45
+ servicePromise?: Promise<TData>;
46
+ };
47
+ onSuccess?: (data: TData, params: TParams) => void;
48
+ onError?: (e: Error, params: TParams) => void;
49
+ onFinally?: (params: TParams, data?: TData, e?: Error) => void;
50
+ onCancel?: () => void;
51
+ onMutate?: (data: TData) => void;
52
+ }
53
+ export type RequestHook<TData = any, TParams extends any[] = any[]> = (service: UseRequestService<TData, TParams>, options: UseRequestOptions<TData, TParams, any>, plugins: UseRequestPlugin<TData, TParams>[]) => useRequestResult<TData, TParams>;
54
+ export type UseRequestMiddleware<TData, TParams extends any[]> = (useRequestNext: RequestHook<TData, TParams>) => RequestHook<TData, TParams>;
55
+ export type UseRequestBasicOptions<TData, TParams extends unknown[]> = {
56
+ /**
57
+ * Init data.
58
+ */
59
+ /**
60
+ * - The default is `false.` That is, the service is automatically executed during initialization.
61
+ * - f set to `true`, you need to manually call `run` or r`unAsync` to trigger execution.
62
+ */
63
+ manual?: boolean;
64
+ /**
65
+ * The parameters passed to the service at the first default execution
66
+ */
67
+ defaultParams?: TParams;
68
+ /**
69
+ * Triggered before service execution
70
+ * @param params TParams
71
+ * @returns void
72
+ */
73
+ onBefore?: (params: TParams) => void;
74
+ /**
75
+ * Triggered when service resolve.
76
+ * @param data TData
77
+ * @param params TParams
78
+ * @returns void
79
+ */
80
+ onSuccess?: (data: TData, params: TParams) => void;
81
+ /**
82
+ * Triggered when service reject.
83
+ * @param e Error
84
+ * @param params TParams
85
+ * @returns void
86
+ */
87
+ onError?: (e: Error, params: TParams) => void;
88
+ /**
89
+ * Triggered when service execution is complete.
90
+ * @param params TParams
91
+ * @param data TData
92
+ * @param e Error
93
+ * @returns void
94
+ */
95
+ onFinally?: (params: TParams, data?: TData, e?: Error) => void;
96
+ /**
97
+ * Is the current request ready
98
+ */
99
+ ready?: Ref<boolean> | boolean;
100
+ /**
101
+ * Dependent on responsive objects, and the `watch` incoming listener object usage for `vue`.
102
+ */
103
+ refreshDeps?: Parameters<typeof watch>[0][] | boolean;
104
+ refreshDepsAction?: () => void;
105
+ /**
106
+ * Set the delay time for `loading` to become `true`.
107
+ *
108
+ */
109
+ loadingDelay?: number | Ref<number>;
110
+ /**
111
+ * open vue devtools,debugKey must existence and uniqueness.
112
+ */
113
+ debugKey?: string;
114
+ /**
115
+ * Format the request results, which recommend to use `useFormatResult`.
116
+ * @param data TData
117
+ * @returns unknown need cover TData
118
+ */
119
+ /**
120
+ * Polling interval, in milliseconds. If the value is greater than 0, the polling mode is activated.
121
+ */
122
+ pollingInterval?: Ref<number> | number;
123
+ /**
124
+ * Whether to continue polling when the page is hidden. If set to false, polling will be temporarily paused when the page is hidden, and resume when the page is visible again.
125
+ */
126
+ pollingWhenHidden?: boolean;
127
+ /**
128
+ * Number of polling error retries. If set to -1, `an infinite number of times`.
129
+ */
130
+ pollingErrorRetryCount?: number;
131
+ /**
132
+ * Whether to re-initiate the request when the screen refocus or revisible.
133
+ */
134
+ refreshOnWindowFocus?: Ref<boolean> | boolean;
135
+ /**
136
+ * Re-request interval, in milliseconds.
137
+ */
138
+ focusTimespan?: Ref<number> | number;
139
+ /**
140
+ * Debounce delay time, in milliseconds. After setting, enter the debounce mode.
141
+ */
142
+ debounceWait?: Ref<number> | number;
143
+ /**
144
+ * Execute the request before the delay starts.
145
+ */
146
+ debounceLeading?: Ref<boolean> | boolean;
147
+ /**
148
+ * Execute the request after the delay ends.
149
+ */
150
+ debounceTrailing?: Ref<boolean> | boolean;
151
+ /**
152
+ * The maximum time request is allowed to be delayed before it’s executed.
153
+ */
154
+ debounceMaxWait?: Ref<number> | number;
155
+ /**
156
+ * Throttle wait time, in milliseconds. After setting, enter the throttle mode.
157
+ */
158
+ throttleWait?: Ref<number> | number;
159
+ /**
160
+ * Execute the request before throttling starts.
161
+ */
162
+ throttleLeading?: Ref<boolean> | boolean;
163
+ /**
164
+ * Execute the request after throttling ends.
165
+ */
166
+ throttleTrailing?: Ref<boolean> | boolean;
167
+ /**
168
+ * A unique ID of the request. If `cacheKey` is set, we will enable the caching mechanism. The data of the same `cacheKey` is globally synchronized.
169
+ */
170
+ cacheKey?: string;
171
+ /**
172
+ * - Set the cache time. By default, the cached data will be cleared after 5 minutes.
173
+ * - If set to `-1`, the cached data will never expire.
174
+ */
175
+ cacheTime?: number;
176
+ /**
177
+ * - Time to consider the cached data is fresh. Within this time interval, the request will not be re-initiated.
178
+ * - If set to `-1`, it means that the data is always fresh
179
+ */
180
+ staleTime?: number;
181
+ /**
182
+ * - Custom set cache.
183
+ * - `setCache` and `getCache` need to be used together.
184
+ * - In the custom cache mode, `cacheTime` and `clearCache` are useless, please implement it yourself according to the actual situation.
185
+ * @param data CachedData
186
+ * @returns void
187
+ */
188
+ setCache?: (data: CachedData<TData, TParams>) => void;
189
+ /**
190
+ * Custom get cache
191
+ * @param params TParams
192
+ * @returns CachedData
193
+ */
194
+ getCache?: (params: TParams) => CachedData<TData, TParams> | undefined;
195
+ /**
196
+ * The number of retries. If set to `-1`, it will try again indefinitely.
197
+ */
198
+ retryCount?: number;
199
+ /**
200
+ * - Retry interval in milliseconds.
201
+ * If not set, the simple exponential backoff algorithm will be used by default, taking `1000 * 2 ** retryCount`, that is, waiting for 2s for the first retry, and 4s for the second retry. By analogy, if it is greater than 30s, take 30s.
202
+ */
203
+ retryInterval?: number;
204
+ /**
205
+ * Middleware
206
+ */
207
+ use?: UseRequestMiddleware<TData, TParams>[];
208
+ rollbackOnError?: boolean | ((params: TParams) => boolean);
209
+ };
210
+ export type UseRequestOptions<TData, TParams extends any[] = any[], TPlugin = any> = UseRequestBasicOptions<TData, TParams> & {
211
+ pluginOptions?: TPlugin;
212
+ };
213
+ export type UseRequestOptionsWithFormatResult<TData, TParams extends any[] = any[], TPlugin = any, SR = any> = UseRequestOptions<TData, TParams, TPlugin> & {
214
+ formatResult: (res: SR) => TData;
215
+ };
216
+ export type UseRequestOptionsWithInitialData<TData, TParams extends any[] = any[], TPlugin = any> = UseRequestOptions<TData, TParams, TPlugin> & {
217
+ initialData: TData extends infer R ? R : TData;
218
+ };
219
+ export interface UseRequestPlugin<TData, TParams extends unknown[] = unknown[], TPlugin = any> {
220
+ (fetchInstance: UseRequestFetch<TData, TParams>, options: UseRequestOptions<TData, TParams, TPlugin>): UseRequestPluginReturn<TData, TParams>;
221
+ onInit?: (options: UseRequestOptions<TData, TParams, TPlugin>) => Partial<UseRequestFetchState<TData, TParams>>;
222
+ }
223
+ export interface useRequestResult<TData, TParams extends unknown[]> {
224
+ /**
225
+ * Is the service being executed.
226
+ */
227
+ loading: Readonly<Ref<boolean>>;
228
+ /**
229
+ * Data returned by service.
230
+ */
231
+ data: Readonly<Ref<TData | undefined>>;
232
+ /**
233
+ * Exception thrown by service.
234
+ */
235
+ error: Readonly<Ref<Error | undefined>>;
236
+ /**
237
+ * params An array of parameters for the service being executed. For example, you triggered `run(1, 2, 3)`, then params is equal to `[1, 2, 3]`.
238
+ */
239
+ params: Readonly<Ref<TParams | []>>;
240
+ total: Readonly<Ref<number>>;
241
+ /**
242
+ * Ignore the current promise response.
243
+ */
244
+ cancel: UseRequestFetch<TData, TParams>['cancel'];
245
+ /**
246
+ * Use the last params, call `run` again.
247
+ */
248
+ refresh: UseRequestFetch<TData, TParams>['refresh'];
249
+ /**
250
+ * Use the last params, call `runAsync` again.
251
+ */
252
+ refreshAsync: UseRequestFetch<TData, TParams>['refreshAsync'];
253
+ /**
254
+ * Manually trigger the execution of the service, and the parameters will be passed to the service.
255
+ */
256
+ run: UseRequestFetch<TData, TParams>['run'];
257
+ /**
258
+ * Automatic handling of exceptions, feedback through `onError`
259
+ */
260
+ runAsync: UseRequestFetch<TData, TParams>['runAsync'];
261
+ /**
262
+ * Mutate `data` directly
263
+ */
264
+ mutate: UseRequestFetch<TData, TParams>['mutate'];
265
+ }
266
+ export type Timeout = ReturnType<typeof setTimeout>;
267
+ export type Interval = ReturnType<typeof setInterval>;
@@ -0,0 +1,2 @@
1
+ // CONCATENATED MODULE: ./src/hooks/use-request/types.ts
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
@@ -0,0 +1,7 @@
1
+ import { UseRequestOptions, UseRequestOptionsWithFormatResult, UseRequestOptionsWithInitialData, UseRequestPlugin, useRequestResult, UseRequestService } from './types';
2
+ export type PluginsMiddleOptionsType<PluginsOptions, TData, TParams extends unknown[] = unknown[]> = PluginsOptions extends (infer P)[] ? P extends UseRequestPlugin<TData, TParams, infer R> ? R : never : never;
3
+ export declare function useRequest<TData, TParams extends unknown[] = unknown[], PluginsOptions extends UseRequestPlugin<TData, TParams>[] = UseRequestPlugin<TData, TParams>[], SR = any>(service: UseRequestService<SR, TParams>, options: UseRequestOptionsWithFormatResult<TData, TParams, PluginsMiddleOptionsType<PluginsOptions, TData, TParams>, SR> & UseRequestOptionsWithInitialData<SR, TParams, PluginsOptions>, plugins?: PluginsOptions): useRequestResult<TData, TParams>;
4
+ export declare function useRequest<TData, TParams extends unknown[] = unknown[], PluginsOptions extends UseRequestPlugin<TData, TParams>[] = UseRequestPlugin<TData, TParams>[], SR = any>(service: UseRequestService<SR, TParams>, options: UseRequestOptionsWithFormatResult<TData, TParams, PluginsMiddleOptionsType<PluginsOptions, TData, TParams>, SR>, plugins?: PluginsOptions): useRequestResult<TData, TParams>;
5
+ export declare function useRequest<TData, TParams extends unknown[] = unknown[], PluginsOptions extends UseRequestPlugin<TData, TParams>[] = UseRequestPlugin<TData, TParams>[]>(service: UseRequestService<TData, TParams>, options: UseRequestOptionsWithInitialData<TData, TParams, PluginsMiddleOptionsType<PluginsOptions, TData, TParams>>, plugins?: PluginsOptions): useRequestResult<TData, TParams>;
6
+ export declare function useRequest<TData, TParams extends unknown[] = unknown[], PluginsOptions extends UseRequestPlugin<TData, TParams>[] = UseRequestPlugin<TData, TParams>[]>(service: UseRequestService<TData, TParams>, options?: UseRequestOptions<TData, TParams, PluginsMiddleOptionsType<PluginsOptions, TData, TParams>>, plugins?: PluginsOptions): useRequestResult<TData, TParams>;
7
+ export default useRequest;
@@ -0,0 +1,28 @@
1
+ import * as __WEBPACK_EXTERNAL_MODULE__plugins_useAutoRunPlugin_js__ from "./plugins/useAutoRunPlugin.js";
2
+ import * as __WEBPACK_EXTERNAL_MODULE__useRequestImplement_js__ from "./useRequestImplement.js";
3
+ import * as __WEBPACK_EXTERNAL_MODULE__utils_resolve_args_js__ from "./utils/resolve-args.js";
4
+ /* eslint-disable @typescript-eslint/no-explicit-any */ // import useCachePlugin from './plugins/useCachePlugin';
5
+ // import useDebouncePlugin from './plugins/useDebouncePlugin';
6
+ // import useDevtoolsPlugin from './plugins/useDevtoolsPlugin';
7
+ // import useLoadingDelayPlugin from './plugins/useLoadingDelayPlugin';
8
+ // import usePollingPlugin from './plugins/usePollingPlugin';
9
+ // import useRefreshOnWindowFocusPlugin from './plugins/useRefreshOnWindowFocusPlugin';
10
+ // import useRetryPlugin from './plugins/useRetryPlugin';
11
+ // import useThrottlePlugin from './plugins/useThrottlePlugin';
12
+ function useRequest_useRequest(service, options, plugins) {
13
+ const BuiltInPlugins = [
14
+ // process?.env?.NODE_ENV === 'development' ? useDevtoolsPlugin : null,
15
+ // useDebouncePlugin,
16
+ // useLoadingDelayPlugin,
17
+ // usePollingPlugin,
18
+ // useRefreshOnWindowFocusPlugin,
19
+ // useThrottlePlugin,
20
+ __WEBPACK_EXTERNAL_MODULE__plugins_useAutoRunPlugin_js__["default"]
21
+ ].filter(Boolean);
22
+ return (0, __WEBPACK_EXTERNAL_MODULE__utils_resolve_args_js__.withArgs)(__WEBPACK_EXTERNAL_MODULE__useRequestImplement_js__["default"], options?.use)(service, options, [
23
+ ...plugins || [],
24
+ ...BuiltInPlugins
25
+ ]);
26
+ }
27
+ /* ESM default export */ const useRequest = useRequest_useRequest;
28
+ export { useRequest as default, useRequest_useRequest as useRequest };
@@ -0,0 +1,3 @@
1
+ import { UseRequestOptions, UseRequestPlugin, useRequestResult, UseRequestService } from './types';
2
+ declare function useRequestImplement<TData, TParams extends any[]>(service: UseRequestService<TData, TParams>, options?: UseRequestOptions<TData, TParams>, plugins?: UseRequestPlugin<TData, TParams>[]): useRequestResult<TData, TParams>;
3
+ export default useRequestImplement;
@@ -0,0 +1,83 @@
1
+ import * as __WEBPACK_EXTERNAL_MODULE_vue__ from "vue";
2
+ import * as __WEBPACK_EXTERNAL_MODULE__Fetch_js__ from "./Fetch.js";
3
+ import * as __WEBPACK_EXTERNAL_MODULE__config_js__ from "./config.js";
4
+ /* eslint-disable @typescript-eslint/no-explicit-any */ function isUseRequestFetchState(state) {
5
+ const keys = Object.keys(state);
6
+ return 4 === keys.filter((i)=>[
7
+ 'data',
8
+ 'loading',
9
+ 'params',
10
+ 'error'
11
+ ].includes(i)).length;
12
+ }
13
+ function useRequestImplement(service, options = {}, plugins = []) {
14
+ // global option
15
+ const USEREQUEST_GLOBAL_OPTIONS = (0, __WEBPACK_EXTERNAL_MODULE_vue__.inject)(__WEBPACK_EXTERNAL_MODULE__config_js__.USEREQUEST_GLOBAL_OPTIONS_PROVIDE_KEY, {});
16
+ // read option
17
+ const { initialData, manual = false, ready = true, ...rest } = {
18
+ ...USEREQUEST_GLOBAL_OPTIONS ?? {},
19
+ ...options ?? {}
20
+ };
21
+ const fetchOptions = {
22
+ manual,
23
+ ready,
24
+ initialData,
25
+ ...rest
26
+ };
27
+ // serviceRef store service
28
+ const serviceRef = (0, __WEBPACK_EXTERNAL_MODULE_vue__.ref)(service);
29
+ // reactive
30
+ const state = (0, __WEBPACK_EXTERNAL_MODULE_vue__.reactive)({
31
+ data: initialData,
32
+ loading: false,
33
+ total: 0,
34
+ restData: void 0,
35
+ params: void 0,
36
+ error: void 0
37
+ });
38
+ const setState = (currentState, field)=>{
39
+ if (field) state[field] = currentState;
40
+ else if (isUseRequestFetchState(currentState)) {
41
+ state.data = currentState.data;
42
+ state.loading = currentState.loading;
43
+ state.error = currentState.error;
44
+ state.params = currentState.params;
45
+ if (currentState.total) state.total = currentState.total;
46
+ if (currentState.restData) state.restData = currentState.restData;
47
+ }
48
+ };
49
+ const initState = plugins.map((p)=>p?.onInit?.(fetchOptions)).filter(Boolean);
50
+ // Fetch Instance
51
+ const fetchInstance = new __WEBPACK_EXTERNAL_MODULE__Fetch_js__["default"](serviceRef, fetchOptions, setState, Object.assign({}, ...initState, state));
52
+ fetchInstance.options = fetchOptions;
53
+ // run plugins
54
+ fetchInstance.pluginImpls = plugins.map((p)=>p(fetchInstance, fetchOptions));
55
+ const readyComputed = (0, __WEBPACK_EXTERNAL_MODULE_vue__.computed)(()=>(0, __WEBPACK_EXTERNAL_MODULE_vue__.isRef)(ready) ? ready.value : ready);
56
+ (0, __WEBPACK_EXTERNAL_MODULE_vue__.watchEffect)(()=>{
57
+ if (!manual) {
58
+ const params = fetchInstance.state.params || options.defaultParams || [];
59
+ // auto collect
60
+ if (readyComputed.value && true === fetchInstance.options.refreshDeps && !!serviceRef.value) fetchInstance.run(...params);
61
+ }
62
+ });
63
+ // manual
64
+ if (!manual && true !== fetchInstance.options.refreshDeps) {
65
+ const params = fetchInstance.state.params || options.defaultParams || [];
66
+ if ((0, __WEBPACK_EXTERNAL_MODULE_vue__.unref)(ready)) fetchInstance.run(...params);
67
+ }
68
+ // onUnmounted cancel request
69
+ (0, __WEBPACK_EXTERNAL_MODULE_vue__.onScopeDispose)(()=>{
70
+ fetchInstance.cancel();
71
+ });
72
+ return {
73
+ ...(0, __WEBPACK_EXTERNAL_MODULE_vue__.toRefs)(state),
74
+ cancel: fetchInstance.cancel.bind(fetchInstance),
75
+ refresh: fetchInstance.refresh.bind(fetchInstance),
76
+ refreshAsync: fetchInstance.refreshAsync.bind(fetchInstance),
77
+ run: fetchInstance.run.bind(fetchInstance),
78
+ runAsync: fetchInstance.runAsync.bind(fetchInstance),
79
+ mutate: fetchInstance.mutate.bind(fetchInstance)
80
+ };
81
+ }
82
+ /* ESM default export */ const use_request_useRequestImplement = useRequestImplement;
83
+ export { use_request_useRequestImplement as default };
@@ -0,0 +1,2 @@
1
+ import type { UseRequestOptions } from './types';
2
+ export default function useRequestProvider(config: UseRequestOptions<unknown, any, any>): void;
@@ -0,0 +1,6 @@
1
+ import * as __WEBPACK_EXTERNAL_MODULE_vue__ from "vue";
2
+ import * as __WEBPACK_EXTERNAL_MODULE__config_js__ from "./config.js";
3
+ /* eslint-disable @typescript-eslint/no-explicit-any */ function useRequestProvider(config) {
4
+ (0, __WEBPACK_EXTERNAL_MODULE_vue__.provide)(__WEBPACK_EXTERNAL_MODULE__config_js__.USEREQUEST_GLOBAL_OPTIONS_PROVIDE_KEY, config);
5
+ }
6
+ export { useRequestProvider as default };
@@ -0,0 +1,17 @@
1
+ type Timer = ReturnType<typeof setTimeout>;
2
+ type CachedKey = string | number;
3
+ export interface CachedData<TData = any, TParams = any> {
4
+ data: TData;
5
+ params: TParams;
6
+ time: number;
7
+ }
8
+ interface RecordData extends CachedData {
9
+ timer: Timer | undefined;
10
+ }
11
+ declare const setCache: (key: CachedKey, cacheTime: number, cachedData: CachedData) => void;
12
+ declare const getCache: (key: CachedKey) => RecordData | undefined;
13
+ declare const getCacheAll: () => {
14
+ [k: string]: RecordData;
15
+ };
16
+ declare const clearCache: (key?: string | string[]) => void;
17
+ export { getCache, setCache, clearCache, getCacheAll };
@@ -0,0 +1,24 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */ const cache = new Map();
2
+ const setCache = (key, cacheTime, cachedData)=>{
3
+ const currentCache = cache.get(key);
4
+ if (currentCache?.timer) clearTimeout(currentCache.timer);
5
+ let timer;
6
+ if (cacheTime > -1) timer = setTimeout(()=>{
7
+ cache.delete(key);
8
+ }, cacheTime);
9
+ cache.set(key, {
10
+ ...cachedData,
11
+ timer
12
+ });
13
+ };
14
+ const getCache = (key)=>cache.get(key);
15
+ const getCacheAll = ()=>Object.fromEntries(cache.entries());
16
+ const clearCache = (key)=>{
17
+ if (key) {
18
+ const cacheKeys = Array.isArray(key) ? key : [
19
+ key
20
+ ];
21
+ cacheKeys.forEach((cacheKey)=>cache.delete(cacheKey));
22
+ } else cache.clear();
23
+ };
24
+ export { clearCache, getCache, getCacheAll, setCache };
@@ -0,0 +1,4 @@
1
+ type CachedKey = string | number;
2
+ declare const getCachePromise: (cacheKey: CachedKey) => Promise<any> | undefined;
3
+ declare const setCachePromise: (cacheKey: CachedKey, promise: Promise<any>) => void;
4
+ export { getCachePromise, setCachePromise };
@@ -0,0 +1,15 @@
1
+ const cachePromise = new Map();
2
+ const getCachePromise = (cacheKey)=>cachePromise.get(cacheKey);
3
+ const setCachePromise = (cacheKey, promise)=>{
4
+ // 应该缓存同样的请求
5
+ cachePromise.set(cacheKey, promise);
6
+ // 兼容-不使用promise.finally
7
+ promise.then((res)=>{
8
+ cachePromise.delete(cacheKey);
9
+ return res;
10
+ }).catch((err)=>{
11
+ cachePromise.delete(cacheKey);
12
+ throw err;
13
+ });
14
+ };
15
+ export { getCachePromise, setCachePromise };
@@ -0,0 +1,5 @@
1
+ type Listener = (data: any) => void;
2
+ declare const trigger: (key: string, data: any) => void;
3
+ declare const subscribe: (key: string, listener: Listener) => () => void;
4
+ declare const otherSubscribe: (listener: Listener) => void;
5
+ export { trigger, subscribe, otherSubscribe };
@@ -0,0 +1,23 @@
1
+ const listeners = {};
2
+ const otherListeners = [];
3
+ const trigger = (key, data)=>{
4
+ if (listeners[key]) {
5
+ listeners[key].forEach((item)=>item(data));
6
+ otherListeners.forEach((item)=>item({
7
+ type: key,
8
+ data
9
+ }));
10
+ }
11
+ };
12
+ const subscribe = (key, listener)=>{
13
+ if (!listeners[key]) listeners[key] = [];
14
+ listeners[key].push(listener);
15
+ return function() {
16
+ const index = listeners[key].indexOf(listener);
17
+ listeners[key].splice(index, 1);
18
+ };
19
+ };
20
+ const otherSubscribe = (listener)=>{
21
+ otherListeners.push(listener);
22
+ };
23
+ export { otherSubscribe, subscribe, trigger };
@@ -0,0 +1,6 @@
1
+ export declare const isObject: (value: unknown) => value is Record<any, any>;
2
+ export declare const isFunction: (value: unknown) => value is Function;
3
+ export declare const isString: (value: unknown) => value is string;
4
+ export declare const isBoolean: (value: unknown) => value is boolean;
5
+ export declare const isNumber: (value: unknown) => value is number;
6
+ export declare const isUndef: (value: unknown) => value is undefined;
@@ -0,0 +1,8 @@
1
+ const isObject = (value)=>null !== value && 'object' == typeof value;
2
+ // eslint-disable-next-line @typescript-eslint/ban-types
3
+ const isFunction = (value)=>'function' == typeof value;
4
+ const isString = (value)=>'string' == typeof value;
5
+ const isBoolean = (value)=>'boolean' == typeof value;
6
+ const isNumber = (value)=>'number' == typeof value;
7
+ const isUndef = (value)=>void 0 === value;
8
+ export { isBoolean, isFunction, isNumber, isObject, isString, isUndef };
@@ -0,0 +1 @@
1
+ export default function isDocumentVisible(): boolean;
@@ -0,0 +1,6 @@
1
+ import * as __WEBPACK_EXTERNAL_MODULE__utils_js__ from "./utils.js";
2
+ function isDocumentVisible() {
3
+ if ((0, __WEBPACK_EXTERNAL_MODULE__utils_js__.canUseDom)()) return 'hidden' !== document.visibilityState;
4
+ return true;
5
+ }
6
+ export { isDocumentVisible as default };
@@ -0,0 +1 @@
1
+ export default function isOnline(): boolean;
@@ -0,0 +1,6 @@
1
+ import * as __WEBPACK_EXTERNAL_MODULE__utils_js__ from "./utils.js";
2
+ function isOnline() {
3
+ if ((0, __WEBPACK_EXTERNAL_MODULE__utils_js__.canUseDom)() && void 0 !== navigator.onLine) return navigator.onLine;
4
+ return true;
5
+ }
6
+ export { isOnline as default };
@@ -0,0 +1 @@
1
+ export default function limit(fn: any, timespan: number): (...args: any[]) => void;
@@ -0,0 +1,12 @@
1
+ function limit(fn, timespan) {
2
+ let pending = false;
3
+ return (...args)=>{
4
+ if (pending) return;
5
+ pending = true;
6
+ fn(...args);
7
+ setTimeout(()=>{
8
+ pending = false;
9
+ }, timespan);
10
+ };
11
+ }
12
+ export { limit as default };
@@ -0,0 +1,2 @@
1
+ import { RequestHook, UseRequestMiddleware, UseRequestOptions, UseRequestPlugin, UseRequestService, useRequestResult } from '../types';
2
+ export declare const withArgs: <TData, TParams extends any[]>(hook: RequestHook<TData, TParams>, use?: UseRequestMiddleware<TData, TParams>[]) => (service: UseRequestService<TData, TParams>, options?: UseRequestOptions<TData, TParams, any>, plugins?: UseRequestPlugin<TData, TParams>[]) => useRequestResult<TData, TParams>;
@@ -0,0 +1,7 @@
1
+ const withArgs = (hook, use)=>function(service, options = {}, plugins = []) {
2
+ let next = hook;
3
+ const middleware = use || [];
4
+ for(let i = middleware.length; i--;)next = middleware[i](next);
5
+ return next(service, options, plugins);
6
+ };
7
+ export { withArgs };
@@ -0,0 +1,3 @@
1
+ type Listener = () => void;
2
+ declare function subscribe(listener: Listener): () => void;
3
+ export default subscribe;
@@ -0,0 +1,25 @@
1
+ import * as __WEBPACK_EXTERNAL_MODULE__utils_js__ from "./utils.js";
2
+ import * as __WEBPACK_EXTERNAL_MODULE__isDocumentVisible_js__ from "./isDocumentVisible.js";
3
+ import * as __WEBPACK_EXTERNAL_MODULE__isOnline_js__ from "./isOnline.js";
4
+ // from swr
5
+ const listeners = [];
6
+ function subscribe(listener) {
7
+ listeners.push(listener);
8
+ return function() {
9
+ const index = listeners.indexOf(listener);
10
+ if (index > -1) listeners.splice(index, 1);
11
+ };
12
+ }
13
+ if (__WEBPACK_EXTERNAL_MODULE__utils_js__["default"]) {
14
+ const revalidate = ()=>{
15
+ if (!(0, __WEBPACK_EXTERNAL_MODULE__isDocumentVisible_js__["default"])() || !(0, __WEBPACK_EXTERNAL_MODULE__isOnline_js__["default"])()) return;
16
+ for(let i = 0; i < listeners.length; i++){
17
+ const listener = listeners[i];
18
+ listener();
19
+ }
20
+ };
21
+ window.addEventListener('visibilitychange', revalidate, false);
22
+ window.addEventListener('focus', revalidate, false);
23
+ }
24
+ /* ESM default export */ const subscribeFocus = subscribe;
25
+ export { subscribeFocus as default };
@@ -0,0 +1,2 @@
1
+ declare function subscribe(listener: () => void): () => void;
2
+ export default subscribe;
@@ -0,0 +1,22 @@
1
+ import * as __WEBPACK_EXTERNAL_MODULE__isDocumentVisible_js__ from "./isDocumentVisible.js";
2
+ import * as __WEBPACK_EXTERNAL_MODULE__utils_js__ from "./utils.js";
3
+ const listeners = [];
4
+ function subscribe(listener) {
5
+ listeners.push(listener);
6
+ return function() {
7
+ const index = listeners.indexOf(listener);
8
+ listeners.splice(index, 1);
9
+ };
10
+ }
11
+ if ((0, __WEBPACK_EXTERNAL_MODULE__utils_js__.canUseDom)()) {
12
+ const revalidate = ()=>{
13
+ if (!(0, __WEBPACK_EXTERNAL_MODULE__isDocumentVisible_js__["default"])()) return;
14
+ for(let i = 0; i < listeners.length; i++){
15
+ const listener = listeners[i];
16
+ listener();
17
+ }
18
+ };
19
+ window.addEventListener("visibilitychange", revalidate, false);
20
+ }
21
+ /* ESM default export */ const subscribeReVisible = subscribe;
22
+ export { subscribeReVisible as default };
@@ -0,0 +1,3 @@
1
+ export declare function canUseDom(): boolean;
2
+ declare const isBrowser: boolean;
3
+ export default isBrowser;
@@ -0,0 +1,6 @@
1
+ function canUseDom() {
2
+ return !!('undefined' != typeof window && window.document && window.document.createElement);
3
+ }
4
+ const isBrowser = !!('undefined' != typeof window && window.document && window.document.createElement);
5
+ /* ESM default export */ const utils = isBrowser;
6
+ export { canUseDom, utils as default };
@@ -0,0 +1,2 @@
1
+ export * from './components/index';
2
+ export * from './hooks/index';