feat: 支持表格单元格快捷编辑
Some checks failed
CI 检查 / lint (pull_request) Has been cancelled
CI 检查 / typecheck (pull_request) Has been cancelled
CI 检查 / test (pull_request) Has been cancelled

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

@@ -4,6 +4,7 @@ import { EditOutlined } from '@ant-design/icons';
import dayjs from 'dayjs';
import api from '../../api';
import { message } from '../../ui/app-message';
import EditableCell from '../../components/EditableCell';
interface TeacherRow {
id: number;
@@ -101,6 +102,15 @@ const TeachersPage: React.FC = () => {
}
};
const saveProfileCell = useCallback(
async (record: TeacherRow, field: string, value: unknown) => {
await api.put(`/rbac/teachers/${record.id}/profile`, { [field]: value });
message.success('已保存');
await fetchData();
},
[fetchData],
);
const columns = useMemo(
() => [
{ title: '姓名', dataIndex: 'name', key: 'name', width: 120 },
@@ -133,14 +143,33 @@ const TeachersPage: React.FC = () => {
dataIndex: 'profile',
key: 'subjects',
width: 130,
render: (p: TeacherRow['profile']) => p?.subjects?.join('、') || '-',
render: (p: TeacherRow['profile'], r: TeacherRow) => (
<EditableCell
value={p?.subjects || []}
editor="tags"
options={(p?.subjects || []).map((value) => ({ value, label: value }))}
permission="teacher:edit"
onSave={(next) => saveProfileCell(r, 'subjects', next)}
>
{p?.subjects?.join('、') || '-'}
</EditableCell>
),
},
{
title: '入职日期',
dataIndex: 'profile',
key: 'joinedAt',
width: 110,
render: (p: TeacherRow['profile']) => p?.joinedAt || '-',
render: (p: TeacherRow['profile'], r: TeacherRow) => (
<EditableCell
value={p?.joinedAt}
editor="date"
permission="teacher:edit"
onSave={(next) => saveProfileCell(r, 'joinedAt', next)}
>
{p?.joinedAt || '-'}
</EditableCell>
),
},
{
title: '状态',
@@ -178,7 +207,7 @@ const TeachersPage: React.FC = () => {
),
},
],
[],
[saveProfileCell],
);
return (