forked from wangziqi/gongxue-base
feat: 支持表格单元格快捷编辑
This commit is contained in:
@@ -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 (
|
||||
|
||||
Reference in New Issue
Block a user