feat(webui): 添加QQ掉线时重启进程提示
- 后端 CheckLoginStatus API 新增 isOffline 字段区分掉线与未登录状态 - 后端 GetQQLoginInfo API 新增返回 online 和 avatarUrl 字段 - 前端掉线时弹窗提示用户是否重启进程 - 修正 isLogin 类型从 string 改为 boolean
This commit is contained in:
1 parent
29d7b95d05
commit
39a2a4028b
3 files changed
+25
-6
No files matched your search
@@ -34,8 +34,11 @@ export const QQCheckLoginStatusHandler: RequestHandler = async (_, res) => {
|
|||||||
const qqLoginStatus = WebUiDataRuntime.getQQLoginStatus();
|
const qqLoginStatus = WebUiDataRuntime.getQQLoginStatus();
|
||||||
// 必须同时满足:已登录且在线(online 必须明确为 true)
|
// 必须同时满足:已登录且在线(online 必须明确为 true)
|
||||||
const isLogin = qqLoginStatus && isOnline === true;
|
const isLogin = qqLoginStatus && isOnline === true;
|
||||||
|
// 检测掉线状态:已登录但不在线
|
||||||
|
const isOffline = qqLoginStatus && isOnline === false;
|
||||||
const data = {
|
const data = {
|
||||||
isLogin,
|
isLogin,
|
||||||
|
isOffline,
|
||||||
qrcodeurl: WebUiDataRuntime.getQQLoginQrcodeURL(),
|
qrcodeurl: WebUiDataRuntime.getQQLoginQrcodeURL(),
|
||||||
loginError: WebUiDataRuntime.getQQLoginError(),
|
loginError: WebUiDataRuntime.getQQLoginError(),
|
||||||
};
|
};
|
||||||
@@ -80,7 +83,17 @@ export const QQGetLoginListNewHandler: RequestHandler = async (_, res) => {
|
|||||||
|
|
||||||
// 获取登录的QQ的信息
|
// 获取登录的QQ的信息
|
||||||
export const getQQLoginInfoHandler: RequestHandler = async (_, res) => {
|
export const getQQLoginInfoHandler: RequestHandler = async (_, res) => {
|
||||||
const data = WebUiDataRuntime.getQQLoginInfo();
|
const basicInfo = WebUiDataRuntime.getQQLoginInfo();
|
||||||
|
// 从 OneBot 上下文获取实时的 selfInfo.online 状态
|
||||||
|
const oneBotContext = WebUiDataRuntime.getOneBotContext();
|
||||||
|
const selfInfo = oneBotContext?.core?.selfInfo;
|
||||||
|
const online = selfInfo?.online ?? undefined;
|
||||||
|
const avatarUrl = selfInfo?.avatarUrl;
|
||||||
|
const data = {
|
||||||
|
...basicInfo,
|
||||||
|
online,
|
||||||
|
avatarUrl,
|
||||||
|
};
|
||||||
return sendSuccess(res, data);
|
return sendSuccess(res, data);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,8 @@ export default class QQManager {
|
|||||||
public static async checkQQLoginStatus () {
|
public static async checkQQLoginStatus () {
|
||||||
const data = await serverRequest.post<
|
const data = await serverRequest.post<
|
||||||
ServerResponse<{
|
ServerResponse<{
|
||||||
isLogin: string;
|
isLogin: boolean;
|
||||||
|
isOffline?: boolean;
|
||||||
qrcodeurl: string;
|
qrcodeurl: string;
|
||||||
}>
|
}>
|
||||||
>('/QQLogin/CheckLoginStatus');
|
>('/QQLogin/CheckLoginStatus');
|
||||||
@@ -31,7 +32,7 @@ export default class QQManager {
|
|||||||
|
|
||||||
public static async checkQQLoginStatusWithQrcode () {
|
public static async checkQQLoginStatusWithQrcode () {
|
||||||
const data = await serverRequest.post<
|
const data = await serverRequest.post<
|
||||||
ServerResponse<{ qrcodeurl: string; isLogin: string; loginError?: string; }>
|
ServerResponse<{ qrcodeurl: string; isLogin: boolean; isOffline?: boolean; loginError?: string; }>
|
||||||
>('/QQLogin/CheckLoginStatus');
|
>('/QQLogin/CheckLoginStatus');
|
||||||
|
|
||||||
return data.data.data;
|
return data.data.data;
|
||||||
|
|||||||
@@ -68,8 +68,8 @@ const Layout: React.FC<{ children: React.ReactNode; }> = ({ children }) => {
|
|||||||
isOnlineRef.current = false;
|
isOnlineRef.current = false;
|
||||||
dialog.confirm({
|
dialog.confirm({
|
||||||
title: '账号已离线',
|
title: '账号已离线',
|
||||||
content: '您的 QQ 账号已下线,请重新登录。',
|
content: '您的 QQ 账号已掉线,是否重启进程以重新登录?',
|
||||||
confirmText: '重新登陆',
|
confirmText: '重启进程',
|
||||||
cancelText: '退出账户',
|
cancelText: '退出账户',
|
||||||
onConfirm: async () => {
|
onConfirm: async () => {
|
||||||
setIsRestarting(true);
|
setIsRestarting(true);
|
||||||
@@ -115,7 +115,12 @@ const Layout: React.FC<{ children: React.ReactNode; }> = ({ children }) => {
|
|||||||
const checkIsQQLogin = async () => {
|
const checkIsQQLogin = async () => {
|
||||||
try {
|
try {
|
||||||
const result = await QQManager.checkQQLoginStatus();
|
const result = await QQManager.checkQQLoginStatus();
|
||||||
if (!result.isLogin) {
|
// 掉线状态由 checkOnlineStatus 定期检测并弹窗处理,这里只处理未登录
|
||||||
|
if (result.isOffline) {
|
||||||
|
// 已登录但掉线,标记状态,等待 checkOnlineStatus 弹窗
|
||||||
|
isOnlineRef.current = false;
|
||||||
|
} else if (!result.isLogin) {
|
||||||
|
// 未登录状态:跳转到登录页面
|
||||||
if (isAuth) {
|
if (isAuth) {
|
||||||
navigate('/qq_login', { replace: true });
|
navigate('/qq_login', { replace: true });
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in new issue
Block a user