daShangDao_psiWebApp/move/demo/ServiceManager.d.ts
2026-06-03 10:53:47 +08:00

128 lines
3.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* ServiceManager - 服务管理类
* 支持:设置路径、连接、状态查询、启动、停止
* DEBUG模式开启后在浏览器控制台输出详细调试信息
*/
export interface ServiceInfo {
id: string;
name: string;
exe_path: string;
running: boolean;
pid: number | null;
port: number | null;
port_open: boolean | null;
status: 'running' | 'stopped';
}
export interface ApiResponse<T = any> {
code: number;
data?: T;
msg?: string;
pid?: number;
killed?: number[];
}
export type LogLevel = 'info' | 'success' | 'error' | 'warn' | 'debug';
export interface LogEntry {
time: string;
level: LogLevel;
message: string;
data?: any;
}
export type StatusChangeCallback = (service: ServiceInfo) => void;
export declare class ServiceManager {
private static DEBUG;
private baseUrl;
private logs;
private maxLogs;
private pollInterval;
private pollTimer;
private onStatusChange;
private previousStatus;
private connected;
constructor(baseUrl?: string);
/**
* 开启DEBUG模式 - 在浏览器控制台输出详细信息
*/
static enableDebug(): void;
/**
* 关闭DEBUG模式
*/
static disableDebug(): void;
/**
* 获取当前DEBUG状态
*/
static isDebugEnabled(): boolean;
private log;
private getConsoleStyle;
/**
* 设置API地址
* @param url API服务器地址如 http://127.0.0.1:5000
*/
setBaseUrl(url: string): void;
/**
* 获取当前API地址
*/
getBaseUrl(): string;
/**
* 设置轮询间隔(毫秒)
* @param ms 间隔时间默认3000ms
*/
setPollInterval(ms: number): void;
/**
* 获取轮询间隔
*/
getPollInterval(): number;
/**
* 获取连接状态
*/
isConnected(): boolean;
/**
* 获取所有服务状态
*/
getServicesStatus(): Promise<ServiceInfo[]>;
/**
* 获取单个服务状态
* @param id 服务ID
*/
getServiceStatus(id: string): Promise<ServiceInfo | null>;
/**
* 启动服务
* @param id 服务ID
*/
startService(id: string): Promise<boolean>;
/**
* 停止服务
* @param id 服务ID
*/
stopService(id: string): Promise<boolean>;
/**
* 启动自动刷新
* @param callback 每次刷新后的回调函数
*/
startAutoRefresh(callback?: (services: ServiceInfo[]) => void): void;
/**
* 停止自动刷新
*/
stopAutoRefresh(): void;
/**
* 检查自动刷新是否运行中
*/
isAutoRefreshRunning(): boolean;
/**
* 设置状态变化回调
* @param callback 服务状态变化时调用
*/
setOnStatusChange(callback: StatusChangeCallback): void;
/**
* 获取所有日志
*/
getLogs(): LogEntry[];
/**
* 清空日志
*/
clearLogs(): void;
/**
* 销毁实例,停止所有定时器
*/
destroy(): void;
}