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 { 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 || '进程重启失败');
|
||||||
}
|
}
|
||||||
|
|||||||
@ -196,6 +196,7 @@ export const WebUiDataRuntime = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
refreshQRCode: async function () {
|
refreshQRCode: async function () {
|
||||||
|
LoginRuntime.QQLoginError = '';
|
||||||
await LoginRuntime.onRefreshQRCode();
|
await LoginRuntime.onRefreshQRCode();
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@ -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;
|
||||||
|
|||||||
@ -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: () => {
|
||||||
|
|||||||
@ -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) {
|
||||||
|
|||||||
@ -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) {
|
||||||
// 如果请求失败(后端没起来),检查是否超时
|
// 如果请求失败(后端没起来),检查是否超时
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user