教学点名强化
This commit is contained in:
@@ -23,6 +23,7 @@ public sealed class AttendanceController(
|
||||
SystemRoles.SuperAdmin + "," +
|
||||
SystemRoles.AcademicAdmin + "," +
|
||||
SystemRoles.CollegeAdmin + "," +
|
||||
SystemRoles.Counselor + "," +
|
||||
SystemRoles.Teacher;
|
||||
|
||||
[HttpGet("my-tasks")]
|
||||
@@ -299,6 +300,220 @@ public sealed class AttendanceController(
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
// ═══════════════ Student endpoints ═══════════════
|
||||
|
||||
[HttpGet("my-records")]
|
||||
[Authorize(Roles = SystemRoles.Student)]
|
||||
public async Task<ActionResult> GetMyRecords(
|
||||
Guid? academicTermId,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var userId = currentUserDataScope.Current.UserId;
|
||||
var studentId = await db.Students
|
||||
.Where(s => s.UserId == userId)
|
||||
.Select(s => (Guid?)s.Id)
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
if (!studentId.HasValue)
|
||||
return ConflictProblem("当前账号未关联学生档案。");
|
||||
|
||||
var source = db.AttendanceRecords.AsNoTracking()
|
||||
.Where(r => r.StudentId == studentId.Value &&
|
||||
r.AttendanceSheet!.Status == AttendanceSheetStatus.Submitted);
|
||||
if (academicTermId.HasValue)
|
||||
source = source.Where(r =>
|
||||
r.AttendanceSheet!.TeachingTask!.AcademicTermId == academicTermId);
|
||||
|
||||
return Ok(await source
|
||||
.OrderByDescending(r => r.AttendanceSheet!.AttendanceDate)
|
||||
.Select(r => new
|
||||
{
|
||||
r.AttendanceSheetId,
|
||||
SheetName = r.AttendanceSheet!.Name,
|
||||
r.AttendanceSheet.AttendanceDate,
|
||||
TaskNumber = r.AttendanceSheet.TeachingTask!.TaskNumber,
|
||||
CourseCode = r.AttendanceSheet.TeachingTask.Course!.Code,
|
||||
CourseName = r.AttendanceSheet.TeachingTask.Course.Name,
|
||||
TeacherNames = r.AttendanceSheet.TeachingTask.Teachers
|
||||
.OrderByDescending(t => t.IsPrimary)
|
||||
.Select(t => t.Teacher!.Name),
|
||||
r.Status,
|
||||
r.Notes,
|
||||
r.AppealStatus,
|
||||
r.AppealReason,
|
||||
r.AppealSubmittedAt,
|
||||
r.AppealReviewComment,
|
||||
r.AppealReviewedAt
|
||||
})
|
||||
.ToListAsync(cancellationToken));
|
||||
}
|
||||
|
||||
[HttpPost("records/appeal")]
|
||||
[Authorize(Roles = SystemRoles.Student)]
|
||||
public async Task<ActionResult> SubmitAppeal(
|
||||
AttendanceAppealRequest request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var userId = currentUserDataScope.Current.UserId;
|
||||
var studentId = await db.Students
|
||||
.Where(s => s.UserId == userId)
|
||||
.Select(s => (Guid?)s.Id)
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
if (!studentId.HasValue)
|
||||
return ConflictProblem("当前账号未关联学生档案。");
|
||||
|
||||
var record = await db.AttendanceRecords
|
||||
.FirstOrDefaultAsync(r =>
|
||||
r.AttendanceSheetId == request.AttendanceSheetId &&
|
||||
r.StudentId == studentId.Value,
|
||||
cancellationToken);
|
||||
if (record is null) return NotFound();
|
||||
if (record.AppealStatus == AttendanceAppealStatus.Pending)
|
||||
return ConflictProblem("已有申诉正在处理中。");
|
||||
if (record.AppealStatus == AttendanceAppealStatus.Approved)
|
||||
return ConflictProblem("该考勤记录申诉已通过。");
|
||||
|
||||
record.AppealStatus = AttendanceAppealStatus.Pending;
|
||||
record.AppealReason = request.Reason.Trim();
|
||||
record.AppealSubmittedAt = DateTime.UtcNow;
|
||||
record.AppealReviewComment = null;
|
||||
record.AppealReviewedAt = null;
|
||||
await db.SaveChangesAsync(cancellationToken);
|
||||
|
||||
// Notify the course teacher
|
||||
var teacherUserIds = await db.TeachingTaskTeachers
|
||||
.Where(x => x.TeachingTaskId == record.AttendanceSheet!.TeachingTaskId)
|
||||
.Select(x => x.Teacher!.UserId)
|
||||
.Where(id => id != null)
|
||||
.Select(id => id!.Value)
|
||||
.ToListAsync(cancellationToken);
|
||||
if (teacherUserIds.Count > 0)
|
||||
{
|
||||
var studentName = await db.Students
|
||||
.Where(s => s.Id == studentId.Value)
|
||||
.Select(s => s.Name)
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
var courseName = record.AttendanceSheet!.TeachingTask?.Course?.Name ?? "";
|
||||
await NotificationService.SendToUserIdsAsync(db, teacherUserIds,
|
||||
"考勤申诉待处理",
|
||||
$"学生 {studentName} 对《{courseName}》考勤记录提出申诉。",
|
||||
"/teacher-attendance", cancellationToken);
|
||||
}
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
// ═══════════════ Counselor endpoints ═══════════════
|
||||
|
||||
[HttpGet("counselor-records")]
|
||||
[Authorize(Roles = SystemRoles.Counselor)]
|
||||
public async Task<ActionResult> GetCounselorRecords(
|
||||
Guid? academicTermId,
|
||||
Guid? classId,
|
||||
bool? withAppeal,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var userId = currentUserDataScope.Current.UserId;
|
||||
var classIds = await db.AdministrativeClasses
|
||||
.Where(c => c.CounselorUserId == userId)
|
||||
.Select(c => c.Id)
|
||||
.ToListAsync(cancellationToken);
|
||||
if (classIds.Count == 0)
|
||||
return ConflictProblem("当前账号未关联任何班级。");
|
||||
|
||||
if (classId.HasValue && !classIds.Contains(classId.Value))
|
||||
return ConflictProblem("您不是该班级的辅导员。");
|
||||
|
||||
var targetClassIds = classId.HasValue
|
||||
? [classId.Value]
|
||||
: classIds;
|
||||
|
||||
var source = db.AttendanceRecords.AsNoTracking()
|
||||
.Where(r =>
|
||||
r.AttendanceSheet!.Status == AttendanceSheetStatus.Submitted &&
|
||||
r.Student!.AdministrativeClassId != null &&
|
||||
targetClassIds.Contains(r.Student.AdministrativeClassId));
|
||||
if (academicTermId.HasValue)
|
||||
source = source.Where(r =>
|
||||
r.AttendanceSheet!.TeachingTask!.AcademicTermId == academicTermId);
|
||||
if (withAppeal == true)
|
||||
source = source.Where(r => r.AppealStatus == AttendanceAppealStatus.Pending);
|
||||
|
||||
return Ok(await source
|
||||
.OrderByDescending(r => r.AttendanceSheet!.AttendanceDate)
|
||||
.Select(r => new
|
||||
{
|
||||
r.AttendanceSheetId,
|
||||
SheetName = r.AttendanceSheet!.Name,
|
||||
r.AttendanceSheet.AttendanceDate,
|
||||
TaskNumber = r.AttendanceSheet.TeachingTask!.TaskNumber,
|
||||
CourseCode = r.AttendanceSheet.TeachingTask.Course!.Code,
|
||||
CourseName = r.AttendanceSheet.TeachingTask.Course.Name,
|
||||
StudentNumber = r.Student!.StudentNumber,
|
||||
StudentName = r.Student.Name,
|
||||
ClassName = r.Student.AdministrativeClass!.Name,
|
||||
r.Status,
|
||||
r.Notes,
|
||||
r.AppealStatus,
|
||||
r.AppealReason,
|
||||
r.AppealSubmittedAt,
|
||||
r.AppealReviewComment
|
||||
})
|
||||
.ToListAsync(cancellationToken));
|
||||
}
|
||||
|
||||
[HttpPost("appeals/{attendanceSheetId:guid}/{studentId:guid}/review")]
|
||||
[Authorize(Roles = AttendanceRoles)]
|
||||
public async Task<ActionResult> ReviewAppeal(
|
||||
Guid attendanceSheetId,
|
||||
Guid studentId,
|
||||
AttendanceAppealReviewRequest request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var record = await db.AttendanceRecords
|
||||
.Include(r => r.AttendanceSheet)
|
||||
.ThenInclude(s => s!.TeachingTask)
|
||||
.ThenInclude(t => t!.Teachers)
|
||||
.FirstOrDefaultAsync(r =>
|
||||
r.AttendanceSheetId == attendanceSheetId &&
|
||||
r.StudentId == studentId,
|
||||
cancellationToken);
|
||||
if (record is null) return NotFound();
|
||||
if (!CanManageSheet(record.AttendanceSheet!))
|
||||
return Forbid();
|
||||
if (record.AppealStatus != AttendanceAppealStatus.Pending)
|
||||
return ConflictProblem("该申诉不在待处理状态。");
|
||||
|
||||
record.AppealStatus = request.Approve
|
||||
? AttendanceAppealStatus.Approved
|
||||
: AttendanceAppealStatus.Rejected;
|
||||
record.AppealReviewComment = request.Comment?.Trim();
|
||||
record.AppealReviewedAt = DateTime.UtcNow;
|
||||
|
||||
// Update record status on approved appeal
|
||||
if (request.Approve)
|
||||
record.Status = AttendanceStatus.Excused;
|
||||
|
||||
await db.SaveChangesAsync(cancellationToken);
|
||||
|
||||
// Notify student
|
||||
var studentUserId = await db.Students
|
||||
.Where(s => s.Id == studentId)
|
||||
.Select(s => s.UserId)
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
if (studentUserId.HasValue)
|
||||
{
|
||||
var result = request.Approve ? "已通过" : "已驳回";
|
||||
await NotificationService.SendAsync(db, studentUserId.Value,
|
||||
$"考勤申诉{result}",
|
||||
request.Comment is not null
|
||||
? $"您的考勤申诉{result}。意见:{request.Comment}"
|
||||
: $"您的考勤申诉{result}。",
|
||||
null, cancellationToken);
|
||||
}
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpDelete("sheets/{id:guid}")]
|
||||
public async Task<ActionResult> Delete(Guid id, CancellationToken cancellationToken)
|
||||
{
|
||||
@@ -320,6 +535,14 @@ public sealed class AttendanceController(
|
||||
if (scope.Scope == DataScope.All) return source;
|
||||
if (scope.Scope == DataScope.College)
|
||||
return source.Where(x => x.Course!.CollegeId == scope.RestrictedCollegeId);
|
||||
if (scope.IsInRole(SystemRoles.Counselor))
|
||||
{
|
||||
var collegeIds = db.AdministrativeClasses
|
||||
.Where(c => c.CounselorUserId == scope.UserId)
|
||||
.Select(c => c.Major!.CollegeId)
|
||||
.Distinct();
|
||||
return source.Where(x => collegeIds.Contains(x.Course!.CollegeId));
|
||||
}
|
||||
if (scope.IsInRole(SystemRoles.Teacher))
|
||||
return source.Where(x =>
|
||||
x.Teachers.Any(item => item.Teacher!.UserId == scope.UserId));
|
||||
@@ -357,3 +580,11 @@ public sealed record AttendanceRecordRequest(
|
||||
Guid StudentId,
|
||||
AttendanceStatus Status,
|
||||
[MaxLength(300)] string? Notes);
|
||||
|
||||
public sealed record AttendanceAppealRequest(
|
||||
Guid AttendanceSheetId,
|
||||
[Required, MaxLength(500)] string Reason);
|
||||
|
||||
public sealed record AttendanceAppealReviewRequest(
|
||||
bool Approve,
|
||||
[MaxLength(300)] string? Comment);
|
||||
|
||||
@@ -21,6 +21,7 @@ public sealed class GradesController(
|
||||
SystemRoles.SuperAdmin + "," +
|
||||
SystemRoles.AcademicAdmin + "," +
|
||||
SystemRoles.CollegeAdmin + "," +
|
||||
SystemRoles.Counselor + "," +
|
||||
SystemRoles.Teacher;
|
||||
|
||||
private const string Reviewers =
|
||||
@@ -587,6 +588,15 @@ public sealed class GradesController(
|
||||
if (scope.Scope == DataScope.All) return source;
|
||||
if (scope.Scope == DataScope.College)
|
||||
return source.Where(x => x.Course!.CollegeId == scope.RestrictedCollegeId);
|
||||
if (scope.IsInRole(SystemRoles.Counselor))
|
||||
{
|
||||
// Counselor sees grades for courses in their managed classes' college
|
||||
var collegeIds = db.AdministrativeClasses
|
||||
.Where(c => c.CounselorUserId == scope.UserId)
|
||||
.Select(c => c.Major!.CollegeId)
|
||||
.Distinct();
|
||||
return source.Where(x => collegeIds.Contains(x.Course!.CollegeId));
|
||||
}
|
||||
if (scope.IsInRole(SystemRoles.Teacher))
|
||||
return source.Where(x =>
|
||||
x.Teachers.Any(item => item.Teacher!.UserId == scope.UserId));
|
||||
|
||||
@@ -22,6 +22,11 @@ public sealed class AttendanceRecord
|
||||
public Student? Student { get; set; }
|
||||
public AttendanceStatus Status { get; set; } = AttendanceStatus.Present;
|
||||
public string? Notes { get; set; }
|
||||
public AttendanceAppealStatus AppealStatus { get; set; } = AttendanceAppealStatus.None;
|
||||
public string? AppealReason { get; set; }
|
||||
public DateTime? AppealSubmittedAt { get; set; }
|
||||
public string? AppealReviewComment { get; set; }
|
||||
public DateTime? AppealReviewedAt { get; set; }
|
||||
}
|
||||
|
||||
public enum AttendanceSheetStatus
|
||||
@@ -38,3 +43,11 @@ public enum AttendanceStatus
|
||||
Leave = 4,
|
||||
Excused = 5
|
||||
}
|
||||
|
||||
public enum AttendanceAppealStatus
|
||||
{
|
||||
None = 0,
|
||||
Pending = 1,
|
||||
Approved = 2,
|
||||
Rejected = 3
|
||||
}
|
||||
|
||||
@@ -543,6 +543,9 @@ public sealed class AppDbContext(DbContextOptions<AppDbContext> options)
|
||||
{
|
||||
entity.HasKey(x => new { x.AttendanceSheetId, x.StudentId });
|
||||
entity.Property(x => x.Notes).HasMaxLength(300);
|
||||
entity.Property(x => x.AppealReason).HasMaxLength(500);
|
||||
entity.Property(x => x.AppealReviewComment).HasMaxLength(300);
|
||||
entity.HasIndex(x => x.AppealStatus);
|
||||
entity.HasOne(x => x.AttendanceSheet)
|
||||
.WithMany(x => x.Records)
|
||||
.HasForeignKey(x => x.AttendanceSheetId)
|
||||
|
||||
@@ -38,6 +38,8 @@ public sealed class DevelopmentSqliteMigrator(
|
||||
"20260725_21_retake_enrollment";
|
||||
private const string CourseAdjustmentsMigration =
|
||||
"20260725_22_course_adjustments";
|
||||
private const string AttendanceAppealMigration =
|
||||
"20260725_23_attendance_appeal";
|
||||
|
||||
public async Task MigrateAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
@@ -255,6 +257,19 @@ public sealed class DevelopmentSqliteMigrator(
|
||||
CourseAdjustmentsMigration,
|
||||
courseAdjustmentsExist ? [] : CourseAdjustmentsStatements,
|
||||
cancellationToken);
|
||||
|
||||
var attendanceAppealExists = await db.Database
|
||||
.SqlQueryRaw<int>(
|
||||
"""
|
||||
SELECT COUNT(*) AS "Value"
|
||||
FROM pragma_table_info('AttendanceRecords')
|
||||
WHERE name = 'AppealStatus'
|
||||
""")
|
||||
.AnyAsync(value => value > 0, cancellationToken);
|
||||
await ApplyMigrationAsync(
|
||||
AttendanceAppealMigration,
|
||||
attendanceAppealExists ? [] : AttendanceAppealStatements,
|
||||
cancellationToken);
|
||||
}
|
||||
|
||||
private async Task ApplyMigrationAsync(
|
||||
@@ -1553,4 +1568,14 @@ public sealed class DevelopmentSqliteMigrator(
|
||||
"""CREATE INDEX "IX_Notifications_UserId_IsRead" ON "Notifications" ("UserId", "IsRead");""",
|
||||
"""CREATE INDEX "IX_Notifications_CreatedAt" ON "Notifications" ("CreatedAt");"""
|
||||
];
|
||||
|
||||
private static readonly string[] AttendanceAppealStatements =
|
||||
[
|
||||
"""ALTER TABLE "AttendanceRecords" ADD COLUMN "AppealStatus" INTEGER NOT NULL DEFAULT 0;""",
|
||||
"""ALTER TABLE "AttendanceRecords" ADD COLUMN "AppealReason" TEXT NULL;""",
|
||||
"""ALTER TABLE "AttendanceRecords" ADD COLUMN "AppealSubmittedAt" TEXT NULL;""",
|
||||
"""ALTER TABLE "AttendanceRecords" ADD COLUMN "AppealReviewComment" TEXT NULL;""",
|
||||
"""ALTER TABLE "AttendanceRecords" ADD COLUMN "AppealReviewedAt" TEXT NULL;""",
|
||||
"""CREATE INDEX IF NOT EXISTS "IX_AttendanceRecords_AppealStatus" ON "AttendanceRecords" ("AppealStatus");"""
|
||||
];
|
||||
}
|
||||
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Jiaowu.Api.Infrastructure.Persistence.Migrations.MySql
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AttendanceAppeal : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "AppealStatus",
|
||||
table: "AttendanceRecords",
|
||||
type: "int",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "AppealReason",
|
||||
table: "AttendanceRecords",
|
||||
type: "varchar(500)",
|
||||
maxLength: 500,
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<DateTime>(
|
||||
name: "AppealSubmittedAt",
|
||||
table: "AttendanceRecords",
|
||||
type: "datetime(6)",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "AppealReviewComment",
|
||||
table: "AttendanceRecords",
|
||||
type: "varchar(300)",
|
||||
maxLength: 300,
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<DateTime>(
|
||||
name: "AppealReviewedAt",
|
||||
table: "AttendanceRecords",
|
||||
type: "datetime(6)",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_AttendanceRecords_AppealStatus",
|
||||
table: "AttendanceRecords",
|
||||
column: "AppealStatus");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_AttendanceRecords_AppealStatus",
|
||||
table: "AttendanceRecords");
|
||||
|
||||
migrationBuilder.DropColumn(name: "AppealReviewedAt", table: "AttendanceRecords");
|
||||
migrationBuilder.DropColumn(name: "AppealReviewComment", table: "AttendanceRecords");
|
||||
migrationBuilder.DropColumn(name: "AppealSubmittedAt", table: "AttendanceRecords");
|
||||
migrationBuilder.DropColumn(name: "AppealReason", table: "AttendanceRecords");
|
||||
migrationBuilder.DropColumn(name: "AppealStatus", table: "AttendanceRecords");
|
||||
}
|
||||
}
|
||||
}
|
||||
+7
-1
@@ -25,6 +25,7 @@ http.interceptors.response.use(
|
||||
|
||||
export function apiErrorMessage(error: unknown) {
|
||||
if (!axios.isAxiosError(error)) return '操作失败,请稍后重试。'
|
||||
const status = error.response?.status
|
||||
const data = error.response?.data
|
||||
if (data?.errors && typeof data.errors === 'object') {
|
||||
const validationMessage = Object.values(data.errors)
|
||||
@@ -37,7 +38,12 @@ export function apiErrorMessage(error: unknown) {
|
||||
const detail = typeof data?.detail === 'string' ? data.detail.trim() : ''
|
||||
if (detail) return detail
|
||||
const title = typeof data?.title === 'string' ? data.title.trim() : ''
|
||||
return title || '操作失败,请检查网络连接。'
|
||||
if (title) return title
|
||||
if (status === 403) return '您没有权限执行此操作,请联系管理员。'
|
||||
if (status === 404) return '请求的资源不存在。'
|
||||
if (status === 401) return '登录已过期,请重新登录。'
|
||||
if (status && status >= 500) return '服务器繁忙,请稍后重试。'
|
||||
return '操作失败,请检查网络连接。'
|
||||
}
|
||||
|
||||
export default http
|
||||
|
||||
@@ -116,7 +116,8 @@ const navigationGroups = computed<NavigationGroup[]>(() => [
|
||||
),
|
||||
...whenVisible(isStudent.value || isTeacher.value, { path: '/my-timetable', label: isTeacher.value ? '我的授课课表' : '我的课表' }),
|
||||
...whenVisible(isStudent.value, { path: '/free-classrooms', label: '空闲教室' }),
|
||||
...whenVisible(isTeacher.value || isTeachingAdmin.value, { path: '/teacher-attendance', label: '教学点名' }),
|
||||
...whenVisible(isTeacher.value || isTeachingAdmin.value || hasAnyRole(['Counselor']), { path: '/teacher-attendance', label: '教学点名' }),
|
||||
...whenVisible(isStudent.value, { path: '/my-attendance', label: '我的考勤' }),
|
||||
...whenVisible(isTeacher.value, { path: '/teacher-roster', label: '选课名单' }),
|
||||
...whenVisible(!isStudent.value, {
|
||||
path: '/class-timetable',
|
||||
@@ -130,8 +131,8 @@ const navigationGroups = computed<NavigationGroup[]>(() => [
|
||||
},
|
||||
),
|
||||
...whenVisible(
|
||||
hasAnyRole(['SuperAdmin', 'AcademicAdmin', 'CollegeAdmin', 'Teacher', 'Student']),
|
||||
{ path: '/grades', label: isStudent.value ? '学业成绩' : '成绩管理' },
|
||||
hasAnyRole(['SuperAdmin', 'AcademicAdmin', 'CollegeAdmin', 'Teacher', 'Student', 'Counselor']),
|
||||
{ path: '/grades', label: isStudent.value ? '学业成绩' : isTeacher.value ? '成绩录入' : '成绩管理' },
|
||||
),
|
||||
...whenVisible(
|
||||
hasAnyRole(['SuperAdmin', 'AcademicAdmin', 'Teacher', 'Student']),
|
||||
|
||||
@@ -159,7 +159,13 @@ const router = createRouter({
|
||||
path: 'teacher-attendance',
|
||||
name: 'teacher-attendance',
|
||||
component: () => import('../views/TeacherAttendanceView.vue'),
|
||||
meta: { roles: ['SuperAdmin', 'AcademicAdmin', 'CollegeAdmin', 'Teacher'] },
|
||||
meta: { roles: ['SuperAdmin', 'AcademicAdmin', 'CollegeAdmin', 'Teacher', 'Counselor'] },
|
||||
},
|
||||
{
|
||||
path: 'my-attendance',
|
||||
name: 'my-attendance',
|
||||
component: () => import('../views/StudentAttendanceView.vue'),
|
||||
meta: { roles: ['Student'] },
|
||||
},
|
||||
{
|
||||
path: 'free-classrooms',
|
||||
@@ -180,7 +186,7 @@ const router = createRouter({
|
||||
name: 'grades',
|
||||
component: () => import('../views/GradesView.vue'),
|
||||
meta: {
|
||||
roles: ['SuperAdmin', 'AcademicAdmin', 'CollegeAdmin', 'Teacher', 'Student'],
|
||||
roles: ['SuperAdmin', 'AcademicAdmin', 'CollegeAdmin', 'Teacher', 'Student', 'Counselor'],
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { Refresh, Warning } from '@element-plus/icons-vue'
|
||||
import http, { apiErrorMessage } from '../api/http'
|
||||
|
||||
const records = ref<any[]>([])
|
||||
const loading = ref(false)
|
||||
const appealDialog = ref(false)
|
||||
const appealTarget = ref<any>(null)
|
||||
const appealReason = ref('')
|
||||
|
||||
const statusLabels: Record<string, string> = {
|
||||
Present: '出勤', Absent: '缺勤', Late: '迟到', Leave: '请假', Excused: '免修',
|
||||
}
|
||||
const statusColors: Record<string, 'success' | 'danger' | 'warning' | 'info' | undefined> = {
|
||||
Present: 'success', Absent: 'danger', Late: 'warning', Leave: 'info', Excused: undefined,
|
||||
}
|
||||
const appealStatusLabels: Record<string, string> = {
|
||||
None: '', Pending: '申诉中', Approved: '已通过', Rejected: '已驳回',
|
||||
}
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
try { records.value = (await http.get('/attendance/my-records')).data }
|
||||
catch (e) { ElMessage.error(apiErrorMessage(e)) }
|
||||
finally { loading.value = false }
|
||||
}
|
||||
|
||||
function openAppeal(record: any) {
|
||||
appealTarget.value = record
|
||||
appealReason.value = ''
|
||||
appealDialog.value = true
|
||||
}
|
||||
|
||||
async function submitAppeal() {
|
||||
if (!appealReason.value.trim()) { ElMessage.warning('请填写申诉原因'); return }
|
||||
try {
|
||||
await http.post('/attendance/records/appeal', {
|
||||
attendanceSheetId: appealTarget.value.attendanceSheetId,
|
||||
reason: appealReason.value,
|
||||
})
|
||||
appealDialog.value = false
|
||||
ElMessage.success('申诉已提交')
|
||||
await load()
|
||||
} catch (e) { ElMessage.error(apiErrorMessage(e)) }
|
||||
}
|
||||
|
||||
function canAppeal(record: any) {
|
||||
return record.appealStatus === 'None' || record.appealStatus === 'Rejected'
|
||||
}
|
||||
|
||||
onMounted(load)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="page-stack att-page">
|
||||
<section class="page-intro">
|
||||
<div>
|
||||
<span class="section-kicker">ATTENDANCE RECORD</span>
|
||||
<h2>我的考勤</h2>
|
||||
<p>查看所有已提交的考勤记录。对记录有异议可以提交申诉,辅导员将进行审核。</p>
|
||||
</div>
|
||||
<el-button :icon="Refresh" @click="load">刷新</el-button>
|
||||
</section>
|
||||
|
||||
<section v-loading="loading" class="att-list">
|
||||
<article v-for="r in records" :key="`${r.attendanceSheetId}`" class="att-card">
|
||||
<div class="att-info">
|
||||
<span>{{ r.courseCode }} · {{ r.taskNumber }}</span>
|
||||
<h3>{{ r.courseName }}</h3>
|
||||
<p>{{ r.sheetName }} · {{ new Date(r.attendanceDate).toLocaleDateString('zh-CN') }} · {{ r.teacherNames.join('、') }}</p>
|
||||
</div>
|
||||
<div class="att-status">
|
||||
<el-tag :type="statusColors[r.status]" size="small">{{ statusLabels[r.status] }}</el-tag>
|
||||
<span v-if="r.notes" class="att-note">{{ r.notes }}</span>
|
||||
</div>
|
||||
<div class="att-appeal">
|
||||
<template v-if="r.appealStatus !== 'None'">
|
||||
<el-tag size="small" :type="r.appealStatus === 'Pending' ? 'warning' : r.appealStatus === 'Approved' ? 'success' : 'danger'">
|
||||
{{ appealStatusLabels[r.appealStatus] }}
|
||||
</el-tag>
|
||||
<span v-if="r.appealReviewComment" class="att-note">{{ r.appealReviewComment }}</span>
|
||||
</template>
|
||||
<el-button
|
||||
v-if="canAppeal(r) && (r.status === 'Absent' || r.status === 'Late')"
|
||||
size="small"
|
||||
type="warning"
|
||||
:icon="Warning"
|
||||
@click="openAppeal(r)"
|
||||
>申诉</el-button>
|
||||
</div>
|
||||
</article>
|
||||
<el-empty v-if="!records.length" description="暂无考勤记录" />
|
||||
</section>
|
||||
|
||||
<el-dialog v-model="appealDialog" title="考勤申诉" width="500px">
|
||||
<el-form label-position="top">
|
||||
<el-form-item label="申诉原因" required>
|
||||
<el-input v-model="appealReason" type="textarea" :rows="4" maxlength="500" show-word-limit placeholder="请说明您对该考勤记录的异议原因" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="appealDialog = false">取消</el-button>
|
||||
<el-button type="primary" @click="submitAppeal">提交申诉</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.att-list { display: grid; gap: 10px; }
|
||||
.att-card { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 18px; background: #fff; border: 1px solid #e4e7ed; border-radius: 8px; flex-wrap: wrap; }
|
||||
.att-info span { font-size: 11px; color: var(--muted); }
|
||||
.att-info h3 { font-size: 14px; margin: 2px 0; }
|
||||
.att-info p { font-size: 12px; color: var(--muted); margin: 0; }
|
||||
.att-status { display: flex; align-items: center; gap: 8px; }
|
||||
.att-appeal { display: flex; align-items: center; gap: 8px; }
|
||||
.att-note { font-size: 11px; color: var(--muted); max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
</style>
|
||||
Reference in New Issue
Block a user