fix: 刷新二维码清楚错误信息

This commit is contained in:
时瑾 2026-01-17 15:35:11 +08:00
parent 1b8860ea7d
commit 5bb8f9af8d
No known key found for this signature in database
GPG Key ID: 023F70A1B8F8C196
6 changed files with 13 additions and 45 deletions

View File

@ -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 || '进程重启失败');
}

View File

@ -196,6 +196,7 @@ export const WebUiDataRuntime = {
},
refreshQRCode: async function () {
LoginRuntime.QQLoginError = '';
await LoginRuntime.onRefreshQRCode();
},
};

View File

@ -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;

View File

@ -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: () => {

View File

@ -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) {

View File

@ -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) {
// 如果请求失败(后端没起来),检查是否超时