支持为同一学期、同一课程的多个教学任务批量创建相同实验项目。
新增批量排课表,可为多个实验项目分别设置日期、节次、实验室和容量。 批量排课采用原子事务:任一项目发生教室、教师、班级或课表冲突,整批不写入。 已发布项目批量新增场次时,继续按原逻辑通知学生。 后端继续执行管理范围、教学任务状态、开放日期和容量校验。 页面在 390px 手机宽度下无横向溢出。
This commit is contained in:
@@ -27,7 +27,7 @@ const statusFilter = ref('')
|
||||
const projectDialog = ref(false)
|
||||
const editingProjectId = ref('')
|
||||
const projectForm = reactive({
|
||||
teachingTaskId: '',
|
||||
teachingTaskIds: [] as string[],
|
||||
code: '',
|
||||
name: '',
|
||||
arrangementMode: 'Centralized',
|
||||
@@ -47,13 +47,20 @@ const sessionForm = reactive({
|
||||
notes: '',
|
||||
})
|
||||
|
||||
const batchSessionDialog = ref(false)
|
||||
const batchSessionProjectIds = ref<string[]>([])
|
||||
const batchSessionRows = ref<any[]>([])
|
||||
|
||||
const participantsDialog = ref(false)
|
||||
const participantSession = ref<any>(null)
|
||||
const participants = ref<any[]>([])
|
||||
const participantsLoading = ref(false)
|
||||
|
||||
const selectedTask = computed(() =>
|
||||
options.tasks.find((task) => task.id === projectForm.teachingTaskId),
|
||||
options.tasks.find((task) => task.id === projectForm.teachingTaskIds[0]),
|
||||
)
|
||||
const batchProjectOptions = computed(() =>
|
||||
projects.value.filter((project) => project.status !== 'Closed'),
|
||||
)
|
||||
const activePeriods = computed(() =>
|
||||
options.periods.filter((period) =>
|
||||
@@ -82,7 +89,7 @@ const statusLabels: Record<string, string> = {
|
||||
function resetProjectForm() {
|
||||
editingProjectId.value = ''
|
||||
Object.assign(projectForm, {
|
||||
teachingTaskId: '',
|
||||
teachingTaskIds: [],
|
||||
code: '',
|
||||
name: '',
|
||||
arrangementMode: 'Centralized',
|
||||
@@ -106,7 +113,7 @@ function openCreateProject() {
|
||||
function openEditProject(project: any) {
|
||||
editingProjectId.value = project.id
|
||||
Object.assign(projectForm, {
|
||||
teachingTaskId: project.teachingTaskId,
|
||||
teachingTaskIds: [project.teachingTaskId],
|
||||
code: project.code,
|
||||
name: project.name,
|
||||
arrangementMode: project.arrangementMode,
|
||||
@@ -118,13 +125,13 @@ function openEditProject(project: any) {
|
||||
}
|
||||
|
||||
async function saveProject() {
|
||||
if (!projectForm.teachingTaskId || !projectForm.code.trim()
|
||||
if (!projectForm.teachingTaskIds.length || !projectForm.code.trim()
|
||||
|| !projectForm.name.trim() || projectForm.dates.length !== 2) {
|
||||
ElMessage.warning('请填写教学任务、项目编码、名称和开放日期')
|
||||
return
|
||||
}
|
||||
const payload = {
|
||||
teachingTaskId: projectForm.teachingTaskId,
|
||||
teachingTaskId: projectForm.teachingTaskIds[0],
|
||||
code: projectForm.code,
|
||||
name: projectForm.name,
|
||||
arrangementMode: projectForm.arrangementMode,
|
||||
@@ -138,8 +145,12 @@ async function saveProject() {
|
||||
await http.put(`/experiments/${editingProjectId.value}`, payload)
|
||||
ElMessage.success('实验项目已更新')
|
||||
} else {
|
||||
await http.post('/experiments', payload)
|
||||
ElMessage.success('实验项目已创建')
|
||||
await http.post('/experiments/batch', {
|
||||
...payload,
|
||||
teachingTaskId: undefined,
|
||||
teachingTaskIds: projectForm.teachingTaskIds,
|
||||
})
|
||||
ElMessage.success(`已为 ${projectForm.teachingTaskIds.length} 个教学任务创建实验项目`)
|
||||
}
|
||||
projectDialog.value = false
|
||||
await load()
|
||||
@@ -148,6 +159,78 @@ async function saveProject() {
|
||||
}
|
||||
}
|
||||
|
||||
function openBatchSession() {
|
||||
batchSessionProjectIds.value = []
|
||||
batchSessionRows.value = []
|
||||
batchSessionDialog.value = true
|
||||
}
|
||||
|
||||
function syncBatchSessionRows() {
|
||||
const existing = new Map(batchSessionRows.value.map((row) => [row.projectId, row]))
|
||||
batchSessionRows.value = batchSessionProjectIds.value.map((projectId) => {
|
||||
const current = existing.get(projectId)
|
||||
if (current) return current
|
||||
const project = projects.value.find((item) => item.id === projectId)
|
||||
const firstPeriod = options.periods.find((item) =>
|
||||
item.academicTermId === project?.academicTermId,
|
||||
)
|
||||
return {
|
||||
projectId,
|
||||
classroomId: '',
|
||||
sessionDate: project?.startDate ?? '',
|
||||
startPeriod: firstPeriod?.periodNumber,
|
||||
periodCount: 2,
|
||||
capacity: 30,
|
||||
notes: '',
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function applyFirstBatchTime() {
|
||||
const first = batchSessionRows.value[0]
|
||||
if (!first) return
|
||||
batchSessionRows.value.slice(1).forEach((row) => {
|
||||
row.sessionDate = first.sessionDate
|
||||
row.startPeriod = first.startPeriod
|
||||
row.periodCount = first.periodCount
|
||||
})
|
||||
ElMessage.success('已套用首行的日期和节次,请分别选择不冲突的实验室')
|
||||
}
|
||||
|
||||
function batchProject(projectId: string) {
|
||||
return projects.value.find((project) => project.id === projectId)
|
||||
}
|
||||
|
||||
function periodsForProject(projectId: string) {
|
||||
const project = batchProject(projectId)
|
||||
return options.periods.filter((period) =>
|
||||
period.academicTermId === project?.academicTermId,
|
||||
)
|
||||
}
|
||||
|
||||
async function saveBatchSessions() {
|
||||
if (!batchSessionRows.value.length) {
|
||||
ElMessage.warning('请至少选择一个实验项目')
|
||||
return
|
||||
}
|
||||
if (batchSessionRows.value.some((row) =>
|
||||
!row.classroomId || !row.sessionDate || !row.startPeriod || !row.periodCount,
|
||||
)) {
|
||||
ElMessage.warning('请完整填写每个项目的日期、节次、实验室和容量')
|
||||
return
|
||||
}
|
||||
try {
|
||||
await http.post('/experiments/sessions/batch', {
|
||||
items: batchSessionRows.value,
|
||||
})
|
||||
batchSessionDialog.value = false
|
||||
ElMessage.success(`已批量安排 ${batchSessionRows.value.length} 个实验场次`)
|
||||
await load()
|
||||
} catch (error) {
|
||||
ElMessage.error(apiErrorMessage(error))
|
||||
}
|
||||
}
|
||||
|
||||
function openSession(project: any) {
|
||||
selectedProject.value = project
|
||||
const firstPeriod = options.periods.find((item) =>
|
||||
@@ -382,8 +465,11 @@ onMounted(async () => {
|
||||
<p v-else>把实验项目分成两条运行轨道:集中排入固定课次,或开放场次供学生自主预约。</p>
|
||||
</div>
|
||||
<div class="intro-actions">
|
||||
<el-button v-if="!isStudent" :icon="Calendar" @click="openBatchSession">
|
||||
批量排课
|
||||
</el-button>
|
||||
<el-button v-if="!isStudent" type="primary" :icon="Plus" @click="openCreateProject">
|
||||
新建实验项目
|
||||
批量设置实验任务
|
||||
</el-button>
|
||||
<el-button :icon="Refresh" @click="load">刷新</el-button>
|
||||
</div>
|
||||
@@ -627,19 +713,22 @@ onMounted(async () => {
|
||||
|
||||
<el-dialog
|
||||
v-model="projectDialog"
|
||||
:title="editingProjectId ? '编辑实验项目' : '新建实验项目'"
|
||||
:title="editingProjectId ? '编辑实验项目' : '批量设置实验任务'"
|
||||
width="720px"
|
||||
top="5vh"
|
||||
>
|
||||
<el-form label-position="top" class="experiment-form">
|
||||
<div class="form-section">
|
||||
<header><span>PROJECT</span><b>规定实验项目</b></header>
|
||||
<el-form-item label="所属教学任务" required>
|
||||
<el-form-item :label="editingProjectId ? '所属教学任务' : '适用教学任务(可多选)'" required>
|
||||
<el-select
|
||||
v-model="projectForm.teachingTaskId"
|
||||
v-model="projectForm.teachingTaskIds"
|
||||
filterable
|
||||
multiple
|
||||
collapse-tags
|
||||
collapse-tags-tooltip
|
||||
:disabled="!!editingProjectId"
|
||||
placeholder="选择已发布教学任务"
|
||||
placeholder="选择同一学期、同一课程的已发布教学任务"
|
||||
@change="onTaskChange"
|
||||
>
|
||||
<el-option
|
||||
@@ -647,8 +736,14 @@ onMounted(async () => {
|
||||
:key="task.id"
|
||||
:label="`${task.courseCode} · ${task.courseName} · ${task.taskNumber}`"
|
||||
:value="task.id"
|
||||
:disabled="!!selectedTask
|
||||
&& (task.academicTermId !== selectedTask.academicTermId
|
||||
|| task.courseId !== selectedTask.courseId)"
|
||||
/>
|
||||
</el-select>
|
||||
<small v-if="!editingProjectId" class="form-help">
|
||||
已选 {{ projectForm.teachingTaskIds.length }} 个;实验编码、名称、内容和开放日期将一次应用到这些教学任务。
|
||||
</small>
|
||||
</el-form-item>
|
||||
<div class="form-grid two">
|
||||
<el-form-item label="项目编码" required>
|
||||
@@ -708,7 +803,13 @@ onMounted(async () => {
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="projectDialog = false">取消</el-button>
|
||||
<el-button type="primary" @click="saveProject">保存项目</el-button>
|
||||
<el-button type="primary" @click="saveProject">
|
||||
{{ editingProjectId
|
||||
? '保存项目'
|
||||
: projectForm.teachingTaskIds.length
|
||||
? `创建 ${projectForm.teachingTaskIds.length} 个项目`
|
||||
: '创建项目' }}
|
||||
</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
@@ -778,6 +879,86 @@ onMounted(async () => {
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog
|
||||
v-model="batchSessionDialog"
|
||||
title="批量安排实验场次"
|
||||
width="min(1180px, 94vw)"
|
||||
top="4vh"
|
||||
>
|
||||
<el-alert
|
||||
title="一次提交整批排课;系统会逐条检查管理范围、开放日期、实验室、课表、教师和班级冲突,任何一条失败都不会写入本批次。"
|
||||
type="info"
|
||||
:closable="false"
|
||||
show-icon
|
||||
/>
|
||||
<el-form label-position="top" class="batch-session-form">
|
||||
<el-form-item label="选择实验项目" required>
|
||||
<el-select
|
||||
v-model="batchSessionProjectIds"
|
||||
multiple
|
||||
filterable
|
||||
collapse-tags
|
||||
collapse-tags-tooltip
|
||||
placeholder="选择需要一起排课的实验项目"
|
||||
@change="syncBatchSessionRows"
|
||||
>
|
||||
<el-option
|
||||
v-for="project in batchProjectOptions"
|
||||
:key="project.id"
|
||||
:label="`${project.courseCode} · ${project.name} · ${project.taskNumber}`"
|
||||
:value="project.id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<div v-if="batchSessionRows.length" class="batch-session-tools">
|
||||
<span>共 {{ batchSessionRows.length }} 条排课</span>
|
||||
<el-button size="small" @click="applyFirstBatchTime">套用首行日期与节次</el-button>
|
||||
</div>
|
||||
<div class="batch-session-table">
|
||||
<article v-for="(row, index) in batchSessionRows" :key="row.projectId" class="batch-session-row">
|
||||
<div class="batch-project-cell">
|
||||
<span>{{ index + 1 }}</span>
|
||||
<div>
|
||||
<b>{{ batchProject(row.projectId)?.name }}</b>
|
||||
<small>{{ batchProject(row.projectId)?.taskNumber }} · {{ batchProject(row.projectId)?.classNames.join('、') || '选课学生' }}</small>
|
||||
</div>
|
||||
</div>
|
||||
<el-date-picker
|
||||
v-model="row.sessionDate"
|
||||
type="date"
|
||||
value-format="YYYY-MM-DD"
|
||||
placeholder="实验日期"
|
||||
/>
|
||||
<el-select v-model="row.startPeriod" placeholder="起始节次">
|
||||
<el-option
|
||||
v-for="period in periodsForProject(row.projectId)"
|
||||
:key="period.periodNumber"
|
||||
:label="period.name"
|
||||
:value="period.periodNumber"
|
||||
/>
|
||||
</el-select>
|
||||
<el-input-number v-model="row.periodCount" :min="1" :max="12" controls-position="right" />
|
||||
<el-select v-model="row.classroomId" filterable placeholder="实验室">
|
||||
<el-option
|
||||
v-for="room in options.classrooms"
|
||||
:key="room.id"
|
||||
:label="`${room.campusName} · ${room.buildingName} ${room.name} · ${room.capacity} 人`"
|
||||
:value="room.id"
|
||||
/>
|
||||
</el-select>
|
||||
<el-input-number v-model="row.capacity" :min="1" :max="10000" controls-position="right" />
|
||||
</article>
|
||||
</div>
|
||||
<el-empty v-if="!batchSessionRows.length" :image-size="60" description="选择实验项目后,在同一张表中完成排课" />
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="batchSessionDialog = false">取消</el-button>
|
||||
<el-button type="primary" :disabled="!batchSessionRows.length" @click="saveBatchSessions">
|
||||
提交整批排课
|
||||
</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog
|
||||
v-model="participantsDialog"
|
||||
:title="`${participantSession?.project?.arrangementMode === 'Centralized' ? '应到名单' : '预约名单'} · ${participantSession ? formatSessionTime(participantSession) : ''}`"
|
||||
@@ -912,6 +1093,7 @@ onMounted(async () => {
|
||||
.student-booking-summary span { display: grid; gap: 2px; color: #365f5b; font-size: 12px; }
|
||||
.student-booking-summary b { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; }
|
||||
.experiment-form { display: grid; gap: 13px; }
|
||||
.form-help { display: block; margin-top: 7px; color: var(--muted); line-height: 1.5; }
|
||||
.form-section { padding: 14px 15px 1px; border: 1px solid var(--line); background: #fbfcfd; }
|
||||
.form-section > header { display: flex; align-items: baseline; gap: 9px; margin-bottom: 13px; }
|
||||
.form-section > header span { color: var(--lab-teal); font: 700 10px/1 Consolas, monospace; letter-spacing: .08em; }
|
||||
@@ -920,6 +1102,25 @@ onMounted(async () => {
|
||||
.mode-choice :deep(.el-radio-button__inner) { display: grid; gap: 5px; width: 100%; padding: 13px; }
|
||||
.mode-choice b { font-size: 13px; }
|
||||
.mode-choice small { font-size: 10px; font-weight: 400; }
|
||||
.batch-session-form { display: grid; gap: 12px; margin-top: 16px; }
|
||||
.batch-session-tools { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 12px; }
|
||||
.batch-session-table { display: grid; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
|
||||
.batch-session-row {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(230px, 1.4fr) 150px 120px 110px minmax(230px, 1.3fr) 110px;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
min-width: 1000px;
|
||||
padding: 10px;
|
||||
border: 1px solid #dce5e9;
|
||||
background: #f9fbfc;
|
||||
}
|
||||
.batch-project-cell { display: flex; align-items: center; gap: 10px; min-width: 0; }
|
||||
.batch-project-cell > span { display: grid; width: 25px; height: 25px; place-items: center; border-radius: 50%; background: #e5f0f5; color: var(--lab-blue); font: 700 11px/1 Consolas, monospace; }
|
||||
.batch-project-cell > div { display: grid; gap: 3px; min-width: 0; }
|
||||
.batch-project-cell b, .batch-project-cell small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.batch-project-cell b { color: var(--lab-ink); font-size: 12px; }
|
||||
.batch-project-cell small { color: var(--muted); font-size: 10px; }
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.session-ticket { transition: none; }
|
||||
}
|
||||
@@ -936,5 +1137,6 @@ onMounted(async () => {
|
||||
.ticket-action { grid-column: 1 / -1; justify-content: flex-start; padding: 0 10px 10px; }
|
||||
.project-actions, .student-booking-summary { padding-inline: 14px; }
|
||||
.mode-choice { grid-template-columns: 1fr; }
|
||||
.intro-actions { flex-wrap: wrap; justify-content: flex-end; }
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user