refactor: 优化代码结构和类型定义
feat(types): 添加express.d.ts类型引用 style: 格式化express.d.ts中的接口定义 refactor: 移除未使用的AntFC类型导入 chore: 删除自动生成的.umi-production文件 feat: 添加店铺管理相关表和初始化脚本 docs: 更新安全规则和交互指南文档 refactor: 统一使用FC类型替代React.FC perf: 优化图表组件导入方式 style: 添加.prettierrc配置文件 refactor: 调整组件导入顺序和结构 feat: 添加平台库存管理路由 fix: 修复订单同步时的库存检查逻辑 docs: 更新RBAC设计和租户管理文档 refactor: 优化部门控制器代码
This commit is contained in:
141
dashboard/src/services/monitoringInit.ts
Normal file
141
dashboard/src/services/monitoringInit.ts
Normal file
@@ -0,0 +1,141 @@
|
||||
/**
|
||||
* [FE-MON] 前端监控初始化模块
|
||||
* @description 统一初始化所有前端监控服务
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
import { performanceMonitor, initPerformanceMonitor } from './performanceMonitorService';
|
||||
import { errorMonitor, initErrorMonitor } from './errorMonitorService';
|
||||
import { behaviorAnalytics, initBehaviorAnalytics } from './behaviorAnalyticsService';
|
||||
|
||||
export interface MonitoringConfig {
|
||||
enabled: boolean;
|
||||
performance: {
|
||||
enabled: boolean;
|
||||
reportInterval: number;
|
||||
};
|
||||
error: {
|
||||
enabled: boolean;
|
||||
reportInterval: number;
|
||||
samplingRate: number;
|
||||
};
|
||||
behavior: {
|
||||
enabled: boolean;
|
||||
reportInterval: number;
|
||||
samplingRate: number;
|
||||
trackPageViews: boolean;
|
||||
trackClicks: boolean;
|
||||
trackScrolls: boolean;
|
||||
trackForms: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
const DEFAULT_CONFIG: MonitoringConfig = {
|
||||
enabled: true,
|
||||
performance: {
|
||||
enabled: true,
|
||||
reportInterval: 30000,
|
||||
},
|
||||
error: {
|
||||
enabled: true,
|
||||
reportInterval: 10000,
|
||||
samplingRate: 1.0,
|
||||
},
|
||||
behavior: {
|
||||
enabled: true,
|
||||
reportInterval: 15000,
|
||||
samplingRate: 1.0,
|
||||
trackPageViews: true,
|
||||
trackClicks: true,
|
||||
trackScrolls: true,
|
||||
trackForms: true,
|
||||
},
|
||||
};
|
||||
|
||||
let isInitialized = false;
|
||||
|
||||
export function initMonitoring(config: Partial<MonitoringConfig> = {}): void {
|
||||
if (isInitialized) {
|
||||
console.warn('[Monitoring] Already initialized');
|
||||
return;
|
||||
}
|
||||
|
||||
const finalConfig: MonitoringConfig = {
|
||||
...DEFAULT_CONFIG,
|
||||
...config,
|
||||
performance: { ...DEFAULT_CONFIG.performance, ...config.performance },
|
||||
error: { ...DEFAULT_CONFIG.error, ...config.error },
|
||||
behavior: { ...DEFAULT_CONFIG.behavior, ...config.behavior },
|
||||
};
|
||||
|
||||
if (!finalConfig.enabled) {
|
||||
console.log('[Monitoring] Monitoring is disabled');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('[Monitoring] Initializing monitoring services...');
|
||||
|
||||
if (finalConfig.performance.enabled) {
|
||||
initPerformanceMonitor();
|
||||
console.log('[Monitoring] Performance monitoring initialized');
|
||||
}
|
||||
|
||||
if (finalConfig.error.enabled) {
|
||||
initErrorMonitor({
|
||||
reportInterval: finalConfig.error.reportInterval,
|
||||
samplingRate: finalConfig.error.samplingRate,
|
||||
});
|
||||
console.log('[Monitoring] Error monitoring initialized');
|
||||
}
|
||||
|
||||
if (finalConfig.behavior.enabled) {
|
||||
initBehaviorAnalytics({
|
||||
reportInterval: finalConfig.behavior.reportInterval,
|
||||
samplingRate: finalConfig.behavior.samplingRate,
|
||||
trackPageViews: finalConfig.behavior.trackPageViews,
|
||||
trackClicks: finalConfig.behavior.trackClicks,
|
||||
trackScrolls: finalConfig.behavior.trackScrolls,
|
||||
trackForms: finalConfig.behavior.trackForms,
|
||||
});
|
||||
console.log('[Monitoring] Behavior analytics initialized');
|
||||
}
|
||||
|
||||
isInitialized = true;
|
||||
console.log('[Monitoring] All monitoring services initialized');
|
||||
}
|
||||
|
||||
export function destroyMonitoring(): void {
|
||||
if (!isInitialized) return;
|
||||
|
||||
performanceMonitor.destroy();
|
||||
errorMonitor.destroy();
|
||||
behaviorAnalytics.destroy();
|
||||
|
||||
isInitialized = false;
|
||||
console.log('[Monitoring] All monitoring services destroyed');
|
||||
}
|
||||
|
||||
export function getMonitoringStatus(): {
|
||||
initialized: boolean;
|
||||
performance: boolean;
|
||||
error: boolean;
|
||||
behavior: boolean;
|
||||
} {
|
||||
return {
|
||||
initialized: isInitialized,
|
||||
performance: (performanceMonitor as any).isInitialized || false,
|
||||
error: (errorMonitor as any).isInitialized || false,
|
||||
behavior: (behaviorAnalytics as any).isInitialized || false,
|
||||
};
|
||||
}
|
||||
|
||||
export { performanceMonitor, errorMonitor, behaviorAnalytics };
|
||||
|
||||
export default {
|
||||
init: initMonitoring,
|
||||
destroy: destroyMonitoring,
|
||||
getStatus: getMonitoringStatus,
|
||||
performanceMonitor,
|
||||
errorMonitor,
|
||||
behaviorAnalytics,
|
||||
};
|
||||
Reference in New Issue
Block a user