修复页面bug
This commit is contained in:
@@ -1,15 +1,6 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { Card, Space, Typography, Row, Col, Statistic, Progress, Button } from 'antd';
|
||||
import {
|
||||
RocketOutlined,
|
||||
TeamOutlined,
|
||||
AppstoreOutlined,
|
||||
CloudServerOutlined,
|
||||
TrophyOutlined,
|
||||
ThunderboltOutlined,
|
||||
GlobalOutlined,
|
||||
SafetyOutlined
|
||||
} from '@ant-design/icons';
|
||||
import { RocketOutlined, TeamOutlined, AppstoreOutlined, CloudServerOutlined, TrophyOutlined, ThunderboltOutlined, GlobalOutlined, SafetyOutlined } from '@ant-design/icons';
|
||||
import TenantScopeFilter from '@/components/TenantScopeFilter';
|
||||
|
||||
const { Title, Paragraph } = Typography;
|
||||
@@ -18,24 +9,15 @@ const Welcome: React.FC = () => {
|
||||
const [time, setTime] = useState(new Date());
|
||||
|
||||
useEffect(() => {
|
||||
let isMounted = true;
|
||||
const timer = setInterval(() => {
|
||||
if (isMounted) {
|
||||
setTime(new Date());
|
||||
}
|
||||
}, 1000);
|
||||
|
||||
return () => {
|
||||
isMounted = false;
|
||||
clearInterval(timer);
|
||||
};
|
||||
const timer = setInterval(() => setTime(new Date()), 1000);
|
||||
return () => clearInterval(timer);
|
||||
}, []);
|
||||
|
||||
const stats = [
|
||||
{ title: '今日订单', value: 1234, icon: <AppstoreOutlined />, color: '#667eea' },
|
||||
{ title: '活跃用户', value: 856, icon: <TeamOutlined />, color: '#764ba2' },
|
||||
{ title: '设备在线', value: 98, suffix: '%', icon: <CloudServerOutlined />, color: '#f093fb' },
|
||||
{ title: '系统状态', value: 99.9, suffix: '%', icon: <SafetyOutlined />, color: '#4facfe' },
|
||||
{ title: '系统可用率', value: 99.9, suffix: '%', icon: <SafetyOutlined />, color: '#4facfe' },
|
||||
];
|
||||
|
||||
const quickActions = [
|
||||
@@ -47,29 +29,15 @@ const Welcome: React.FC = () => {
|
||||
|
||||
return (
|
||||
<div className="page-enter" style={{ padding: 24 }}>
|
||||
{/* 欢迎横幅 */}
|
||||
<Card
|
||||
className="modern-card"
|
||||
style={{
|
||||
background: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)',
|
||||
border: 'none',
|
||||
marginBottom: 24,
|
||||
color: 'white'
|
||||
}}
|
||||
>
|
||||
<Card className="modern-card" style={{ background: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)', border: 'none', marginBottom: 24, color: 'white' }}>
|
||||
<Row align="middle" justify="space-between">
|
||||
<Col>
|
||||
<Space direction="vertical" size={8}>
|
||||
<Title level={2} style={{ color: 'white', margin: 0 }}>
|
||||
<RocketOutlined style={{ marginRight: 12 }} />
|
||||
欢迎使用 Go-Fly Admin
|
||||
<RocketOutlined style={{ marginRight: 12 }} /> 欢迎使用 Go-Fly Admin
|
||||
</Title>
|
||||
<Paragraph style={{ color: 'rgba(255,255,255,0.8)', margin: 0, fontSize: 16 }}>
|
||||
现代化的智能管理平台 · 科技驱动未来
|
||||
</Paragraph>
|
||||
<Paragraph style={{ color: 'rgba(255,255,255,0.6)', margin: 0 }}>
|
||||
当前时间:{time.toLocaleString()}
|
||||
</Paragraph>
|
||||
<Paragraph style={{ color: 'rgba(255,255,255,0.8)', margin: 0, fontSize: 16 }}>现代化的智能管理平台 · 科技驱动未来</Paragraph>
|
||||
<Paragraph style={{ color: 'rgba(255,255,255,0.6)', margin: 0 }}>当前时间:{time.toLocaleString()}</Paragraph>
|
||||
</Space>
|
||||
</Col>
|
||||
<Col>
|
||||
@@ -78,45 +46,20 @@ const Welcome: React.FC = () => {
|
||||
</Row>
|
||||
</Card>
|
||||
|
||||
{/* 数据统计卡片 */}
|
||||
<Row gutter={[24, 24]} style={{ marginBottom: 24 }}>
|
||||
{stats.map((stat, index) => (
|
||||
<Col xs={12} sm={12} md={6} key={index}>
|
||||
<Card
|
||||
className="modern-card"
|
||||
style={{
|
||||
textAlign: 'center',
|
||||
borderLeft: `4px solid ${stat.color}`,
|
||||
background: 'var(--bg-card)'
|
||||
}}
|
||||
>
|
||||
<div style={{ color: stat.color, fontSize: 24, marginBottom: 8 }}>
|
||||
{stat.icon}
|
||||
</div>
|
||||
<Statistic
|
||||
title={stat.title}
|
||||
value={stat.value}
|
||||
suffix={stat.suffix}
|
||||
valueStyle={{
|
||||
color: 'var(--text-primary)',
|
||||
fontSize: 28,
|
||||
fontWeight: 'bold'
|
||||
}}
|
||||
/>
|
||||
<Card className="modern-card" style={{ textAlign: 'center', borderLeft: `4px solid ${stat.color}`, background: 'var(--bg-card)' }}>
|
||||
<div style={{ color: stat.color, fontSize: 24, marginBottom: 8 }}>{stat.icon}</div>
|
||||
<Statistic title={stat.title} value={stat.value} suffix={stat.suffix} valueStyle={{ color: 'var(--text-primary)', fontSize: 28, fontWeight: 'bold' }} />
|
||||
</Card>
|
||||
</Col>
|
||||
))}
|
||||
</Row>
|
||||
|
||||
<Row gutter={[24, 24]}>
|
||||
{/* 系统状态 */}
|
||||
<Col xs={24} md={12}>
|
||||
<Card className="modern-card" title={
|
||||
<span style={{ color: 'var(--text-primary)' }}>
|
||||
<ThunderboltOutlined style={{ marginRight: 8, color: '#667eea' }} />
|
||||
系统状态
|
||||
</span>
|
||||
}>
|
||||
<Card className="modern-card" title={<span style={{ color: 'var(--text-primary)' }}><ThunderboltOutlined style={{ marginRight: 8, color: '#667eea' }} />系统状态</span>}>
|
||||
<Space direction="vertical" style={{ width: '100%' }} size={16}>
|
||||
<div>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: 8 }}>
|
||||
@@ -143,14 +86,8 @@ const Welcome: React.FC = () => {
|
||||
</Card>
|
||||
</Col>
|
||||
|
||||
{/* 快捷操作 */}
|
||||
<Col xs={24} md={12}>
|
||||
<Card className="modern-card" title={
|
||||
<span style={{ color: 'var(--text-primary)' }}>
|
||||
<TrophyOutlined style={{ marginRight: 8, color: '#667eea' }} />
|
||||
快捷操作
|
||||
</span>
|
||||
}>
|
||||
<Card className="modern-card" title={<span style={{ color: 'var(--text-primary)' }}><TrophyOutlined style={{ marginRight: 8, color: '#667eea' }} />快捷操作</span>}>
|
||||
<Row gutter={[16, 16]}>
|
||||
{quickActions.map((action, index) => (
|
||||
<Col span={12} key={index}>
|
||||
@@ -158,16 +95,7 @@ const Welcome: React.FC = () => {
|
||||
block
|
||||
size="large"
|
||||
className="tech-button"
|
||||
style={{
|
||||
height: 64,
|
||||
background: `linear-gradient(135deg, ${action.color}33, ${action.color}11)`,
|
||||
border: `1px solid ${action.color}44`,
|
||||
color: action.color,
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center'
|
||||
}}
|
||||
style={{ height: 64, background: `linear-gradient(135deg, ${action.color}33, ${action.color}11)`, border: `1px solid ${action.color}44`, color: action.color, display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center' }}
|
||||
>
|
||||
<div style={{ fontSize: 20, marginBottom: 4 }}>{action.icon}</div>
|
||||
<div style={{ fontSize: 12 }}>{action.title}</div>
|
||||
@@ -179,45 +107,13 @@ const Welcome: React.FC = () => {
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
{/* 功能介绍 */}
|
||||
<Card className="modern-card" style={{ marginTop: 24 }} title={
|
||||
<span style={{ color: 'var(--text-primary)' }}>
|
||||
<GlobalOutlined style={{ marginRight: 8, color: '#667eea' }} />
|
||||
平台特性
|
||||
</span>
|
||||
}>
|
||||
<Card className="modern-card" style={{ marginTop: 24 }} title={<span style={{ color: 'var(--text-primary)' }}><GlobalOutlined style={{ marginRight: 8, color: '#667eea' }} />平台特性</span>}>
|
||||
<Row gutter={[24, 24]}>
|
||||
<Col xs={24} sm={12} md={8}>
|
||||
<div style={{ textAlign: 'center', padding: 16 }}>
|
||||
<div style={{ fontSize: 32, color: '#667eea', marginBottom: 12 }}>
|
||||
<RocketOutlined />
|
||||
</div>
|
||||
<div style={{ fontSize: 32, color: '#667eea', marginBottom: 12 }}><RocketOutlined /></div>
|
||||
<Title level={4} style={{ color: 'var(--text-primary)' }}>高性能架构</Title>
|
||||
<Paragraph style={{ color: 'var(--text-secondary)' }}>
|
||||
基于微服务架构,支持高并发访问,确保系统稳定运行
|
||||
</Paragraph>
|
||||
</div>
|
||||
</Col>
|
||||
<Col xs={24} sm={12} md={8}>
|
||||
<div style={{ textAlign: 'center', padding: 16 }}>
|
||||
<div style={{ fontSize: 32, color: '#764ba2', marginBottom: 12 }}>
|
||||
<SafetyOutlined />
|
||||
</div>
|
||||
<Title level={4} style={{ color: 'var(--text-primary)' }}>安全可靠</Title>
|
||||
<Paragraph style={{ color: 'var(--text-secondary)' }}>
|
||||
多层安全防护,数据加密传输,保障业务数据安全
|
||||
</Paragraph>
|
||||
</div>
|
||||
</Col>
|
||||
<Col xs={24} sm={12} md={8}>
|
||||
<div style={{ textAlign: 'center', padding: 16 }}>
|
||||
<div style={{ fontSize: 32, color: '#f093fb', marginBottom: 12 }}>
|
||||
<ThunderboltOutlined />
|
||||
</div>
|
||||
<Title level={4} style={{ color: 'var(--text-primary)' }}>智能运维</Title>
|
||||
<Paragraph style={{ color: 'var(--text-secondary)' }}>
|
||||
实时监控预警,自动化运维管理,降低运维成本
|
||||
</Paragraph>
|
||||
<Paragraph style={{ color: 'var(--text-secondary)' }}>基于微服务架构,支持高并发访问,确保系统稳定运行</Paragraph>
|
||||
</div>
|
||||
</Col>
|
||||
</Row>
|
||||
@@ -226,5 +122,4 @@ const Welcome: React.FC = () => {
|
||||
);
|
||||
};
|
||||
|
||||
export default Welcome;
|
||||
|
||||
export default Welcome;
|
||||
@@ -1,165 +1,237 @@
|
||||
import React, { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import type { ActionType, ProColumns } from '@ant-design/pro-components';
|
||||
import { ModalForm, PageContainer, ProForm, ProFormText, ProFormTextArea, ProTable } from '@ant-design/pro-components';
|
||||
import { Button, Card, Col, Form, message, Popconfirm, Row, Space, Switch, Tree, TreeSelect } from 'antd';
|
||||
import { PlusOutlined } from '@ant-design/icons';
|
||||
import { tenantApi, TenantInfo, TenantTreeNode } from '@/services/tenant';
|
||||
import { ActionBar, SearchBarPlus } from '@/components/ui';
|
||||
import React, { useCallback, useEffect, useState } from "react";
|
||||
import { PageContainer } from "@ant-design/pro-components";
|
||||
import { Space, message, Button } from "antd";
|
||||
import { ActionBar, GradientButton, GlassCard } from "@/components/ui";
|
||||
import { PlusOutlined } from "@ant-design/icons";
|
||||
import TenantForm from "./components/TenantForm";
|
||||
import TenantTreeTable from "./components/TenantTreeTable";
|
||||
import { tenantApi, TenantInfo, TenantTreeNode } from "@/services/tenant";
|
||||
|
||||
const toTreeData = (nodes: TenantTreeNode[] = []): any[] =>
|
||||
nodes.map((n) => ({ title: n.tenantName, value: n.tenantId, key: n.tenantId, children: n.children ? toTreeData(n.children) : undefined }));
|
||||
// UI 表单初始值:status 允许 boolean | number,便于与 Switch 绑定
|
||||
type UITenantFormValues = Partial<TenantInfo> & { status?: boolean | number };
|
||||
|
||||
const TenantManage: React.FC = () => {
|
||||
const actionRef = useRef<ActionType>();
|
||||
const [form] = Form.useForm<TenantInfo>();
|
||||
const [orgTree, setOrgTree] = useState<TenantTreeNode[]>([]);
|
||||
const [loadingTree, setLoadingTree] = useState(false);
|
||||
const [currentNode, setCurrentNode] = useState<string | undefined>(undefined);
|
||||
const [visible, setVisible] = useState(false);
|
||||
const [data, setData] = useState<TenantTreeNode[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [formOpen, setFormOpen] = useState(false);
|
||||
const [editing, setEditing] = useState(false);
|
||||
const [initialValues, setInitialValues] = useState<UITenantFormValues | undefined>(undefined);
|
||||
const [treeCache, setTreeCache] = useState<TenantTreeNode[]>([]);
|
||||
|
||||
const treeSelectData = useMemo(() => toTreeData(orgTree), [orgTree]);
|
||||
|
||||
const loadTree = async () => {
|
||||
setLoadingTree(true);
|
||||
const fetchTree = useCallback(async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const res = await tenantApi.getAccessibleTenants();
|
||||
if (res.success) setOrgTree(res.data || []);
|
||||
} finally {
|
||||
setLoadingTree(false);
|
||||
const res: any = await tenantApi.getAccessibleTenants();
|
||||
let list: TenantTreeNode[] = [];
|
||||
if (typeof res?.success !== "undefined") {
|
||||
list = res.success ? (res.data || []) : [];
|
||||
} else if (Array.isArray(res)) {
|
||||
list = res as TenantTreeNode[];
|
||||
}
|
||||
if (!list || list.length === 0) {
|
||||
// 回退:至少返回当前租户
|
||||
const cur: any = await tenantApi.getCurrentTenant();
|
||||
if (cur?.success && cur?.data?.tenantId) {
|
||||
list = [{ tenantId: cur.data.tenantId, tenantName: cur.data.tenantName } as any];
|
||||
} else {
|
||||
const stats: any = await tenantApi.getScopeStats();
|
||||
const id = stats?.data?.currentTenantId;
|
||||
if (id) list = [{ tenantId: id, tenantName: id } as any];
|
||||
}
|
||||
}
|
||||
// 若只有根节点且无子节点,尝试加载一层子租户以展示层级
|
||||
if (list && list.length === 1 && !Array.isArray((list[0] as any).children)) {
|
||||
try {
|
||||
const parentId = (list[0] as any).tenantId;
|
||||
const resPage: any = await tenantApi.getTenantList({ parentTenantId: parentId, current: 1, pageSize: 1000 } as any);
|
||||
const children = resPage?.data?.data || [];
|
||||
if (children && children.length) {
|
||||
(list[0] as any).children = children.map((c: any) => ({ tenantId: c.tenantId, tenantName: c.tenantName, tenantType: c.tenantType, status: c.status, contactPerson: c.contactPerson, contactPhone: c.contactPhone }));
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
// 补充每个根的一层直接子租户,便于默认展开时可见
|
||||
try {
|
||||
await Promise.all(
|
||||
(list || []).map(async (node: any) => {
|
||||
if (!node) return;
|
||||
// 顶层节点缺失类型/状态/联系人信息时,补充详情
|
||||
try {
|
||||
if (node.tenantType == null || node.status == null || node.contactPerson == null || node.contactPhone == null) {
|
||||
const detail: any = await tenantApi.getTenantDetail(node.tenantId);
|
||||
const d = detail?.data || {};
|
||||
if (node.tenantType == null) node.tenantType = d.tenantType;
|
||||
if (node.status == null) node.status = d.status;
|
||||
if (node.contactPerson == null) node.contactPerson = d.contactPerson;
|
||||
if (node.contactPhone == null) node.contactPhone = d.contactPhone;
|
||||
}
|
||||
} catch {}
|
||||
// 确保至少补一层孩子,方便默认展开后可见
|
||||
if (!Array.isArray(node.children) || node.children.length === 0) {
|
||||
const resp: any = await tenantApi.getTenantList({ parentTenantId: node.tenantId, current: 1, pageSize: 1000 } as any);
|
||||
const children = resp?.data?.data || [];
|
||||
if (children && children.length) {
|
||||
node.children = children.map((c: any) => ({ tenantId: c.tenantId, tenantName: c.tenantName, tenantType: c.tenantType, status: c.status, contactPerson: c.contactPerson, contactPhone: c.contactPhone }));
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
} catch {}
|
||||
setTreeCache(list);
|
||||
setData(list);
|
||||
} catch (e) {
|
||||
message.error("获取租户数据失败");
|
||||
} finally { setLoading(false); }
|
||||
}, []);
|
||||
|
||||
|
||||
useEffect(() => { fetchTree(); }, [fetchTree]);
|
||||
|
||||
const openCreateRoot = () => {
|
||||
setEditing(false);
|
||||
setInitialValues({ status: 1 });
|
||||
setFormOpen(true);
|
||||
};
|
||||
|
||||
const handleAddChild = (record: TenantTreeNode) => {
|
||||
setEditing(false);
|
||||
setInitialValues({ parentTenantId: record.tenantId, status: 1 });
|
||||
setFormOpen(true);
|
||||
};
|
||||
|
||||
const handleEdit = async (record: TenantTreeNode) => {
|
||||
try {
|
||||
const d: any = await tenantApi.getTenantDetail(record.tenantId);
|
||||
if (d?.success) {
|
||||
setEditing(true);
|
||||
const iv = d.data || {};
|
||||
const patched = { ...iv, status: typeof iv.status === 'number' ? iv.status : (iv.status ? 1 : 0) } as any;
|
||||
setInitialValues(patched);
|
||||
setFormOpen(true);
|
||||
}
|
||||
} catch (e) {
|
||||
message.error("获取租户详情失败");
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => { loadTree(); }, []);
|
||||
|
||||
const columns: ProColumns<TenantInfo>[] = [
|
||||
{ dataIndex: 'index', valueType: 'indexBorder', width: 48 },
|
||||
{ title: '租户ID', dataIndex: 'tenantId', copyable: true },
|
||||
{ title: '租户名称', dataIndex: 'tenantName' },
|
||||
{ title: '类型', dataIndex: 'tenantType' },
|
||||
{ title: '父租户ID', dataIndex: 'parentTenantId', hideInSearch: true },
|
||||
{ title: '状态', dataIndex: 'status', valueType: 'select', valueEnum: { 1: { text: '启用' }, 0: { text: '停用' } } },
|
||||
{
|
||||
title: '操作', valueType: 'option', width: 200,
|
||||
render: (_, record) => (
|
||||
<Space>
|
||||
<a onClick={async () => {
|
||||
setEditing(true);
|
||||
const d = await tenantApi.getTenantDetail(record.tenantId);
|
||||
if (d.success) {
|
||||
form.setFieldsValue(d.data);
|
||||
setVisible(true);
|
||||
}
|
||||
}}>编辑</a>
|
||||
<Popconfirm title={`确认删除租户[${record.tenantName}]?`} onConfirm={async () => {
|
||||
const hide = message.loading('删除中...');
|
||||
try {
|
||||
const r = await tenantApi.deleteTenant(record.tenantId);
|
||||
if (r.success) {
|
||||
message.success('删除成功');
|
||||
actionRef.current?.reload();
|
||||
loadTree();
|
||||
} else {
|
||||
message.error(r.msg || '删除失败');
|
||||
}
|
||||
} finally { hide(); }
|
||||
}}>
|
||||
<a>删除</a>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
)
|
||||
}
|
||||
];
|
||||
|
||||
const onSave = async (vals: TenantInfo) => {
|
||||
const hide = message.loading('保存中...');
|
||||
const handleDelete = async (record: TenantTreeNode) => {
|
||||
const hide = message.loading("删除中...");
|
||||
try {
|
||||
const payload = { ...vals, status: vals.status ?? 1 };
|
||||
const res = editing ? await tenantApi.updateTenant(payload) : await tenantApi.createTenant(payload);
|
||||
if (res.success) {
|
||||
message.success(editing ? '修改成功' : '新增成功');
|
||||
setVisible(false);
|
||||
actionRef.current?.reload();
|
||||
loadTree();
|
||||
return true;
|
||||
const r: any = await tenantApi.deleteTenant(record.tenantId);
|
||||
if (r?.success) {
|
||||
message.success("删除成功");
|
||||
fetchTree();
|
||||
} else {
|
||||
message.error(r?.msg || "删除失败");
|
||||
}
|
||||
message.error(res.msg || '保存失败');
|
||||
return false;
|
||||
} finally { hide(); }
|
||||
};
|
||||
|
||||
return (
|
||||
<PageContainer header={{ title: '租户管理' }}>
|
||||
<SearchBarPlus defaultCollapsed split span={8} onTenantChanged={() => { actionRef.current?.reload(); loadTree(); }} />
|
||||
<PageContainer header={{ title: "租户管理" }}>
|
||||
<ActionBar
|
||||
right={(
|
||||
left={(
|
||||
<Space>
|
||||
<Button size="middle" type="primary" icon={<PlusOutlined />} onClick={() => {
|
||||
setEditing(false);
|
||||
form.resetFields();
|
||||
form.setFieldsValue({ parentTenantId: currentNode, status: 1 });
|
||||
setVisible(true);
|
||||
}}>新增租户</Button>
|
||||
<GradientButton size="middle" type="primary" icon={<PlusOutlined />} onClick={openCreateRoot}>新增</GradientButton>
|
||||
<Button onClick={fetchTree}>刷新</Button>
|
||||
</Space>
|
||||
)}
|
||||
/>
|
||||
<Row gutter={16}>
|
||||
<Col span={6}>
|
||||
<Card size="small" title="组织">
|
||||
<Tree treeData={toTreeData(orgTree)} defaultExpandAll onSelect={(keys) => {
|
||||
const k = (keys && keys[0]) as string | undefined;
|
||||
setCurrentNode(k);
|
||||
actionRef.current?.reload();
|
||||
}} />
|
||||
</Card>
|
||||
</Col>
|
||||
<Col span={18}>
|
||||
<ProTable<TenantInfo>
|
||||
actionRef={actionRef}
|
||||
rowKey="tenantId"
|
||||
columns={columns}
|
||||
toolBarRender={false}
|
||||
request={async (p) => {
|
||||
const res = await tenantApi.getTenantList({ parentTenantId: currentNode, tenantName: (p as any).tenantName, status: (p as any).status as any, current: (p as any).current, pageSize: (p as any).pageSize });
|
||||
const list = res.data?.data || [];
|
||||
const total = res.data?.total || list.length;
|
||||
return { data: list, total, success: true };
|
||||
}}
|
||||
pagination={{ pageSize: 10 }}
|
||||
search={{ labelWidth: 'auto' }}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<ModalForm<TenantInfo>
|
||||
title={editing ? '编辑租户' : '新建租户'}
|
||||
open={visible}
|
||||
onOpenChange={setVisible}
|
||||
form={form}
|
||||
width={640}
|
||||
onFinish={onSave}
|
||||
modalProps={{ destroyOnClose: true }}
|
||||
>
|
||||
<ProForm.Group>
|
||||
<ProFormText name="tenantId" label="租户ID" rules={[{ required: true }]} disabled={editing} />
|
||||
<ProFormText name="tenantName" label="租户名称" rules={[{ required: true }]} />
|
||||
</ProForm.Group>
|
||||
<ProForm.Group>
|
||||
<ProForm.Item name="parentTenantId" label="上级租户">
|
||||
<TreeSelect style={{ width: 260 }} allowClear dropdownStyle={{ maxHeight: 400, overflow: 'auto' }} treeDefaultExpandAll treeData={treeSelectData} />
|
||||
</ProForm.Item>
|
||||
<ProFormText name="tenantType" label="类型" rules={[{ required: true }]} />
|
||||
</ProForm.Group>
|
||||
<ProFormText name="tenantCode" label="租户编码" />
|
||||
<ProFormText name="contactPerson" label="联系人" />
|
||||
<ProFormText name="contactPhone" label="联系电话" />
|
||||
<ProFormText name="address" label="地址" />
|
||||
<ProFormTextArea name="description" label="描述" />
|
||||
<ProForm.Item name="status" label="状态" valuePropName="checked"><Switch checkedChildren="启用" unCheckedChildren="停用" /></ProForm.Item>
|
||||
</ModalForm>
|
||||
<GlassCard>
|
||||
<TenantTreeTable
|
||||
data={data}
|
||||
loading={loading}
|
||||
onAddChild={handleAddChild}
|
||||
onEdit={handleEdit}
|
||||
onDelete={handleDelete}
|
||||
/>
|
||||
</GlassCard>
|
||||
|
||||
<TenantForm
|
||||
title={editing ? "编辑租户" : "新建租户"}
|
||||
visible={formOpen}
|
||||
onVisibleChange={setFormOpen}
|
||||
onFinish={async (values) => {
|
||||
const hide = message.loading("保存中...");
|
||||
try {
|
||||
const payload: any = { ...initialValues, ...values };
|
||||
payload.status = typeof payload.status === 'boolean' ? (payload.status ? 1 : 0) : (payload.status ?? 1);
|
||||
// 计算 tenantPath / tenantLevel(后端未计算或为null时做兜底)
|
||||
if (!editing) {
|
||||
if (payload.parentTenantId) {
|
||||
try {
|
||||
const parent: any = await tenantApi.getTenantDetail(payload.parentTenantId);
|
||||
const p = parent?.data || {};
|
||||
const base = p.tenantPath || p.tenantId || '';
|
||||
payload.tenantPath = base ? `${base}/${payload.tenantId}` : payload.tenantId;
|
||||
payload.tenantLevel = (p.tenantLevel || 0) + 1;
|
||||
} catch {
|
||||
payload.tenantPath = payload.parentTenantId ? `${payload.parentTenantId}/${payload.tenantId}` : payload.tenantId;
|
||||
payload.tenantLevel = 1;
|
||||
}
|
||||
} else {
|
||||
payload.tenantPath = payload.tenantId;
|
||||
payload.tenantLevel = 1;
|
||||
}
|
||||
}
|
||||
// 编辑模式下兜底补齐关键字段,防止后端校验失败
|
||||
if (editing) {
|
||||
try {
|
||||
const cur: any = await tenantApi.getTenantDetail(payload.tenantId);
|
||||
const cd = cur?.data || {};
|
||||
if (!payload.parentTenantId && cd.parentTenantId) payload.parentTenantId = cd.parentTenantId;
|
||||
const joinPath = (base?: string, id?: string) => {
|
||||
const b = String(base || '').replace(/\/+$/g, '').replace(/^null/gi, '');
|
||||
const t = String(id || '').replace(/^\/+/, '');
|
||||
return b ? `${b}/${t}` : t;
|
||||
};
|
||||
const badPath = !payload.tenantPath || /^null/i.test(String(payload.tenantPath)) || /\/$/.test(String(payload.tenantPath));
|
||||
if (badPath) {
|
||||
let base = '';
|
||||
if (payload.parentTenantId) {
|
||||
try {
|
||||
const pRes: any = await tenantApi.getTenantDetail(payload.parentTenantId);
|
||||
const p = pRes?.data || {};
|
||||
base = p.tenantPath || p.tenantId || payload.parentTenantId;
|
||||
} catch { base = payload.parentTenantId; }
|
||||
}
|
||||
payload.tenantPath = joinPath(base, payload.tenantId);
|
||||
}
|
||||
if (payload.tenantLevel == null) {
|
||||
payload.tenantLevel = cd.tenantLevel ?? 1;
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
// 仅提交后端可识别字段,避免多余只读字段导致绑定失败
|
||||
const allowedKeys = ['tenantId','tenantName','parentTenantId','tenantType','tenantCode','contactPerson','contactPhone','address','description','status','tenantLevel','tenantPath'];
|
||||
const submitData: any = {};
|
||||
for (const k of allowedKeys) if (Object.prototype.hasOwnProperty.call(payload, k)) submitData[k] = (payload as any)[k];
|
||||
const res: any = editing ? await tenantApi.updateTenant(submitData) : await tenantApi.createTenant(submitData);
|
||||
if (res?.success) {
|
||||
message.success(editing ? "修改成功" : "新增成功");
|
||||
setFormOpen(false);
|
||||
await fetchTree();
|
||||
return true;
|
||||
}
|
||||
message.error(res?.msg || "保存失败");
|
||||
return false;
|
||||
} finally { hide(); }
|
||||
}}
|
||||
initialValues={initialValues}
|
||||
tree={treeCache}
|
||||
/>
|
||||
</PageContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export default TenantManage;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React from 'react';
|
||||
import React from 'react';
|
||||
import { Button, Upload } from 'antd';
|
||||
import { ExportOutlined, ImportOutlined, PlusOutlined } from '@ant-design/icons';
|
||||
import { GradientButton } from '@/components/ui';
|
||||
@@ -8,13 +8,17 @@ export interface ToolbarProps {
|
||||
onCreate: () => void;
|
||||
// 导出
|
||||
onExport: () => void;
|
||||
// 是否隐藏“新增”按钮(例如:APP 用户)
|
||||
hideCreate?: boolean;
|
||||
}
|
||||
|
||||
// 统一:新增按钮固定在左侧;去掉刷新按钮(以查询为主)
|
||||
const Toolbar: React.FC<ToolbarProps> = ({ onCreate, onExport }) => {
|
||||
const Toolbar: React.FC<ToolbarProps> = ({ onCreate, onExport, hideCreate }) => {
|
||||
return (
|
||||
<>
|
||||
<GradientButton size="middle" key="add" type="primary" icon={<PlusOutlined />} onClick={onCreate}>新增</GradientButton>
|
||||
{!hideCreate ? (
|
||||
<GradientButton size="middle" key="add" type="primary" icon={<PlusOutlined />} onClick={onCreate}>新增</GradientButton>
|
||||
) : null}
|
||||
<Button size="middle" key="export" icon={<ExportOutlined />} onClick={onExport}>导出</Button>
|
||||
<Upload key="import" action="/api-user/users/import" showUploadList={false} accept=".xls,.xlsx">
|
||||
<Button size="middle" icon={<ImportOutlined />}>导入</Button>
|
||||
@@ -23,5 +27,4 @@ const Toolbar: React.FC<ToolbarProps> = ({ onCreate, onExport }) => {
|
||||
);
|
||||
};
|
||||
|
||||
export default Toolbar;
|
||||
|
||||
export default Toolbar;
|
||||
@@ -1,23 +1,26 @@
|
||||
import React from 'react';
|
||||
import React from 'react';
|
||||
import { ModalForm, ProForm, ProFormRadio, ProFormSelect, ProFormText, ProFormTextArea } from '@ant-design/pro-components';
|
||||
import { systemApi, UserItem } from '@/services/system';
|
||||
import TenantSelector from '@/components/ui/TenantSelector';
|
||||
|
||||
export interface UserFormProps {
|
||||
open: boolean;
|
||||
visible: boolean;
|
||||
title: string;
|
||||
initialValues?: Partial<UserItem>;
|
||||
onOpenChange: (v: boolean) => void;
|
||||
onFinish: (values: UserItem) => Promise<boolean>;
|
||||
initialValues?: Partial<UserItem & { company?: string; type?: string }>;
|
||||
onVisibleChange: (v: boolean) => void;
|
||||
onFinish: (values: UserItem & { company?: string; type?: string }) => Promise<boolean>;
|
||||
// 是否显示“所属租户”(company)选择(仅系统用户需要)
|
||||
showCompany?: boolean;
|
||||
}
|
||||
|
||||
const UserForm: React.FC<UserFormProps> = ({ open, title, initialValues, onOpenChange, onFinish }) => {
|
||||
const UserForm: React.FC<UserFormProps> = ({ visible, title, initialValues, onVisibleChange, onFinish, showCompany = true }) => {
|
||||
return (
|
||||
<ModalForm<UserItem>
|
||||
<ModalForm<UserItem & { company?: string; type?: string }>
|
||||
title={title}
|
||||
visible={open}
|
||||
onVisibleChange={onOpenChange}
|
||||
visible={visible}
|
||||
onVisibleChange={onVisibleChange}
|
||||
onFinish={onFinish}
|
||||
initialValues={initialValues}
|
||||
initialValues={{ type: 'BACKEND', ...(initialValues || {}) }}
|
||||
modalProps={{ destroyOnClose: true }}
|
||||
>
|
||||
<ProForm.Group>
|
||||
@@ -27,9 +30,17 @@ const UserForm: React.FC<UserFormProps> = ({ open, title, initialValues, onOpenC
|
||||
</ProForm.Group>
|
||||
<ProFormRadio.Group name="sex" label="性别" options={[{ label: '男', value: 0 }, { label: '女', value: 1 }]} />
|
||||
<ProFormSelect name="roleIds" label="角色" mode="multiple" request={systemApi.roles} placeholder="选择角色" />
|
||||
|
||||
{showCompany ? (
|
||||
<TenantSelector nameTenant="company" labelTenant="所属租户" hideIncludeChildren />
|
||||
) : null}
|
||||
|
||||
<ProFormTextArea name="remark" label="备注" />
|
||||
{/* 类型固定为系统用户,默认也会按 BACKEND 新建 */}
|
||||
<ProFormText name="type" label="用户类型" initialValue="BACKEND" disabled hidden />
|
||||
</ModalForm>
|
||||
);
|
||||
};
|
||||
|
||||
export default UserForm;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { forwardRef, useImperativeHandle, useRef } from 'react';
|
||||
import React, { forwardRef, useImperativeHandle, useRef } from 'react';
|
||||
import type { ActionType, ProColumns } from '@ant-design/pro-components';
|
||||
import { ProTable } from '@ant-design/pro-components';
|
||||
import { Space, Switch, Popconfirm } from 'antd';
|
||||
@@ -73,4 +73,4 @@ const UserTable = forwardRef<UserTableRef, UserTableProps>(({ onEdit, onResetPas
|
||||
);
|
||||
});
|
||||
|
||||
export default UserTable;
|
||||
export default UserTable;
|
||||
@@ -1,5 +1,5 @@
|
||||
import React, { useRef, useState } from 'react';
|
||||
import { PageContainer, ProFormText } from '@ant-design/pro-components';
|
||||
import { PageContainer, ProFormSelect, ProFormText } from '@ant-design/pro-components';
|
||||
import { message } from 'antd';
|
||||
import { ActionBar, GlassCard, SearchBarPlus } from '@/components/ui';
|
||||
import { systemApi, UserItem } from '@/services/system';
|
||||
@@ -9,15 +9,15 @@ import UserForm from './components/UserForm';
|
||||
|
||||
const UsersPage: React.FC = () => {
|
||||
const tableRef = useRef<UserTableRef>(null);
|
||||
const [params, setParams] = useState<Record<string, any>>({});
|
||||
const [params, setParams] = useState<Record<string, any>>({ type: 'BACKEND' });
|
||||
const [createVisible, setCreateVisible] = useState(false);
|
||||
const [editVisible, setEditVisible] = useState(false);
|
||||
const [currentRow, setCurrentRow] = useState<UserItem | undefined>(undefined);
|
||||
|
||||
const addUser = async (values: UserItem) => {
|
||||
const addUser = async (values: UserItem & { company?: string; type?: string }) => {
|
||||
const hide = message.loading('正在添加');
|
||||
try {
|
||||
const res = await systemApi.saveOrUpdateUser(values);
|
||||
await systemApi.saveOrUpdateUser({ ...(values as any), roleId: (values as any)?.roleIds ? (values as any).roleIds.join(',') : (values as any)?.roleId } as any);
|
||||
hide();
|
||||
message.success('添加用户成功');
|
||||
tableRef.current?.reload();
|
||||
@@ -29,10 +29,10 @@ const UsersPage: React.FC = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const editUser = async (values: UserItem) => {
|
||||
const editUser = async (values: UserItem & { company?: string; type?: string }) => {
|
||||
const hide = message.loading('正在更新');
|
||||
try {
|
||||
const res = await systemApi.saveOrUpdateUser({ ...currentRow, ...values });
|
||||
await systemApi.saveOrUpdateUser({ ...(currentRow as any), ...(values as any), roleId: (values as any)?.roleIds ? (values as any).roleIds.join(',') : (values as any)?.roleId } as any);
|
||||
hide();
|
||||
message.success('修改用户成功');
|
||||
tableRef.current?.reload();
|
||||
@@ -44,19 +44,6 @@ const UsersPage: React.FC = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const switchEnabled = async (record: UserItem) => {
|
||||
const hide = message.loading('正在更新');
|
||||
try {
|
||||
await systemApi.updateEnabled(record.id!, !record.enabled);
|
||||
hide();
|
||||
message.success('修改用户成功');
|
||||
tableRef.current?.reload();
|
||||
} catch (e) {
|
||||
hide();
|
||||
message.error('修改用户失败');
|
||||
}
|
||||
};
|
||||
|
||||
const resetPwd = async (record: UserItem) => {
|
||||
const hide = message.loading('正在更新');
|
||||
try {
|
||||
@@ -82,16 +69,11 @@ const UsersPage: React.FC = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const isAppType = params?.type === 'APP';
|
||||
|
||||
return (
|
||||
<PageContainer header={{ title: '用户管理' }}>
|
||||
<ActionBar
|
||||
left={
|
||||
<Toolbar
|
||||
onCreate={() => setCreateVisible(true)}
|
||||
onExport={() => systemApi.exportUser()}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
<ActionBar left={<Toolbar onCreate={() => setCreateVisible(true)} onExport={() => systemApi.exportUser()} hideCreate={isAppType} />} />
|
||||
|
||||
<SearchBarPlus
|
||||
defaultCollapsed={false}
|
||||
@@ -103,6 +85,7 @@ const UsersPage: React.FC = () => {
|
||||
tableRef.current?.reload();
|
||||
}}
|
||||
>
|
||||
<ProFormSelect name="type" label="用户类型" valueEnum={{ BACKEND: '系统用户', APP: 'C端用户' }} initialValue="BACKEND" />
|
||||
<ProFormText name="username" label="用户名" placeholder="请输入用户名" />
|
||||
<ProFormText name="mobile" label="手机号" placeholder="请输入手机号" />
|
||||
</SearchBarPlus>
|
||||
@@ -117,24 +100,14 @@ const UsersPage: React.FC = () => {
|
||||
/>
|
||||
</GlassCard>
|
||||
|
||||
{/* 新建 */}
|
||||
<UserForm
|
||||
title="新建用户"
|
||||
open={createVisible}
|
||||
onOpenChange={setCreateVisible}
|
||||
onFinish={addUser}
|
||||
/>
|
||||
{/* 新建(仅系统用户) */}
|
||||
<UserForm title="新建用户" visible={createVisible} onVisibleChange={setCreateVisible} onFinish={addUser} showCompany={!isAppType ? true : false} />
|
||||
|
||||
{/* 编辑 */}
|
||||
<UserForm
|
||||
title="修改用户"
|
||||
open={editVisible}
|
||||
onOpenChange={setEditVisible}
|
||||
onFinish={editUser}
|
||||
initialValues={currentRow}
|
||||
/>
|
||||
<UserForm title="修改用户" visible={editVisible} onVisibleChange={setEditVisible} onFinish={editUser} initialValues={currentRow} showCompany={!isAppType ? true : false} />
|
||||
</PageContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export default UsersPage;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user