2026-02-12 06:20:54 +00:00
|
|
|
|
import {
|
|
|
|
|
|
Button,
|
|
|
|
|
|
Card,
|
|
|
|
|
|
Drawer,
|
|
|
|
|
|
Form,
|
|
|
|
|
|
Input,
|
|
|
|
|
|
message,
|
|
|
|
|
|
Popconfirm,
|
|
|
|
|
|
Space,
|
|
|
|
|
|
Table,
|
|
|
|
|
|
Tag,
|
|
|
|
|
|
Typography,
|
|
|
|
|
|
DatePicker,
|
|
|
|
|
|
Row,
|
|
|
|
|
|
Col,
|
|
|
|
|
|
Select
|
|
|
|
|
|
} from "antd";
|
2026-02-25 01:44:43 +00:00
|
|
|
|
import { useEffect, useState } from "react";
|
|
|
|
|
|
import { useTranslation } from "react-i18next";
|
2026-02-12 06:20:54 +00:00
|
|
|
|
import { createTenant, deleteTenant, listTenants, updateTenant } from "../api";
|
|
|
|
|
|
import { usePermission } from "../hooks/usePermission";
|
2026-02-27 02:27:57 +00:00
|
|
|
|
import { useDict } from "../hooks/useDict";
|
2026-02-12 06:20:54 +00:00
|
|
|
|
import {
|
|
|
|
|
|
PlusOutlined,
|
|
|
|
|
|
EditOutlined,
|
|
|
|
|
|
DeleteOutlined,
|
|
|
|
|
|
SearchOutlined,
|
|
|
|
|
|
ReloadOutlined,
|
|
|
|
|
|
ShopOutlined,
|
|
|
|
|
|
CalendarOutlined,
|
|
|
|
|
|
PhoneOutlined,
|
|
|
|
|
|
UserOutlined
|
|
|
|
|
|
} from "@ant-design/icons";
|
|
|
|
|
|
import type { SysTenant } from "../types";
|
2026-02-27 02:27:57 +00:00
|
|
|
|
import PageHeader from "../components/shared/PageHeader";
|
2026-02-12 06:20:54 +00:00
|
|
|
|
import dayjs from "dayjs";
|
|
|
|
|
|
|
|
|
|
|
|
const { Title, Text } = Typography;
|
|
|
|
|
|
|
|
|
|
|
|
export default function Tenants() {
|
2026-02-25 01:44:43 +00:00
|
|
|
|
const { t } = useTranslation();
|
2026-02-12 06:20:54 +00:00
|
|
|
|
const { can } = usePermission();
|
2026-02-27 02:27:57 +00:00
|
|
|
|
|
|
|
|
|
|
// Dictionaries
|
|
|
|
|
|
const { items: statusDict } = useDict("sys_common_status");
|
|
|
|
|
|
|
2026-02-12 06:20:54 +00:00
|
|
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
|
|
const [saving, setSaving] = useState(false);
|
|
|
|
|
|
const [data, setData] = useState<SysTenant[]>([]);
|
|
|
|
|
|
const [total, setTotal] = useState(0);
|
|
|
|
|
|
const [params, setParams] = useState({
|
|
|
|
|
|
current: 1,
|
|
|
|
|
|
size: 10,
|
|
|
|
|
|
name: "",
|
|
|
|
|
|
code: ""
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const [drawerOpen, setDrawerOpen] = useState(false);
|
|
|
|
|
|
const [editing, setEditing] = useState<SysTenant | null>(null);
|
|
|
|
|
|
const [form] = Form.useForm();
|
|
|
|
|
|
|
|
|
|
|
|
const loadData = async (currentParams = params) => {
|
|
|
|
|
|
setLoading(true);
|
|
|
|
|
|
try {
|
|
|
|
|
|
const result = await listTenants(currentParams);
|
|
|
|
|
|
setData(result.records || []);
|
|
|
|
|
|
setTotal(result.total || 0);
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
setLoading(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
loadData();
|
|
|
|
|
|
}, [params.current, params.size]);
|
|
|
|
|
|
|
|
|
|
|
|
const handleSearch = () => {
|
|
|
|
|
|
setParams({ ...params, current: 1 });
|
|
|
|
|
|
loadData({ ...params, current: 1 });
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const handleReset = () => {
|
|
|
|
|
|
const resetParams = {
|
|
|
|
|
|
current: 1,
|
|
|
|
|
|
size: 10,
|
|
|
|
|
|
name: "",
|
|
|
|
|
|
code: ""
|
|
|
|
|
|
};
|
|
|
|
|
|
setParams(resetParams);
|
|
|
|
|
|
loadData(resetParams);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const openCreate = () => {
|
|
|
|
|
|
setEditing(null);
|
|
|
|
|
|
form.resetFields();
|
|
|
|
|
|
form.setFieldsValue({ status: 1 });
|
|
|
|
|
|
setDrawerOpen(true);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const openEdit = (record: SysTenant) => {
|
|
|
|
|
|
setEditing(record);
|
|
|
|
|
|
form.setFieldsValue({
|
|
|
|
|
|
...record,
|
|
|
|
|
|
expireTime: record.expireTime ? dayjs(record.expireTime) : null
|
|
|
|
|
|
});
|
|
|
|
|
|
setDrawerOpen(true);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const handleDelete = async (id: number) => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
await deleteTenant(id);
|
2026-02-25 01:44:43 +00:00
|
|
|
|
message.success(t('common.success'));
|
2026-02-12 06:20:54 +00:00
|
|
|
|
loadData();
|
|
|
|
|
|
} catch (e) {
|
2026-02-26 09:09:14 +00:00
|
|
|
|
// Handled by interceptor
|
2026-02-12 06:20:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const submit = async () => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const values = await form.validateFields();
|
|
|
|
|
|
setSaving(true);
|
|
|
|
|
|
const payload = {
|
|
|
|
|
|
...values,
|
|
|
|
|
|
expireTime: values.expireTime ? values.expireTime.format("YYYY-MM-DD HH:mm:ss") : null
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if (editing) {
|
|
|
|
|
|
await updateTenant(editing.id, payload);
|
2026-02-25 01:44:43 +00:00
|
|
|
|
message.success(t('common.success'));
|
2026-02-12 06:20:54 +00:00
|
|
|
|
} else {
|
|
|
|
|
|
await createTenant(payload);
|
2026-02-25 01:44:43 +00:00
|
|
|
|
message.success(t('common.success'));
|
2026-02-12 06:20:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
setDrawerOpen(false);
|
|
|
|
|
|
loadData();
|
|
|
|
|
|
} catch (e) {
|
2026-02-26 09:09:14 +00:00
|
|
|
|
// Handled by interceptor
|
2026-02-12 06:20:54 +00:00
|
|
|
|
} finally {
|
|
|
|
|
|
setSaving(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const columns = [
|
|
|
|
|
|
{
|
2026-02-25 01:44:43 +00:00
|
|
|
|
title: t('tenants.tenantInfo'),
|
2026-02-12 06:20:54 +00:00
|
|
|
|
key: "tenant",
|
|
|
|
|
|
render: (_: any, record: SysTenant) => (
|
|
|
|
|
|
<Space>
|
|
|
|
|
|
<div style={{ width: 40, height: 40, background: '#f0f5ff', borderRadius: 8, display: 'flex', alignItems: 'center', justifyContent: 'center', color: '#1890ff', fontSize: 20 }}>
|
|
|
|
|
|
<ShopOutlined aria-hidden="true" />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<div style={{ fontWeight: 600, color: '#262626' }}>{record.tenantName}</div>
|
|
|
|
|
|
<div style={{ fontSize: 12, color: '#8c8c8c' }} className="tabular-nums">{record.tenantCode}</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</Space>
|
|
|
|
|
|
),
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
2026-02-25 01:44:43 +00:00
|
|
|
|
title: t('tenants.contact'),
|
2026-02-12 06:20:54 +00:00
|
|
|
|
key: "contact",
|
|
|
|
|
|
render: (_: any, record: SysTenant) => (
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<div><UserOutlined style={{ marginRight: 4, color: '#8c8c8c' }} />{record.contactName || "-"}</div>
|
|
|
|
|
|
<div style={{ fontSize: 12, color: '#8c8c8c' }} className="tabular-nums"><PhoneOutlined style={{ marginRight: 4 }} />{record.contactPhone || "-"}</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
2026-02-25 01:44:43 +00:00
|
|
|
|
title: t('common.status'),
|
2026-02-12 06:20:54 +00:00
|
|
|
|
dataIndex: "status",
|
|
|
|
|
|
width: 100,
|
2026-02-27 02:27:57 +00:00
|
|
|
|
render: (status: number) => {
|
|
|
|
|
|
const item = statusDict.find(i => i.itemValue === String(status));
|
|
|
|
|
|
return (
|
|
|
|
|
|
<Tag color={status === 1 ? "green" : "red"}>
|
|
|
|
|
|
{item ? item.itemLabel : (status === 1 ? "正常" : "禁用")}
|
|
|
|
|
|
</Tag>
|
|
|
|
|
|
);
|
|
|
|
|
|
},
|
2026-02-12 06:20:54 +00:00
|
|
|
|
},
|
|
|
|
|
|
{
|
2026-02-25 01:44:43 +00:00
|
|
|
|
title: t('tenants.expireTime'),
|
2026-02-12 06:20:54 +00:00
|
|
|
|
dataIndex: "expireTime",
|
|
|
|
|
|
width: 180,
|
|
|
|
|
|
render: (text: string) => (
|
|
|
|
|
|
<Space>
|
|
|
|
|
|
<CalendarOutlined style={{ color: '#8c8c8c' }} />
|
2026-02-25 01:44:43 +00:00
|
|
|
|
<Text className="tabular-nums">{text ? text.substring(0, 10) : t('tenants.forever')}</Text>
|
2026-02-12 06:20:54 +00:00
|
|
|
|
</Space>
|
|
|
|
|
|
)
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
2026-02-25 01:44:43 +00:00
|
|
|
|
title: t('common.action'),
|
2026-02-12 06:20:54 +00:00
|
|
|
|
key: "action",
|
|
|
|
|
|
width: 120,
|
|
|
|
|
|
fixed: "right" as const,
|
|
|
|
|
|
render: (_: any, record: SysTenant) => (
|
|
|
|
|
|
<Space>
|
|
|
|
|
|
{can("sys_tenant:update") && (
|
|
|
|
|
|
<Button
|
|
|
|
|
|
type="text"
|
|
|
|
|
|
icon={<EditOutlined aria-hidden="true" />}
|
|
|
|
|
|
onClick={() => openEdit(record)}
|
2026-02-25 01:44:43 +00:00
|
|
|
|
aria-label={t('common.edit')}
|
2026-02-12 06:20:54 +00:00
|
|
|
|
/>
|
|
|
|
|
|
)}
|
|
|
|
|
|
{can("sys_tenant:delete") && (
|
|
|
|
|
|
<Popconfirm title={`确定删除租户 "${record.tenantName}" 吗?`} onConfirm={() => handleDelete(record.id)}>
|
2026-02-25 01:44:43 +00:00
|
|
|
|
<Button type="text" danger icon={<DeleteOutlined aria-hidden="true" />} aria-label={t('common.delete')} />
|
2026-02-12 06:20:54 +00:00
|
|
|
|
</Popconfirm>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</Space>
|
|
|
|
|
|
),
|
|
|
|
|
|
},
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<div className="p-6">
|
2026-02-27 02:27:57 +00:00
|
|
|
|
<PageHeader
|
|
|
|
|
|
title={t('tenants.title')}
|
|
|
|
|
|
subtitle={t('tenants.subtitle')}
|
|
|
|
|
|
extra={can("sys_tenant:create") && (
|
2026-02-12 06:20:54 +00:00
|
|
|
|
<Button type="primary" icon={<PlusOutlined aria-hidden="true" />} onClick={openCreate}>
|
2026-02-25 01:44:43 +00:00
|
|
|
|
{t('tenants.drawerTitleCreate')}
|
2026-02-12 06:20:54 +00:00
|
|
|
|
</Button>
|
|
|
|
|
|
)}
|
2026-02-27 02:27:57 +00:00
|
|
|
|
/>
|
2026-02-12 06:20:54 +00:00
|
|
|
|
|
|
|
|
|
|
<Card className="shadow-sm mb-4">
|
|
|
|
|
|
<Space wrap size="middle">
|
|
|
|
|
|
<Input
|
2026-02-25 01:44:43 +00:00
|
|
|
|
placeholder={t('tenants.tenantName')}
|
2026-02-12 06:20:54 +00:00
|
|
|
|
prefix={<SearchOutlined aria-hidden="true" className="text-gray-400" />}
|
|
|
|
|
|
style={{ width: 200 }}
|
|
|
|
|
|
value={params.name}
|
|
|
|
|
|
onChange={e => setParams({ ...params, name: e.target.value })}
|
|
|
|
|
|
allowClear
|
|
|
|
|
|
/>
|
|
|
|
|
|
<Input
|
2026-02-25 01:44:43 +00:00
|
|
|
|
placeholder={t('tenants.tenantCode')}
|
2026-02-12 06:20:54 +00:00
|
|
|
|
style={{ width: 180 }}
|
|
|
|
|
|
value={params.code}
|
|
|
|
|
|
onChange={e => setParams({ ...params, code: e.target.value })}
|
|
|
|
|
|
allowClear
|
|
|
|
|
|
/>
|
2026-02-25 01:44:43 +00:00
|
|
|
|
<Button type="primary" icon={<SearchOutlined aria-hidden="true" />} onClick={handleSearch}>{t('common.search')}</Button>
|
|
|
|
|
|
<Button icon={<ReloadOutlined aria-hidden="true" />} onClick={handleReset}>{t('common.reset')}</Button>
|
2026-02-12 06:20:54 +00:00
|
|
|
|
</Space>
|
|
|
|
|
|
</Card>
|
|
|
|
|
|
|
|
|
|
|
|
<Card className="shadow-sm" styles={{ body: { padding: 0 } }}>
|
|
|
|
|
|
<Table
|
|
|
|
|
|
rowKey="id"
|
|
|
|
|
|
columns={columns}
|
|
|
|
|
|
dataSource={data}
|
|
|
|
|
|
loading={loading}
|
2026-02-25 01:44:43 +00:00
|
|
|
|
size="middle"
|
2026-02-12 06:20:54 +00:00
|
|
|
|
pagination={{
|
|
|
|
|
|
current: params.current,
|
|
|
|
|
|
pageSize: params.size,
|
|
|
|
|
|
total: total,
|
|
|
|
|
|
showSizeChanger: true,
|
|
|
|
|
|
onChange: (page, size) => setParams({ ...params, current: page, size }),
|
2026-02-25 01:44:43 +00:00
|
|
|
|
showTotal: (total) => t('common.total', { total })
|
2026-02-12 06:20:54 +00:00
|
|
|
|
}}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</Card>
|
|
|
|
|
|
|
|
|
|
|
|
<Drawer
|
|
|
|
|
|
title={
|
|
|
|
|
|
<Space>
|
|
|
|
|
|
<ShopOutlined aria-hidden="true" />
|
2026-02-25 01:44:43 +00:00
|
|
|
|
<span>{editing ? t('tenants.drawerTitleEdit') : t('tenants.drawerTitleCreate')}</span>
|
2026-02-12 06:20:54 +00:00
|
|
|
|
</Space>
|
|
|
|
|
|
}
|
|
|
|
|
|
open={drawerOpen}
|
|
|
|
|
|
onClose={() => setDrawerOpen(false)}
|
|
|
|
|
|
width={480}
|
|
|
|
|
|
destroyOnClose
|
|
|
|
|
|
footer={
|
|
|
|
|
|
<div className="flex justify-end gap-2 p-2">
|
2026-02-25 01:44:43 +00:00
|
|
|
|
<Button onClick={() => setDrawerOpen(false)}>{t('common.cancel')}</Button>
|
|
|
|
|
|
<Button type="primary" loading={saving} onClick={submit}>{t('common.confirm')}</Button>
|
2026-02-12 06:20:54 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
}
|
|
|
|
|
|
>
|
|
|
|
|
|
<Form form={form} layout="vertical">
|
|
|
|
|
|
<Row gutter={16}>
|
|
|
|
|
|
<Col span={12}>
|
2026-02-25 01:44:43 +00:00
|
|
|
|
<Form.Item label={t('tenants.tenantName')} name="tenantName" rules={[{ required: true, message: t('tenants.tenantName') }]}>
|
2026-02-12 06:20:54 +00:00
|
|
|
|
<Input placeholder="例如:云合智慧" />
|
|
|
|
|
|
</Form.Item>
|
|
|
|
|
|
</Col>
|
|
|
|
|
|
<Col span={12}>
|
2026-02-25 01:44:43 +00:00
|
|
|
|
<Form.Item label={t('tenants.tenantCode')} name="tenantCode" rules={[{ required: true, message: t('tenants.tenantCode') }]}>
|
2026-02-12 06:20:54 +00:00
|
|
|
|
<Input placeholder="例如:UNIS" disabled={!!editing} className="tabular-nums" />
|
|
|
|
|
|
</Form.Item>
|
|
|
|
|
|
</Col>
|
|
|
|
|
|
</Row>
|
|
|
|
|
|
|
|
|
|
|
|
<Row gutter={16}>
|
|
|
|
|
|
<Col span={12}>
|
2026-02-25 01:44:43 +00:00
|
|
|
|
<Form.Item label={t('tenants.contactName')} name="contactName">
|
2026-02-12 06:20:54 +00:00
|
|
|
|
<Input placeholder="姓名" />
|
|
|
|
|
|
</Form.Item>
|
|
|
|
|
|
</Col>
|
|
|
|
|
|
<Col span={12}>
|
2026-02-25 01:44:43 +00:00
|
|
|
|
<Form.Item label={t('tenants.contactPhone')} name="contactPhone">
|
2026-02-12 06:20:54 +00:00
|
|
|
|
<Input placeholder="手机或座机" className="tabular-nums" />
|
|
|
|
|
|
</Form.Item>
|
|
|
|
|
|
</Col>
|
|
|
|
|
|
</Row>
|
|
|
|
|
|
|
2026-02-25 01:44:43 +00:00
|
|
|
|
<Form.Item label={t('tenants.expireTime')} name="expireTime">
|
|
|
|
|
|
<DatePicker style={{ width: "100%" }} placeholder={t('tenants.forever')} />
|
2026-02-12 06:20:54 +00:00
|
|
|
|
</Form.Item>
|
|
|
|
|
|
|
2026-02-25 01:44:43 +00:00
|
|
|
|
<Form.Item label={t('common.status')} name="status" initialValue={1}>
|
2026-02-27 02:27:57 +00:00
|
|
|
|
<Select options={statusDict.map(i => ({ label: i.itemLabel, value: Number(i.itemValue) }))} />
|
2026-02-12 06:20:54 +00:00
|
|
|
|
</Form.Item>
|
|
|
|
|
|
|
2026-02-25 01:44:43 +00:00
|
|
|
|
<Form.Item label={t('common.remark')} name="remark">
|
2026-02-12 06:20:54 +00:00
|
|
|
|
<Input.TextArea rows={3} placeholder="选填,租户详细背景说明…" />
|
|
|
|
|
|
</Form.Item>
|
|
|
|
|
|
</Form>
|
|
|
|
|
|
</Drawer>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|