fix: 归档删除改为软删除
This commit is contained in:
@@ -27,10 +27,10 @@ import {
|
||||
CalendarOutlined,
|
||||
LeftOutlined,
|
||||
RightOutlined,
|
||||
DeleteOutlined,
|
||||
CloudSyncOutlined,
|
||||
PlusOutlined,
|
||||
EditOutlined,
|
||||
StopOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import dayjs, { Dayjs } from 'dayjs';
|
||||
import api from '../../api';
|
||||
@@ -455,26 +455,30 @@ const SchedulesPage: React.FC = () => {
|
||||
void loadClassTeachers(editableSchedule.classId);
|
||||
};
|
||||
|
||||
// ---- Delete schedule ----
|
||||
const removeScheduleFromSelection = (id: number) => {
|
||||
const remaining = selectedSchedules.filter((s) => s.id !== id);
|
||||
setSelectedSchedules(remaining);
|
||||
if (remaining.length === 0) {
|
||||
setModalOpen(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleDelete = async (id: number | null) => {
|
||||
// ---- Disable / delete schedule ----
|
||||
|
||||
const handleDisable = async (id: number | null) => {
|
||||
if (id === null) return;
|
||||
try {
|
||||
await api.delete(`/class-schedules/${id}`);
|
||||
message.success('排课已删除');
|
||||
// Refresh the displayed schedules
|
||||
const remaining = selectedSchedules.filter((s) => s.id !== id);
|
||||
setSelectedSchedules(remaining);
|
||||
if (remaining.length === 0) {
|
||||
setModalOpen(false);
|
||||
}
|
||||
await api.put(`/class-schedules/${id}`, { status: 'inactive' });
|
||||
message.success('排课已停用,历史考勤记录已保留,教室占用已释放');
|
||||
removeScheduleFromSelection(id);
|
||||
fetchData();
|
||||
} catch (e: unknown) {
|
||||
const err = e as { message?: string };
|
||||
message.error(err?.message || '删除失败');
|
||||
message.error(err?.message || '停用失败');
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// ---- Classroom select options ----
|
||||
|
||||
const classroomOptions = useMemo(
|
||||
@@ -1113,21 +1117,23 @@ const SchedulesPage: React.FC = () => {
|
||||
编辑
|
||||
</PermissionButton>
|
||||
)}
|
||||
<Popconfirm
|
||||
title="确认删除该排课?"
|
||||
onConfirm={() => handleDelete(s.id)}
|
||||
okText="删除"
|
||||
cancelText="取消"
|
||||
>
|
||||
<PermissionButton
|
||||
permission="schedule:delete"
|
||||
size="small"
|
||||
danger
|
||||
icon={<DeleteOutlined />}
|
||||
{s.scheduleType !== 'RENTAL' && s.status === 'active' && (
|
||||
<Popconfirm
|
||||
title="确认停用该排课?"
|
||||
description="停用后历史考勤记录会保留,但该排课不会再显示或占用教室。"
|
||||
onConfirm={() => handleDisable(s.id)}
|
||||
okText="停用"
|
||||
cancelText="取消"
|
||||
>
|
||||
删除
|
||||
</PermissionButton>
|
||||
</Popconfirm>
|
||||
<PermissionButton
|
||||
permission="schedule:edit"
|
||||
size="small"
|
||||
icon={<StopOutlined />}
|
||||
>
|
||||
停用
|
||||
</PermissionButton>
|
||||
</Popconfirm>
|
||||
)}
|
||||
</Space>
|
||||
)}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user