Files
zeling_f/mock/appointment.ts

175 lines
7.6 KiB
TypeScript
Raw Permalink Normal View History

2026-03-17 14:30:02 +08:00
const allAppointments = [
// 已预约
{ id: 1, name: '能力提升面试', category: '模拟面试', time: '2025.08.10', session: '14:00:00-16:00:00', teacher: '李老师', location: '教室1', status: 'booked' },
{ id: 2, name: '能力提升面试', category: '模拟面试', time: '2025.08.10', session: '14:00:00-16:00:00', teacher: '李老师', location: '教室1', status: 'booked' },
{ id: 3, name: '能力提升面试', category: '模拟面试', time: '2025.08.10', session: '14:00:00-16:00:00', teacher: '李老师', location: '教室1', status: 'booked' },
{ id: 4, name: '职业规划咨询', category: '职业咨询', time: '2025.08.12', session: '09:00:00-11:00:00', teacher: '王老师', location: '会议室A', status: 'booked' },
{ id: 5, name: '简历修改指导', category: '简历指导', time: '2025.08.15', session: '10:00:00-12:00:00', teacher: '张老师', location: '教室3', status: 'booked' },
// 预约待确认
{ id: 6, name: '模拟群面练习', category: '模拟面试', time: '2025.08.18', session: '14:00:00-16:00:00', teacher: '赵老师', location: '教室2', status: 'pending' },
{ id: 7, name: '行业分析讲座', category: '讲座', time: '2025.08.20', session: '09:00:00-11:00:00', teacher: '刘老师', location: '报告厅', status: 'pending' },
{ id: 8, name: '职业规划咨询', category: '职业咨询', time: '2025.08.22', session: '14:00:00-16:00:00', teacher: '王老师', location: '会议室A', status: 'pending' },
// 已完成
{ id: 9, name: '能力提升面试', category: '模拟面试', time: '2025.07.20', session: '14:00:00-16:00:00', teacher: '李老师', location: '教室1', status: 'completed' },
{ id: 10, name: '简历修改指导', category: '简历指导', time: '2025.07.15', session: '10:00:00-12:00:00', teacher: '张老师', location: '教室3', status: 'completed' },
{ id: 11, name: '职业规划咨询', category: '职业咨询', time: '2025.07.10', session: '09:00:00-11:00:00', teacher: '王老师', location: '会议室A', status: 'completed' },
{ id: 12, name: '模拟群面练习', category: '模拟面试', time: '2025.07.05', session: '14:00:00-16:00:00', teacher: '赵老师', location: '教室2', status: 'completed' },
// 已取消
{ id: 13, name: '行业分析讲座', category: '讲座', time: '2025.07.25', session: '09:00:00-11:00:00', teacher: '刘老师', location: '报告厅', status: 'cancelled' },
{ id: 14, name: '能力提升面试', category: '模拟面试', time: '2025.07.22', session: '14:00:00-16:00:00', teacher: '李老师', location: '教室1', status: 'cancelled' },
];
// 预约管理数据
const specialManage = [
{ id: 101, name: '能力提升面试', category: '模拟面试', startTime: '2025.09.01', endTime: '2026.10.01', remaining: 20, total: 300, sessions: 20, teacher: '李老师', status: 'ongoing' },
{ id: 102, name: '能力提升面试', category: '模拟面试', startTime: '2025.09.01', endTime: '2026.10.01', remaining: 20, total: 300, sessions: 20, teacher: '李老师', status: 'ended' },
{ id: 103, name: '能力提升面试', category: '模拟面试', startTime: '2025.09.01', endTime: '2026.10.01', remaining: 0, total: 300, sessions: 20, teacher: '李老师', status: 'ongoing' },
];
const categories = ['模拟面试', '职业咨询', '简历指导'];
const teachers = ['李老师', '王老师', '张老师', '赵老师', '刘老师', '陈老师', '周老师', '吴老师'];
const statuses = ['ongoing', 'notStarted', 'ongoing', 'ongoing', 'ongoing', 'ongoing', 'ended', 'ongoing'];
const names = ['能力提升面试', '职业规划咨询', '简历修改指导', '模拟群面练习', '行业分析讲座', '求职技巧培训'];
const manageAppointments = [
...specialManage,
...Array.from({ length: 97 }, (_, i) => ({
id: 104 + i,
name: names[i % names.length],
category: categories[i % categories.length],
startTime: '2025.09.01',
endTime: '2026.10.01',
remaining: 20 + (i % 50),
total: 300,
sessions: 10 + (i % 20),
teacher: teachers[i % teachers.length],
status: statuses[i % statuses.length],
})),
];
// 用户映射userId=2 的用户没有任何预约数据
const userAppointments: Record<number, number[]> = {
1: allAppointments.map((a) => a.id), // 默认用户有所有数据
2: [], // 空白用户
};
export default {
// 获取预约列表
'GET /api/appointment/list': (req: any, res: any) => {
const { status, name, student, date, page = 1, pageSize = 10, userId = 1 } = req.query;
const uid = Number(userId);
const userIds = userAppointments[uid] ?? userAppointments[1];
let filtered = allAppointments.filter((item) => userIds.includes(item.id));
// 按状态筛选
if (status) {
filtered = filtered.filter((item) => item.status === status);
}
// 按预约名称模糊搜索
if (name) {
filtered = filtered.filter((item) => item.name.includes(name));
}
// 按日期筛选
if (date) {
filtered = filtered.filter((item) => item.time === date);
}
const total = filtered.length;
const start = (Number(page) - 1) * Number(pageSize);
const end = start + Number(pageSize);
const list = filtered.slice(start, end);
res.json({
code: 0,
data: {
list,
total,
page: Number(page),
pageSize: Number(pageSize),
},
message: 'ok',
});
},
// 预约管理列表
'GET /api/appointment/manage': (req: any, res: any) => {
const { name, category, teacher, status, page = 1, pageSize = 10 } = req.query;
let filtered = [...manageAppointments];
if (name) {
filtered = filtered.filter((item) => item.name.includes(name));
}
if (category) {
filtered = filtered.filter((item) => item.category === category);
}
if (teacher) {
filtered = filtered.filter((item) => item.teacher.includes(teacher));
}
if (status) {
filtered = filtered.filter((item) => item.status === status);
}
const total = filtered.length;
const start = (Number(page) - 1) * Number(pageSize);
const end = start + Number(pageSize);
const list = filtered.slice(start, end);
res.json({
code: 0,
data: { list, total, page: Number(page), pageSize: Number(pageSize) },
message: 'ok',
});
},
// 预约操作
'POST /api/appointment/book': (req: any, res: any) => {
const { id } = req.body;
const item = manageAppointments.find((a) => a.id === Number(id));
if (!item) {
res.json({ code: 404, message: '预约项目不存在' });
return;
}
if (item.status === 'ended') {
res.json({ code: 400, message: '该项目已结束,不可预约' });
return;
}
if (item.remaining <= 0) {
res.json({ code: 400, message: '名额已满,不可预约' });
return;
}
item.remaining -= 1;
res.json({ code: 0, message: '预约成功' });
},
// 取消预约
'POST /api/appointment/cancel': (req: any, res: any) => {
const { id } = req.body;
const appointment = allAppointments.find((a) => a.id === Number(id));
if (!appointment) {
res.json({ code: 404, message: '预约不存在' });
return;
}
// 已完成的不能取消
if (appointment.status === 'completed') {
res.json({ code: 400, message: '已结束的预约不能取消' });
return;
}
// 已取消的不能重复取消
if (appointment.status === 'cancelled') {
res.json({ code: 400, message: '该预约已取消' });
return;
}
// 只有 booked 和 pending 可以取消
appointment.status = 'cancelled';
res.json({ code: 0, message: '取消成功' });
},
};