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 { WebUiDataRuntime } from '../helper/Data';
import { sendError, sendSuccess } from '../utils/response'; import { sendError, sendSuccess } from '../utils/response';
export interface RestartRequestBody {
/**
* : 'manual' () 'automatic' ()
* 'manual'
*/
restartType?: 'manual' | 'automatic';
}
/** /**
* *
* POST /api/Process/Restart * 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 { try {
const { restartType = 'manual' } = (req.body as RestartRequestBody) || {};
const result = await WebUiDataRuntime.requestRestartProcess(); const result = await WebUiDataRuntime.requestRestartProcess();
if (result.result) { if (result.result) {
return sendSuccess(res, { return sendSuccess(res, { message: result.message || '进程重启请求已发送' });
message: result.message || '进程重启请求已发送',
restartType,
});
} else { } else {
return sendError(res, result.message || '进程重启失败'); return sendError(res, result.message || '进程重启失败');
} }

View File

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

View File

@ -1,19 +1,12 @@
import { serverRequest } from '@/utils/request'; import { serverRequest } from '@/utils/request';
export interface RestartProcessResponse {
message: string;
restartType?: 'manual' | 'automatic';
}
export default class ProcessManager { export default class ProcessManager {
/** /**
* *
* @param restartType : 'manual' () 'automatic' ()
*/ */
public static async restartProcess (restartType: 'manual' | 'automatic' = 'manual') { public static async restartProcess () {
const data = await serverRequest.post<ServerResponse<RestartProcessResponse>>( const data = await serverRequest.post<ServerResponse<{ message: string; }>>(
'/Process/Restart', '/Process/Restart'
{ restartType }
); );
return data.data.data; return data.data.data;

View File

@ -74,7 +74,7 @@ const Layout: React.FC<{ children: React.ReactNode; }> = ({ children }) => {
onConfirm: async () => { onConfirm: async () => {
setIsRestarting(true); setIsRestarting(true);
try { try {
await ProcessManager.restartProcess('automatic'); await ProcessManager.restartProcess();
} catch (_e) { } catch (_e) {
// 忽略错误,因为后端正在重启关闭连接 // 忽略错误,因为后端正在重启关闭连接
} }
@ -84,7 +84,7 @@ const Layout: React.FC<{ children: React.ReactNode; }> = ({ children }) => {
15000, // 15秒超时 15000, // 15秒超时
() => { () => {
setIsRestarting(false); setIsRestarting(false);
// 前端发起的重启不清除登录态,无感恢复 window.location.reload();
}, },
() => { () => {
setIsRestarting(false); setIsRestarting(false);
@ -92,8 +92,7 @@ const Layout: React.FC<{ children: React.ReactNode; }> = ({ children }) => {
title: '启动超时', title: '启动超时',
content: '后端在 15 秒内未响应,请检查 NapCat 运行日志或手动重启。', content: '后端在 15 秒内未响应,请检查 NapCat 运行日志或手动重启。',
}); });
}, }
false // 前端发起的重启不清除登录态
); );
}, },
onCancel: () => { onCancel: () => {

View File

@ -60,7 +60,7 @@ const LoginConfigCard = () => {
const onRestartProcess = async () => { const onRestartProcess = async () => {
setIsRestarting(true); setIsRestarting(true);
try { try {
const result = await ProcessManager.restartProcess('manual'); const result = await ProcessManager.restartProcess();
toast.success(result.message || '进程重启请求已发送'); toast.success(result.message || '进程重启请求已发送');
// 轮询探测后端是否恢复 // 轮询探测后端是否恢复
@ -73,8 +73,7 @@ const LoginConfigCard = () => {
() => { () => {
setIsRestarting(false); setIsRestarting(false);
toast.error('后端在 30 秒内未响应,请检查 NapCat 运行日志'); toast.error('后端在 30 秒内未响应,请检查 NapCat 运行日志');
}, }
false // 前端发起的重启不清除登录态
); );
if (!isReady) { if (!isReady) {

View File

@ -5,13 +5,11 @@ import QQManager from '@/controllers/qq_manager';
* @param maxWaitTime * @param maxWaitTime
* @param onSuccess * @param onSuccess
* @param onTimeout * @param onTimeout
* @param shouldLogout true () false ()
*/ */
export async function waitForBackendReady ( export async function waitForBackendReady (
maxWaitTime: number = 15000, maxWaitTime: number = 15000,
onSuccess?: () => void, onSuccess?: () => void,
onTimeout?: () => void, onTimeout?: () => void
shouldLogout: boolean = true
): Promise<boolean> { ): Promise<boolean> {
const startTime = Date.now(); const startTime = Date.now();
@ -22,15 +20,7 @@ export async function waitForBackendReady (
await QQManager.getQQLoginInfo({ timeout: 500 }); await QQManager.getQQLoginInfo({ timeout: 500 });
// 如果能走到这一步说明请求成功了 // 如果能走到这一步说明请求成功了
clearInterval(timer); clearInterval(timer);
// 如果需要登出,刷新页面来清除会话
if (shouldLogout) {
window.location.reload();
} else {
// 否则直接调用成功回调
onSuccess?.(); onSuccess?.();
}
resolve(true); resolve(true);
} catch (_e) { } catch (_e) {
// 如果请求失败(后端没起来),检查是否超时 // 如果请求失败(后端没起来),检查是否超时