fix: 调度页面只显示有项目的时间段
从编排数据中提取实际有项目的时间段,过滤掉没有比赛的时间段 Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
factory-droid[bot]
parent
1643acf767
commit
0cd46d125f
@@ -130,6 +130,7 @@ export default {
|
||||
selectedVenueId: null,
|
||||
venues: [], // 场地列表
|
||||
timeSlots: [], // 时间段列表
|
||||
timeSlotIndexMap: {}, // 显示索引到实际时间段索引的映射
|
||||
dispatchGroups: [], // 调度分组列表
|
||||
hasChanges: false, // 是否有未保存的更改
|
||||
originalData: null // 原始数据(用于取消时恢复)
|
||||
@@ -189,8 +190,16 @@ export default {
|
||||
const data = res.data?.data
|
||||
|
||||
if (data) {
|
||||
// 生成时间段
|
||||
this.generateTimeSlots(data.competitionStartTime || data.competition_start_time, data.competitionEndTime || data.competition_end_time)
|
||||
// 获取编排数据以确定有项目的时间段
|
||||
let scheduleGroups = []
|
||||
try {
|
||||
const scheduleRes = await getScheduleResult(this.competitionId)
|
||||
scheduleGroups = scheduleRes.data?.data?.competitionGroups || scheduleRes.data?.data?.scheduleGroups || []
|
||||
} catch (e) {
|
||||
console.warn('获取编排数据失败:', e)
|
||||
}
|
||||
// 生成时间段(只显示有项目的时间段)
|
||||
this.generateTimeSlots(data.competitionStartTime || data.competition_start_time, data.competitionEndTime || data.competition_end_time, scheduleGroups)
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('加载赛事信息失败', err)
|
||||
@@ -200,17 +209,29 @@ export default {
|
||||
}
|
||||
},
|
||||
|
||||
// 生成时间段列表
|
||||
generateTimeSlots(startTime, endTime) {
|
||||
// 生成时间段列表(只显示有项目的时间段)
|
||||
generateTimeSlots(startTime, endTime, scheduleGroups) {
|
||||
if (!startTime || !endTime) {
|
||||
this.timeSlots = ['2025年11月6日 上午8:30', '2025年11月6日 下午13:30']
|
||||
this.timeSlotIndexMap = { 0: 0, 1: 1 }
|
||||
return
|
||||
}
|
||||
|
||||
const slots = []
|
||||
// 从编排数据中提取实际有项目的时间段索引
|
||||
const usedTimeSlotIndices = new Set()
|
||||
if (scheduleGroups && scheduleGroups.length > 0) {
|
||||
scheduleGroups.forEach(group => {
|
||||
if (group.timeSlotIndex !== undefined && group.timeSlotIndex !== null) {
|
||||
usedTimeSlotIndices.add(group.timeSlotIndex)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const allSlots = []
|
||||
const start = new Date(startTime)
|
||||
const end = new Date(endTime)
|
||||
let currentDate = new Date(start)
|
||||
let slotIndex = 0
|
||||
|
||||
while (currentDate <= end) {
|
||||
const year = currentDate.getFullYear()
|
||||
@@ -218,13 +239,28 @@ export default {
|
||||
const day = currentDate.getDate()
|
||||
const dateStr = `${year}年${month}月${day}日`
|
||||
|
||||
slots.push(`${dateStr} 上午8:30`)
|
||||
slots.push(`${dateStr} 下午13:30`)
|
||||
allSlots.push({ label: `${dateStr} 上午8:30`, index: slotIndex++ })
|
||||
allSlots.push({ label: `${dateStr} 下午13:30`, index: slotIndex++ })
|
||||
|
||||
currentDate.setDate(currentDate.getDate() + 1)
|
||||
}
|
||||
|
||||
this.timeSlots = slots
|
||||
// 如果有编排数据,只显示有项目的时间段
|
||||
if (usedTimeSlotIndices.size > 0) {
|
||||
const filteredSlots = allSlots.filter(slot => usedTimeSlotIndices.has(slot.index))
|
||||
this.timeSlots = filteredSlots.map(slot => slot.label)
|
||||
// 保存映射关系:显示索引 -> 实际时间段索引
|
||||
this.timeSlotIndexMap = {}
|
||||
filteredSlots.forEach((slot, displayIndex) => {
|
||||
this.timeSlotIndexMap[displayIndex] = slot.index
|
||||
})
|
||||
} else {
|
||||
this.timeSlots = allSlots.map(slot => slot.label)
|
||||
this.timeSlotIndexMap = {}
|
||||
allSlots.forEach((slot, displayIndex) => {
|
||||
this.timeSlotIndexMap[displayIndex] = slot.index
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
// 加载场地列表
|
||||
@@ -269,7 +305,7 @@ export default {
|
||||
const res = await getDispatchData({
|
||||
competitionId: this.competitionId,
|
||||
venueId: this.selectedVenueId,
|
||||
timeSlotIndex: this.selectedTime
|
||||
timeSlotIndex: this.timeSlotIndexMap[this.selectedTime] !== undefined ? this.timeSlotIndexMap[this.selectedTime] : this.selectedTime
|
||||
})
|
||||
|
||||
if (res.data.success) {
|
||||
|
||||
Reference in New Issue
Block a user