@taicode/common-web 3.7.4 → 3.7.7
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/LICENSE +21 -0
- package/package.json +12 -13
- package/styles.css +2 -0
- package/output/components/alert-dialog.d.ts +0 -20
- package/output/components/alert-dialog.d.ts.map +0 -1
- package/output/components/alert-dialog.js +0 -65
- package/output/components/alert.d.ts +0 -11
- package/output/components/alert.d.ts.map +0 -1
- package/output/components/alert.js +0 -38
- package/output/components/avatar.d.ts +0 -13
- package/output/components/avatar.d.ts.map +0 -1
- package/output/components/avatar.js +0 -40
- package/output/components/badge.d.ts +0 -11
- package/output/components/badge.d.ts.map +0 -1
- package/output/components/badge.js +0 -39
- package/output/components/button.d.ts +0 -12
- package/output/components/button.d.ts.map +0 -1
- package/output/components/button.js +0 -48
- package/output/components/calendar.d.ts +0 -13
- package/output/components/calendar.d.ts.map +0 -1
- package/output/components/calendar.js +0 -57
- package/output/components/card.d.ts +0 -13
- package/output/components/card.d.ts.map +0 -1
- package/output/components/card.js +0 -43
- package/output/components/chart.d.ts +0 -56
- package/output/components/chart.d.ts.map +0 -1
- package/output/components/chart.js +0 -127
- package/output/components/checkbox.d.ts +0 -5
- package/output/components/checkbox.d.ts.map +0 -1
- package/output/components/checkbox.js +0 -21
- package/output/components/command.d.ts +0 -20
- package/output/components/command.d.ts.map +0 -1
- package/output/components/command.js +0 -55
- package/output/components/dialog.d.ts +0 -20
- package/output/components/dialog.d.ts.map +0 -1
- package/output/components/dialog.js +0 -58
- package/output/components/direction.d.ts +0 -9
- package/output/components/direction.d.ts.map +0 -1
- package/output/components/direction.js +0 -10
- package/output/components/drawer.d.ts +0 -14
- package/output/components/drawer.d.ts.map +0 -1
- package/output/components/drawer.js +0 -56
- package/output/components/dropdown-menu.d.ts +0 -29
- package/output/components/dropdown-menu.d.ts.map +0 -1
- package/output/components/dropdown-menu.js +0 -78
- package/output/components/field.d.ts +0 -39
- package/output/components/field.d.ts.map +0 -1
- package/output/components/field.js +0 -102
- package/output/components/footer/index.d.ts +0 -27
- package/output/components/footer/index.d.ts.map +0 -1
- package/output/components/footer/index.js +0 -17
- package/output/components/form.d.ts +0 -26
- package/output/components/form.d.ts.map +0 -1
- package/output/components/form.js +0 -69
- package/output/components/index.d.ts +0 -46
- package/output/components/index.d.ts.map +0 -1
- package/output/components/index.js +0 -45
- package/output/components/input-group.d.ts +0 -17
- package/output/components/input-group.d.ts.map +0 -1
- package/output/components/input-group.js +0 -75
- package/output/components/input.d.ts +0 -4
- package/output/components/input.d.ts.map +0 -1
- package/output/components/input.js +0 -19
- package/output/components/item.d.ts +0 -25
- package/output/components/item.d.ts.map +0 -1
- package/output/components/item.js +0 -89
- package/output/components/json-view/index.d.ts +0 -11
- package/output/components/json-view/index.d.ts.map +0 -1
- package/output/components/json-view/index.js +0 -52
- package/output/components/json-view/lazy/index.d.ts +0 -18
- package/output/components/json-view/lazy/index.d.ts.map +0 -1
- package/output/components/json-view/lazy/index.js +0 -22
- package/output/components/kbd.d.ts +0 -4
- package/output/components/kbd.d.ts.map +0 -1
- package/output/components/kbd.js +0 -22
- package/output/components/label.d.ts +0 -5
- package/output/components/label.d.ts.map +0 -1
- package/output/components/label.js +0 -20
- package/output/components/list-actions/index.d.ts +0 -23
- package/output/components/list-actions/index.d.ts.map +0 -1
- package/output/components/list-actions/index.js +0 -15
- package/output/components/loading-button/index.d.ts +0 -44
- package/output/components/loading-button/index.d.ts.map +0 -1
- package/output/components/loading-button/index.js +0 -75
- package/output/components/loading-button/index.test.d.ts +0 -2
- package/output/components/loading-button/index.test.d.ts.map +0 -1
- package/output/components/loading-button/index.test.js +0 -203
- package/output/components/native-select.d.ts +0 -9
- package/output/components/native-select.d.ts.map +0 -1
- package/output/components/native-select.js +0 -28
- package/output/components/page-back-button/index.d.ts +0 -8
- package/output/components/page-back-button/index.d.ts.map +0 -1
- package/output/components/page-back-button/index.js +0 -7
- package/output/components/page-state.d.ts +0 -19
- package/output/components/page-state.d.ts.map +0 -1
- package/output/components/page-state.js +0 -13
- package/output/components/pagination/index.d.ts +0 -34
- package/output/components/pagination/index.d.ts.map +0 -1
- package/output/components/pagination/index.js +0 -75
- package/output/components/popover.d.ts +0 -11
- package/output/components/popover.d.ts.map +0 -1
- package/output/components/popover.js +0 -44
- package/output/components/progress.d.ts +0 -5
- package/output/components/progress.d.ts.map +0 -1
- package/output/components/progress.js +0 -21
- package/output/components/radio-group.d.ts +0 -6
- package/output/components/radio-group.d.ts.map +0 -1
- package/output/components/radio-group.js +0 -25
- package/output/components/route-pending-indicator/index.d.ts +0 -20
- package/output/components/route-pending-indicator/index.d.ts.map +0 -1
- package/output/components/route-pending-indicator/index.js +0 -17
- package/output/components/scroll-area.d.ts +0 -6
- package/output/components/scroll-area.d.ts.map +0 -1
- package/output/components/scroll-area.js +0 -24
- package/output/components/searchable-select/index.d.ts +0 -41
- package/output/components/searchable-select/index.d.ts.map +0 -1
- package/output/components/searchable-select/index.js +0 -46
- package/output/components/select.d.ts +0 -17
- package/output/components/select.d.ts.map +0 -1
- package/output/components/select.js +0 -58
- package/output/components/separator.d.ts +0 -5
- package/output/components/separator.d.ts.map +0 -1
- package/output/components/separator.js +0 -20
- package/output/components/sheet.d.ts +0 -16
- package/output/components/sheet.d.ts.map +0 -1
- package/output/components/sheet.js +0 -58
- package/output/components/sidebar.d.ts +0 -78
- package/output/components/sidebar.d.ts.map +0 -1
- package/output/components/sidebar.js +0 -233
- package/output/components/size-provider/index.d.ts +0 -2
- package/output/components/size-provider/index.d.ts.map +0 -1
- package/output/components/size-provider/index.js +0 -1
- package/output/components/size-provider/size-provider.d.ts +0 -9
- package/output/components/size-provider/size-provider.d.ts.map +0 -1
- package/output/components/size-provider/size-provider.js +0 -29
- package/output/components/skeleton.d.ts +0 -3
- package/output/components/skeleton.d.ts.map +0 -1
- package/output/components/skeleton.js +0 -18
- package/output/components/sonner.d.ts +0 -8
- package/output/components/sonner.d.ts.map +0 -1
- package/output/components/sonner.js +0 -34
- package/output/components/spinner.d.ts +0 -3
- package/output/components/spinner.d.ts.map +0 -1
- package/output/components/spinner.js +0 -19
- package/output/components/switch.d.ts +0 -8
- package/output/components/switch.d.ts.map +0 -1
- package/output/components/switch.js +0 -20
- package/output/components/table.d.ts +0 -11
- package/output/components/table.d.ts.map +0 -1
- package/output/components/table.js +0 -47
- package/output/components/tabs.d.ts +0 -12
- package/output/components/tabs.d.ts.map +0 -1
- package/output/components/tabs.js +0 -45
- package/output/components/textarea.d.ts +0 -4
- package/output/components/textarea.d.ts.map +0 -1
- package/output/components/textarea.js +0 -19
- package/output/components/theme-switcher.d.ts +0 -6
- package/output/components/theme-switcher.d.ts.map +0 -1
- package/output/components/theme-switcher.js +0 -19
- package/output/components/toaster/index.d.ts +0 -16
- package/output/components/toaster/index.d.ts.map +0 -1
- package/output/components/toaster/index.js +0 -70
- package/output/components/toggle-group.d.ts +0 -12
- package/output/components/toggle-group.d.ts.map +0 -1
- package/output/components/toggle-group.js +0 -38
- package/output/components/toggle.d.ts +0 -10
- package/output/components/toggle.d.ts.map +0 -1
- package/output/components/toggle.js +0 -38
- package/output/components/tooltip.d.ts +0 -8
- package/output/components/tooltip.d.ts.map +0 -1
- package/output/components/tooltip.js +0 -33
- package/output/features/confirm-dialog/index.d.ts +0 -41
- package/output/features/confirm-dialog/index.d.ts.map +0 -1
- package/output/features/confirm-dialog/index.js +0 -19
- package/output/features/input-confirm/index.d.ts +0 -26
- package/output/features/input-confirm/index.d.ts.map +0 -1
- package/output/features/input-confirm/index.js +0 -59
- package/output/features/signin/context.d.ts +0 -14
- package/output/features/signin/context.d.ts.map +0 -1
- package/output/features/signin/context.js +0 -13
- package/output/features/signin/index.d.ts +0 -58
- package/output/features/signin/index.d.ts.map +0 -1
- package/output/features/signin/index.js +0 -137
- package/output/features/signin/service.d.ts +0 -92
- package/output/features/signin/service.d.ts.map +0 -1
- package/output/features/signin/service.js +0 -519
- package/output/features/signin/service.test.d.ts +0 -2
- package/output/features/signin/service.test.d.ts.map +0 -1
- package/output/features/signin/service.test.js +0 -211
- package/output/features/signin/types.d.ts +0 -63
- package/output/features/signin/types.d.ts.map +0 -1
- package/output/features/signin/types.js +0 -1
- package/output/hooks/use-loading/index.d.ts +0 -6
- package/output/hooks/use-loading/index.d.ts.map +0 -1
- package/output/hooks/use-loading/index.js +0 -14
- package/output/hooks/use-loading/index.test.d.ts +0 -2
- package/output/hooks/use-loading/index.test.d.ts.map +0 -1
- package/output/hooks/use-loading/index.test.js +0 -24
- package/output/hooks/use-mobile/index.d.ts +0 -2
- package/output/hooks/use-mobile/index.d.ts.map +0 -1
- package/output/hooks/use-mobile/index.js +0 -16
- package/output/hooks/use-observer/index.d.ts +0 -2
- package/output/hooks/use-observer/index.d.ts.map +0 -1
- package/output/hooks/use-observer/index.js +0 -1
- package/output/hooks/use-observer/use-observer.d.ts +0 -3
- package/output/hooks/use-observer/use-observer.d.ts.map +0 -1
- package/output/hooks/use-observer/use-observer.js +0 -16
- package/output/hooks/use-observer/use-observer.test.d.ts +0 -2
- package/output/hooks/use-observer/use-observer.test.d.ts.map +0 -1
- package/output/hooks/use-observer/use-observer.test.js +0 -134
- package/output/hooks/use-offline/index.d.ts +0 -6
- package/output/hooks/use-offline/index.d.ts.map +0 -1
- package/output/hooks/use-offline/index.js +0 -19
- package/output/layout/app/index.d.ts +0 -34
- package/output/layout/app/index.d.ts.map +0 -1
- package/output/layout/app/index.js +0 -34
- package/output/layout/dashboard/index.d.ts +0 -76
- package/output/layout/dashboard/index.d.ts.map +0 -1
- package/output/layout/dashboard/index.js +0 -84
- package/output/layout/index.d.ts +0 -3
- package/output/layout/index.d.ts.map +0 -1
- package/output/layout/index.js +0 -2
- package/output/services/cache-api/cache-api.d.ts +0 -23
- package/output/services/cache-api/cache-api.d.ts.map +0 -1
- package/output/services/cache-api/cache-api.js +0 -145
- package/output/services/cache-api/cache-api.test.d.ts +0 -2
- package/output/services/cache-api/cache-api.test.d.ts.map +0 -1
- package/output/services/cache-api/cache-api.test.js +0 -610
- package/output/services/cache-api/index.d.ts +0 -2
- package/output/services/cache-api/index.d.ts.map +0 -1
- package/output/services/cache-api/index.js +0 -1
- package/output/services/cached-fetch/index.d.ts +0 -50
- package/output/services/cached-fetch/index.d.ts.map +0 -1
- package/output/services/cached-fetch/index.js +0 -196
- package/output/services/service/index.d.ts +0 -2
- package/output/services/service/index.d.ts.map +0 -1
- package/output/services/service/index.js +0 -1
- package/output/services/service/service.d.ts +0 -135
- package/output/services/service/service.d.ts.map +0 -1
- package/output/services/service/service.js +0 -276
- package/output/services/service/service.test.d.ts +0 -2
- package/output/services/service/service.test.d.ts.map +0 -1
- package/output/services/service/service.test.js +0 -1399
- package/output/services/side-cache/index.d.ts +0 -2
- package/output/services/side-cache/index.d.ts.map +0 -1
- package/output/services/side-cache/index.js +0 -1
- package/output/services/side-cache/side-cache.d.ts +0 -11
- package/output/services/side-cache/side-cache.d.ts.map +0 -1
- package/output/services/side-cache/side-cache.js +0 -161
- package/output/services/side-cache/side-cache.test.d.ts +0 -2
- package/output/services/side-cache/side-cache.test.d.ts.map +0 -1
- package/output/services/side-cache/side-cache.test.js +0 -271
- package/output/utils/avatar/index.d.ts +0 -28
- package/output/utils/avatar/index.d.ts.map +0 -1
- package/output/utils/avatar/index.js +0 -35
- package/output/utils/delay/index.d.ts +0 -2
- package/output/utils/delay/index.d.ts.map +0 -1
- package/output/utils/delay/index.js +0 -5
- package/output/utils/form/index.d.ts +0 -3
- package/output/utils/form/index.d.ts.map +0 -1
- package/output/utils/form/index.js +0 -1
- package/output/utils/merge-class-names/index.d.ts +0 -3
- package/output/utils/merge-class-names/index.d.ts.map +0 -1
- package/output/utils/merge-class-names/index.js +0 -5
- package/output/utils/merge-class-names/index.test.d.ts +0 -2
- package/output/utils/merge-class-names/index.test.d.ts.map +0 -1
- package/output/utils/merge-class-names/index.test.js +0 -7
- package/output/utils/performance/index.d.ts +0 -82
- package/output/utils/performance/index.d.ts.map +0 -1
- package/output/utils/performance/index.js +0 -129
- package/output/utils/redirect/index.d.ts +0 -6
- package/output/utils/redirect/index.d.ts.map +0 -1
- package/output/utils/redirect/index.js +0 -32
|
@@ -1,82 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,129 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,32 +0,0 @@
|
|
|
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
|
-
}
|