mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-01-18 14:30:29 +00:00
fix: 刷新二维码清楚错误信息
This commit is contained in:
parent
1b8860ea7d
commit
5bb8f9af8d
@ -2,30 +2,16 @@ import type { Request, Response } from 'express';
|
||||
import { WebUiDataRuntime } from '../helper/Data';
|
||||
import { sendError, sendSuccess } from '../utils/response';
|
||||
|
||||
export interface RestartRequestBody {
|
||||
/**
|
||||
* 重启类型: 'manual' (用户手动触发) 或 'automatic' (系统自动触发)
|
||||
* 默认为 'manual'
|
||||
*/
|
||||
restartType?: 'manual' | 'automatic';
|
||||
}
|
||||
|
||||
/**
|
||||
* 重启进程处理器
|
||||
* POST /api/Process/Restart
|
||||
* Body: { restartType?: 'manual' | 'automatic' }
|
||||
*/
|
||||
export async function RestartProcessHandler (req: Request, res: Response) {
|
||||
export async function RestartProcessHandler (_req: Request, res: Response) {
|
||||
try {
|
||||
const { restartType = 'manual' } = (req.body as RestartRequestBody) || {};
|
||||
|
||||
const result = await WebUiDataRuntime.requestRestartProcess();
|
||||
|
||||
if (result.result) {
|
||||
return sendSuccess(res, {
|
||||
message: result.message || '进程重启请求已发送',
|
||||
restartType,
|
||||
});
|
||||
return sendSuccess(res, { message: result.message || '进程重启请求已发送' });
|
||||
} else {
|
||||
return sendError(res, result.message || '进程重启失败');
|
||||
}
|
||||
|
||||
@ -196,6 +196,7 @@ export const WebUiDataRuntime = {
|
||||
},
|
||||
|
||||
refreshQRCode: async function () {
|
||||
LoginRuntime.QQLoginError = '';
|
||||
await LoginRuntime.onRefreshQRCode();
|
||||
},
|
||||
};
|
||||
|
||||
@ -1,19 +1,12 @@
|
||||
import { serverRequest } from '@/utils/request';
|
||||
|
||||
export interface RestartProcessResponse {
|
||||
message: string;
|
||||
restartType?: 'manual' | 'automatic';
|
||||
}
|
||||
|
||||
export default class ProcessManager {
|
||||
/**
|
||||
* 重启进程
|
||||
* @param restartType 重启类型: 'manual' (用户手动触发) 或 'automatic' (系统自动触发)
|
||||
*/
|
||||
public static async restartProcess (restartType: 'manual' | 'automatic' = 'manual') {
|
||||
const data = await serverRequest.post<ServerResponse<RestartProcessResponse>>(
|
||||
'/Process/Restart',
|
||||
{ restartType }
|
||||
public static async restartProcess () {
|
||||
const data = await serverRequest.post<ServerResponse<{ message: string; }>>(
|
||||
'/Process/Restart'
|
||||
);
|
||||
|
||||
return data.data.data;
|
||||
|
||||
@ -74,7 +74,7 @@ const Layout: React.FC<{ children: React.ReactNode; }> = ({ children }) => {
|
||||
onConfirm: async () => {
|
||||
setIsRestarting(true);
|
||||
try {
|
||||
await ProcessManager.restartProcess('automatic');
|
||||
await ProcessManager.restartProcess();
|
||||
} catch (_e) {
|
||||
// 忽略错误,因为后端正在重启关闭连接
|
||||
}
|
||||
@ -84,7 +84,7 @@ const Layout: React.FC<{ children: React.ReactNode; }> = ({ children }) => {
|
||||
15000, // 15秒超时
|
||||
() => {
|
||||
setIsRestarting(false);
|
||||
// 前端发起的重启不清除登录态,无感恢复
|
||||
window.location.reload();
|
||||
},
|
||||
() => {
|
||||
setIsRestarting(false);
|
||||
@ -92,8 +92,7 @@ const Layout: React.FC<{ children: React.ReactNode; }> = ({ children }) => {
|
||||
title: '启动超时',
|
||||
content: '后端在 15 秒内未响应,请检查 NapCat 运行日志或手动重启。',
|
||||
});
|
||||
},
|
||||
false // 前端发起的重启不清除登录态
|
||||
}
|
||||
);
|
||||
},
|
||||
onCancel: () => {
|
||||
|
||||
@ -60,7 +60,7 @@ const LoginConfigCard = () => {
|
||||
const onRestartProcess = async () => {
|
||||
setIsRestarting(true);
|
||||
try {
|
||||
const result = await ProcessManager.restartProcess('manual');
|
||||
const result = await ProcessManager.restartProcess();
|
||||
toast.success(result.message || '进程重启请求已发送');
|
||||
|
||||
// 轮询探测后端是否恢复
|
||||
@ -73,8 +73,7 @@ const LoginConfigCard = () => {
|
||||
() => {
|
||||
setIsRestarting(false);
|
||||
toast.error('后端在 30 秒内未响应,请检查 NapCat 运行日志');
|
||||
},
|
||||
false // 前端发起的重启不清除登录态
|
||||
}
|
||||
);
|
||||
|
||||
if (!isReady) {
|
||||
|
||||
@ -5,13 +5,11 @@ import QQManager from '@/controllers/qq_manager';
|
||||
* @param maxWaitTime 最大等待时间,单位毫秒
|
||||
* @param onSuccess 成功回调
|
||||
* @param onTimeout 超时回调
|
||||
* @param shouldLogout 是否在成功后登出用户。默认为 true (清除登录态),前端发起的重启应传 false (保留会话)
|
||||
*/
|
||||
export async function waitForBackendReady (
|
||||
maxWaitTime: number = 15000,
|
||||
onSuccess?: () => void,
|
||||
onTimeout?: () => void,
|
||||
shouldLogout: boolean = true
|
||||
onTimeout?: () => void
|
||||
): Promise<boolean> {
|
||||
const startTime = Date.now();
|
||||
|
||||
@ -22,15 +20,7 @@ export async function waitForBackendReady (
|
||||
await QQManager.getQQLoginInfo({ timeout: 500 });
|
||||
// 如果能走到这一步说明请求成功了
|
||||
clearInterval(timer);
|
||||
|
||||
// 如果需要登出,刷新页面来清除会话
|
||||
if (shouldLogout) {
|
||||
window.location.reload();
|
||||
} else {
|
||||
// 否则直接调用成功回调
|
||||
onSuccess?.();
|
||||
}
|
||||
|
||||
onSuccess?.();
|
||||
resolve(true);
|
||||
} catch (_e) {
|
||||
// 如果请求失败(后端没起来),检查是否超时
|
||||
|
||||
Loading…
Reference in New Issue
Block a user