Files
Academic-Affairs-System/web/src/views/SchedulesView.vue
T

1671 lines
74 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
import { useI18n } from 'vue-i18n'
const { t } = useI18n()
import { computed, onBeforeUnmount, onMounted, reactive, ref } from 'vue'
import { CopyDocument, EditPen, Plus, Promotion, Refresh, Search, Setting } from '@element-plus/icons-vue'
import http, { apiErrorMessage } from '../api/http'
import { academicTermLabel, academicTermOptionClass, defaultAcademicTermId } from '../utils/academicTerms'
const plans = ref<any[]>([])
const selected = ref<any | null>(null)
const terms = ref<any[]>([])
const tasks = ref<any[]>([])
const classrooms = ref<any[]>([])
const campuses = ref<any[]>([])
const buildings = ref<any[]>([])
const timeSlots = ref<any[]>([])
const constraints = ref<any[]>([])
const loading = ref(false)
const detailLoading = ref(false)
const autoJob = ref<any | null>(null)
const publishJob = ref<any | null>(null)
const planDialog = ref(false)
const cloneDialog = ref(false)
const entryDialog = ref(false)
const settingsDrawer = ref(false)
const settingsTab = ref('time')
const constraintDialog = ref(false)
const constraintBatchDialog = ref(false)
const constraintBatchSaving = ref(false)
const editingPlanId = ref('')
const editingEntryId = ref('')
const keyword = ref('')
const termId = ref<string | undefined>()
const planForm = reactive<Record<string, any>>({})
const cloneForm = reactive<Record<string, any>>({})
const revisingPublishedPlan = ref(false)
const entryForm = reactive<Record<string, any>>({})
const constraintForm = reactive<Record<string, any>>({})
const constraintBatchForm = reactive<Record<string, any>>({})
const optimizationSettings = reactive({
teacherSameDayWeight: 120,
classSameDayWeight: 100,
classGapWeight: 240,
consecutiveClassWeight: 60,
earlyPeriodPenalty: 30,
latePeriodPenalty: 30,
roomCapacityWasteWeight: 1,
coursePreferenceWeight: 180,
geneticPopulationSize: 32,
geneticGenerationCount: 80,
geneticMutationRatePercent: 12,
})
const optimizationSaving = ref(false)
const constraintFilters = reactive({
keyword: '',
collegeId: undefined as string | undefined,
schedulingMode: undefined as string | undefined,
classroomMode: undefined as string | undefined,
constraintState: undefined as string | undefined,
})
let autoPollTimer: ReturnType<typeof setTimeout> | undefined
let publishPollTimer: ReturnType<typeof setTimeout> | undefined
const weekdays = computed(() => [
{ value: 1, label: t('schedulesScript.k0') },
{ value: 2, label: t('schedulesScript.k1') },
{ value: 3, label: t('schedulesScript.k2') },
{ value: 4, label: t('schedulesScript.k3') },
{ value: 5, label: t('schedulesScript.k4') },
{ value: 6, label: t('schedulesScript.k5') },
{ value: 7, label: t('schedulesScript.k6') },
])
const experimentVenueNatures = computed(() => [
{ value: 1, label: t('schedulesScript.k7') }, { value: 2, label: t('schedulesScript.k8') },
{ value: 4, label: t('schedulesScript.k9') }, { value: 8, label: t('schedulesScript.k10') },
{ value: 16, label: t('schedulesScript.k11') }, { value: 32, label: t('schedulesScript.k12') },
{ value: 64, label: t('schedulesScript.k13') },
])
const venueNatureValue = (value: unknown) => {
if (typeof value === 'number') return value
if (typeof value !== 'string') return 0
const names: Record<string, number> = {
GeneralClassroom: 1, Laboratory: 2, TrainingRoom: 4, ComputerLab: 8,
LanguageLab: 16, SportsVenue: 32, ArtsVenue: 64,
}
return value.split(',').reduce((sum, name) => sum | (names[name.trim()] ?? 0), 0)
}
const periods = computed(() => {
const configured = timeSlots.value
.filter((item) => item.isEnabled)
.map((item) => item.periodNumber)
return configured.length ? configured : Array.from({ length: 12 }, (_, index) => index + 1)
})
const statusLabels = computed<Record<string, string>>(() => ({
Draft: t('schedulesScript.k14'),
Published: t('schedulesScript.k15'),
Archived: t('schedulesScript.k16'),
}))
const patternLabels = computed<Record<string, string>>(() => ({
All: t('schedulesScript.k17'),
Odd: t('schedulesScript.k18'),
Even: t('schedulesScript.k19'),
}))
const isDraft = computed(() => selected.value?.status === 'Draft')
const autoLoading = computed(() =>
autoJob.value?.status === 'Queued' || autoJob.value?.status === 'Running',
)
const publishLoading = computed(() =>
publishJob.value?.status === 'Queued' || publishJob.value?.status === 'Running',
)
const scheduleJobLoading = computed(() => autoLoading.value || publishLoading.value)
const autoProgress = computed(() => {
if (!autoJob.value?.totalTasks) return 0
return Math.min(
100,
Math.round(autoJob.value.processedTasks / autoJob.value.totalTasks * 100),
)
})
const autoProgressStatus = computed(() => {
if (autoJob.value?.status === 'Succeeded') return 'success'
if (autoJob.value?.status === 'Failed') return 'exception'
return undefined
})
const autoStatusText = computed(() => {
if (!autoJob.value) return ''
if (autoJob.value.status === 'Queued') return t('schedulesScript.k20')
if (autoJob.value.status === 'Running') {
if (autoJob.value.totalGenerations) {
return t('schedulesScript.generation', { current: autoJob.value.currentGeneration, total: autoJob.value.totalGenerations })
}
return t('schedulesScript.processing', { processed: autoJob.value.processedTasks, total: autoJob.value.totalTasks, entries: autoJob.value.createdEntries })
}
if (autoJob.value.status === 'Succeeded') {
return t('schedulesScript.complete', { entries: autoJob.value.createdEntries })
}
return autoJob.value.errorMessage || t('schedulesScript.k21')
})
const publishProgress = computed(() => {
if (!publishJob.value?.totalSteps) return 0
return Math.min(
100,
Math.round(publishJob.value.completedSteps / publishJob.value.totalSteps * 100),
)
})
const publishProgressStatus = computed(() => {
if (publishJob.value?.status === 'Succeeded') return 'success'
if (publishJob.value?.status === 'Failed') return 'exception'
return undefined
})
const publishStatusText = computed(() => {
if (!publishJob.value) return ''
if (publishJob.value.status === 'Queued') return t('schedulesScript.k22')
if (publishJob.value.status === 'Running') {
return publishJob.value.currentStep || t('schedulesScript.k23')
}
if (publishJob.value.status === 'Succeeded') return t('schedulesScript.k24')
return publishJob.value.errorMessage || t('schedulesScript.k25')
})
const selectedTaskConstraint = computed(() =>
constraints.value.find((item) => item.id === entryForm.teachingTaskId),
)
const entryClassrooms = computed(() =>
classrooms.value.filter((room) =>
(entryForm.kind === 'Experiment' || !selectedTaskConstraint.value?.requiredCampusId
|| room.campusId === selectedTaskConstraint.value.requiredCampusId) &&
(entryForm.kind === 'Experiment' || !selectedTaskConstraint.value?.requiredBuildingId
|| room.buildingId === selectedTaskConstraint.value.requiredBuildingId) &&
(entryForm.kind === 'Experiment' || !selectedTaskConstraint.value?.allowedClassroomIds?.length
|| selectedTaskConstraint.value.allowedClassroomIds.includes(room.id)) &&
(entryForm.kind !== 'Experiment' || !selectedTaskConstraint.value?.experimentRequiredCampusId
|| room.campusId === selectedTaskConstraint.value.experimentRequiredCampusId) &&
(entryForm.kind !== 'Experiment' || !selectedTaskConstraint.value?.experimentRequiredBuildingId
|| room.buildingId === selectedTaskConstraint.value.experimentRequiredBuildingId) &&
(entryForm.kind !== 'Experiment' ||
!selectedTaskConstraint.value?.allowedExperimentClassroomIds?.length ||
selectedTaskConstraint.value.allowedExperimentClassroomIds.includes(room.id)),
),
)
const entryWeekdays = computed(() => {
const allowedDays = selectedTaskConstraint.value?.allowedDayOfWeeks ?? []
return allowedDays.length
? weekdays.value.filter((day) => allowedDays.includes(day.value))
: weekdays.value
})
const constraintColleges = computed(() => {
const result = new Map<string, string>()
constraints.value.forEach((item) => result.set(item.collegeId, item.collegeName))
return [...result].map(([id, name]) => ({ id, name })).sort((a, b) =>
a.name.localeCompare(b.name, 'zh-CN'),
)
})
const filteredConstraints = computed(() => {
const text = constraintFilters.keyword.trim().toLowerCase()
return constraints.value.filter((item) => {
const matchesKeyword = !text || [
item.taskNumber,
item.name,
item.courseCode,
item.courseName,
...item.teacherNames,
].some((value) => String(value).toLowerCase().includes(text))
const matchesCollege = !constraintFilters.collegeId ||
item.collegeId === constraintFilters.collegeId
const matchesMode = !constraintFilters.schedulingMode ||
item.schedulingMode === constraintFilters.schedulingMode
const matchesClassroom = !constraintFilters.classroomMode ||
(constraintFilters.classroomMode === 'required'
? item.requiresClassroom
: !item.requiresClassroom)
const matchesState = !constraintFilters.constraintState ||
(constraintFilters.constraintState === 'custom'
? item.hasCustomConstraint
: !item.hasCustomConstraint)
return matchesKeyword && matchesCollege && matchesMode &&
matchesClassroom && matchesState
})
})
const filteredBuildings = computed(() =>
constraintForm.requiredCampusId
? buildings.value.filter((item) => item.campusId === constraintForm.requiredCampusId)
: buildings.value,
)
const filteredClassrooms = computed(() =>
classrooms.value.filter((item) =>
(!constraintForm.requiredCampusId || item.campusId === constraintForm.requiredCampusId) &&
(!constraintForm.requiredBuildingId || item.buildingId === constraintForm.requiredBuildingId),
),
)
const filteredExperimentBuildings = computed(() =>
constraintForm.experimentRequiredCampusId
? buildings.value.filter((item) => item.campusId === constraintForm.experimentRequiredCampusId)
: buildings.value,
)
const filteredExperimentClassrooms = computed(() =>
classrooms.value.filter((item) =>
(!constraintForm.experimentRequiredCampusId ||
item.campusId === constraintForm.experimentRequiredCampusId) &&
(!constraintForm.experimentRequiredBuildingId ||
item.buildingId === constraintForm.experimentRequiredBuildingId) &&
(!(constraintForm.allowedExperimentVenueNatures ?? []).length ||
(venueNatureValue(item.teachingVenueNature) & (constraintForm.allowedExperimentVenueNatures ?? [])
.reduce((value: number, nature: number) => value | nature, 0)) !== 0),
),
)
const batchFilteredBuildings = computed(() =>
constraintBatchForm.requiredCampusId
? buildings.value.filter((item) => item.campusId === constraintBatchForm.requiredCampusId)
: buildings.value,
)
const batchFilteredClassrooms = computed(() =>
classrooms.value.filter((item) =>
(!constraintBatchForm.requiredCampusId ||
item.campusId === constraintBatchForm.requiredCampusId) &&
(!constraintBatchForm.requiredBuildingId ||
item.buildingId === constraintBatchForm.requiredBuildingId),
),
)
const batchFilteredExperimentBuildings = computed(() =>
constraintBatchForm.experimentRequiredCampusId
? buildings.value.filter((item) => item.campusId === constraintBatchForm.experimentRequiredCampusId)
: buildings.value,
)
const batchFilteredExperimentClassrooms = computed(() =>
classrooms.value.filter((item) =>
(!constraintBatchForm.experimentRequiredCampusId ||
item.campusId === constraintBatchForm.experimentRequiredCampusId) &&
(!constraintBatchForm.experimentRequiredBuildingId ||
item.buildingId === constraintBatchForm.experimentRequiredBuildingId) &&
(!(constraintBatchForm.allowedExperimentVenueNatures ?? []).length ||
(venueNatureValue(item.teachingVenueNature) &
(constraintBatchForm.allowedExperimentVenueNatures ?? [])
.reduce((value: number, nature: number) => value | nature, 0)) !== 0),
),
)
const filteredEntries = computed(() => {
const text = keyword.value.trim().toLowerCase()
if (!text) return selected.value?.entries ?? []
return (selected.value?.entries ?? []).filter((entry: any) =>
[
entry.taskNumber,
entry.taskName,
entry.courseCode,
entry.courseName,
entry.classroomName,
...entry.teacherNames,
...entry.classNames,
].some((value) => String(value).toLowerCase().includes(text)),
)
})
function entriesAt(day: number, period: number) {
return filteredEntries.value.filter(
(entry: any) => entry.dayOfWeek === day && entry.startPeriod === period,
)
}
function timeLabel(period: number) {
const slot = timeSlots.value.find((item) => item.periodNumber === period)
return slot ? `${slot.startsAt}—${slot.endsAt}` : t('schedulesScript.period', { period })
}
async function loadSchedulingSettings() {
if (!termId.value) return
try {
const [timeRes, constraintRes, optimizationRes] = await Promise.all([
http.get('/schedules/time-slots', { params: { academicTermId: termId.value } }),
http.get('/schedules/constraints', { params: { academicTermId: termId.value } }),
http.get('/schedules/optimization-settings', { params: { academicTermId: termId.value } }),
])
timeSlots.value = timeRes.data
constraints.value = constraintRes.data
tasks.value = constraintRes.data.filter(
(item: any) => item.schedulingMode === 'Standard',
)
Object.assign(optimizationSettings, optimizationRes.data)
} catch (error) {
ElMessage.error(apiErrorMessage(error))
}
}
async function saveOptimizationSettings() {
if (!termId.value) return
try {
optimizationSaving.value = true
const { data } = await http.put(
`/schedules/optimization-settings/${termId.value}`,
optimizationSettings,
)
Object.assign(optimizationSettings, data)
ElMessage.success(t('schedulesScript.k26'))
} catch (error) {
ElMessage.error(apiErrorMessage(error))
} finally {
optimizationSaving.value = false
}
}
async function changeTerm() {
await Promise.all([loadPlans(false), loadSchedulingSettings()])
}
function initializeTimeSlots() {
const defaults = [
['08:00', '08:45'], ['08:55', '09:40'], ['10:00', '10:45'], ['10:55', '11:40'],
['14:00', '14:45'], ['14:55', '15:40'], ['16:00', '16:45'], ['16:55', '17:40'],
['19:00', '19:45'], ['19:55', '20:40'],
]
timeSlots.value = defaults.map(([startsAt, endsAt], index) => ({
periodNumber: index + 1,
name: `第 ${index + 1} 节`,
startsAt,
endsAt,
isEnabled: true,
}))
}
function addTimeSlot() {
const last = timeSlots.value.at(-1)
timeSlots.value.push({
periodNumber: (last?.periodNumber ?? 0) + 1,
name: `第 ${(last?.periodNumber ?? 0) + 1} 节`,
startsAt: '08:00',
endsAt: '08:45',
isEnabled: true,
})
}
async function saveTimeSlots() {
try {
await http.put(`/schedules/time-slots/${termId.value}`, timeSlots.value)
ElMessage.success(t('schedulesScript.k27'))
await loadSchedulingSettings()
} catch (error) {
ElMessage.error(apiErrorMessage(error))
}
}
function openConstraint(item: any) {
Object.assign(constraintForm, {
teachingTaskId: item.id,
title: `${item.taskNumber} · ${item.name}`,
coursePracticeHours: item.coursePracticeHours,
schedulingMode: item.schedulingMode,
requiresClassroom: item.requiresClassroom,
requiredCampusId: item.requiredCampusId,
requiredBuildingId: item.requiredBuildingId,
experimentRequiredCampusId: item.experimentRequiredCampusId,
experimentRequiredBuildingId: item.experimentRequiredBuildingId,
allowedClassroomIds: [...item.allowedClassroomIds],
allowedExperimentClassroomIds: [...item.allowedExperimentClassroomIds],
allowedExperimentVenueNatures: experimentVenueNatures.value
.filter((nature) => (Number(item.allowedExperimentVenueNatures) & nature.value) !== 0)
.map((nature) => nature.value),
allowedDayOfWeeks: item.allowedDayOfWeeks.length
? [...item.allowedDayOfWeeks]
: [1, 2, 3, 4, 5],
earliestPeriod: item.earliestPeriod,
latestPeriod: item.latestPeriod,
preferredDayOfWeeks: [...(item.preferredDayOfWeeks ?? [])],
preferredEarliestPeriod: item.preferredEarliestPeriod,
preferredLatestPeriod: item.preferredLatestPeriod,
})
constraintDialog.value = true
}
async function saveConstraint() {
try {
const payload = {
schedulingMode: constraintForm.schedulingMode,
requiresClassroom: constraintForm.requiresClassroom,
requiredCampusId: constraintForm.requiredCampusId || null,
requiredBuildingId: constraintForm.requiredBuildingId || null,
experimentRequiredCampusId: constraintForm.experimentRequiredCampusId || null,
experimentRequiredBuildingId: constraintForm.experimentRequiredBuildingId || null,
allowedClassroomIds: constraintForm.allowedClassroomIds ?? [],
allowedExperimentClassroomIds: constraintForm.allowedExperimentClassroomIds ?? [],
allowedExperimentVenueNatures: (constraintForm.allowedExperimentVenueNatures ?? [])
.reduce((value: number, nature: number) => value | nature, 0),
allowedDayOfWeeks: constraintForm.allowedDayOfWeeks ?? [],
earliestPeriod: constraintForm.earliestPeriod || null,
latestPeriod: constraintForm.latestPeriod || null,
preferredDayOfWeeks: constraintForm.preferredDayOfWeeks ?? [],
preferredEarliestPeriod: constraintForm.preferredEarliestPeriod || null,
preferredLatestPeriod: constraintForm.preferredLatestPeriod || null,
}
await http.put(`/schedules/constraints/${constraintForm.teachingTaskId}`, payload)
constraintDialog.value = false
ElMessage.success(t('schedulesScript.k28'))
await loadSchedulingSettings()
} catch (error) {
ElMessage.error(apiErrorMessage(error))
}
}
function resetConstraintFilters() {
Object.assign(constraintFilters, {
keyword: '',
collegeId: undefined,
schedulingMode: undefined,
classroomMode: undefined,
constraintState: undefined,
})
}
function openConstraintBatch() {
if (!filteredConstraints.value.length) {
ElMessage.warning(t('schedulesScript.k29'))
return
}
Object.keys(constraintBatchForm).forEach((key) => delete constraintBatchForm[key])
Object.assign(constraintBatchForm, {
updateSchedulingMode: false,
schedulingMode: 'Standard',
updateRequiresClassroom: false,
requiresClassroom: true,
updateClassroomScope: false,
requiredCampusId: undefined,
requiredBuildingId: undefined,
allowedClassroomIds: [],
updateExperimentClassroomScope: false,
experimentRequiredCampusId: undefined,
experimentRequiredBuildingId: undefined,
allowedExperimentVenueNatures: [],
allowedExperimentClassroomIds: [],
updateDays: false,
allowedDayOfWeeks: [1, 2, 3, 4, 5],
updatePeriodRange: false,
earliestPeriod: undefined,
latestPeriod: undefined,
})
constraintBatchDialog.value = true
}
async function saveConstraintBatch() {
if (!constraintBatchForm.updateSchedulingMode &&
!constraintBatchForm.updateRequiresClassroom &&
!constraintBatchForm.updateClassroomScope &&
!constraintBatchForm.updateExperimentClassroomScope &&
!constraintBatchForm.updateDays &&
!constraintBatchForm.updatePeriodRange) {
ElMessage.warning(t('schedulesScript.k30'))
return
}
const targets = [...filteredConstraints.value]
try {
await ElMessageBox.confirm(
t('schedulesScript.confirmBulk', { count: targets.length }),
t('schedulesScript.k31'),
{ type: 'warning', confirmButtonText: t('schedulesScript.k32'), cancelButtonText: t('schedulesScript.k33') },
)
constraintBatchSaving.value = true
const flexible = constraintBatchForm.updateSchedulingMode &&
constraintBatchForm.schedulingMode === 'Flexible'
const updateClassroomScope = !flexible &&
!(constraintBatchForm.updateRequiresClassroom &&
!constraintBatchForm.requiresClassroom) &&
constraintBatchForm.updateClassroomScope
const updateExperimentClassroomScope = !flexible &&
!(constraintBatchForm.updateRequiresClassroom && !constraintBatchForm.requiresClassroom) &&
constraintBatchForm.updateExperimentClassroomScope
const { data } = await http.put('/schedules/constraints/batch', {
academicTermId: termId.value,
teachingTaskIds: targets.map((item) => item.id),
schedulingMode: constraintBatchForm.updateSchedulingMode
? constraintBatchForm.schedulingMode
: null,
requiresClassroom: !flexible && constraintBatchForm.updateRequiresClassroom
? constraintBatchForm.requiresClassroom
: null,
updateClassroomScope,
requiredCampusId: updateClassroomScope
? constraintBatchForm.requiredCampusId || null
: null,
requiredBuildingId: updateClassroomScope
? constraintBatchForm.requiredBuildingId || null
: null,
allowedClassroomIds: updateClassroomScope
? constraintBatchForm.allowedClassroomIds
: null,
updateExperimentClassroomScope,
experimentRequiredCampusId: updateExperimentClassroomScope
? constraintBatchForm.experimentRequiredCampusId || null
: null,
experimentRequiredBuildingId: updateExperimentClassroomScope
? constraintBatchForm.experimentRequiredBuildingId || null
: null,
allowedExperimentVenueNatures: updateExperimentClassroomScope
? (constraintBatchForm.allowedExperimentVenueNatures ?? [])
.reduce((value: number, nature: number) => value | nature, 0)
: null,
allowedExperimentClassroomIds: updateExperimentClassroomScope
? constraintBatchForm.allowedExperimentClassroomIds
: null,
allowedDayOfWeeks: !flexible && constraintBatchForm.updateDays
? constraintBatchForm.allowedDayOfWeeks
: null,
updatePeriodRange: !flexible && constraintBatchForm.updatePeriodRange,
earliestPeriod: !flexible && constraintBatchForm.updatePeriodRange
? constraintBatchForm.earliestPeriod || null
: null,
latestPeriod: !flexible && constraintBatchForm.updatePeriodRange
? constraintBatchForm.latestPeriod || null
: null,
})
constraintBatchDialog.value = false
ElMessage.success(t('schedulesScript.updated', { count: data.affectedCount }))
await loadSchedulingSettings()
} catch (error: any) {
if (error !== 'cancel' && error !== 'close') ElMessage.error(apiErrorMessage(error))
} finally {
constraintBatchSaving.value = false
}
}
function openManualHandling() {
settingsTab.value = 'constraints'
settingsDrawer.value = true
}
async function autoSchedule() {
try {
await ElMessageBox.confirm(
t('schedulesScript.k34'),
t('schedulesScript.k35'),
{ type: 'warning', confirmButtonText: t('schedulesScript.k36'), cancelButtonText: t('schedulesScript.k33') },
)
const planId = selected.value.id
const { data } = await http.post(`/schedules/plans/${planId}/auto-schedule`)
autoJob.value = data
ElMessage.success(t('schedulesScript.k37'))
scheduleAutoSchedulePoll(data.id, planId)
} catch (error: any) {
if (error !== 'cancel' && error !== 'close') ElMessage.error(apiErrorMessage(error))
}
}
function clearPublishPoll() {
if (publishPollTimer) clearTimeout(publishPollTimer)
publishPollTimer = undefined
}
function schedulePublishPoll(jobId: string, planId: string) {
clearPublishPoll()
publishPollTimer = setTimeout(() => pollPublishJob(jobId, planId), 1000)
}
async function pollPublishJob(jobId: string, planId: string) {
try {
const { data } = await http.get(`/schedules/publish-jobs/${jobId}`)
if (selected.value?.id !== planId) return
publishJob.value = data
if (data.status === 'Queued' || data.status === 'Running') {
schedulePublishPoll(jobId, planId)
return
}
clearPublishPoll()
if (data.status === 'Succeeded') {
ElMessage.success(t('schedulesScript.k38'))
await loadPlans()
} else {
ElMessage.error(data.errorMessage || t('schedulesScript.k39'))
}
} catch {
if (selected.value?.id === planId) {
schedulePublishPoll(jobId, planId)
}
}
}
async function resumePublish(planId: string) {
clearPublishPoll()
publishJob.value = null
const { data } = await http.get(`/schedules/plans/${planId}/publish-job`)
if (selected.value?.id !== planId || !data) return
publishJob.value = data
if (data.status === 'Queued' || data.status === 'Running') {
schedulePublishPoll(data.id, planId)
}
}
function clearAutoSchedulePoll() {
if (autoPollTimer) clearTimeout(autoPollTimer)
autoPollTimer = undefined
}
function scheduleAutoSchedulePoll(jobId: string, planId: string) {
clearAutoSchedulePoll()
autoPollTimer = setTimeout(() => pollAutoScheduleJob(jobId, planId), 1000)
}
async function pollAutoScheduleJob(jobId: string, planId: string) {
try {
const { data } = await http.get(`/schedules/auto-schedule-jobs/${jobId}`)
if (selected.value?.id !== planId) return
autoJob.value = data
if (data.status === 'Queued' || data.status === 'Running') {
scheduleAutoSchedulePoll(jobId, planId)
return
}
clearAutoSchedulePoll()
if (data.status === 'Succeeded') {
await loadDetail(planId, false)
const summary = plans.value.find((item) => item.id === planId)
if (summary) summary.entryCount = selected.value.entries.length
if (data.messages.length) {
ElMessage.warning(
t('schedulesScript.completeManual', { entries: data.createdEntries, tasks: data.messages.length }),
)
} else {
ElMessage.success(t('schedulesScript.complete', { entries: data.createdEntries }))
}
} else {
ElMessage.error(data.errorMessage || t('schedulesScript.k21'))
}
} catch {
if (selected.value?.id === planId) {
scheduleAutoSchedulePoll(jobId, planId)
}
}
}
async function resumeAutoSchedule(planId: string) {
clearAutoSchedulePoll()
autoJob.value = null
const { data } = await http.get(`/schedules/plans/${planId}/auto-schedule-job`)
if (selected.value?.id !== planId || !data) return
autoJob.value = data
scheduleAutoSchedulePoll(data.id, planId)
}
async function loadPlans(keepSelection = true) {
loading.value = true
try {
plans.value = (await http.get('/schedules/plans', {
params: { academicTermId: termId.value },
})).data
const id = keepSelection && selected.value
? selected.value.id
: plans.value[0]?.id
if (id && plans.value.some((item) => item.id === id)) {
await loadDetail(id)
} else {
selected.value = null
clearAutoSchedulePoll()
autoJob.value = null
clearPublishPoll()
publishJob.value = null
}
} catch (error) {
ElMessage.error(apiErrorMessage(error))
} finally {
loading.value = false
}
}
async function loadDetail(id: string, resumeJob = true) {
detailLoading.value = true
try {
selected.value = (await http.get(`/schedules/plans/${id}`)).data
if (resumeJob && selected.value.status === 'Draft') {
await Promise.all([resumeAutoSchedule(id), resumePublish(id)])
} else if (resumeJob) {
clearAutoSchedulePoll()
autoJob.value = null
await resumePublish(id)
}
} catch (error) {
ElMessage.error(apiErrorMessage(error))
} finally {
detailLoading.value = false
}
}
function openPlan(plan?: any) {
editingPlanId.value = plan?.id ?? ''
Object.assign(planForm, {
academicTermId: plan?.academicTermId ?? termId.value,
name: plan?.name ?? '',
version: plan?.version ?? `V${plans.value.length + 1}`,
notes: plan?.notes ?? '',
})
planDialog.value = true
}
async function savePlan() {
if (!planForm.academicTermId || !planForm.name?.trim() || !planForm.version?.trim()) {
ElMessage.warning(t('schedulesScript.k40'))
return
}
try {
if (editingPlanId.value) {
await http.put(`/schedules/plans/${editingPlanId.value}`, planForm)
} else {
await http.post('/schedules/plans', planForm)
}
planDialog.value = false
await loadPlans(false)
} catch (error) {
ElMessage.error(apiErrorMessage(error))
}
}
function openClone() {
revisingPublishedPlan.value = selected.value.status === 'Published'
Object.assign(cloneForm, {
name: `${selected.value.name}(修订版)`,
version: `V${plans.value.length + 1}`,
})
cloneDialog.value = true
}
async function clonePlan() {
try {
const { data } = await http.post(
`/schedules/plans/${selected.value.id}/clone`,
cloneForm,
)
cloneDialog.value = false
ElMessage.success(
revisingPublishedPlan.value
? t('schedulesScript.k41')
: t('schedulesScript.k42'),
)
await loadPlans(false)
if (data.id && selected.value?.id !== data.id) await loadDetail(data.id)
} catch (error) {
ElMessage.error(apiErrorMessage(error))
}
}
async function publishPlan() {
try {
await ElMessageBox.confirm(
t('schedulesScript.k43'),
t('schedulesScript.k44'),
{ type: 'warning', confirmButtonText: t('schedulesScript.k45'), cancelButtonText: t('schedulesScript.k33') },
)
const planId = selected.value.id
const { data } = await http.post(`/schedules/plans/${planId}/publish`)
publishJob.value = data
ElMessage.success(t('schedulesScript.k46'))
schedulePublishPoll(data.id, planId)
} catch (error: any) {
if (error !== 'cancel' && error !== 'close') ElMessage.error(apiErrorMessage(error))
}
}
async function deletePlan() {
try {
await ElMessageBox.confirm(t('schedulesScript.k47'), t('schedulesScript.k48'), {
type: 'warning',
})
await http.delete(`/schedules/plans/${selected.value.id}`)
await loadPlans(false)
} catch (error: any) {
if (error !== 'cancel' && error !== 'close') ElMessage.error(apiErrorMessage(error))
}
}
function openEntry(entry?: any, day?: number, period?: number) {
editingEntryId.value = entry?.id ?? ''
Object.assign(entryForm, {
teachingTaskId: entry?.teachingTaskId,
kind: entry?.kind ?? 'Lecture',
classroomId: entry?.classroomId,
dayOfWeek: entry?.dayOfWeek ?? day ?? 1,
startPeriod: entry?.startPeriod ?? period ?? 1,
periodCount: entry?.periodCount ?? 2,
startWeek: entry?.startWeek ?? 1,
endWeek: entry?.endWeek ?? 16,
weekPattern: entry?.weekPattern ?? 'All',
notes: entry?.notes ?? '',
})
entryDialog.value = true
}
function changeEntryTask() {
if (editingEntryId.value) return
const task = selectedTaskConstraint.value
if (!task) return
entryForm.startWeek = task.startWeek
entryForm.endWeek = task.endWeek
if (task.allowedDayOfWeeks?.length &&
!task.allowedDayOfWeeks.includes(entryForm.dayOfWeek)) {
entryForm.dayOfWeek = task.allowedDayOfWeeks[0]
}
if (task.requiresClassroom === false && entryForm.kind !== 'Experiment') {
entryForm.classroomId = null
return
}
const room = classrooms.value.find((item) => item.id === entryForm.classroomId)
if (room && (
(entryForm.kind !== 'Experiment' && task.requiredCampusId && room.campusId !== task.requiredCampusId) ||
(entryForm.kind !== 'Experiment' && task.requiredBuildingId && room.buildingId !== task.requiredBuildingId) ||
(entryForm.kind !== 'Experiment' && task.allowedClassroomIds?.length && !task.allowedClassroomIds.includes(room.id)) ||
(entryForm.kind === 'Experiment' && task.experimentRequiredCampusId && room.campusId !== task.experimentRequiredCampusId) ||
(entryForm.kind === 'Experiment' && task.experimentRequiredBuildingId && room.buildingId !== task.experimentRequiredBuildingId) ||
(entryForm.kind === 'Experiment' && task.allowedExperimentClassroomIds?.length &&
!task.allowedExperimentClassroomIds.includes(room.id))
)) {
entryForm.classroomId = null
}
}
function changeEntryKind() {
const room = classrooms.value.find((item) => item.id === entryForm.classroomId)
const task = selectedTaskConstraint.value
if (entryForm.kind === 'Experiment' && room && task?.allowedExperimentClassroomIds?.length &&
!task.allowedExperimentClassroomIds.includes(room.id)) {
entryForm.classroomId = null
}
}
async function preflightSchedule() {
try {
const { data } = await http.get(`/schedules/plans/${selected.value.id}/preflight`)
const message = data.unscheduledTasks
? t('schedulesScript.unscheduled', { count: data.unscheduledTasks, messages: data.messages.join('\n') })
: t('schedulesScript.k49')
await ElMessageBox.alert(message, t('schedulesScript.checkTitle', { scheduled: data.scheduledTasks, total: data.totalTasks }), { confirmButtonText: t('schedulesScript.k50') })
} catch (error) { ElMessage.error(apiErrorMessage(error)) }
}
async function saveEntry() {
if (!entryForm.teachingTaskId ||
((entryForm.kind === 'Experiment' ||
selectedTaskConstraint.value?.requiresClassroom !== false) &&
!entryForm.classroomId)) {
ElMessage.warning(t('schedulesScript.k51'))
return
}
const task = selectedTaskConstraint.value
if (task && (
entryForm.startWeek < task.startWeek ||
entryForm.endWeek > task.endWeek
)) {
ElMessage.warning(
t('schedulesScript.weekRange', { start: task.startWeek, end: task.endWeek }),
)
return
}
if (task?.allowedDayOfWeeks?.length &&
!task.allowedDayOfWeeks.includes(entryForm.dayOfWeek)) {
ElMessage.warning(t('schedulesScript.k52'))
return
}
if (entryForm.kind !== 'Experiment' &&
selectedTaskConstraint.value?.requiresClassroom === false) entryForm.classroomId = null
try {
const base = `/schedules/plans/${selected.value.id}/entries`
if (editingEntryId.value) await http.put(`${base}/${editingEntryId.value}`, entryForm)
else await http.post(base, entryForm)
entryDialog.value = false
ElMessage.success(editingEntryId.value ? t('schedulesScript.k53') : t('schedulesScript.k54'))
await loadDetail(selected.value.id)
} catch (error) {
ElMessage.error(apiErrorMessage(error))
}
}
async function deleteEntry(entry: any) {
try {
await ElMessageBox.confirm(t('schedulesScript.remove', { name: entry.taskName }), t('schedulesScript.k55'), {
type: 'warning',
})
await http.delete(`/schedules/plans/${selected.value.id}/entries/${entry.id}`)
await loadDetail(selected.value.id)
} catch (error: any) {
if (error !== 'cancel' && error !== 'close') ElMessage.error(apiErrorMessage(error))
}
}
onMounted(async () => {
const [termRes, classroomRes, campusRes, buildingRes] = await Promise.all([
http.get('/base-data/terms'),
http.get('/base-data/classrooms'),
http.get('/base-data/campuses'),
http.get('/base-data/buildings'),
])
terms.value = termRes.data
classrooms.value = classroomRes.data.filter((item: any) => item.isEnabled)
campuses.value = campusRes.data.filter((item: any) => item.isEnabled)
buildings.value = buildingRes.data.filter((item: any) => item.isEnabled)
termId.value = defaultAcademicTermId(terms.value)
await Promise.all([loadPlans(false), loadSchedulingSettings()])
})
onBeforeUnmount(() => {
clearAutoSchedulePoll()
clearPublishPoll()
})
</script>
<template>
<div class="page-stack">
<section class="page-intro">
<div>
<span class="section-kicker">TIMETABLE BOARD</span>
<h2>{{ t('dashboard.admin.actions.schedules.label') }}</h2>
<p>{{ t('schedulesTemplate.k0') }}</p>
</div>
<div class="page-actions">
<el-button :icon="Setting" @click="settingsDrawer = true">{{ t('schedulesTemplate.k1') }}</el-button>
<el-button type="primary" :icon="Plus" @click="openPlan()">{{ t('schedulesTemplate.k23') }}</el-button>
</div>
</section>
<section class="schedule-toolbar">
<el-select v-model="termId" :placeholder="t('batchBusiness.k16')" @change="changeTerm">
<el-option v-for="item in terms" :key="item.id" :label="academicTermLabel(item)" :value="item.id" :class="academicTermOptionClass(item)" />
</el-select>
<div class="schedule-version-strip">
<button
v-for="plan in plans"
:key="plan.id"
type="button"
:class="{ active: selected?.id === plan.id }"
@click="loadDetail(plan.id)"
>
<b>{{ plan.version }}</b>
<span>{{ statusLabels[plan.status] }}</span>
<small>{{ t('schedulesDynamic.entries', { count: plan.entryCount }) }}</small>
</button>
<span v-if="plans.length === 0">{{ t('schedulesTemplate.k3') }}</span>
</div>
</section>
<section v-if="selected" v-loading="detailLoading" class="schedule-sheet">
<header class="schedule-sheet-head">
<div>
<span>{{ selected.termName }} · {{ selected.version }}</span>
<h3>{{ selected.name }}</h3>
<p>{{ t('schedulesDynamic.entriesStatus', { count: selected.entries.length, status: statusLabels[selected.status] }) }}</p>
</div>
<div class="plan-actions">
<el-button v-if="isDraft" :disabled="scheduleJobLoading" @click="openPlan(selected)">{{ t('schedulesTemplate.k4') }}</el-button>
<el-button
v-if="selected.status === 'Published'"
type="warning"
plain
:icon="EditPen"
@click="openClone"
>
{{ t('schedulesTemplate.k5') }}
</el-button>
<el-button
v-else
:icon="CopyDocument"
:disabled="scheduleJobLoading"
@click="openClone"
>
{{ t('schedulesTemplate.k6') }}
</el-button>
<el-button
v-if="isDraft"
:disabled="scheduleJobLoading"
@click="preflightSchedule"
>
{{ t('schedulesTemplate.k7') }}
</el-button>
<el-button
v-if="isDraft"
type="warning"
plain
:icon="Promotion"
:loading="autoLoading"
:disabled="publishLoading"
@click="autoSchedule"
>
{{ t('operationsBatch.k55') }}
</el-button>
<el-button v-if="isDraft" type="primary" :icon="Plus" :disabled="scheduleJobLoading" @click="openEntry()">{{ t('schedulesTemplate.k8') }}</el-button>
<el-button
v-if="isDraft"
type="success"
:icon="Promotion"
:loading="publishLoading"
:disabled="autoLoading"
@click="publishPlan"
>
{{ publishLoading ? t('schedulesTemplate.k9') : t('schedulesTemplate.k10') }}
</el-button>
<el-button v-if="isDraft" type="danger" plain :disabled="scheduleJobLoading" @click="deletePlan">{{ t('workflowBatch.k1') }}</el-button>
</div>
</header>
<div
v-if="autoJob"
class="auto-schedule-progress"
:class="`is-${String(autoJob.status).toLowerCase()}`"
>
<div>
<b>{{ autoStatusText }}</b>
<span v-if="autoJob.status === 'Running'">
{{ t('schedulesTemplate.k11') }}
</span>
<span v-else-if="autoJob.status === 'Succeeded' && autoJob.messages.length">
{{ t('schedulesDynamic.manual', { count: autoJob.messages.length }) }}
</span>
</div>
<el-progress
:percentage="autoProgress"
:status="autoProgressStatus"
:indeterminate="autoJob.status === 'Queued'"
:duration="2"
/>
<div
v-if="autoJob.status === 'Succeeded' && autoJob.messages.length"
class="auto-schedule-issues"
>
<div class="auto-schedule-issues-head">
<b>{{ t('schedulesTemplate.k12') }}</b>
<el-button size="small" type="warning" plain @click="openManualHandling">
{{ t('schedulesTemplate.k13') }}
</el-button>
</div>
<ol>
<li v-for="message in autoJob.messages" :key="message">{{ message }}</li>
</ol>
</div>
</div>
<div
v-if="publishJob"
class="auto-schedule-progress"
:class="`is-${String(publishJob.status).toLowerCase()}`"
>
<div>
<b>{{ publishStatusText }}</b>
<span v-if="publishLoading">{{ t('schedulesTemplate.k11') }}</span>
<span v-else-if="publishJob.status === 'Failed'">
{{ t('schedulesTemplate.k14') }}
</span>
</div>
<el-progress
:percentage="publishProgress"
:status="publishProgressStatus"
:indeterminate="publishJob.status === 'Queued'"
:duration="2"
/>
</div>
<div class="schedule-search">
<el-input v-model="keyword" :prefix-icon="Search" clearable :placeholder="t('schedulesTemplate.k15')" />
<el-button :icon="Refresh" @click="keyword = ''">{{ t('schedulesTemplate.k16') }}</el-button>
<span>{{ t('schedulesTemplate.k17') }}</span>
</div>
<div class="timetable-scroll">
<div class="timetable-grid">
<div class="timetable-corner">{{ t('attendanceBatch.k117') }}</div>
<div v-for="day in weekdays" :key="day.value" class="timetable-day">{{ day.label }}</div>
<template v-for="period in periods" :key="period">
<div class="timetable-period">
<b>{{ period }}</b>
<span>{{ timeLabel(period) }}</span>
</div>
<div
v-for="day in weekdays"
:key="`${day.value}-${period}`"
class="timetable-cell"
:class="{ editable: isDraft }"
@dblclick="isDraft && openEntry(undefined, day.value, period)"
>
<article
v-for="entry in entriesAt(day.value, period)"
:key="entry.id"
class="schedule-card"
:class="{ readonly: !isDraft, experiment: entry.kind === 'Experiment' }"
@click="isDraft && openEntry(entry)"
>
<span>
{{ entry.kind === 'Experiment' ? t('attendanceBatch.k119') : t('schedulesTemplate.k18') }} ·
{{ entry.courseCode }} · {{ patternLabels[entry.weekPattern] }}
</span>
<b>{{ entry.courseName }}</b>
<small>{{ entry.teacherNames.join('、') }} · {{ entry.classroomName || t('schedulesTemplate.k19') }}</small>
<i>{{ t('schedulesDynamic.weekPeriods', { start: entry.startWeek, end: entry.endWeek, count: entry.periodCount }) }}</i>
<button v-if="isDraft" type="button" @click.stop="deleteEntry(entry)">×</button>
</article>
<span v-if="isDraft && entriesAt(day.value, period).length === 0" class="cell-add">{{ t('schedulesTemplate.k20') }}</span>
</div>
</template>
</div>
</div>
</section>
<el-empty v-else :description="t('schedulesTemplate.k21')" />
<el-dialog v-model="planDialog" :title="editingPlanId ? t('schedulesTemplate.k22') : t('schedulesTemplate.k23')" width="560px">
<el-form label-position="top">
<el-form-item :label="t('businessLabels.term')" required><el-select v-model="planForm.academicTermId"><el-option v-for="item in terms" :key="item.id" :label="academicTermLabel(item)" :value="item.id" :class="academicTermOptionClass(item)" /></el-select></el-form-item>
<el-form-item :label="t('schedulesTemplate.k24')" required><el-input v-model="planForm.name" :placeholder="t('schedulesTemplate.k25')" /></el-form-item>
<el-form-item :label="t('batchBusiness.k14')" required><el-input v-model="planForm.version" :placeholder="t('schedulesDynamic.versionExample')" /></el-form-item>
<el-form-item :label="t('businessLabels.notes')"><el-input v-model="planForm.notes" type="textarea" :rows="2" /></el-form-item>
</el-form>
<template #footer><el-button @click="planDialog = false">{{ t('businessLabels.cancel') }}</el-button><el-button type="primary" @click="savePlan">{{ t('businessLabels.save') }}</el-button></template>
</el-dialog>
<el-dialog
v-model="cloneDialog"
:title="revisingPublishedPlan ? t('schedulesTemplate.k26') : t('schedulesTemplate.k27')"
width="520px"
>
<el-alert
v-if="revisingPublishedPlan"
:title="t('schedulesTemplate.k28')"
type="info"
:closable="false"
show-icon
/>
<el-form label-position="top">
<el-form-item :label="t('schedulesTemplate.k29')" required><el-input v-model="cloneForm.name" /></el-form-item>
<el-form-item :label="t('batchBusiness.k15')" required><el-input v-model="cloneForm.version" /></el-form-item>
</el-form>
<template #footer>
<el-button @click="cloneDialog = false">{{ t('businessLabels.cancel') }}</el-button>
<el-button type="primary" @click="clonePlan">
{{ revisingPublishedPlan ? t('schedulesTemplate.k30') : t('venueManager.copy') }}
</el-button>
</template>
</el-dialog>
<el-dialog v-model="entryDialog" :title="editingEntryId ? t('schedulesTemplate.k31') : t('schedulesTemplate.k8')" width="680px">
<el-form label-position="top">
<el-form-item :label="t('dashboard.teacher.teachingTasks')" required>
<el-select v-model="entryForm.teachingTaskId" filterable @change="changeEntryTask">
<el-option v-for="item in tasks" :key="item.id" :label="`${item.taskNumber} · ${item.name}`" :value="item.id" />
</el-select>
</el-form-item>
<el-form-item :label="t('schedulesTemplate.k32')" required>
<el-radio-group v-model="entryForm.kind" @change="changeEntryKind">
<el-radio-button value="Lecture">{{ t('schedulesTemplate.k18') }}</el-radio-button>
<el-radio-button value="Experiment" :disabled="!selectedTaskConstraint?.coursePracticeHours">
{{ t('attendanceBatch.k119') }}
</el-radio-button>
</el-radio-group>
</el-form-item>
<el-alert
v-if="selectedTaskConstraint"
:title="t('schedulesDynamic.constraint', { total: selectedTaskConstraint.courseTotalHours, theory: selectedTaskConstraint.courseTotalHours - selectedTaskConstraint.coursePracticeHours, practice: selectedTaskConstraint.coursePracticeHours, start: selectedTaskConstraint.startWeek, end: selectedTaskConstraint.endWeek, days: entryWeekdays.map((day) => day.label).join(', ') })"
type="info"
:closable="false"
show-icon
/>
<el-alert
v-if="selectedTaskConstraint?.requiresClassroom === false && entryForm.kind !== 'Experiment'"
:title="t('schedulesTemplate.k33')"
type="info"
:closable="false"
show-icon
/>
<el-form-item
v-else
:label="entryForm.kind === 'Experiment' ? t('classroomReservation.kicker') : t('baseData.classroom')"
required
:hint="selectedTaskConstraint?.requiredBuildingId ? t('schedulesTemplate.k34') : ''"
>
<el-select v-model="entryForm.classroomId" filterable>
<el-option
v-for="item in entryClassrooms"
:key="item.id"
:label="t('schedulesDynamic.roomFull', { campus: item.campusName, building: item.buildingName, name: item.name, type: item.roomType, capacity: item.capacity })"
:value="item.id"
/>
</el-select>
</el-form-item>
<div class="form-grid three">
<el-form-item :label="t('freeClassrooms.weekday')"><el-select v-model="entryForm.dayOfWeek"><el-option v-for="day in entryWeekdays" :key="day.value" :label="day.label" :value="day.value" /></el-select></el-form-item>
<el-form-item :label="t('freeClassrooms.startPeriod')">
<el-select v-model="entryForm.startPeriod">
<el-option
v-for="period in periods"
:key="period"
:label="t('schedulesDynamic.periodTime', { period, time: timeLabel(period) })"
:value="period"
/>
</el-select>
</el-form-item>
<el-form-item :label="t('freeClassrooms.periodCount')"><el-input-number v-model="entryForm.periodCount" :min="1" :max="6" /></el-form-item>
</div>
<div class="form-grid three">
<el-form-item :label="t('batchBusiness.k41')"><el-input-number v-model="entryForm.startWeek" :min="1" :max="30" /></el-form-item>
<el-form-item :label="t('batchBusiness.k42')"><el-input-number v-model="entryForm.endWeek" :min="1" :max="30" /></el-form-item>
<el-form-item :label="t('schedulesTemplate.k35')"><el-select v-model="entryForm.weekPattern"><el-option v-for="(label, value) in patternLabels" :key="value" :label="label" :value="value" /></el-select></el-form-item>
</div>
<el-form-item :label="t('businessLabels.notes')"><el-input v-model="entryForm.notes" type="textarea" :rows="2" /></el-form-item>
</el-form>
<template #footer><el-button @click="entryDialog = false">{{ t('businessLabels.cancel') }}</el-button><el-button type="primary" @click="saveEntry">{{ t('schedulesTemplate.k36') }}</el-button></template>
</el-dialog>
<el-drawer v-model="settingsDrawer" :title="t('schedulesTemplate.k1')" size="760px" class="schedule-settings-drawer">
<el-tabs v-model="settingsTab">
<el-tab-pane :label="t('schedulesTemplate.k37')" name="time">
<div class="settings-lead">
<div>
<b>{{ t('schedulesTemplate.k37') }}</b>
<span>{{ t('schedulesTemplate.k38') }}</span>
</div>
<div>
<el-button v-if="!timeSlots.length" @click="initializeTimeSlots">{{ t('schedulesTemplate.k39') }}</el-button>
<el-button @click="addTimeSlot">{{ t('schedulesTemplate.k40') }}</el-button>
<el-button type="primary" @click="saveTimeSlots">{{ t('schedulesTemplate.k41') }}</el-button>
</div>
</div>
<el-table :data="timeSlots" class="settings-table">
<el-table-column :label="t('attendanceBatch.k117')" width="100">
<template #default="{ row }"><el-input-number v-model="row.periodNumber" :min="1" :max="30" controls-position="right" /></template>
</el-table-column>
<el-table-column :label="t('baseData.name')" min-width="130">
<template #default="{ row }"><el-input v-model="row.name" /></template>
</el-table-column>
<el-table-column :label="t('schedulesTemplate.k42')" width="130">
<template #default="{ row }"><el-time-select v-model="row.startsAt" start="06:00" step="00:05" end="23:00" /></template>
</el-table-column>
<el-table-column :label="t('schedulesTemplate.k43')" width="130">
<template #default="{ row }"><el-time-select v-model="row.endsAt" start="06:00" step="00:05" end="23:00" /></template>
</el-table-column>
<el-table-column :label="t('schedulesTemplate.k44')" width="90">
<template #default="{ row }"><el-switch v-model="row.isEnabled" /></template>
</el-table-column>
<el-table-column width="60">
<template #default="{ $index }"><el-button link type="danger" @click="timeSlots.splice($index, 1)">{{ t('businessLabels.remove') }}</el-button></template>
</el-table-column>
</el-table>
</el-tab-pane>
<el-tab-pane :label="t('schedulesTemplate.k45')" name="optimization">
<div class="settings-lead">
<div>
<b>{{ t('schedulesTemplate.k46') }}</b>
<span>{{ t('schedulesTemplate.k47') }}</span>
</div>
<el-button type="primary" :loading="optimizationSaving" @click="saveOptimizationSettings">
{{ t('schedulesTemplate.k48') }}
</el-button>
</div>
<el-alert
:title="t('schedulesTemplate.k49')"
type="info"
:closable="false"
show-icon
/>
<el-form label-position="top" class="optimization-form">
<div class="form-grid">
<el-form-item :label="t('schedulesTemplate.k50')">
<el-input-number v-model="optimizationSettings.teacherSameDayWeight" :min="0" :max="10000" />
<small class="field-hint">{{ t('schedulesTemplate.k51') }}</small>
</el-form-item>
<el-form-item :label="t('schedulesTemplate.k52')">
<el-input-number v-model="optimizationSettings.classSameDayWeight" :min="0" :max="10000" />
<small class="field-hint">{{ t('schedulesTemplate.k53') }}</small>
</el-form-item>
<el-form-item :label="t('schedulesTemplate.k54')">
<el-input-number v-model="optimizationSettings.classGapWeight" :min="0" :max="10000" />
<small class="field-hint">{{ t('schedulesTemplate.k55') }}</small>
</el-form-item>
<el-form-item :label="t('schedulesTemplate.k56')">
<el-input-number v-model="optimizationSettings.consecutiveClassWeight" :min="0" :max="10000" />
<small class="field-hint">{{ t('schedulesTemplate.k57') }}</small>
</el-form-item>
<el-form-item :label="t('schedulesTemplate.k58')">
<el-input-number v-model="optimizationSettings.earlyPeriodPenalty" :min="0" :max="10000" />
<small class="field-hint">{{ t('schedulesTemplate.k59') }}</small>
</el-form-item>
<el-form-item :label="t('schedulesTemplate.k60')">
<el-input-number v-model="optimizationSettings.latePeriodPenalty" :min="0" :max="10000" />
<small class="field-hint">{{ t('schedulesTemplate.k61') }}</small>
</el-form-item>
<el-form-item :label="t('schedulesTemplate.k62')">
<el-input-number v-model="optimizationSettings.roomCapacityWasteWeight" :min="0" :max="10000" />
<small class="field-hint">{{ t('schedulesTemplate.k63') }}</small>
</el-form-item>
<el-form-item :label="t('schedulesTemplate.k64')">
<el-input-number v-model="optimizationSettings.coursePreferenceWeight" :min="0" :max="10000" />
<small class="field-hint">{{ t('schedulesTemplate.k65') }}</small>
</el-form-item>
<el-form-item :label="t('schedulesTemplate.k66')">
<el-input-number v-model="optimizationSettings.geneticPopulationSize" :min="12" :max="64" />
<small class="field-hint">{{ t('schedulesTemplate.k67') }}</small>
</el-form-item>
<el-form-item :label="t('schedulesTemplate.k68')">
<el-input-number v-model="optimizationSettings.geneticGenerationCount" :min="12" :max="160" />
<small class="field-hint">{{ t('schedulesTemplate.k69') }}</small>
</el-form-item>
<el-form-item :label="t('schedulesTemplate.k70')">
<el-input-number v-model="optimizationSettings.geneticMutationRatePercent" :min="1" :max="50" />
<small class="field-hint">{{ t('schedulesTemplate.k71') }}</small>
</el-form-item>
</div>
</el-form>
</el-tab-pane>
<el-tab-pane :label="t('schedulesTemplate.k72')" name="constraints">
<div class="settings-lead">
<div>
<b>{{ t('schedulesTemplate.k72') }}</b>
<span>{{ t('schedulesTemplate.k73') }}</span>
</div>
<div>
<el-button @click="resetConstraintFilters">{{ t('schedulesTemplate.k74') }}</el-button>
<el-button
type="primary"
:disabled="!filteredConstraints.length"
@click="openConstraintBatch"
>{{ t('schedulesDynamic.bulkTitle', { count: filteredConstraints.length }) }}</el-button>
</div>
</div>
<div class="constraint-filter-grid">
<el-input
v-model="constraintFilters.keyword"
clearable
:placeholder="t('schedulesTemplate.k75')"
:prefix-icon="Search"
/>
<el-select v-model="constraintFilters.collegeId" clearable :placeholder="t('batchBusiness.k1')">
<el-option v-for="item in constraintColleges" :key="item.id" :label="item.name" :value="item.id" />
</el-select>
<el-select v-model="constraintFilters.schedulingMode" clearable :placeholder="t('schedulesTemplate.k76')">
<el-option :label="t('workflowBatch.k23')" value="Standard" />
<el-option :label="t('workflowBatch.k2')" value="Flexible" />
</el-select>
<el-select v-model="constraintFilters.classroomMode" clearable :placeholder="t('schedulesTemplate.k77')">
<el-option :label="t('schedulesTemplate.k78')" value="required" />
<el-option :label="t('schedulesTemplate.k79')" value="not-required" />
</el-select>
<el-select v-model="constraintFilters.constraintState" clearable :placeholder="t('schedulesTemplate.k80')">
<el-option :label="t('schedulesTemplate.k81')" value="custom" />
<el-option :label="t('schedulesTemplate.k82')" value="default" />
</el-select>
</div>
<div class="constraint-result-summary">
{{ t('schedulesDynamic.taskCounts', { total: constraints.length, shown: filteredConstraints.length }) }}
</div>
<div class="constraint-list">
<article v-for="item in filteredConstraints" :key="item.id">
<div>
<span>{{ t('schedulesDynamic.weeklyHours', { number: item.taskNumber, hours: item.weeklyHours }) }}</span>
<b>{{ item.name }} · {{ item.courseName }}</b>
<small>{{ item.collegeName }} · {{ item.teacherNames.join('、') || t('schedulesTemplate.k83') }} · {{ item.capacity }} {{ t('graduationAudits.people') }}</small>
</div>
<div class="constraint-badges">
<el-tag v-if="item.schedulingMode === 'Flexible'" type="success">{{ t('workflowBatch.k2') }}</el-tag>
<el-tag :type="item.requiresClassroom ? 'primary' : 'info'">
{{ item.requiresClassroom ? t('schedulesTemplate.k84') : t('schedulesTemplate.k79') }}
</el-tag>
<el-tag v-if="item.requiredBuildingId" type="warning">{{ t('schedulesTemplate.k85') }}</el-tag>
<el-tag v-if="item.allowedClassroomIds.length" type="warning">
{{ t('schedulesDynamic.specifiedRooms', { count: item.allowedClassroomIds.length }) }}
</el-tag>
</div>
<el-button @click="openConstraint(item)">{{ t('schedulesTemplate.k86') }}</el-button>
</article>
<el-empty v-if="!filteredConstraints.length" :description="t('schedulesTemplate.k87')" />
</div>
</el-tab-pane>
</el-tabs>
</el-drawer>
<el-dialog v-model="constraintDialog" :title="t('schedulesTemplate.k88')" width="720px">
<div class="constraint-title">{{ constraintForm.title }}</div>
<el-form label-position="top">
<el-form-item :label="t('batchBusiness.k40')">
<el-radio-group v-model="constraintForm.schedulingMode">
<el-radio-button value="Standard">{{ t('workflowBatch.k23') }}</el-radio-button>
<el-radio-button value="Flexible">{{ t('workflowBatch.k2') }}</el-radio-button>
</el-radio-group>
<small class="field-hint">{{ t('schedulesTemplate.k89') }}</small>
</el-form-item>
<template v-if="constraintForm.schedulingMode === 'Standard'">
<el-form-item>
<el-switch
v-model="constraintForm.requiresClassroom"
:active-text="t('schedulesTemplate.k90')"
in:active-text="t('schedulesTemplate.k19')"
/>
</el-form-item>
<template v-if="constraintForm.requiresClassroom">
<div class="form-grid">
<el-form-item :label="t('schedulesTemplate.k91')">
<el-select v-model="constraintForm.requiredCampusId" clearable @change="constraintForm.requiredBuildingId = undefined; constraintForm.allowedClassroomIds = []">
<el-option v-for="item in campuses" :key="item.id" :label="item.name" :value="item.id" />
</el-select>
</el-form-item>
<el-form-item :label="t('schedulesTemplate.k85')">
<el-select v-model="constraintForm.requiredBuildingId" clearable @change="constraintForm.allowedClassroomIds = []">
<el-option v-for="item in filteredBuildings" :key="item.id" :label="item.name" :value="item.id" />
</el-select>
</el-form-item>
</div>
<el-form-item :label="t('schedulesTemplate.k92')">
<el-select v-model="constraintForm.allowedClassroomIds" multiple filterable collapse-tags>
<el-option
v-for="item in filteredClassrooms"
:key="item.id"
:label="t('schedulesDynamic.room', { building: item.buildingName, name: item.name, capacity: item.capacity })"
:value="item.id"
/>
</el-select>
</el-form-item>
<el-form-item :label="t('schedulesTemplate.k93')">
<el-checkbox-group v-model="constraintForm.allowedExperimentVenueNatures">
<el-checkbox v-for="nature in experimentVenueNatures" :key="nature.value" :value="nature.value">{{ nature.label }}</el-checkbox>
</el-checkbox-group>
<small class="field-hint">{{ t('schedulesTemplate.k94') }}</small>
</el-form-item>
<section v-if="constraintForm.coursePracticeHours" class="experiment-classroom-scope">
<div class="experiment-classroom-scope__title">{{ t('schedulesTemplate.k95') }}</div>
<div class="form-grid">
<el-form-item :label="t('schedulesTemplate.k96')">
<el-select v-model="constraintForm.experimentRequiredCampusId" clearable @change="constraintForm.experimentRequiredBuildingId = undefined; constraintForm.allowedExperimentClassroomIds = []">
<el-option v-for="item in campuses" :key="item.id" :label="item.name" :value="item.id" />
</el-select>
</el-form-item>
<el-form-item :label="t('schedulesTemplate.k97')">
<el-select v-model="constraintForm.experimentRequiredBuildingId" clearable @change="constraintForm.allowedExperimentClassroomIds = []">
<el-option v-for="item in filteredExperimentBuildings" :key="item.id" :label="item.name" :value="item.id" />
</el-select>
</el-form-item>
</div>
<el-form-item :label="t('schedulesTemplate.k95')">
<el-select v-model="constraintForm.allowedExperimentClassroomIds" multiple filterable collapse-tags>
<el-option
v-for="item in filteredExperimentClassrooms"
:key="item.id"
:label="t('schedulesDynamic.roomType', { building: item.buildingName, name: item.name, type: item.roomType, capacity: item.capacity })"
:value="item.id"
/>
</el-select>
<small class="field-hint">{{ t('schedulesTemplate.k98') }}</small>
</el-form-item>
</section>
</template>
<el-form-item :label="t('schedulesTemplate.k99')">
<el-checkbox-group v-model="constraintForm.allowedDayOfWeeks">
<el-checkbox v-for="day in weekdays" :key="day.value" :value="day.value">{{ day.label }}</el-checkbox>
</el-checkbox-group>
</el-form-item>
<div class="form-grid">
<el-form-item :label="t('schedulesTemplate.k100')">
<el-select v-model="constraintForm.earliestPeriod" clearable>
<el-option v-for="period in periods" :key="period" :label="t('schedulesDynamic.periodTime', { period, time: timeLabel(period) })" :value="period" />
</el-select>
</el-form-item>
<el-form-item :label="t('schedulesTemplate.k101')">
<el-select v-model="constraintForm.latestPeriod" clearable>
<el-option v-for="period in periods" :key="period" :label="t('schedulesDynamic.periodTime', { period, time: timeLabel(period) })" :value="period" />
</el-select>
</el-form-item>
</div>
<el-divider content-position="left">{{ t('schedulesTemplate.k102') }}</el-divider>
<el-form-item :label="t('schedulesTemplate.k103')">
<el-checkbox-group v-model="constraintForm.preferredDayOfWeeks">
<el-checkbox v-for="day in weekdays" :key="day.value" :value="day.value">{{ day.label }}</el-checkbox>
</el-checkbox-group>
<small class="field-hint">{{ t('schedulesTemplate.k104') }}</small>
</el-form-item>
<div class="form-grid">
<el-form-item :label="t('schedulesTemplate.k105')">
<el-select v-model="constraintForm.preferredEarliestPeriod" clearable>
<el-option v-for="period in periods" :key="period" :label="t('schedulesDynamic.periodTime', { period, time: timeLabel(period) })" :value="period" />
</el-select>
</el-form-item>
<el-form-item :label="t('schedulesTemplate.k106')">
<el-select v-model="constraintForm.preferredLatestPeriod" clearable>
<el-option v-for="period in periods" :key="period" :label="t('schedulesDynamic.periodTime', { period, time: timeLabel(period) })" :value="period" />
</el-select>
</el-form-item>
</div>
</template>
</el-form>
<template #footer>
<el-button @click="constraintDialog = false">{{ t('businessLabels.cancel') }}</el-button>
<el-button type="primary" @click="saveConstraint">{{ t('schedulesTemplate.k107') }}</el-button>
</template>
</el-dialog>
<el-dialog v-model="constraintBatchDialog" :title="t('schedulesTemplate.k108')" width="720px">
<div class="constraint-title">
{{ t('schedulesDynamic.affects', { count: filteredConstraints.length }) }}
</div>
<el-alert
:title="t('schedulesTemplate.k109')"
type="info"
:closable="false"
show-icon
/>
<el-form label-position="top" class="constraint-batch-form">
<el-checkbox v-model="constraintBatchForm.updateSchedulingMode">{{ t('schedulesTemplate.k110') }}</el-checkbox>
<el-form-item v-if="constraintBatchForm.updateSchedulingMode" :label="t('schedulesTemplate.k111')">
<el-radio-group v-model="constraintBatchForm.schedulingMode">
<el-radio-button value="Standard">{{ t('workflowBatch.k23') }}</el-radio-button>
<el-radio-button value="Flexible">{{ t('workflowBatch.k2') }}</el-radio-button>
</el-radio-group>
</el-form-item>
<template v-if="!(constraintBatchForm.updateSchedulingMode && constraintBatchForm.schedulingMode === 'Flexible')">
<el-checkbox v-model="constraintBatchForm.updateRequiresClassroom">{{ t('schedulesTemplate.k112') }}</el-checkbox>
<el-form-item v-if="constraintBatchForm.updateRequiresClassroom" :label="t('schedulesTemplate.k113')">
<el-switch
v-model="constraintBatchForm.requiresClassroom"
:active-text="t('schedulesTemplate.k90')"
in:active-text="t('schedulesTemplate.k19')"
@change="!constraintBatchForm.requiresClassroom && (constraintBatchForm.updateClassroomScope = false)"
/>
</el-form-item>
<template v-if="!(constraintBatchForm.updateRequiresClassroom && !constraintBatchForm.requiresClassroom)">
<el-checkbox v-model="constraintBatchForm.updateClassroomScope">
{{ t('schedulesTemplate.k114') }}
</el-checkbox>
<div v-if="constraintBatchForm.updateClassroomScope" class="batch-classroom-scope">
<el-alert
:title="t('schedulesTemplate.k115')"
type="warning"
:closable="false"
show-icon
/>
<div class="form-grid">
<el-form-item :label="t('schedulesTemplate.k116')">
<el-select
v-model="constraintBatchForm.requiredCampusId"
clearable
@change="constraintBatchForm.requiredBuildingId = undefined; constraintBatchForm.allowedClassroomIds = []"
>
<el-option v-for="item in campuses" :key="item.id" :label="item.name" :value="item.id" />
</el-select>
</el-form-item>
<el-form-item :label="t('schedulesTemplate.k117')">
<el-select
v-model="constraintBatchForm.requiredBuildingId"
clearable
@change="constraintBatchForm.allowedClassroomIds = []"
>
<el-option v-for="item in batchFilteredBuildings" :key="item.id" :label="item.name" :value="item.id" />
</el-select>
</el-form-item>
</div>
<el-form-item :label="t('schedulesTemplate.k118')">
<el-select
v-model="constraintBatchForm.allowedClassroomIds"
multiple
filterable
collapse-tags
collapse-tags-tooltip
:placeholder="t('schedulesTemplate.k119')"
>
<el-option
v-for="item in batchFilteredClassrooms"
:key="item.id"
:label="t('schedulesDynamic.room', { building: item.buildingName, name: item.name, capacity: item.capacity })"
:value="item.id"
/>
</el-select>
</el-form-item>
</div>
</template>
<el-checkbox v-model="constraintBatchForm.updateExperimentClassroomScope">
{{ t('schedulesTemplate.k120') }}
</el-checkbox>
<div v-if="constraintBatchForm.updateExperimentClassroomScope" class="batch-classroom-scope">
<el-alert
:title="t('schedulesTemplate.k121')"
type="warning"
:closable="false"
show-icon
/>
<el-form-item :label="t('schedulesTemplate.k122')">
<el-checkbox-group v-model="constraintBatchForm.allowedExperimentVenueNatures">
<el-checkbox v-for="nature in experimentVenueNatures" :key="nature.value" :value="nature.value">{{ nature.label }}</el-checkbox>
</el-checkbox-group>
</el-form-item>
<div class="form-grid">
<el-form-item :label="t('schedulesTemplate.k123')">
<el-select
v-model="constraintBatchForm.experimentRequiredCampusId"
clearable
@change="constraintBatchForm.experimentRequiredBuildingId = undefined; constraintBatchForm.allowedExperimentClassroomIds = []"
>
<el-option v-for="item in campuses" :key="item.id" :label="item.name" :value="item.id" />
</el-select>
</el-form-item>
<el-form-item :label="t('schedulesTemplate.k124')">
<el-select
v-model="constraintBatchForm.experimentRequiredBuildingId"
clearable
@change="constraintBatchForm.allowedExperimentClassroomIds = []"
>
<el-option v-for="item in batchFilteredExperimentBuildings" :key="item.id" :label="item.name" :value="item.id" />
</el-select>
</el-form-item>
</div>
<el-form-item :label="t('schedulesTemplate.k125')">
<el-select v-model="constraintBatchForm.allowedExperimentClassroomIds" multiple filterable collapse-tags :placeholder="t('schedulesTemplate.k126')">
<el-option
v-for="item in batchFilteredExperimentClassrooms"
:key="item.id"
:label="t('schedulesDynamic.roomType', { building: item.buildingName, name: item.name, type: item.roomType, capacity: item.capacity })"
:value="item.id"
/>
</el-select>
</el-form-item>
</div>
<el-checkbox v-model="constraintBatchForm.updateDays">{{ t('schedulesTemplate.k127') }}</el-checkbox>
<el-form-item v-if="constraintBatchForm.updateDays" :label="t('schedulesTemplate.k128')">
<el-checkbox-group v-model="constraintBatchForm.allowedDayOfWeeks">
<el-checkbox v-for="day in weekdays" :key="day.value" :value="day.value">{{ day.label }}</el-checkbox>
</el-checkbox-group>
</el-form-item>
<el-checkbox v-model="constraintBatchForm.updatePeriodRange">{{ t('schedulesTemplate.k129') }}</el-checkbox>
<div v-if="constraintBatchForm.updatePeriodRange" class="form-grid">
<el-form-item :label="t('schedulesTemplate.k130')">
<el-select v-model="constraintBatchForm.earliestPeriod" clearable>
<el-option v-for="period in periods" :key="period" :label="t('schedulesDynamic.period', { period })" :value="period" />
</el-select>
</el-form-item>
<el-form-item :label="t('schedulesTemplate.k131')">
<el-select v-model="constraintBatchForm.latestPeriod" clearable>
<el-option v-for="period in periods" :key="period" :label="t('schedulesDynamic.period', { period })" :value="period" />
</el-select>
</el-form-item>
</div>
</template>
</el-form>
<template #footer>
<el-button @click="constraintBatchDialog = false">{{ t('businessLabels.cancel') }}</el-button>
<el-button type="primary" :loading="constraintBatchSaving" @click="saveConstraintBatch">
{{ t('schedulesTemplate.k132') }}
</el-button>
</template>
</el-dialog>
</div>
</template>