feat: 可视化大屏展示
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import React from 'react';
|
||||
import { Spin } from 'antd';
|
||||
import { LoadingOutlined } from '@ant-design/icons';
|
||||
|
||||
const PageLoading: React.FC = () => {
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
height: '100vh',
|
||||
background: '#0a0e27',
|
||||
color: '#ffffff'
|
||||
}}
|
||||
>
|
||||
<div style={{ textAlign: 'center' }}>
|
||||
<Spin
|
||||
indicator={<LoadingOutlined style={{ fontSize: 32, color: '#00d4ff' }} spin />}
|
||||
size="large"
|
||||
/>
|
||||
<div
|
||||
style={{
|
||||
marginTop: 16,
|
||||
fontSize: 16,
|
||||
color: '#8b9dc3'
|
||||
}}
|
||||
>
|
||||
正在加载...
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default PageLoading;
|
||||
@@ -0,0 +1,113 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { Space, Button, TreeSelect, Checkbox, message } from 'antd';
|
||||
import { tenantApi } from '@/services/tenant';
|
||||
|
||||
interface TenantNode {
|
||||
tenantId?: string;
|
||||
tenantName?: string;
|
||||
children?: TenantNode[];
|
||||
status?: number | boolean;
|
||||
}
|
||||
|
||||
interface Props {
|
||||
onChanged?: (tenantId: string, includeChildren: boolean) => void;
|
||||
useSwitchTenant?: boolean;
|
||||
autoApply?: boolean;
|
||||
size?: 'small' | 'middle' | 'large';
|
||||
}
|
||||
|
||||
// 简单的响应式检测
|
||||
const useIsMobile = () => {
|
||||
const [isMobile, setIsMobile] = useState(window.innerWidth < 768);
|
||||
useEffect(() => {
|
||||
const handler = () => setIsMobile(window.innerWidth < 768);
|
||||
window.addEventListener('resize', handler);
|
||||
return () => window.removeEventListener('resize', handler);
|
||||
}, []);
|
||||
return isMobile;
|
||||
};
|
||||
|
||||
const TenantScopeFilter: React.FC<Props> = ({ onChanged, useSwitchTenant = false, autoApply = false, size = 'middle' }) => {
|
||||
const isMobile = useIsMobile();
|
||||
const [tree, setTree] = useState<TenantNode[]>([]);
|
||||
const [tenantId, setTenantId] = useState<string | undefined>();
|
||||
const [includeChildren, setIncludeChildren] = useState<boolean>(true);
|
||||
const [loading, setLoading] = useState<boolean>(false);
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const treeRes: any = await tenantApi.getAccessibleTenants();
|
||||
let list: TenantNode[] = [];
|
||||
if (Array.isArray(treeRes)) list = treeRes as any;
|
||||
else if (Array.isArray(treeRes?.data)) list = treeRes.data as any;
|
||||
else if (treeRes?.resp_code === 0 && Array.isArray(treeRes?.data)) list = treeRes.data as any;
|
||||
setTree(list || []);
|
||||
|
||||
const curRes: any = await tenantApi.getCurrentTenant();
|
||||
const curId = curRes?.data?.tenantId || (curRes?.resp_code === 0 ? curRes?.data?.tenantId : undefined);
|
||||
if (curId) setTenantId(curId);
|
||||
} catch {
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
})();
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!autoApply) return;
|
||||
if (!tenantId) return;
|
||||
onChanged?.(tenantId, includeChildren);
|
||||
}, [tenantId, includeChildren, autoApply]);
|
||||
|
||||
const toTreeData = (nodes?: TenantNode[]): any[] =>
|
||||
(nodes || []).map((n) => ({
|
||||
title: n.tenantName && n.tenantId ? `${n.tenantName} (${n.tenantId})` : (n.tenantName || n.tenantId || '-'),
|
||||
value: n.tenantId,
|
||||
key: n.tenantId,
|
||||
children: n.children ? toTreeData(n.children) : undefined,
|
||||
}));
|
||||
|
||||
const handleApply = async () => {
|
||||
if (!tenantId) return;
|
||||
try {
|
||||
if (useSwitchTenant) {
|
||||
const res: any = await tenantApi.switchTenant(tenantId);
|
||||
if (!(res?.success ?? res?.resp_code === 0)) {
|
||||
message.error(res?.msg || '切换失败');
|
||||
return;
|
||||
}
|
||||
message.success('租户范围已更新');
|
||||
}
|
||||
onChanged?.(tenantId, includeChildren);
|
||||
} catch {
|
||||
message.error('操作失败');
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Space direction={isMobile ? 'vertical' : 'horizontal'} style={{ width: isMobile ? '100%' : 'auto' }}>
|
||||
<TreeSelect
|
||||
size={size}
|
||||
style={{ minWidth: isMobile ? 0 : 260, width: isMobile ? '100%' : undefined }}
|
||||
showSearch
|
||||
loading={loading}
|
||||
treeNodeFilterProp="title"
|
||||
listHeight={400}
|
||||
popupMatchSelectWidth
|
||||
getPopupContainer={() => document.body}
|
||||
placeholder="选择租户(含子租户)"
|
||||
value={tenantId}
|
||||
onChange={(val) => setTenantId(val)}
|
||||
treeData={toTreeData(tree)}
|
||||
/>
|
||||
<Checkbox checked={includeChildren} onChange={(e) => setIncludeChildren(e.target.checked)}>包含子租户</Checkbox>
|
||||
{!autoApply && (
|
||||
<Button type="primary" size={isMobile ? 'small' : 'middle'} onClick={handleApply}>应用</Button>
|
||||
)}
|
||||
</Space>
|
||||
);
|
||||
};
|
||||
|
||||
export default TenantScopeFilter;
|
||||
Reference in New Issue
Block a user