zf-dbs 2.0.1 → 2.0.2
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.
- package/dist/index.d.ts +88 -13
- package/dist/index.mjs +117 -95
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -183,9 +183,32 @@ readonly appElement: HTMLElement | null;
|
|
|
183
183
|
readonly appViewElement: HTMLElement | null;
|
|
184
184
|
}>;
|
|
185
185
|
|
|
186
|
-
|
|
186
|
+
/**
|
|
187
|
+
* 轮询 Hook
|
|
188
|
+
*
|
|
189
|
+
* 类型推导效果:
|
|
190
|
+
* - listener 返回 Promise<User>,state => User | D
|
|
191
|
+
* - defaultValue 不传,state => User | undefined
|
|
192
|
+
* - defaultValue 传 0,state => User | 0
|
|
193
|
+
*
|
|
194
|
+
* setConfig 只允许修改运行时安全项:
|
|
195
|
+
* - delay
|
|
196
|
+
* - leading
|
|
197
|
+
* - resetOnExecute
|
|
198
|
+
* - throwError
|
|
199
|
+
* - onError
|
|
200
|
+
* - onSuccess
|
|
201
|
+
*
|
|
202
|
+
* 不允许修改:
|
|
203
|
+
* - shallow
|
|
204
|
+
* - immediate
|
|
205
|
+
*/
|
|
206
|
+
export declare function usePolling<TListener extends UsePollingListener<any>, D = undefined, TConfig extends UsePollingConfig<UsePollingResolvedValue<TListener>> = UsePollingConfig<UsePollingResolvedValue<TListener>>>(listener: TListener, defaultValue?: UsePollingDefaultValue<D>, config?: TConfig): UsePollingResponse<UsePollingResolvedValue<TListener>, TConfig, D>;
|
|
187
207
|
|
|
188
|
-
|
|
208
|
+
/**
|
|
209
|
+
* 原始配置
|
|
210
|
+
*/
|
|
211
|
+
declare type UsePollingConfig<TResult> = {
|
|
189
212
|
delay?: number;
|
|
190
213
|
immediate?: boolean;
|
|
191
214
|
leading?: boolean;
|
|
@@ -193,43 +216,95 @@ declare type UsePollingConfig<T> = {
|
|
|
193
216
|
resetOnExecute?: boolean;
|
|
194
217
|
throwError?: boolean;
|
|
195
218
|
onError?: (error: unknown) => void;
|
|
196
|
-
onSuccess?: (result:
|
|
219
|
+
onSuccess?: (result: TResult) => void;
|
|
197
220
|
};
|
|
198
221
|
|
|
222
|
+
/**
|
|
223
|
+
* 默认值
|
|
224
|
+
* 允许不传,也允许显式传 undefined
|
|
225
|
+
*/
|
|
199
226
|
declare type UsePollingDefaultValue<T = undefined> = T | undefined;
|
|
200
227
|
|
|
201
|
-
|
|
228
|
+
/**
|
|
229
|
+
* 轮询监听器
|
|
230
|
+
* 支持同步值,也支持 Promise
|
|
231
|
+
*/
|
|
232
|
+
declare type UsePollingListener<TResult> = () => TResult | Promise<TResult>;
|
|
202
233
|
|
|
203
|
-
|
|
234
|
+
/**
|
|
235
|
+
* 允许运行时修改的配置
|
|
236
|
+
* shallow / immediate 不允许改
|
|
237
|
+
*/
|
|
238
|
+
declare type UsePollingMutableConfig<TResult> = Omit<UsePollingConfig<TResult>, 'shallow' | 'immediate'>;
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* 仅返回 state 的版本
|
|
242
|
+
* 参数、类型推导、默认值行为都和 usePolling 完全一致
|
|
243
|
+
*/
|
|
244
|
+
export declare function usePollingRef<TListener extends UsePollingListener<any>, D = undefined, TConfig extends UsePollingConfig<Awaited<ReturnType<TListener>>> = UsePollingConfig<Awaited<ReturnType<TListener>>>>(listener: TListener, defaultValue?: UsePollingDefaultValue<D>, config?: TConfig): UsePollingResponse<Awaited<ReturnType<TListener>>, TConfig, D>['state'];
|
|
204
245
|
|
|
205
|
-
|
|
206
|
-
|
|
246
|
+
/**
|
|
247
|
+
* listener 的最终返回值
|
|
248
|
+
* Promise<T> 会自动解包成 T
|
|
249
|
+
*/
|
|
250
|
+
declare type UsePollingResolvedValue<TListener extends UsePollingListener<any>> = Awaited<ReturnType<TListener>>;
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* 对外返回值
|
|
254
|
+
*/
|
|
255
|
+
declare type UsePollingResponse<TResult, TConfig extends UsePollingConfig<TResult>, D = undefined> = {
|
|
256
|
+
state: UsePollingStateTypeRef<TResult, TConfig, D>;
|
|
207
257
|
isLoading: Ref_2<boolean>;
|
|
208
258
|
error: Ref_2<unknown>;
|
|
209
|
-
execute: UsePollingResponseExecute<
|
|
259
|
+
execute: UsePollingResponseExecute<TResult>;
|
|
210
260
|
pause: () => void;
|
|
211
261
|
resume: UsePollingResponseResume;
|
|
212
262
|
reset: () => void;
|
|
263
|
+
setConfig: (config: UsePollingSetConfig<TResult>) => void;
|
|
213
264
|
};
|
|
214
265
|
|
|
215
|
-
|
|
266
|
+
/**
|
|
267
|
+
* 主动执行
|
|
268
|
+
*/
|
|
269
|
+
declare type UsePollingResponseExecute<TResult> = (config?: UsePollingResponseExecuteConfig<TResult>) => Promise<void>;
|
|
216
270
|
|
|
217
|
-
|
|
271
|
+
/**
|
|
272
|
+
* 执行时可覆盖的配置
|
|
273
|
+
*/
|
|
274
|
+
declare type UsePollingResponseExecuteConfig<TResult> = {
|
|
218
275
|
resetOnExecute?: boolean;
|
|
219
276
|
throwError?: boolean;
|
|
220
277
|
onError?: (error: unknown) => void;
|
|
221
|
-
onSuccess?: (result:
|
|
278
|
+
onSuccess?: (result: TResult) => void;
|
|
222
279
|
};
|
|
223
280
|
|
|
281
|
+
/**
|
|
282
|
+
* 继续轮询
|
|
283
|
+
*/
|
|
224
284
|
declare type UsePollingResponseResume = (config?: UsePollingResponseResumeConfig) => void;
|
|
225
285
|
|
|
286
|
+
/**
|
|
287
|
+
* 继续轮询时的配置
|
|
288
|
+
*/
|
|
226
289
|
declare type UsePollingResponseResumeConfig = {
|
|
227
290
|
leading?: boolean;
|
|
228
291
|
};
|
|
229
292
|
|
|
230
|
-
|
|
293
|
+
/**
|
|
294
|
+
* setConfig 的入参
|
|
295
|
+
*/
|
|
296
|
+
declare type UsePollingSetConfig<TResult> = Partial<UsePollingMutableConfig<TResult>>;
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* state 的值类型
|
|
300
|
+
* 结果类型 + 默认值类型
|
|
301
|
+
*/
|
|
302
|
+
declare type UsePollingStateType<TResult, D = undefined> = TResult | D;
|
|
231
303
|
|
|
232
|
-
|
|
304
|
+
/**
|
|
305
|
+
* shallow 模式下返回 ShallowRef,否则返回 Ref
|
|
306
|
+
*/
|
|
307
|
+
declare type UsePollingStateTypeRef<TResult, TConfig extends UsePollingConfig<TResult>, D = undefined> = TConfig['shallow'] extends true ? ShallowRef<UsePollingStateType<TResult, D>> : Ref_2<UsePollingStateType<TResult, D>>;
|
|
233
308
|
|
|
234
309
|
export declare const ZfApp: __VLS_WithTemplateSlots<DefineComponent< {}, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<globalThis.ExtractPropTypes<{}>>, {}, {}>, {
|
|
235
310
|
default?(_: {}): any;
|
package/dist/index.mjs
CHANGED
|
@@ -1,22 +1,17 @@
|
|
|
1
|
-
import { a as b, g as
|
|
2
|
-
import { z as
|
|
3
|
-
import { _ as
|
|
4
|
-
import { _ as
|
|
5
|
-
import { z as
|
|
6
|
-
import { ref as
|
|
7
|
-
import { ElNotification as
|
|
8
|
-
import { Z as
|
|
9
|
-
const
|
|
1
|
+
import { a as b, g as O, m as A, t as S, _ as q } from "./chunks/qN7meZTV.mjs";
|
|
2
|
+
import { z as X, d as Y, u as ee, b as oe } from "./chunks/qN7meZTV.mjs";
|
|
3
|
+
import { _ as j } from "./chunks/Ck0Cdfr_.mjs";
|
|
4
|
+
import { _ as N } from "./chunks/BHHE86vT.mjs";
|
|
5
|
+
import { z as ne } from "./chunks/BHHE86vT.mjs";
|
|
6
|
+
import { ref as i, shallowRef as z, onMounted as P, onBeforeUnmount as T } from "vue";
|
|
7
|
+
import { ElNotification as U } from "element-plus";
|
|
8
|
+
import { Z as se } from "./chunks/DbOTUn3A.mjs";
|
|
9
|
+
const L = function(e) {
|
|
10
10
|
return e;
|
|
11
11
|
};
|
|
12
|
-
function
|
|
13
|
-
return
|
|
14
|
-
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
function j(e, t, o) {
|
|
18
|
-
o = Object.assign({
|
|
19
|
-
delay: 3e3,
|
|
12
|
+
function Z() {
|
|
13
|
+
return {
|
|
14
|
+
delay: b.value?.pollingInterval || 3e3,
|
|
20
15
|
immediate: !0,
|
|
21
16
|
leading: !0,
|
|
22
17
|
resetOnExecute: !1,
|
|
@@ -26,146 +21,173 @@ function j(e, t, o) {
|
|
|
26
21
|
},
|
|
27
22
|
onSuccess: () => {
|
|
28
23
|
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function H() {
|
|
27
|
+
return new Promise((e) => {
|
|
28
|
+
requestAnimationFrame(() => e());
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
function I(e, o, t) {
|
|
32
|
+
const n = Object.assign(Z(), t ?? {}), r = i(0), f = o, p = n.shallow ? z(f) : i(f), d = i(!1), v = i(null), l = i(null), u = i(!0), m = () => {
|
|
33
|
+
l.value !== null && (clearTimeout(l.value), l.value = null);
|
|
34
|
+
}, C = (c) => {
|
|
35
|
+
Object.assign(n, c);
|
|
36
|
+
}, w = async (c) => {
|
|
37
|
+
const g = Object.assign(
|
|
38
|
+
{
|
|
39
|
+
resetOnExecute: n.resetOnExecute,
|
|
40
|
+
throwError: n.throwError,
|
|
41
|
+
onError: n.onError,
|
|
42
|
+
onSuccess: n.onSuccess
|
|
43
|
+
},
|
|
44
|
+
c ?? {}
|
|
45
|
+
);
|
|
46
|
+
r.value += 1;
|
|
47
|
+
const E = r.value;
|
|
48
|
+
d.value = !0, g.resetOnExecute && (p.value = o);
|
|
35
49
|
try {
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
} catch (
|
|
39
|
-
if (
|
|
40
|
-
throw
|
|
50
|
+
const s = await Promise.resolve(e());
|
|
51
|
+
E === r.value && (v.value = null, p.value = s, g.onSuccess?.(s));
|
|
52
|
+
} catch (s) {
|
|
53
|
+
if (E === r.value && (v.value = s, g.onError?.(s), g.throwError))
|
|
54
|
+
throw s;
|
|
41
55
|
} finally {
|
|
42
|
-
|
|
56
|
+
E === r.value && (d.value = !1);
|
|
43
57
|
}
|
|
44
|
-
},
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
|
|
58
|
+
}, _ = () => {
|
|
59
|
+
m(), !u.value && (l.value = setTimeout(async () => {
|
|
60
|
+
if (l.value = null, !u.value)
|
|
61
|
+
try {
|
|
62
|
+
await w();
|
|
63
|
+
} catch {
|
|
64
|
+
} finally {
|
|
65
|
+
await H(), u.value || _();
|
|
66
|
+
}
|
|
67
|
+
}, n.delay));
|
|
68
|
+
}, h = () => {
|
|
69
|
+
u.value = !0, m();
|
|
70
|
+
}, x = (c = { leading: n.leading }) => {
|
|
71
|
+
u.value = !1, m(), c.leading && w().catch(() => {
|
|
72
|
+
}), _();
|
|
73
|
+
}, y = () => {
|
|
74
|
+
h(), r.value = 0, p.value = o, d.value = !1, v.value = null, n.immediate && x();
|
|
56
75
|
};
|
|
57
|
-
return
|
|
58
|
-
|
|
76
|
+
return P(() => {
|
|
77
|
+
y();
|
|
78
|
+
}), T(() => {
|
|
79
|
+
h();
|
|
59
80
|
}), {
|
|
60
|
-
state:
|
|
61
|
-
isLoading:
|
|
62
|
-
error:
|
|
63
|
-
execute:
|
|
64
|
-
pause:
|
|
65
|
-
resume:
|
|
66
|
-
reset:
|
|
81
|
+
state: p,
|
|
82
|
+
isLoading: d,
|
|
83
|
+
error: v,
|
|
84
|
+
execute: w,
|
|
85
|
+
pause: h,
|
|
86
|
+
resume: x,
|
|
87
|
+
reset: y,
|
|
88
|
+
setConfig: C
|
|
67
89
|
};
|
|
68
90
|
}
|
|
69
|
-
function
|
|
70
|
-
return
|
|
91
|
+
function k(e, o, t) {
|
|
92
|
+
return I(e, o, t).state;
|
|
71
93
|
}
|
|
72
|
-
function
|
|
94
|
+
function R() {
|
|
73
95
|
if (!b.value)
|
|
74
96
|
throw new Error("请先调用 defineAppConfig 进行配置");
|
|
75
97
|
return b.value;
|
|
76
98
|
}
|
|
77
|
-
const
|
|
78
|
-
return
|
|
99
|
+
const a = Object.assign(function(e) {
|
|
100
|
+
return U({
|
|
79
101
|
...e,
|
|
80
|
-
appendTo:
|
|
102
|
+
appendTo: O().appViewElement || document.body || void 0
|
|
81
103
|
});
|
|
82
104
|
}, {
|
|
83
105
|
success(e) {
|
|
84
|
-
return
|
|
106
|
+
return a({
|
|
85
107
|
...e,
|
|
86
108
|
type: "success"
|
|
87
109
|
});
|
|
88
110
|
},
|
|
89
111
|
info(e) {
|
|
90
|
-
return
|
|
112
|
+
return a({
|
|
91
113
|
...e,
|
|
92
114
|
type: "info"
|
|
93
115
|
});
|
|
94
116
|
},
|
|
95
117
|
warning(e) {
|
|
96
|
-
return
|
|
118
|
+
return a({
|
|
97
119
|
...e,
|
|
98
120
|
type: "warning"
|
|
99
121
|
});
|
|
100
122
|
},
|
|
101
123
|
error(e) {
|
|
102
|
-
return
|
|
124
|
+
return a({
|
|
103
125
|
...e,
|
|
104
126
|
type: "error"
|
|
105
127
|
});
|
|
106
128
|
}
|
|
107
|
-
}),
|
|
108
|
-
const e =
|
|
129
|
+
}), G = A(() => {
|
|
130
|
+
const e = R();
|
|
109
131
|
return {
|
|
110
132
|
...e.request,
|
|
111
|
-
errorHandle(
|
|
112
|
-
if (e.request.showErrorMessage &&
|
|
113
|
-
return e.request.errorHandle(
|
|
133
|
+
errorHandle(o, t, n) {
|
|
134
|
+
if (e.request.showErrorMessage && a.error({ message: t }), e.request.errorHandle)
|
|
135
|
+
return e.request.errorHandle(o, t, n);
|
|
114
136
|
}
|
|
115
137
|
};
|
|
116
138
|
});
|
|
117
|
-
class
|
|
139
|
+
class $ extends S {
|
|
118
140
|
/**
|
|
119
141
|
* 发送事件
|
|
120
142
|
* @param {string} name 事件名称
|
|
121
143
|
* @param {unknown[]} args 参数
|
|
122
144
|
*/
|
|
123
|
-
emit(
|
|
124
|
-
return
|
|
145
|
+
emit(o, ...t) {
|
|
146
|
+
return t = t.map((n) => JSON.parse(JSON.stringify(n))), console.log(`%c发送UE事件 %c${o}`, "color: #529b2e; font-weight: bold;", "color: #337ecc", ...t), window?.ue?.web?.[o]?.(...t);
|
|
125
147
|
}
|
|
126
148
|
/**
|
|
127
149
|
* 注册事件
|
|
128
150
|
* @param {string} name 事件名称
|
|
129
151
|
* @param {UnknownFunction} listener 事件处理函数
|
|
130
152
|
*/
|
|
131
|
-
on(
|
|
132
|
-
return console.log(`%c注册UE事件 %c${
|
|
153
|
+
on(o, t) {
|
|
154
|
+
return console.log(`%c注册UE事件 %c${o}`, "color: #b88230; font-weight: bold;", "color: #337ecc"), window[o] || (window[o] = this.dispatchEvent.bind(this, o)), super.on(o, t);
|
|
133
155
|
}
|
|
134
156
|
/**
|
|
135
157
|
* 注销事件
|
|
136
158
|
* @param {string} name 事件名称
|
|
137
159
|
* @param {UnknownFunction} listener 事件处理函数
|
|
138
160
|
*/
|
|
139
|
-
off(
|
|
140
|
-
console.log(`%c注销UE事件 %c${
|
|
141
|
-
const n = super.off(
|
|
142
|
-
return this.listeners(
|
|
161
|
+
off(o, t) {
|
|
162
|
+
console.log(`%c注销UE事件 %c${o}`, "color: #909399; font-weight: bold;", "color: #337ecc");
|
|
163
|
+
const n = super.off(o, t);
|
|
164
|
+
return this.listeners(o).length || delete window[o], n;
|
|
143
165
|
}
|
|
144
166
|
}
|
|
145
|
-
const
|
|
167
|
+
const K = new $(), Q = {
|
|
146
168
|
install(e) {
|
|
147
|
-
Object.entries(/* @__PURE__ */ Object.assign({ "./components/zf-app/index.ts":
|
|
148
|
-
const r = n.default,
|
|
149
|
-
e.component(
|
|
169
|
+
Object.entries(/* @__PURE__ */ Object.assign({ "./components/zf-app/index.ts": q, "./components/zf-scale-container/index.ts": j, "./components/zf-tween-number/index.ts": N })).forEach(([t, n]) => {
|
|
170
|
+
const r = n.default, f = t.split("/")[2];
|
|
171
|
+
e.component(f, r);
|
|
150
172
|
});
|
|
151
173
|
}
|
|
152
174
|
};
|
|
153
175
|
export {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
176
|
+
$ as Ue,
|
|
177
|
+
X as ZfApp,
|
|
178
|
+
se as ZfScaleContainer,
|
|
179
|
+
ne as ZfTweenNumber,
|
|
180
|
+
Q as default,
|
|
181
|
+
Y as defineAppConfig,
|
|
182
|
+
A as defineRequest,
|
|
183
|
+
L as defineService,
|
|
184
|
+
R as getAppConfig,
|
|
185
|
+
O as getAppInfo,
|
|
186
|
+
a as notify,
|
|
187
|
+
G as request,
|
|
188
|
+
K as ue,
|
|
189
|
+
ee as useAppConfig,
|
|
190
|
+
oe as useAppInfo,
|
|
191
|
+
I as usePolling,
|
|
192
|
+
k as usePollingRef
|
|
171
193
|
};
|