@taicode/common-web 3.7.7 → 3.7.8
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/output/components/alert-dialog.d.ts +20 -0
- package/output/components/alert-dialog.d.ts.map +1 -0
- package/output/components/alert-dialog.js +65 -0
- package/output/components/alert.d.ts +11 -0
- package/output/components/alert.d.ts.map +1 -0
- package/output/components/alert.js +38 -0
- package/output/components/avatar.d.ts +13 -0
- package/output/components/avatar.d.ts.map +1 -0
- package/output/components/avatar.js +40 -0
- package/output/components/badge.d.ts +11 -0
- package/output/components/badge.d.ts.map +1 -0
- package/output/components/badge.js +39 -0
- package/output/components/button.d.ts +12 -0
- package/output/components/button.d.ts.map +1 -0
- package/output/components/button.js +48 -0
- package/output/components/calendar.d.ts +13 -0
- package/output/components/calendar.d.ts.map +1 -0
- package/output/components/calendar.js +57 -0
- package/output/components/card.d.ts +13 -0
- package/output/components/card.d.ts.map +1 -0
- package/output/components/card.js +43 -0
- package/output/components/chart.d.ts +56 -0
- package/output/components/chart.d.ts.map +1 -0
- package/output/components/chart.js +127 -0
- package/output/components/checkbox.d.ts +5 -0
- package/output/components/checkbox.d.ts.map +1 -0
- package/output/components/checkbox.js +21 -0
- package/output/components/command.d.ts +20 -0
- package/output/components/command.d.ts.map +1 -0
- package/output/components/command.js +55 -0
- package/output/components/dialog.d.ts +20 -0
- package/output/components/dialog.d.ts.map +1 -0
- package/output/components/dialog.js +58 -0
- package/output/components/direction.d.ts +9 -0
- package/output/components/direction.d.ts.map +1 -0
- package/output/components/direction.js +10 -0
- package/output/components/drawer.d.ts +14 -0
- package/output/components/drawer.d.ts.map +1 -0
- package/output/components/drawer.js +56 -0
- package/output/components/dropdown-menu.d.ts +29 -0
- package/output/components/dropdown-menu.d.ts.map +1 -0
- package/output/components/dropdown-menu.js +78 -0
- package/output/components/field.d.ts +39 -0
- package/output/components/field.d.ts.map +1 -0
- package/output/components/field.js +102 -0
- package/output/components/footer/index.d.ts +27 -0
- package/output/components/footer/index.d.ts.map +1 -0
- package/output/components/footer/index.js +17 -0
- package/output/components/form.d.ts +26 -0
- package/output/components/form.d.ts.map +1 -0
- package/output/components/form.js +69 -0
- package/output/components/index.d.ts +46 -0
- package/output/components/index.d.ts.map +1 -0
- package/output/components/index.js +45 -0
- package/output/components/input-group.d.ts +17 -0
- package/output/components/input-group.d.ts.map +1 -0
- package/output/components/input-group.js +75 -0
- package/output/components/input.d.ts +4 -0
- package/output/components/input.d.ts.map +1 -0
- package/output/components/input.js +19 -0
- package/output/components/item.d.ts +25 -0
- package/output/components/item.d.ts.map +1 -0
- package/output/components/item.js +89 -0
- package/output/components/json-view/index.d.ts +11 -0
- package/output/components/json-view/index.d.ts.map +1 -0
- package/output/components/json-view/index.js +52 -0
- package/output/components/json-view/lazy/index.d.ts +18 -0
- package/output/components/json-view/lazy/index.d.ts.map +1 -0
- package/output/components/json-view/lazy/index.js +22 -0
- package/output/components/kbd.d.ts +4 -0
- package/output/components/kbd.d.ts.map +1 -0
- package/output/components/kbd.js +22 -0
- package/output/components/label.d.ts +5 -0
- package/output/components/label.d.ts.map +1 -0
- package/output/components/label.js +20 -0
- package/output/components/list-actions/index.d.ts +23 -0
- package/output/components/list-actions/index.d.ts.map +1 -0
- package/output/components/list-actions/index.js +15 -0
- package/output/components/loading-button/index.d.ts +44 -0
- package/output/components/loading-button/index.d.ts.map +1 -0
- package/output/components/loading-button/index.js +75 -0
- package/output/components/loading-button/index.test.d.ts +2 -0
- package/output/components/loading-button/index.test.d.ts.map +1 -0
- package/output/components/loading-button/index.test.js +203 -0
- package/output/components/native-select.d.ts +9 -0
- package/output/components/native-select.d.ts.map +1 -0
- package/output/components/native-select.js +28 -0
- package/output/components/page-back-button/index.d.ts +8 -0
- package/output/components/page-back-button/index.d.ts.map +1 -0
- package/output/components/page-back-button/index.js +7 -0
- package/output/components/page-state.d.ts +19 -0
- package/output/components/page-state.d.ts.map +1 -0
- package/output/components/page-state.js +13 -0
- package/output/components/pagination/index.d.ts +34 -0
- package/output/components/pagination/index.d.ts.map +1 -0
- package/output/components/pagination/index.js +75 -0
- package/output/components/popover.d.ts +11 -0
- package/output/components/popover.d.ts.map +1 -0
- package/output/components/popover.js +44 -0
- package/output/components/progress.d.ts +5 -0
- package/output/components/progress.d.ts.map +1 -0
- package/output/components/progress.js +21 -0
- package/output/components/radio-group.d.ts +6 -0
- package/output/components/radio-group.d.ts.map +1 -0
- package/output/components/radio-group.js +25 -0
- package/output/components/route-pending-indicator/index.d.ts +20 -0
- package/output/components/route-pending-indicator/index.d.ts.map +1 -0
- package/output/components/route-pending-indicator/index.js +17 -0
- package/output/components/scroll-area.d.ts +6 -0
- package/output/components/scroll-area.d.ts.map +1 -0
- package/output/components/scroll-area.js +24 -0
- package/output/components/searchable-select/index.d.ts +41 -0
- package/output/components/searchable-select/index.d.ts.map +1 -0
- package/output/components/searchable-select/index.js +46 -0
- package/output/components/select.d.ts +17 -0
- package/output/components/select.d.ts.map +1 -0
- package/output/components/select.js +58 -0
- package/output/components/separator.d.ts +5 -0
- package/output/components/separator.d.ts.map +1 -0
- package/output/components/separator.js +20 -0
- package/output/components/sheet.d.ts +16 -0
- package/output/components/sheet.d.ts.map +1 -0
- package/output/components/sheet.js +58 -0
- package/output/components/sidebar.d.ts +78 -0
- package/output/components/sidebar.d.ts.map +1 -0
- package/output/components/sidebar.js +233 -0
- package/output/components/size-provider/index.d.ts +2 -0
- package/output/components/size-provider/index.d.ts.map +1 -0
- package/output/components/size-provider/index.js +1 -0
- package/output/components/size-provider/size-provider.d.ts +9 -0
- package/output/components/size-provider/size-provider.d.ts.map +1 -0
- package/output/components/size-provider/size-provider.js +29 -0
- package/output/components/skeleton.d.ts +3 -0
- package/output/components/skeleton.d.ts.map +1 -0
- package/output/components/skeleton.js +18 -0
- package/output/components/sonner.d.ts +8 -0
- package/output/components/sonner.d.ts.map +1 -0
- package/output/components/sonner.js +34 -0
- package/output/components/spinner.d.ts +3 -0
- package/output/components/spinner.d.ts.map +1 -0
- package/output/components/spinner.js +19 -0
- package/output/components/switch.d.ts +8 -0
- package/output/components/switch.d.ts.map +1 -0
- package/output/components/switch.js +20 -0
- package/output/components/table.d.ts +11 -0
- package/output/components/table.d.ts.map +1 -0
- package/output/components/table.js +47 -0
- package/output/components/tabs.d.ts +12 -0
- package/output/components/tabs.d.ts.map +1 -0
- package/output/components/tabs.js +45 -0
- package/output/components/textarea.d.ts +4 -0
- package/output/components/textarea.d.ts.map +1 -0
- package/output/components/textarea.js +19 -0
- package/output/components/theme-switcher.d.ts +6 -0
- package/output/components/theme-switcher.d.ts.map +1 -0
- package/output/components/theme-switcher.js +19 -0
- package/output/components/toaster/index.d.ts +16 -0
- package/output/components/toaster/index.d.ts.map +1 -0
- package/output/components/toaster/index.js +70 -0
- package/output/components/toggle-group.d.ts +12 -0
- package/output/components/toggle-group.d.ts.map +1 -0
- package/output/components/toggle-group.js +38 -0
- package/output/components/toggle.d.ts +10 -0
- package/output/components/toggle.d.ts.map +1 -0
- package/output/components/toggle.js +38 -0
- package/output/components/tooltip.d.ts +8 -0
- package/output/components/tooltip.d.ts.map +1 -0
- package/output/components/tooltip.js +33 -0
- package/output/features/confirm-dialog/index.d.ts +41 -0
- package/output/features/confirm-dialog/index.d.ts.map +1 -0
- package/output/features/confirm-dialog/index.js +19 -0
- package/output/features/input-confirm/index.d.ts +26 -0
- package/output/features/input-confirm/index.d.ts.map +1 -0
- package/output/features/input-confirm/index.js +59 -0
- package/output/features/signin/context.d.ts +14 -0
- package/output/features/signin/context.d.ts.map +1 -0
- package/output/features/signin/context.js +13 -0
- package/output/features/signin/index.d.ts +58 -0
- package/output/features/signin/index.d.ts.map +1 -0
- package/output/features/signin/index.js +137 -0
- package/output/features/signin/service.d.ts +92 -0
- package/output/features/signin/service.d.ts.map +1 -0
- package/output/features/signin/service.js +519 -0
- package/output/features/signin/service.test.d.ts +2 -0
- package/output/features/signin/service.test.d.ts.map +1 -0
- package/output/features/signin/service.test.js +211 -0
- package/output/features/signin/types.d.ts +63 -0
- package/output/features/signin/types.d.ts.map +1 -0
- package/output/features/signin/types.js +1 -0
- package/output/hooks/use-loading/index.d.ts +6 -0
- package/output/hooks/use-loading/index.d.ts.map +1 -0
- package/output/hooks/use-loading/index.js +14 -0
- package/output/hooks/use-loading/index.test.d.ts +2 -0
- package/output/hooks/use-loading/index.test.d.ts.map +1 -0
- package/output/hooks/use-loading/index.test.js +24 -0
- package/output/hooks/use-mobile/index.d.ts +2 -0
- package/output/hooks/use-mobile/index.d.ts.map +1 -0
- package/output/hooks/use-mobile/index.js +16 -0
- package/output/hooks/use-observer/index.d.ts +2 -0
- package/output/hooks/use-observer/index.d.ts.map +1 -0
- package/output/hooks/use-observer/index.js +1 -0
- package/output/hooks/use-observer/use-observer.d.ts +3 -0
- package/output/hooks/use-observer/use-observer.d.ts.map +1 -0
- package/output/hooks/use-observer/use-observer.js +16 -0
- package/output/hooks/use-observer/use-observer.test.d.ts +2 -0
- package/output/hooks/use-observer/use-observer.test.d.ts.map +1 -0
- package/output/hooks/use-observer/use-observer.test.js +134 -0
- package/output/hooks/use-offline/index.d.ts +6 -0
- package/output/hooks/use-offline/index.d.ts.map +1 -0
- package/output/hooks/use-offline/index.js +19 -0
- package/output/layout/app/index.d.ts +34 -0
- package/output/layout/app/index.d.ts.map +1 -0
- package/output/layout/app/index.js +34 -0
- package/output/layout/dashboard/index.d.ts +76 -0
- package/output/layout/dashboard/index.d.ts.map +1 -0
- package/output/layout/dashboard/index.js +84 -0
- package/output/layout/index.d.ts +3 -0
- package/output/layout/index.d.ts.map +1 -0
- package/output/layout/index.js +2 -0
- package/output/services/cache-api/cache-api.d.ts +23 -0
- package/output/services/cache-api/cache-api.d.ts.map +1 -0
- package/output/services/cache-api/cache-api.js +145 -0
- package/output/services/cache-api/cache-api.test.d.ts +2 -0
- package/output/services/cache-api/cache-api.test.d.ts.map +1 -0
- package/output/services/cache-api/cache-api.test.js +610 -0
- package/output/services/cache-api/index.d.ts +2 -0
- package/output/services/cache-api/index.d.ts.map +1 -0
- package/output/services/cache-api/index.js +1 -0
- package/output/services/cached-fetch/index.d.ts +50 -0
- package/output/services/cached-fetch/index.d.ts.map +1 -0
- package/output/services/cached-fetch/index.js +196 -0
- package/output/services/service/index.d.ts +2 -0
- package/output/services/service/index.d.ts.map +1 -0
- package/output/services/service/index.js +1 -0
- package/output/services/service/service.d.ts +135 -0
- package/output/services/service/service.d.ts.map +1 -0
- package/output/services/service/service.js +276 -0
- package/output/services/service/service.test.d.ts +2 -0
- package/output/services/service/service.test.d.ts.map +1 -0
- package/output/services/service/service.test.js +1399 -0
- package/output/services/side-cache/index.d.ts +2 -0
- package/output/services/side-cache/index.d.ts.map +1 -0
- package/output/services/side-cache/index.js +1 -0
- package/output/services/side-cache/side-cache.d.ts +11 -0
- package/output/services/side-cache/side-cache.d.ts.map +1 -0
- package/output/services/side-cache/side-cache.js +161 -0
- package/output/services/side-cache/side-cache.test.d.ts +2 -0
- package/output/services/side-cache/side-cache.test.d.ts.map +1 -0
- package/output/services/side-cache/side-cache.test.js +271 -0
- package/output/utils/avatar/index.d.ts +28 -0
- package/output/utils/avatar/index.d.ts.map +1 -0
- package/output/utils/avatar/index.js +35 -0
- package/output/utils/delay/index.d.ts +2 -0
- package/output/utils/delay/index.d.ts.map +1 -0
- package/output/utils/delay/index.js +5 -0
- package/output/utils/form/index.d.ts +3 -0
- package/output/utils/form/index.d.ts.map +1 -0
- package/output/utils/form/index.js +1 -0
- package/output/utils/merge-class-names/index.d.ts +3 -0
- package/output/utils/merge-class-names/index.d.ts.map +1 -0
- package/output/utils/merge-class-names/index.js +5 -0
- package/output/utils/merge-class-names/index.test.d.ts +2 -0
- package/output/utils/merge-class-names/index.test.d.ts.map +1 -0
- package/output/utils/merge-class-names/index.test.js +7 -0
- package/output/utils/performance/index.d.ts +82 -0
- package/output/utils/performance/index.d.ts.map +1 -0
- package/output/utils/performance/index.js +129 -0
- package/output/utils/redirect/index.d.ts +6 -0
- package/output/utils/redirect/index.d.ts.map +1 -0
- package/output/utils/redirect/index.js +32 -0
- package/package.json +2 -2
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { type Metric } from 'web-vitals';
|
|
2
|
+
/**
|
|
3
|
+
* 性能指标类型
|
|
4
|
+
*/
|
|
5
|
+
export interface PerformanceMetrics {
|
|
6
|
+
cls?: Metric;
|
|
7
|
+
fcp?: Metric;
|
|
8
|
+
inp?: Metric;
|
|
9
|
+
lcp?: Metric;
|
|
10
|
+
ttfb?: Metric;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* 性能监控配置
|
|
14
|
+
*/
|
|
15
|
+
export interface PerformanceMonitorConfig {
|
|
16
|
+
/**
|
|
17
|
+
* 是否启用性能监控
|
|
18
|
+
*/
|
|
19
|
+
enabled: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* 是否在控制台输出日志
|
|
22
|
+
*/
|
|
23
|
+
logToConsole: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* 性能指标上报回调
|
|
26
|
+
*/
|
|
27
|
+
onMetric?: (metric: Metric) => void;
|
|
28
|
+
/**
|
|
29
|
+
* 错误追踪回调
|
|
30
|
+
*/
|
|
31
|
+
onError?: (error: Error) => void;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 性能监控器类
|
|
35
|
+
*/
|
|
36
|
+
export declare class PerformanceMonitor {
|
|
37
|
+
private config;
|
|
38
|
+
private metrics;
|
|
39
|
+
private isInitialized;
|
|
40
|
+
constructor(config?: Partial<PerformanceMonitorConfig>);
|
|
41
|
+
/**
|
|
42
|
+
* 初始化性能监控
|
|
43
|
+
*/
|
|
44
|
+
init(): void;
|
|
45
|
+
/**
|
|
46
|
+
* 处理性能指标
|
|
47
|
+
*/
|
|
48
|
+
private handleMetric;
|
|
49
|
+
/**
|
|
50
|
+
* 输出性能指标到控制台
|
|
51
|
+
*/
|
|
52
|
+
private logMetric;
|
|
53
|
+
/**
|
|
54
|
+
* 设置错误追踪
|
|
55
|
+
*/
|
|
56
|
+
private setupErrorTracking;
|
|
57
|
+
/**
|
|
58
|
+
* 处理错误
|
|
59
|
+
*/
|
|
60
|
+
private handleError;
|
|
61
|
+
/**
|
|
62
|
+
* 获取当前收集的所有性能指标
|
|
63
|
+
*/
|
|
64
|
+
getMetrics(): PerformanceMetrics;
|
|
65
|
+
/**
|
|
66
|
+
* 手动记录自定义性能指标
|
|
67
|
+
*/
|
|
68
|
+
recordCustomMetric(name: string, value: number, metadata?: Record<string, unknown>): void;
|
|
69
|
+
/**
|
|
70
|
+
* 手动报告错误
|
|
71
|
+
*/
|
|
72
|
+
reportError(error: Error | string): void;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* 获取性能监控器单例
|
|
76
|
+
*/
|
|
77
|
+
export declare function getPerformanceMonitor(config?: Partial<PerformanceMonitorConfig>): PerformanceMonitor;
|
|
78
|
+
/**
|
|
79
|
+
* 初始化性能监控(便捷函数)
|
|
80
|
+
*/
|
|
81
|
+
export declare function initPerformanceMonitoring(config?: Partial<PerformanceMonitorConfig>): void;
|
|
82
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/utils/performance/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsC,KAAK,MAAM,EAAE,MAAM,YAAY,CAAA;AAE5E;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC;;OAEG;IACH,OAAO,EAAE,OAAO,CAAA;IAChB;;OAEG;IACH,YAAY,EAAE,OAAO,CAAA;IACrB;;OAEG;IACH,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAA;IACnC;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAA;CACjC;AAUD;;GAEG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,MAAM,CAA0B;IACxC,OAAO,CAAC,OAAO,CAAyB;IACxC,OAAO,CAAC,aAAa,CAAQ;gBAEjB,MAAM,CAAC,EAAE,OAAO,CAAC,wBAAwB,CAAC;IAItD;;OAEG;IACH,IAAI,IAAI,IAAI;IAsBZ;;OAEG;IACH,OAAO,CAAC,YAAY;IAYpB;;OAEG;IACH,OAAO,CAAC,SAAS;IAWjB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAU1B;;OAEG;IACH,OAAO,CAAC,WAAW;IAUnB;;OAEG;IACH,UAAU,IAAI,kBAAkB;IAIhC;;OAEG;IACH,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAkBzF;;OAEG;IACH,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,GAAG,IAAI;CAIzC;AAKD;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,wBAAwB,CAAC,GAAG,kBAAkB,CAKpG;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,wBAAwB,CAAC,GAAG,IAAI,CAG1F"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { onCLS, onFCP, onINP, onLCP, onTTFB } from 'web-vitals';
|
|
2
|
+
/**
|
|
3
|
+
* 默认配置
|
|
4
|
+
*/
|
|
5
|
+
const defaultConfig = {
|
|
6
|
+
enabled: true,
|
|
7
|
+
logToConsole: true,
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* 性能监控器类
|
|
11
|
+
*/
|
|
12
|
+
export class PerformanceMonitor {
|
|
13
|
+
constructor(config) {
|
|
14
|
+
this.metrics = {};
|
|
15
|
+
this.isInitialized = false;
|
|
16
|
+
this.config = Object.assign(Object.assign({}, defaultConfig), config);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* 初始化性能监控
|
|
20
|
+
*/
|
|
21
|
+
init() {
|
|
22
|
+
if (this.isInitialized || !this.config.enabled) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
this.isInitialized = true;
|
|
26
|
+
// 注册 Core Web Vitals 监听器
|
|
27
|
+
onCLS(this.handleMetric.bind(this));
|
|
28
|
+
onFCP(this.handleMetric.bind(this));
|
|
29
|
+
onINP(this.handleMetric.bind(this));
|
|
30
|
+
onLCP(this.handleMetric.bind(this));
|
|
31
|
+
onTTFB(this.handleMetric.bind(this));
|
|
32
|
+
// 注册全局错误监听器
|
|
33
|
+
this.setupErrorTracking();
|
|
34
|
+
if (this.config.logToConsole) {
|
|
35
|
+
console.log('[PerformanceMonitor] 性能监控已初始化');
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* 处理性能指标
|
|
40
|
+
*/
|
|
41
|
+
handleMetric(metric) {
|
|
42
|
+
this.metrics[metric.name.toLowerCase()] = metric;
|
|
43
|
+
if (this.config.logToConsole) {
|
|
44
|
+
this.logMetric(metric);
|
|
45
|
+
}
|
|
46
|
+
if (this.config.onMetric) {
|
|
47
|
+
this.config.onMetric(metric);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* 输出性能指标到控制台
|
|
52
|
+
*/
|
|
53
|
+
logMetric(metric) {
|
|
54
|
+
const { name, value, rating } = metric;
|
|
55
|
+
const color = rating === 'good' ? '#22c55e' : rating === 'needs-improvement' ? '#eab308' : '#ef4444';
|
|
56
|
+
console.log(`%c[Performance] ${name}: ${value.toFixed(2)} (${rating})`, `color: ${color}; font-weight: bold;`);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* 设置错误追踪
|
|
60
|
+
*/
|
|
61
|
+
setupErrorTracking() {
|
|
62
|
+
window.addEventListener('error', (event) => {
|
|
63
|
+
this.handleError(event.error || new Error(event.message));
|
|
64
|
+
});
|
|
65
|
+
window.addEventListener('unhandledrejection', (event) => {
|
|
66
|
+
this.handleError(new Error(`Unhandled Promise Rejection: ${event.reason}`));
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* 处理错误
|
|
71
|
+
*/
|
|
72
|
+
handleError(error) {
|
|
73
|
+
if (this.config.logToConsole) {
|
|
74
|
+
console.error('[PerformanceMonitor] 捕获到错误:', error);
|
|
75
|
+
}
|
|
76
|
+
if (this.config.onError) {
|
|
77
|
+
this.config.onError(error);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* 获取当前收集的所有性能指标
|
|
82
|
+
*/
|
|
83
|
+
getMetrics() {
|
|
84
|
+
return Object.assign({}, this.metrics);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* 手动记录自定义性能指标
|
|
88
|
+
*/
|
|
89
|
+
recordCustomMetric(name, value, metadata) {
|
|
90
|
+
const customMetric = {
|
|
91
|
+
name,
|
|
92
|
+
value,
|
|
93
|
+
rating: value < 100 ? 'good' : value < 300 ? 'needs-improvement' : 'poor',
|
|
94
|
+
delta: value,
|
|
95
|
+
entries: [],
|
|
96
|
+
id: `custom-${Date.now()}`,
|
|
97
|
+
navigationType: 'navigate',
|
|
98
|
+
};
|
|
99
|
+
this.handleMetric(customMetric);
|
|
100
|
+
if (this.config.logToConsole && metadata) {
|
|
101
|
+
console.log('[PerformanceMonitor] 自定义指标元数据:', metadata);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* 手动报告错误
|
|
106
|
+
*/
|
|
107
|
+
reportError(error) {
|
|
108
|
+
const errorObj = typeof error === 'string' ? new Error(error) : error;
|
|
109
|
+
this.handleError(errorObj);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
// 创建单例实例
|
|
113
|
+
let monitorInstance = null;
|
|
114
|
+
/**
|
|
115
|
+
* 获取性能监控器单例
|
|
116
|
+
*/
|
|
117
|
+
export function getPerformanceMonitor(config) {
|
|
118
|
+
if (!monitorInstance) {
|
|
119
|
+
monitorInstance = new PerformanceMonitor(config);
|
|
120
|
+
}
|
|
121
|
+
return monitorInstance;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* 初始化性能监控(便捷函数)
|
|
125
|
+
*/
|
|
126
|
+
export function initPerformanceMonitoring(config) {
|
|
127
|
+
const monitor = getPerformanceMonitor(config);
|
|
128
|
+
monitor.init();
|
|
129
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/utils/redirect/index.ts"],"names":[],"mappings":"AAEA,UAAU,gBAAgB;IACxB,MAAM,EAAE,MAAM,CAAA;CACf;AAgBD,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,EAAE,MAAM,EAAE,MAAM,GAAG,gBAAgB,GAAG,IAAI,CAwBzG"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const LOCALE_SEGMENT_REGEX = /^\/(zh-CN|en-US)(\/|$)/;
|
|
2
|
+
function withLocalePrefix(pathname, locale) {
|
|
3
|
+
const normalizedPathname = pathname.startsWith('/') ? pathname : `/${pathname}`;
|
|
4
|
+
if (LOCALE_SEGMENT_REGEX.test(normalizedPathname)) {
|
|
5
|
+
return normalizedPathname;
|
|
6
|
+
}
|
|
7
|
+
if (normalizedPathname === '/') {
|
|
8
|
+
return `/${locale}`;
|
|
9
|
+
}
|
|
10
|
+
return `/${locale}${normalizedPathname}`;
|
|
11
|
+
}
|
|
12
|
+
export function resolveSafeRedirect(redirect, locale) {
|
|
13
|
+
if (!(redirect === null || redirect === void 0 ? void 0 : redirect.trim())) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
try {
|
|
17
|
+
const url = new URL(redirect, window.location.origin);
|
|
18
|
+
if (!['http:', 'https:'].includes(url.protocol)) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
if (url.origin !== window.location.origin) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
const pathname = withLocalePrefix(url.pathname, locale);
|
|
25
|
+
return {
|
|
26
|
+
target: `${pathname}${url.search}${url.hash}`,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
catch (_a) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@taicode/common-web",
|
|
3
|
-
"version": "3.7.
|
|
3
|
+
"version": "3.7.8",
|
|
4
4
|
"author": "Alain",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"description": "",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"mobx": ">=6",
|
|
55
55
|
"mobx-react-lite": "^4.1.1",
|
|
56
56
|
"react": ">=18",
|
|
57
|
-
"@taicode/common-base": "^3.7.
|
|
57
|
+
"@taicode/common-base": "^3.7.8"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"@headlessui/react": "^2.2.9",
|