feat: 支持表格单元格快捷编辑

This commit is contained in:
2026-07-21 14:17:08 +08:00
parent fe0b71a0a9
commit a585fd42d5
17 changed files with 2197 additions and 303 deletions

View File

@@ -3,6 +3,7 @@ import { Alert, Empty, Form, Input, Modal, Popconfirm, Select, Space, Table, Tag
import { BankOutlined, InboxOutlined, PlusOutlined, UndoOutlined } from '@ant-design/icons';
import api from '../../api';
import PermissionButton from '../../components/PermissionButton';
import EditableCell from '../../components/EditableCell';
import { message } from '../../ui/app-message';
const PRESET_COLORS = [
@@ -93,46 +94,108 @@ const OrganizationsPage: React.FC = () => {
}
};
const saveCell = async (record: OrganizationItem, field: string, value: unknown) => {
await api.put(`/organizations/${record.id}`, { [field]: value });
message.success('已保存');
await fetchData();
};
const columns = [
{
title: '机构',
dataIndex: 'name',
width: 220,
render: (name: string, record: OrganizationItem) => (
<Space>
<span
style={{
width: 10,
height: 10,
borderRadius: '50%',
background: record.color || '#8c8c8c',
}}
/>
<strong>{name}</strong>
{record.isHost ? (
<Tag color="blue" icon={<BankOutlined />}>
</Tag>
) : (
<Tag></Tag>
)}
</Space>
<EditableCell
value={name}
required
permission="organization:edit"
disabled={record.status === 'archived'}
onSave={(next) => saveCell(record, 'name', next)}
>
<Space>
<span
style={{
width: 10,
height: 10,
borderRadius: '50%',
background: record.color || '#8c8c8c',
}}
/>
<strong>{name}</strong>
{record.isHost ? (
<Tag color="blue" icon={<BankOutlined />}>
</Tag>
) : (
<Tag></Tag>
)}
</Space>
</EditableCell>
),
},
{
title: '机构编码',
dataIndex: 'code',
width: 130,
render: (value: string) => <code>{value}</code>,
render: (value: string, record: OrganizationItem) => (
<EditableCell
value={value}
required
permission="organization:edit"
disabled={record.status === 'archived'}
onSave={(next) => saveCell(record, 'code', next)}
>
<code>{value}</code>
</EditableCell>
),
},
{
title: '联系人',
dataIndex: 'contactName',
width: 120,
render: (value?: string) => value || '-',
render: (value: string | undefined, record: OrganizationItem) => (
<EditableCell
value={value}
permission="organization:edit"
disabled={record.status === 'archived'}
onSave={(next) => saveCell(record, 'contactName', next)}
>
{value || '-'}
</EditableCell>
),
},
{
title: '电话',
dataIndex: 'phone',
width: 140,
render: (value: string | undefined, record: OrganizationItem) => (
<EditableCell
value={value}
permission="organization:edit"
disabled={record.status === 'archived'}
onSave={(next) => saveCell(record, 'phone', next)}
>
{value || '-'}
</EditableCell>
),
},
{
title: '备注',
dataIndex: 'notes',
ellipsis: true,
render: (value: string | undefined, record: OrganizationItem) => (
<EditableCell
value={value}
editor="textarea"
permission="organization:edit"
disabled={record.status === 'archived'}
onSave={(next) => saveCell(record, 'notes', next)}
>
{value || '-'}
</EditableCell>
),
},
{ title: '电话', dataIndex: 'phone', width: 140, render: (value?: string) => value || '-' },
{ title: '备注', dataIndex: 'notes', ellipsis: true, render: (value?: string) => value || '-' },
{
title: '状态',
dataIndex: 'status',