|
@@ -18,6 +18,13 @@ import {
|
|
|
ApiResponse
|
|
ApiResponse
|
|
|
} from '../types/feiePrinter';
|
|
} from '../types/feiePrinter';
|
|
|
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * 生成API路径(不包含baseURL)
|
|
|
|
|
+ */
|
|
|
|
|
+function apiUrl(path: string): string {
|
|
|
|
|
+ return path.startsWith('/') ? path : `/${path}`;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 飞鹅打印API客户端配置
|
|
* 飞鹅打印API客户端配置
|
|
|
*/
|
|
*/
|
|
@@ -64,7 +71,7 @@ export class FeiePrinterClient {
|
|
|
* 查询打印机列表
|
|
* 查询打印机列表
|
|
|
*/
|
|
*/
|
|
|
async getPrinters(params?: PrinterQueryParams): Promise<PrinterListResponse> {
|
|
async getPrinters(params?: PrinterQueryParams): Promise<PrinterListResponse> {
|
|
|
- const response = await this.client.get<ApiResponse<PrinterListResponse>>('/api/feie/printers', {
|
|
|
|
|
|
|
+ const response = await this.client.get<ApiResponse<PrinterListResponse>>(apiUrl('/printers'), {
|
|
|
params
|
|
params
|
|
|
});
|
|
});
|
|
|
if (!response.data.success) {
|
|
if (!response.data.success) {
|
|
@@ -77,7 +84,7 @@ export class FeiePrinterClient {
|
|
|
* 添加打印机
|
|
* 添加打印机
|
|
|
*/
|
|
*/
|
|
|
async addPrinter(request: CreatePrinterRequest): Promise<FeiePrinter> {
|
|
async addPrinter(request: CreatePrinterRequest): Promise<FeiePrinter> {
|
|
|
- const response = await this.client.post<ApiResponse<FeiePrinter>>('/api/feie/printers', request);
|
|
|
|
|
|
|
+ const response = await this.client.post<ApiResponse<FeiePrinter>>(apiUrl(`/printers`), request);
|
|
|
if (!response.data.success) {
|
|
if (!response.data.success) {
|
|
|
throw new Error(response.data.message || '添加打印机失败');
|
|
throw new Error(response.data.message || '添加打印机失败');
|
|
|
}
|
|
}
|
|
@@ -88,7 +95,7 @@ export class FeiePrinterClient {
|
|
|
* 获取打印机详情
|
|
* 获取打印机详情
|
|
|
*/
|
|
*/
|
|
|
async getPrinter(printerSn: string): Promise<FeiePrinter> {
|
|
async getPrinter(printerSn: string): Promise<FeiePrinter> {
|
|
|
- const response = await this.client.get<ApiResponse<FeiePrinter>>(`/api/feie/printers/${printerSn}`);
|
|
|
|
|
|
|
+ const response = await this.client.get<ApiResponse<FeiePrinter>>(apiUrl(`/printers/${printerSn}`));
|
|
|
if (!response.data.success) {
|
|
if (!response.data.success) {
|
|
|
throw new Error(response.data.message || '获取打印机详情失败');
|
|
throw new Error(response.data.message || '获取打印机详情失败');
|
|
|
}
|
|
}
|
|
@@ -99,7 +106,7 @@ export class FeiePrinterClient {
|
|
|
* 更新打印机
|
|
* 更新打印机
|
|
|
*/
|
|
*/
|
|
|
async updatePrinter(printerSn: string, request: UpdatePrinterRequest): Promise<FeiePrinter> {
|
|
async updatePrinter(printerSn: string, request: UpdatePrinterRequest): Promise<FeiePrinter> {
|
|
|
- const response = await this.client.put<ApiResponse<FeiePrinter>>(`/api/feie/printers/${printerSn}`, request);
|
|
|
|
|
|
|
+ const response = await this.client.put<ApiResponse<FeiePrinter>>(apiUrl(`/printers/${printerSn}`), request);
|
|
|
if (!response.data.success) {
|
|
if (!response.data.success) {
|
|
|
throw new Error(response.data.message || '更新打印机失败');
|
|
throw new Error(response.data.message || '更新打印机失败');
|
|
|
}
|
|
}
|
|
@@ -110,7 +117,7 @@ export class FeiePrinterClient {
|
|
|
* 删除打印机
|
|
* 删除打印机
|
|
|
*/
|
|
*/
|
|
|
async deletePrinter(printerSn: string): Promise<void> {
|
|
async deletePrinter(printerSn: string): Promise<void> {
|
|
|
- const response = await this.client.delete<ApiResponse<void>>(`/api/feie/printers/${printerSn}`);
|
|
|
|
|
|
|
+ const response = await this.client.delete<ApiResponse<void>>(apiUrl(`/printers/${printerSn}`));
|
|
|
if (!response.data.success) {
|
|
if (!response.data.success) {
|
|
|
throw new Error(response.data.message || '删除打印机失败');
|
|
throw new Error(response.data.message || '删除打印机失败');
|
|
|
}
|
|
}
|
|
@@ -121,7 +128,7 @@ export class FeiePrinterClient {
|
|
|
*/
|
|
*/
|
|
|
async getPrinterStatus(printerSn: string): Promise<{ status: string; lastCheck: string }> {
|
|
async getPrinterStatus(printerSn: string): Promise<{ status: string; lastCheck: string }> {
|
|
|
const response = await this.client.get<ApiResponse<{ status: string; lastCheck: string }>>(
|
|
const response = await this.client.get<ApiResponse<{ status: string; lastCheck: string }>>(
|
|
|
- `/api/feie/printers/${printerSn}/status`
|
|
|
|
|
|
|
+ apiUrl(`/printers/${printerSn}/status`)
|
|
|
);
|
|
);
|
|
|
if (!response.data.success) {
|
|
if (!response.data.success) {
|
|
|
throw new Error(response.data.message || '获取打印机状态失败');
|
|
throw new Error(response.data.message || '获取打印机状态失败');
|
|
@@ -134,7 +141,7 @@ export class FeiePrinterClient {
|
|
|
*/
|
|
*/
|
|
|
async setDefaultPrinter(printerSn: string): Promise<FeiePrinter> {
|
|
async setDefaultPrinter(printerSn: string): Promise<FeiePrinter> {
|
|
|
const response = await this.client.post<ApiResponse<FeiePrinter>>(
|
|
const response = await this.client.post<ApiResponse<FeiePrinter>>(
|
|
|
- `/api/feie/printers/${printerSn}/set-default`
|
|
|
|
|
|
|
+ apiUrl(`/printers/${printerSn}/set-default`)
|
|
|
);
|
|
);
|
|
|
if (!response.data.success) {
|
|
if (!response.data.success) {
|
|
|
throw new Error(response.data.message || '设置默认打印机失败');
|
|
throw new Error(response.data.message || '设置默认打印机失败');
|
|
@@ -148,7 +155,7 @@ export class FeiePrinterClient {
|
|
|
* 查询打印任务列表
|
|
* 查询打印任务列表
|
|
|
*/
|
|
*/
|
|
|
async getPrintTasks(params?: PrintTaskQueryParams): Promise<PrintTaskListResponse> {
|
|
async getPrintTasks(params?: PrintTaskQueryParams): Promise<PrintTaskListResponse> {
|
|
|
- const response = await this.client.get<ApiResponse<PrintTaskListResponse>>('/api/feie/tasks', {
|
|
|
|
|
|
|
+ const response = await this.client.get<ApiResponse<PrintTaskListResponse>>(apiUrl('/tasks'), {
|
|
|
params
|
|
params
|
|
|
});
|
|
});
|
|
|
if (!response.data.success) {
|
|
if (!response.data.success) {
|
|
@@ -161,7 +168,7 @@ export class FeiePrinterClient {
|
|
|
* 获取打印任务详情
|
|
* 获取打印任务详情
|
|
|
*/
|
|
*/
|
|
|
async getPrintTask(taskId: string): Promise<FeiePrintTask> {
|
|
async getPrintTask(taskId: string): Promise<FeiePrintTask> {
|
|
|
- const response = await this.client.get<ApiResponse<FeiePrintTask>>(`/api/feie/tasks/${taskId}`);
|
|
|
|
|
|
|
+ const response = await this.client.get<ApiResponse<FeiePrintTask>>(apiUrl(`/tasks/${taskId}`));
|
|
|
if (!response.data.success) {
|
|
if (!response.data.success) {
|
|
|
throw new Error(response.data.message || '获取打印任务详情失败');
|
|
throw new Error(response.data.message || '获取打印任务详情失败');
|
|
|
}
|
|
}
|
|
@@ -172,7 +179,7 @@ export class FeiePrinterClient {
|
|
|
* 提交打印任务
|
|
* 提交打印任务
|
|
|
*/
|
|
*/
|
|
|
async submitPrintTask(request: SubmitPrintTaskRequest): Promise<SubmitPrintTaskResponse> {
|
|
async submitPrintTask(request: SubmitPrintTaskRequest): Promise<SubmitPrintTaskResponse> {
|
|
|
- const response = await this.client.post<ApiResponse<SubmitPrintTaskResponse>>('/api/feie/tasks', request);
|
|
|
|
|
|
|
+ const response = await this.client.post<ApiResponse<SubmitPrintTaskResponse>>(apiUrl('/tasks'), request);
|
|
|
if (!response.data.success) {
|
|
if (!response.data.success) {
|
|
|
throw new Error(response.data.message || '提交打印任务失败');
|
|
throw new Error(response.data.message || '提交打印任务失败');
|
|
|
}
|
|
}
|
|
@@ -184,7 +191,7 @@ export class FeiePrinterClient {
|
|
|
*/
|
|
*/
|
|
|
async getPrintTaskStatus(taskId: string): Promise<{ status: string; lastUpdate: string }> {
|
|
async getPrintTaskStatus(taskId: string): Promise<{ status: string; lastUpdate: string }> {
|
|
|
const response = await this.client.get<ApiResponse<{ status: string; lastUpdate: string }>>(
|
|
const response = await this.client.get<ApiResponse<{ status: string; lastUpdate: string }>>(
|
|
|
- `/api/feie/tasks/${taskId}/status`
|
|
|
|
|
|
|
+ apiUrl(`/tasks/${taskId}/status`)
|
|
|
);
|
|
);
|
|
|
if (!response.data.success) {
|
|
if (!response.data.success) {
|
|
|
throw new Error(response.data.message || '获取打印任务状态失败');
|
|
throw new Error(response.data.message || '获取打印任务状态失败');
|
|
@@ -197,7 +204,7 @@ export class FeiePrinterClient {
|
|
|
*/
|
|
*/
|
|
|
async cancelPrintTask(request: CancelPrintTaskRequest): Promise<FeiePrintTask> {
|
|
async cancelPrintTask(request: CancelPrintTaskRequest): Promise<FeiePrintTask> {
|
|
|
const response = await this.client.post<ApiResponse<FeiePrintTask>>(
|
|
const response = await this.client.post<ApiResponse<FeiePrintTask>>(
|
|
|
- `/api/feie/tasks/${request.taskId}/cancel`,
|
|
|
|
|
|
|
+ apiUrl(`/tasks/${request.taskId}/cancel`),
|
|
|
{ reason: request.reason }
|
|
{ reason: request.reason }
|
|
|
);
|
|
);
|
|
|
if (!response.data.success) {
|
|
if (!response.data.success) {
|
|
@@ -211,7 +218,7 @@ export class FeiePrinterClient {
|
|
|
*/
|
|
*/
|
|
|
async retryPrintTask(request: RetryPrintTaskRequest): Promise<FeiePrintTask> {
|
|
async retryPrintTask(request: RetryPrintTaskRequest): Promise<FeiePrintTask> {
|
|
|
const response = await this.client.post<ApiResponse<FeiePrintTask>>(
|
|
const response = await this.client.post<ApiResponse<FeiePrintTask>>(
|
|
|
- `/api/feie/tasks/${request.taskId}/retry`
|
|
|
|
|
|
|
+ apiUrl(`/tasks/${request.taskId}/retry`)
|
|
|
);
|
|
);
|
|
|
if (!response.data.success) {
|
|
if (!response.data.success) {
|
|
|
throw new Error(response.data.message || '重试打印任务失败');
|
|
throw new Error(response.data.message || '重试打印任务失败');
|
|
@@ -225,7 +232,7 @@ export class FeiePrinterClient {
|
|
|
* 查询打印配置列表
|
|
* 查询打印配置列表
|
|
|
*/
|
|
*/
|
|
|
async getPrintConfigs(): Promise<ConfigListResponse> {
|
|
async getPrintConfigs(): Promise<ConfigListResponse> {
|
|
|
- const response = await this.client.get<ApiResponse<ConfigListResponse>>('/api/feie/config');
|
|
|
|
|
|
|
+ const response = await this.client.get<ApiResponse<ConfigListResponse>>(apiUrl('/config'));
|
|
|
if (!response.data.success) {
|
|
if (!response.data.success) {
|
|
|
throw new Error(response.data.message || '获取打印配置列表失败');
|
|
throw new Error(response.data.message || '获取打印配置列表失败');
|
|
|
}
|
|
}
|
|
@@ -237,7 +244,7 @@ export class FeiePrinterClient {
|
|
|
*/
|
|
*/
|
|
|
async updatePrintConfig(configKey: string, request: UpdateConfigRequest): Promise<FeieConfig> {
|
|
async updatePrintConfig(configKey: string, request: UpdateConfigRequest): Promise<FeieConfig> {
|
|
|
const response = await this.client.put<ApiResponse<FeieConfig>>(
|
|
const response = await this.client.put<ApiResponse<FeieConfig>>(
|
|
|
- `/api/feie/config/${configKey}`,
|
|
|
|
|
|
|
+ apiUrl(`/config/${configKey}`),
|
|
|
request
|
|
request
|
|
|
);
|
|
);
|
|
|
if (!response.data.success) {
|
|
if (!response.data.success) {
|
|
@@ -253,8 +260,7 @@ export class FeiePrinterClient {
|
|
|
*/
|
|
*/
|
|
|
async getSchedulerStatus(): Promise<{ running: boolean; lastRun: string; nextRun: string }> {
|
|
async getSchedulerStatus(): Promise<{ running: boolean; lastRun: string; nextRun: string }> {
|
|
|
const response = await this.client.get<ApiResponse<{ running: boolean; lastRun: string; nextRun: string }>>(
|
|
const response = await this.client.get<ApiResponse<{ running: boolean; lastRun: string; nextRun: string }>>(
|
|
|
- '/api/feie/scheduler/status'
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ apiUrl('/scheduler/status'));
|
|
|
if (!response.data.success) {
|
|
if (!response.data.success) {
|
|
|
throw new Error(response.data.message || '获取调度器状态失败');
|
|
throw new Error(response.data.message || '获取调度器状态失败');
|
|
|
}
|
|
}
|
|
@@ -265,7 +271,7 @@ export class FeiePrinterClient {
|
|
|
* 启动调度器
|
|
* 启动调度器
|
|
|
*/
|
|
*/
|
|
|
async startScheduler(): Promise<void> {
|
|
async startScheduler(): Promise<void> {
|
|
|
- const response = await this.client.post<ApiResponse<void>>('/api/feie/scheduler/start');
|
|
|
|
|
|
|
+ const response = await this.client.post<ApiResponse<void>>(apiUrl('/scheduler/start'));
|
|
|
if (!response.data.success) {
|
|
if (!response.data.success) {
|
|
|
throw new Error(response.data.message || '启动调度器失败');
|
|
throw new Error(response.data.message || '启动调度器失败');
|
|
|
}
|
|
}
|
|
@@ -275,7 +281,7 @@ export class FeiePrinterClient {
|
|
|
* 停止调度器
|
|
* 停止调度器
|
|
|
*/
|
|
*/
|
|
|
async stopScheduler(): Promise<void> {
|
|
async stopScheduler(): Promise<void> {
|
|
|
- const response = await this.client.post<ApiResponse<void>>('/api/feie/scheduler/stop');
|
|
|
|
|
|
|
+ const response = await this.client.post<ApiResponse<void>>(apiUrl('/scheduler/stop'));
|
|
|
if (!response.data.success) {
|
|
if (!response.data.success) {
|
|
|
throw new Error(response.data.message || '停止调度器失败');
|
|
throw new Error(response.data.message || '停止调度器失败');
|
|
|
}
|
|
}
|
|
@@ -286,8 +292,7 @@ export class FeiePrinterClient {
|
|
|
*/
|
|
*/
|
|
|
async getSchedulerHealth(): Promise<{ healthy: boolean; message: string; timestamp: string }> {
|
|
async getSchedulerHealth(): Promise<{ healthy: boolean; message: string; timestamp: string }> {
|
|
|
const response = await this.client.get<ApiResponse<{ healthy: boolean; message: string; timestamp: string }>>(
|
|
const response = await this.client.get<ApiResponse<{ healthy: boolean; message: string; timestamp: string }>>(
|
|
|
- '/api/feie/scheduler/health'
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ apiUrl('/scheduler/health'));
|
|
|
if (!response.data.success) {
|
|
if (!response.data.success) {
|
|
|
throw new Error(response.data.message || '获取调度器健康状态失败');
|
|
throw new Error(response.data.message || '获取调度器健康状态失败');
|
|
|
}
|
|
}
|
|
@@ -298,7 +303,7 @@ export class FeiePrinterClient {
|
|
|
/**
|
|
/**
|
|
|
* 创建默认的飞鹅打印API客户端
|
|
* 创建默认的飞鹅打印API客户端
|
|
|
*/
|
|
*/
|
|
|
-export function createFeiePrinterClient(baseURL: string = '/api'): FeiePrinterClient {
|
|
|
|
|
|
|
+export function createFeiePrinterClient(baseURL: string = '/api/v1/feie'): FeiePrinterClient {
|
|
|
return new FeiePrinterClient({
|
|
return new FeiePrinterClient({
|
|
|
baseURL,
|
|
baseURL,
|
|
|
timeout: 10000
|
|
timeout: 10000
|