nhanh-pure-function 1.1.0 → 1.2.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.
- package/lib/Index.d.ts +5 -1
- package/lib/Index.js +2 -1
- package/lib/User.d.ts +18 -14
- package/lib/User.js +32 -10
- package/lib/Utility.d.ts +40 -3
- package/lib/Utility.js +53 -0
- package/lib/index.css +8 -0
- package/lib/index.less +5 -0
- package/lib/test.ts +1 -0
- package/package.json +1 -1
package/lib/Index.d.ts
CHANGED
package/lib/Index.js
CHANGED
package/lib/User.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export function _AddScrollBottomListener(
|
|
|
13
13
|
* @param ask 请求方法
|
|
14
14
|
* @param config 请求参数
|
|
15
15
|
*/
|
|
16
|
-
export function _PagingQuery<Ask extends
|
|
16
|
+
export function _PagingQuery<Ask extends (...args: any[]) => any>(
|
|
17
17
|
ask: Ask,
|
|
18
18
|
config: {
|
|
19
19
|
currentPage: number;
|
|
@@ -70,10 +70,10 @@ export function _SetQuantifierAttribute<T>(
|
|
|
70
70
|
*/
|
|
71
71
|
export function _SetDefaultValue<T>(
|
|
72
72
|
data: T,
|
|
73
|
-
options
|
|
73
|
+
options?: {
|
|
74
74
|
defaultValue?: string;
|
|
75
75
|
fieldsNotRequiringAction?: (string | number | symbol)[];
|
|
76
|
-
}
|
|
76
|
+
}
|
|
77
77
|
): T;
|
|
78
78
|
|
|
79
79
|
/**
|
|
@@ -116,7 +116,7 @@ export function _SetPhoto<T>(
|
|
|
116
116
|
*/
|
|
117
117
|
export function _Exhibit_details<T>(
|
|
118
118
|
data: T,
|
|
119
|
-
options
|
|
119
|
+
options?: {
|
|
120
120
|
dictionaryOptions?: { [key in keyof T]: { [key: string | number]: any } };
|
|
121
121
|
dictionaryLabel?: (keyof T)[];
|
|
122
122
|
dictionaryLabelJoin?: (keyof T)[];
|
|
@@ -141,7 +141,7 @@ export function _Exhibit_details<T>(
|
|
|
141
141
|
filterLabel?: (keyof T)[];
|
|
142
142
|
|
|
143
143
|
defaultValue?: string;
|
|
144
|
-
}
|
|
144
|
+
}
|
|
145
145
|
): T;
|
|
146
146
|
|
|
147
147
|
// 定义加载状态更新函数类型
|
|
@@ -149,7 +149,7 @@ type LoadingStateUpdater = (newState: boolean) => void;
|
|
|
149
149
|
// 定义加载控制器的类型
|
|
150
150
|
interface LoadingController {
|
|
151
151
|
invokers: Set<any>; // 假设invoker可以是任何类型
|
|
152
|
-
timer:
|
|
152
|
+
timer: number | null;
|
|
153
153
|
startTime: number;
|
|
154
154
|
loadingState: LoadingStateUpdater;
|
|
155
155
|
delayTime: number;
|
|
@@ -159,11 +159,9 @@ interface LoadingController {
|
|
|
159
159
|
export class _LoadingController {
|
|
160
160
|
#controllersCollection: Map<string, LoadingController>;
|
|
161
161
|
|
|
162
|
-
constructor() {}
|
|
163
|
-
|
|
164
162
|
// addController方法的类型定义
|
|
165
163
|
addController(
|
|
166
|
-
key
|
|
164
|
+
key: string,
|
|
167
165
|
config: {
|
|
168
166
|
loadingState: LoadingStateUpdater;
|
|
169
167
|
delayTime?: number;
|
|
@@ -190,14 +188,20 @@ export class _LoadingController {
|
|
|
190
188
|
type UiLibrary = "naiveUI" | "ElementPlus" | "Element";
|
|
191
189
|
/**
|
|
192
190
|
* 点击非指定dom(包含子级dom)时执行 callback
|
|
193
|
-
* @param
|
|
191
|
+
* @param querySelector 允许点击的 dom 顶层祖先元素选择器
|
|
194
192
|
* @param callback 满足条件时执行的回调
|
|
195
|
-
*
|
|
193
|
+
*
|
|
194
|
+
* @param options 其他配置
|
|
195
|
+
* @param options.uiLibrary 项目使用的 ui库 , 用于排除 ui库 创建的元素 , 避免点击 ui库 创建的元素时意外的执行 callback
|
|
196
|
+
* @param options.isClickAllowed 是否允许该点击 ( 如果不确定可以返回 undefined )
|
|
196
197
|
*/
|
|
197
198
|
export function _CloseOnOutsideClick(
|
|
198
|
-
|
|
199
|
+
querySelector: string[],
|
|
199
200
|
callback: Function,
|
|
200
|
-
|
|
201
|
+
options?: {
|
|
202
|
+
uiLibrary?: UiLibrary[];
|
|
203
|
+
isClickAllowed?: (event: MouseEvent) => boolean | undefined;
|
|
204
|
+
}
|
|
201
205
|
): void;
|
|
202
206
|
|
|
203
207
|
/** 拖拽配置 */
|
|
@@ -250,7 +254,7 @@ export class LocalDrag {
|
|
|
250
254
|
* @param parentDom 被拖拽元素的祖先元素
|
|
251
255
|
* @param option 局部拖拽配置
|
|
252
256
|
*/
|
|
253
|
-
init(parentDom: HTMLElement, options
|
|
257
|
+
init(parentDom: HTMLElement, options?: LocalDragOptions): void;
|
|
254
258
|
/** 结束拖拽 */
|
|
255
259
|
finish(): void;
|
|
256
260
|
}
|
package/lib/User.js
CHANGED
|
@@ -413,17 +413,38 @@ export class _LoadingController {
|
|
|
413
413
|
|
|
414
414
|
/**
|
|
415
415
|
* 点击非指定dom(包含子级dom)时执行 callback
|
|
416
|
-
* @param
|
|
416
|
+
* @param querySelector 允许点击的 dom 顶层祖先元素选择器
|
|
417
417
|
* @param callback 满足条件时执行的回调
|
|
418
|
-
*
|
|
418
|
+
*
|
|
419
|
+
* @param options 其他配置
|
|
420
|
+
* @param options.uiLibrary 项目使用的 ui库 , 用于排除 ui库 创建的元素 , 避免点击 ui库 创建的元素时意外的执行 callback
|
|
421
|
+
* @param options.isClickAllowed 是否允许该点击 ( 如果不确定可以返回 undefined )
|
|
419
422
|
*/
|
|
420
423
|
export function _CloseOnOutsideClick(
|
|
421
|
-
|
|
424
|
+
querySelector,
|
|
422
425
|
callback,
|
|
423
|
-
|
|
426
|
+
options = {
|
|
427
|
+
uiLibrary: ["naiveUI", "ElementPlus", "Element"],
|
|
428
|
+
}
|
|
424
429
|
) {
|
|
430
|
+
function end() {
|
|
431
|
+
callback();
|
|
432
|
+
document.removeEventListener("mousedown", mousedown);
|
|
433
|
+
}
|
|
425
434
|
function mousedown(event) {
|
|
435
|
+
const { isClickAllowed, uiLibrary } = options;
|
|
436
|
+
|
|
437
|
+
if (isClickAllowed) {
|
|
438
|
+
const bool = isClickAllowed(event);
|
|
439
|
+
if (bool) return;
|
|
440
|
+
if (bool === false) return end();
|
|
441
|
+
}
|
|
442
|
+
|
|
426
443
|
const target = event.target;
|
|
444
|
+
|
|
445
|
+
/** 元素这时可能已经被删除了 */
|
|
446
|
+
if (!target?.closest("body")) return;
|
|
447
|
+
|
|
427
448
|
const UI = (function (obj) {
|
|
428
449
|
const arr = [];
|
|
429
450
|
for (const key in obj) {
|
|
@@ -433,18 +454,19 @@ export function _CloseOnOutsideClick(
|
|
|
433
454
|
}
|
|
434
455
|
return arr;
|
|
435
456
|
})({
|
|
436
|
-
naiveUI: [
|
|
457
|
+
naiveUI: [
|
|
458
|
+
".v-binder-follower-container",
|
|
459
|
+
".n-image-preview-container",
|
|
460
|
+
".n-modal-container",
|
|
461
|
+
],
|
|
437
462
|
ElementPlus: ["el-popper"],
|
|
438
463
|
Element: ["el-popper"],
|
|
439
464
|
});
|
|
440
|
-
const isClickable =
|
|
465
|
+
const isClickable = querySelector
|
|
441
466
|
.concat(UI)
|
|
442
467
|
.some((className) => Boolean(target?.closest(className)));
|
|
443
468
|
|
|
444
|
-
if (!isClickable)
|
|
445
|
-
callback();
|
|
446
|
-
document.removeEventListener("mousedown", mousedown);
|
|
447
|
-
}
|
|
469
|
+
if (!isClickable) end();
|
|
448
470
|
}
|
|
449
471
|
requestAnimationFrame(() =>
|
|
450
472
|
document.addEventListener("mousedown", mousedown)
|
package/lib/Utility.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ExtractParameters } from "./Index";
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* 非null | undefined判断
|
|
3
5
|
* @param value any
|
|
@@ -40,7 +42,7 @@ export function _ConvertToPercentage(
|
|
|
40
42
|
export function _WaitForCondition(
|
|
41
43
|
conditionChecker: () => boolean,
|
|
42
44
|
timeoutMillis: number
|
|
43
|
-
): Promise
|
|
45
|
+
): Promise<"完成" | "超时">;
|
|
44
46
|
|
|
45
47
|
/**
|
|
46
48
|
* 排除子串
|
|
@@ -116,7 +118,7 @@ export function _DownloadFile(href: string, fileName?: string): void;
|
|
|
116
118
|
*/
|
|
117
119
|
export function _GetFrameRate(
|
|
118
120
|
callback: (fps: number, frameTime: number) => void,
|
|
119
|
-
referenceNode: number
|
|
121
|
+
referenceNode: number
|
|
120
122
|
): void;
|
|
121
123
|
|
|
122
124
|
/**
|
|
@@ -126,7 +128,7 @@ export function _GetFrameRate(
|
|
|
126
128
|
*/
|
|
127
129
|
export function _Schedule(
|
|
128
130
|
callback: (schedule: number) => void,
|
|
129
|
-
TIME: number
|
|
131
|
+
TIME: number
|
|
130
132
|
): void;
|
|
131
133
|
|
|
132
134
|
/**
|
|
@@ -165,3 +167,38 @@ export function _CreateAndDownloadFile(
|
|
|
165
167
|
fileName: string,
|
|
166
168
|
options?: BlobPropertyBag
|
|
167
169
|
): void;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* 获取url参数
|
|
173
|
+
* @param {string} url
|
|
174
|
+
* @returns {Object}
|
|
175
|
+
*/
|
|
176
|
+
export function _GetQueryParams(url: string): void;
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* 生成uuid
|
|
180
|
+
* @returns {string}
|
|
181
|
+
*/
|
|
182
|
+
export function _GenerateUUID(): string;
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* 防抖
|
|
186
|
+
* @param {Function} fn
|
|
187
|
+
* @param {number} delay
|
|
188
|
+
* @returns {Function}
|
|
189
|
+
*/
|
|
190
|
+
export function _Debounce<T extends Function>(
|
|
191
|
+
fn: T,
|
|
192
|
+
delay: number
|
|
193
|
+
): (...args: ExtractParameters<T>) => void;
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* 节流
|
|
197
|
+
* @param {Function} fn
|
|
198
|
+
* @param {number} delay
|
|
199
|
+
* @returns {Function}
|
|
200
|
+
*/
|
|
201
|
+
export function _Throttle<T extends Function>(
|
|
202
|
+
fn: T,
|
|
203
|
+
delay: number
|
|
204
|
+
): (...args: ExtractParameters<T>) => void;
|
package/lib/Utility.js
CHANGED
|
@@ -328,3 +328,56 @@ export function _CreateAndDownloadFile(content, fileName, options) {
|
|
|
328
328
|
// 最后,别忘了撤销 Blob 对象的 URL,以释放资源
|
|
329
329
|
URL.revokeObjectURL(url);
|
|
330
330
|
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* 获取url参数
|
|
334
|
+
* @param {string} url
|
|
335
|
+
* @returns {Object}
|
|
336
|
+
*/
|
|
337
|
+
export function _GetQueryParams(url) {
|
|
338
|
+
return Object.fromEntries(new URL(url).searchParams);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* 生成uuid
|
|
343
|
+
* @returns {string}
|
|
344
|
+
*/
|
|
345
|
+
export function _GenerateUUID() {
|
|
346
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
|
|
347
|
+
const r = (Math.random() * 16) | 0; // 随机生成一个0到15的数
|
|
348
|
+
const v = c === "x" ? r : (r & 0x3) | 0x8; // 对于'y'位, v = (r & 0x3 | 0x8) 确保变体正确
|
|
349
|
+
return v.toString(16); // 将数字转换为16进制
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* 防抖
|
|
355
|
+
* @param {Function} fn
|
|
356
|
+
* @param {number} delay
|
|
357
|
+
* @returns {Function}
|
|
358
|
+
*/
|
|
359
|
+
export function _Debounce(fn, delay) {
|
|
360
|
+
let timeoutId;
|
|
361
|
+
return function (...args) {
|
|
362
|
+
clearTimeout(timeoutId);
|
|
363
|
+
timeoutId = setTimeout(() => fn.apply(this, args), delay);
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* 节流
|
|
369
|
+
* @param {Function} fn
|
|
370
|
+
* @param {number} delay
|
|
371
|
+
* @returns {Function}
|
|
372
|
+
*/
|
|
373
|
+
export function _Throttle(fn, delay) {
|
|
374
|
+
let timer;
|
|
375
|
+
return function (...args) {
|
|
376
|
+
if (!timer) {
|
|
377
|
+
timer = setTimeout(() => {
|
|
378
|
+
fn.apply(this, args);
|
|
379
|
+
timer = null;
|
|
380
|
+
}, delay);
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
}
|
package/lib/index.css
ADDED
package/lib/index.less
ADDED
package/lib/test.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/** 用于测试 js / ts 功能实现及类型是否正确 */
|