mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-07-13 08:06:06 +00:00
72b97efa8a
Surface ~400 hardcoded English labels, tooltips, placeholders, dt/divider text, modal okText/cancelText, and Spin loading from the panel pages (clients/groups/inbounds/nodes/settings/xray/sub/index) into web/translation/en-US.json under existing pages.<page>.* namespaces, with JSX swapped to t(...). Brand and protocol identifiers (TLS, MTU, SNI, NordVPN, Cloudflare WARP, etc.) stay literal. Sync all 12 non-English locales (ar-EG, es-ES, fa-IR, id-ID, ja-JP, pt-BR, ru-RU, tr-TR, uk-UA, vi-VN, zh-CN, zh-TW) to match en-US's structure and translate the 521 new key paths per locale. Every locale file now has 1539 lines, mirroring en-US ordering. Also remove a dead duplicate "info": "Info" key under pages.inbounds that collided with the new pages.inbounds.info.* object. Backend: bulk attach/detach errors in web/service/client.go now route through logger.Warningf (so they appear under /panel/api/server/logs/) instead of only living on the response payload.
170 lines
6.2 KiB
TypeScript
170 lines
6.2 KiB
TypeScript
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
import { useTranslation } from 'react-i18next';
|
|
import { Card, Col, ConfigProvider, Layout, Modal, Row, Spin, Statistic, message } from 'antd';
|
|
import {
|
|
CheckCircleOutlined,
|
|
CloseCircleOutlined,
|
|
CloudServerOutlined,
|
|
ThunderboltOutlined,
|
|
} from '@ant-design/icons';
|
|
|
|
import { useTheme } from '@/hooks/useTheme';
|
|
import { useMediaQuery } from '@/hooks/useMediaQuery';
|
|
import { useNodesQuery } from '@/api/queries/useNodesQuery';
|
|
import type { NodeRecord } from '@/api/queries/useNodesQuery';
|
|
import { useNodeMutations } from '@/api/queries/useNodeMutations';
|
|
import AppSidebar from '@/components/AppSidebar';
|
|
import NodeList from './NodeList';
|
|
import NodeFormModal from './NodeFormModal';
|
|
import { setMessageInstance } from '@/utils/messageBus';
|
|
|
|
export default function NodesPage() {
|
|
const { t } = useTranslation();
|
|
const { isDark, isUltra, antdThemeConfig } = useTheme();
|
|
const { isMobile } = useMediaQuery();
|
|
const [modal, modalContextHolder] = Modal.useModal();
|
|
const [messageApi, messageContextHolder] = message.useMessage();
|
|
useEffect(() => { setMessageInstance(messageApi); }, [messageApi]);
|
|
|
|
const { nodes, loading, fetched, totals } = useNodesQuery();
|
|
const { create, update, remove, setEnable, testConnection, probe } = useNodeMutations();
|
|
|
|
const [formOpen, setFormOpen] = useState(false);
|
|
const [formMode, setFormMode] = useState<'add' | 'edit'>('add');
|
|
const [formNode, setFormNode] = useState<NodeRecord | null>(null);
|
|
|
|
const onAdd = useCallback(() => {
|
|
setFormMode('add');
|
|
setFormNode(null);
|
|
setFormOpen(true);
|
|
}, []);
|
|
|
|
const onEdit = useCallback((node: NodeRecord) => {
|
|
setFormMode('edit');
|
|
setFormNode({ ...node });
|
|
setFormOpen(true);
|
|
}, []);
|
|
|
|
const onSave = useCallback(async (payload: Partial<NodeRecord>) => {
|
|
if (formMode === 'edit' && formNode?.id) {
|
|
return update(formNode.id, payload);
|
|
}
|
|
return create(payload);
|
|
}, [formMode, formNode, update, create]);
|
|
|
|
const onDelete = useCallback((node: NodeRecord) => {
|
|
modal.confirm({
|
|
title: t('pages.nodes.deleteConfirmTitle', { name: node.name }),
|
|
content: t('pages.nodes.deleteConfirmContent'),
|
|
okText: t('delete'),
|
|
okType: 'danger',
|
|
cancelText: t('cancel'),
|
|
onOk: async () => {
|
|
const msg = await remove(node.id);
|
|
if (msg?.success) messageApi.success(t('pages.nodes.toasts.deleted'));
|
|
},
|
|
});
|
|
}, [modal, t, remove, messageApi]);
|
|
|
|
const onProbe = useCallback(async (node: NodeRecord) => {
|
|
const msg = await probe(node.id);
|
|
if (msg?.success && msg.obj) {
|
|
if (msg.obj.status === 'online') {
|
|
messageApi.success(t('pages.nodes.connectionOk', { ms: msg.obj.latencyMs }));
|
|
} else {
|
|
messageApi.error(msg.obj.error || t('pages.nodes.toasts.probeFailed'));
|
|
}
|
|
}
|
|
}, [probe, t, messageApi]);
|
|
|
|
const onToggleEnable = useCallback(async (node: NodeRecord, next: boolean) => {
|
|
await setEnable(node.id, next);
|
|
}, [setEnable]);
|
|
|
|
const pageClass = useMemo(() => {
|
|
const classes = ['nodes-page'];
|
|
if (isDark) classes.push('is-dark');
|
|
if (isUltra) classes.push('is-ultra');
|
|
return classes.join(' ');
|
|
}, [isDark, isUltra]);
|
|
|
|
return (
|
|
<ConfigProvider theme={antdThemeConfig}>
|
|
{messageContextHolder}
|
|
{modalContextHolder}
|
|
<Layout className={pageClass}>
|
|
<AppSidebar />
|
|
|
|
<Layout className="content-shell">
|
|
<Layout.Content id="content-layout" className="content-area">
|
|
<Spin spinning={!fetched} delay={200} description={t('loading')} size="large">
|
|
{!fetched ? (
|
|
<div className="loading-spacer" />
|
|
) : (
|
|
<Row gutter={[isMobile ? 8 : 16, isMobile ? 8 : 12]}>
|
|
<Col span={24}>
|
|
<Card size="small" hoverable className="summary-card">
|
|
<Row gutter={[16, isMobile ? 16 : 12]}>
|
|
<Col xs={12} sm={12} md={6}>
|
|
<Statistic
|
|
title={t('pages.nodes.totalNodes')}
|
|
value={String(totals.total)}
|
|
prefix={<CloudServerOutlined />}
|
|
/>
|
|
</Col>
|
|
<Col xs={12} sm={12} md={6}>
|
|
<Statistic
|
|
title={t('pages.nodes.onlineNodes')}
|
|
value={String(totals.online)}
|
|
prefix={<CheckCircleOutlined style={{ color: 'var(--ant-color-success)' }} />}
|
|
/>
|
|
</Col>
|
|
<Col xs={12} sm={12} md={6}>
|
|
<Statistic
|
|
title={t('pages.nodes.offlineNodes')}
|
|
value={String(totals.offline)}
|
|
prefix={<CloseCircleOutlined style={{ color: 'var(--ant-color-error)' }} />}
|
|
/>
|
|
</Col>
|
|
<Col xs={12} sm={12} md={6}>
|
|
<Statistic
|
|
title={t('pages.nodes.avgLatency')}
|
|
value={totals.avgLatency > 0 ? `${totals.avgLatency} ms` : '-'}
|
|
prefix={<ThunderboltOutlined />}
|
|
/>
|
|
</Col>
|
|
</Row>
|
|
</Card>
|
|
</Col>
|
|
|
|
<Col span={24}>
|
|
<NodeList
|
|
nodes={nodes}
|
|
loading={loading}
|
|
isMobile={isMobile}
|
|
onAdd={onAdd}
|
|
onEdit={onEdit}
|
|
onDelete={onDelete}
|
|
onProbe={onProbe}
|
|
onToggleEnable={onToggleEnable}
|
|
/>
|
|
</Col>
|
|
</Row>
|
|
)}
|
|
</Spin>
|
|
</Layout.Content>
|
|
</Layout>
|
|
|
|
<NodeFormModal
|
|
open={formOpen}
|
|
mode={formMode}
|
|
node={formNode}
|
|
testConnection={testConnection}
|
|
save={onSave}
|
|
onOpenChange={setFormOpen}
|
|
/>
|
|
</Layout>
|
|
</ConfigProvider>
|
|
);
|
|
}
|