refactor: 同步QQBot核心管理页
This commit is contained in:
parent
5f270cff5c
commit
eceadc36f8
@ -5,6 +5,14 @@ import { requestClient } from '#/api/request';
|
|||||||
|
|
||||||
export namespace QqbotApi {
|
export namespace QqbotApi {
|
||||||
export type PluginTriggerMode = 'command' | 'event';
|
export type PluginTriggerMode = 'command' | 'event';
|
||||||
|
export type OneBotStatus = 'offline' | 'online';
|
||||||
|
export type WebuiStatus = 'offline' | 'online' | 'unknown';
|
||||||
|
export type QqLoginStatus =
|
||||||
|
| 'offline'
|
||||||
|
| 'online'
|
||||||
|
| 'qrcode_expired'
|
||||||
|
| 'qrcode_pending'
|
||||||
|
| 'unknown';
|
||||||
|
|
||||||
export interface PageResult<T> {
|
export interface PageResult<T> {
|
||||||
list: T[];
|
list: T[];
|
||||||
@ -37,6 +45,7 @@ export namespace QqbotApi {
|
|||||||
clientRole?: string;
|
clientRole?: string;
|
||||||
connectStatus: 'offline' | 'online';
|
connectStatus: 'offline' | 'online';
|
||||||
connectionMode: 'reverse-ws';
|
connectionMode: 'reverse-ws';
|
||||||
|
containerStatus?: AccountNapcatRuntime['containerStatus'];
|
||||||
createTime?: string;
|
createTime?: string;
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
id: string;
|
id: string;
|
||||||
@ -45,8 +54,12 @@ export namespace QqbotApi {
|
|||||||
lastHeartbeatAt?: string;
|
lastHeartbeatAt?: string;
|
||||||
name: string;
|
name: string;
|
||||||
napcat?: AccountNapcatRuntime | null;
|
napcat?: AccountNapcatRuntime | null;
|
||||||
|
oneBotStatus?: OneBotStatus;
|
||||||
|
qqLoginMessage?: null | string;
|
||||||
|
qqLoginStatus?: QqLoginStatus;
|
||||||
remark?: string;
|
remark?: string;
|
||||||
selfId: string;
|
selfId: string;
|
||||||
|
webuiStatus?: WebuiStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AccountNapcatRuntime {
|
export interface AccountNapcatRuntime {
|
||||||
@ -61,12 +74,7 @@ export namespace QqbotApi {
|
|||||||
lastStartedAt?: string;
|
lastStartedAt?: string;
|
||||||
oneBotOnline?: boolean;
|
oneBotOnline?: boolean;
|
||||||
qqLoginMessage?: null | string;
|
qqLoginMessage?: null | string;
|
||||||
qqLoginStatus?:
|
qqLoginStatus?: QqLoginStatus;
|
||||||
| 'offline'
|
|
||||||
| 'online'
|
|
||||||
| 'qrcode_expired'
|
|
||||||
| 'qrcode_pending'
|
|
||||||
| 'unknown';
|
|
||||||
webuiOnline?: boolean | null;
|
webuiOnline?: boolean | null;
|
||||||
webuiPort?: null | number;
|
webuiPort?: null | number;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -294,7 +294,7 @@ export default defineComponent({
|
|||||||
permissionCodes: ['QqBot:Account:Delete'],
|
permissionCodes: ['QqBot:Account:Delete'],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
disabled: (row) => row.connectStatus !== 'online',
|
disabled: (row) => getOneBotStatus(row) !== 'online',
|
||||||
key: 'kick',
|
key: 'kick',
|
||||||
label: '断开',
|
label: '断开',
|
||||||
onClick: async (row, context) => {
|
onClick: async (row, context) => {
|
||||||
@ -696,7 +696,7 @@ export default defineComponent({
|
|||||||
if (!row.enabled) {
|
if (!row.enabled) {
|
||||||
return <Tag color="default">已停用</Tag>;
|
return <Tag color="default">已停用</Tag>;
|
||||||
}
|
}
|
||||||
const online = row.napcat?.oneBotOnline ?? row.connectStatus === 'online';
|
const online = getOneBotStatus(row) === 'online';
|
||||||
return (
|
return (
|
||||||
<Tag color={online ? 'success' : 'default'}>
|
<Tag color={online ? 'success' : 'default'}>
|
||||||
{online ? 'OneBot 在线' : 'OneBot 离线'}
|
{online ? 'OneBot 在线' : 'OneBot 离线'}
|
||||||
@ -705,14 +705,13 @@ export default defineComponent({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const renderQqLoginStatus = (row: QqbotApi.Account) => {
|
const renderQqLoginStatus = (row: QqbotApi.Account) => {
|
||||||
const meta = getQqLoginStatusMeta(row.napcat);
|
const meta = getQqLoginStatusMeta(row);
|
||||||
|
const message = getQqLoginMessage(row);
|
||||||
return (
|
return (
|
||||||
<Space direction="vertical" size={2}>
|
<Space direction="vertical" size={2}>
|
||||||
<Tag color={meta.color}>{meta.label}</Tag>
|
<Tag color={meta.color}>{meta.label}</Tag>
|
||||||
{row.napcat?.qqLoginMessage ? (
|
{message ? (
|
||||||
<ATypographyText type="secondary">
|
<ATypographyText type="secondary">{message}</ATypographyText>
|
||||||
{row.napcat.qqLoginMessage}
|
|
||||||
</ATypographyText>
|
|
||||||
) : null}
|
) : null}
|
||||||
</Space>
|
</Space>
|
||||||
);
|
);
|
||||||
@ -720,8 +719,8 @@ export default defineComponent({
|
|||||||
|
|
||||||
const renderNapcatRuntime = (row: QqbotApi.Account) => {
|
const renderNapcatRuntime = (row: QqbotApi.Account) => {
|
||||||
const napcat = row.napcat;
|
const napcat = row.napcat;
|
||||||
const meta = getNapcatStatusMeta(napcat);
|
const meta = getNapcatStatusMeta(row);
|
||||||
const webuiMeta = getNapcatWebuiMeta(napcat);
|
const webuiMeta = getNapcatWebuiMeta(row);
|
||||||
return (
|
return (
|
||||||
<Space direction="vertical" size={2}>
|
<Space direction="vertical" size={2}>
|
||||||
<Space size={4} wrap>
|
<Space size={4} wrap>
|
||||||
@ -762,13 +761,12 @@ export default defineComponent({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
function getNapcatStatusMeta(
|
function getNapcatStatusMeta(row: QqbotApi.Account) {
|
||||||
napcat?: null | QqbotApi.AccountNapcatRuntime,
|
const status = row.containerStatus || row.napcat?.containerStatus;
|
||||||
) {
|
if (!row.napcat && !status) {
|
||||||
if (!napcat) {
|
|
||||||
return { color: 'default', label: '未绑定专属容器' };
|
return { color: 'default', label: '未绑定专属容器' };
|
||||||
}
|
}
|
||||||
if (!napcat.containerStatus) {
|
if (!status) {
|
||||||
return { color: 'warning', label: '容器记录缺失' };
|
return { color: 'warning', label: '容器记录缺失' };
|
||||||
}
|
}
|
||||||
const statusMap: Record<
|
const statusMap: Record<
|
||||||
@ -780,26 +778,29 @@ export default defineComponent({
|
|||||||
running: { color: 'success', label: '容器运行中' },
|
running: { color: 'success', label: '容器运行中' },
|
||||||
stopped: { color: 'default', label: '容器已停止' },
|
stopped: { color: 'default', label: '容器已停止' },
|
||||||
};
|
};
|
||||||
return statusMap[napcat.containerStatus];
|
return statusMap[status];
|
||||||
}
|
}
|
||||||
|
|
||||||
function getNapcatWebuiMeta(napcat?: null | QqbotApi.AccountNapcatRuntime) {
|
function getNapcatWebuiMeta(row: QqbotApi.Account) {
|
||||||
if (!napcat) return { color: 'default', label: 'WebUI 未绑定' };
|
const status = getWebuiStatus(row);
|
||||||
if (napcat.webuiOnline === true) {
|
if (!row.napcat && status === 'unknown') {
|
||||||
|
return { color: 'default', label: 'WebUI 未绑定' };
|
||||||
|
}
|
||||||
|
if (status === 'online') {
|
||||||
return { color: 'success', label: 'WebUI 可用' };
|
return { color: 'success', label: 'WebUI 可用' };
|
||||||
}
|
}
|
||||||
if (napcat.webuiOnline === false) {
|
if (status === 'offline') {
|
||||||
return { color: 'error', label: 'WebUI 不可用' };
|
return { color: 'error', label: 'WebUI 不可用' };
|
||||||
}
|
}
|
||||||
return { color: 'default', label: 'WebUI 未检查' };
|
return { color: 'default', label: 'WebUI 未检查' };
|
||||||
}
|
}
|
||||||
|
|
||||||
function getQqLoginStatusMeta(
|
function getQqLoginStatusMeta(row: QqbotApi.Account) {
|
||||||
napcat?: null | QqbotApi.AccountNapcatRuntime,
|
if (!row.napcat && !row.qqLoginStatus) {
|
||||||
) {
|
return { color: 'default', label: '未绑定容器' };
|
||||||
if (!napcat) return { color: 'default', label: '未绑定容器' };
|
}
|
||||||
const statusMap: Record<
|
const statusMap: Record<
|
||||||
NonNullable<QqbotApi.AccountNapcatRuntime['qqLoginStatus']>,
|
QqbotApi.QqLoginStatus,
|
||||||
{ color: string; label: string }
|
{ color: string; label: string }
|
||||||
> = {
|
> = {
|
||||||
offline: { color: 'error', label: 'QQ 离线' },
|
offline: { color: 'error', label: 'QQ 离线' },
|
||||||
@ -808,7 +809,30 @@ export default defineComponent({
|
|||||||
qrcode_pending: { color: 'processing', label: '等待扫码' },
|
qrcode_pending: { color: 'processing', label: '等待扫码' },
|
||||||
unknown: { color: 'default', label: '状态未知' },
|
unknown: { color: 'default', label: '状态未知' },
|
||||||
};
|
};
|
||||||
return statusMap[napcat.qqLoginStatus || 'unknown'];
|
return statusMap[getQqLoginStatus(row)];
|
||||||
|
}
|
||||||
|
|
||||||
|
function getOneBotStatus(row: QqbotApi.Account): QqbotApi.OneBotStatus {
|
||||||
|
if (row.oneBotStatus) return row.oneBotStatus;
|
||||||
|
if (row.napcat?.oneBotOnline !== undefined) {
|
||||||
|
return row.napcat.oneBotOnline ? 'online' : 'offline';
|
||||||
|
}
|
||||||
|
return row.connectStatus === 'online' ? 'online' : 'offline';
|
||||||
|
}
|
||||||
|
|
||||||
|
function getWebuiStatus(row: QqbotApi.Account): QqbotApi.WebuiStatus {
|
||||||
|
if (row.webuiStatus) return row.webuiStatus;
|
||||||
|
if (row.napcat?.webuiOnline === true) return 'online';
|
||||||
|
if (row.napcat?.webuiOnline === false) return 'offline';
|
||||||
|
return 'unknown';
|
||||||
|
}
|
||||||
|
|
||||||
|
function getQqLoginStatus(row: QqbotApi.Account): QqbotApi.QqLoginStatus {
|
||||||
|
return row.qqLoginStatus || row.napcat?.qqLoginStatus || 'unknown';
|
||||||
|
}
|
||||||
|
|
||||||
|
function getQqLoginMessage(row: QqbotApi.Account) {
|
||||||
|
return row.qqLoginMessage ?? row.napcat?.qqLoginMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getRecentActivity(row: QqbotApi.Account) {
|
function getRecentActivity(row: QqbotApi.Account) {
|
||||||
@ -836,31 +860,35 @@ export default defineComponent({
|
|||||||
if (row.lastError) {
|
if (row.lastError) {
|
||||||
return { level: 'warning', text: `账号异常:${row.lastError}` };
|
return { level: 'warning', text: `账号异常:${row.lastError}` };
|
||||||
}
|
}
|
||||||
if (row.napcat?.qqLoginMessage) {
|
const qqLoginMessage = getQqLoginMessage(row);
|
||||||
|
const qqLoginStatus = getQqLoginStatus(row);
|
||||||
|
const containerStatus =
|
||||||
|
row.containerStatus || row.napcat?.containerStatus;
|
||||||
|
if (qqLoginMessage) {
|
||||||
return {
|
return {
|
||||||
level: 'warning',
|
level: 'warning',
|
||||||
text: `QQ 登录:${row.napcat.qqLoginMessage}`,
|
text: `QQ 登录:${qqLoginMessage}`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (row.napcat?.lastError) {
|
if (row.napcat?.lastError) {
|
||||||
return { level: 'warning', text: `NapCat:${row.napcat.lastError}` };
|
return { level: 'warning', text: `NapCat:${row.napcat.lastError}` };
|
||||||
}
|
}
|
||||||
if (row.napcat?.qqLoginStatus === 'qrcode_expired') {
|
if (qqLoginStatus === 'qrcode_expired') {
|
||||||
return { level: 'warning', text: '二维码已过期,点击更新登录' };
|
return { level: 'warning', text: '二维码已过期,点击更新登录' };
|
||||||
}
|
}
|
||||||
if (row.connectStatus === 'online') {
|
if (getOneBotStatus(row) === 'online') {
|
||||||
return { level: 'normal', text: '消息链路可用' };
|
return { level: 'normal', text: '消息链路可用' };
|
||||||
}
|
}
|
||||||
if (row.napcat?.qqLoginStatus === 'online') {
|
if (qqLoginStatus === 'online') {
|
||||||
return { level: 'warning', text: 'QQ 在线,等待 OneBot 连接' };
|
return { level: 'warning', text: 'QQ 在线,等待 OneBot 连接' };
|
||||||
}
|
}
|
||||||
if (row.napcat?.containerStatus === 'running') {
|
if (containerStatus === 'running') {
|
||||||
return { level: 'warning', text: 'NapCat 运行中,等待 OneBot 连接' };
|
return { level: 'warning', text: 'NapCat 运行中,等待 OneBot 连接' };
|
||||||
}
|
}
|
||||||
if (row.napcat?.containerStatus === 'creating') {
|
if (containerStatus === 'creating') {
|
||||||
return { level: 'warning', text: '容器创建中' };
|
return { level: 'warning', text: '容器创建中' };
|
||||||
}
|
}
|
||||||
if (row.napcat?.containerStatus === 'stopped') {
|
if (containerStatus === 'stopped') {
|
||||||
return { level: 'warning', text: '容器已停止' };
|
return { level: 'warning', text: '容器已停止' };
|
||||||
}
|
}
|
||||||
if (!row.napcat) {
|
if (!row.napcat) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user