驾驶舱大屏

master
lion 1 week ago
parent b831ad68a9
commit de783bd825

@ -12,9 +12,9 @@
</template>
</div>
<div class="alumni-news-pagination">
<button v-if="!displayMode" :disabled="loading || page <= 1" @click="load(page - 1)">上一页</button>
<button type="button" :disabled="displayMode ? lastPage <= 1 : loading || page <= 1" @click="changePage(-1)">上一页</button>
<span>{{ page }} / {{ lastPage }} 页 · 共 {{ total }} 条</span>
<button v-if="!displayMode" :disabled="loading || page >= lastPage" @click="load(page + 1)">下一页</button>
<button type="button" :disabled="displayMode ? lastPage <= 1 : loading || page >= lastPage" @click="changePage(1)">下一页</button>
</div>
</div>
</template>
@ -28,17 +28,30 @@ export default {
data() { return { rows: [], page: 1, lastPage: 1, total: 0, loading: false, error: false, sequence: 0, rotationTimer: null } },
created() { this.load(1) },
mounted() {
if (this.displayMode) {
this.rotationTimer = setInterval(() => {
if (!this.loading) this.load(this.page % this.lastPage + 1)
}, 15000)
}
if (this.displayMode) this.startRotation()
},
beforeDestroy() {
clearInterval(this.rotationTimer)
this.sequence++
},
methods: {
startRotation() {
clearInterval(this.rotationTimer)
this.rotationTimer = setInterval(() => {
if (!this.loading) this.load(this.page % this.lastPage + 1)
}, 15000)
},
changePage(direction) {
if (this.loading) return
const target = this.page + direction
if (this.displayMode) {
if (this.lastPage <= 1) return
this.startRotation()
this.load((target - 1 + this.lastPage) % this.lastPage + 1)
} else {
this.load(target)
}
},
originalUrl(value) {
if (typeof value !== 'string' || !/^https?:\/\//i.test(value.trim())) return ''
try { const url = new URL(value.trim()); return ['http:', 'https:'].includes(url.protocol) ? url.href : '' } catch (_) { return '' }

@ -89,32 +89,34 @@
<!-- 年份按钮组 -->
<div class="year-buttons-wrapper" v-if="yearConfigs && yearConfigs.length > 0">
<div class="year-buttons" ref="yearButtons">
<div
<button
v-for="(config, index) in yearConfigs"
:key="index"
type="button"
:class="['year-button', { active: currentYearIndex === index }]"
@click="!displayMode && switchYear(index)"
:aria-pressed="currentYearIndex === index"
@click="switchYear(index, true)"
>
{{ config.name }}
</div>
</button>
</div>
</div>
</div>
<div class="system-table">
<div class="table-header">
<div class="table-cell">课程体系</div>
<div class="table-cell">已开设期数</div>
<div class="table-cell">培养人数(去重)</div>
</div>
<div ref="courseTypeRows" class="table-body">
<div
v-for="(item, index) in visibleCourseTypes"
<div ref="courseTypeRows" class="table-body" :style="displayMode ? displayCourseRowStyle : null">
<div
v-for="(item, index) in currentCourseTypes"
:key="`course-${currentYearIndex}-${index}`"
class="table-row"
>
<div class="table-cell">{{ item.name }}</div>
class="table-row"
>
<div class="table-cell">{{ item.name }}</div>
<div class="table-cell">{{ item.course_periods_total }}期</div>
<div class="table-cell">{{ item.course_signs_total }}人</div>
</div>
</div>
</div>
<div class="table-footer" v-if="currentCourseTypesTotal">
<div class="table-row table-row-total">
@ -154,8 +156,8 @@
<div class="map-title">
<div style="font-size: 1.1vw; font-weight: bold; color: #93ccfd;">学员分布地图</div>
<div class="map-tabs">
<div class="tab" :class="{ active: mapType === 'suzhou' }" @click="!displayMode && (mapType = 'suzhou')">苏州</div>
<div class="tab" :class="{ active: mapType === 'national' }" @click="!displayMode && (mapType = 'national')">全国</div>
<button type="button" class="tab" :class="{ active: mapType === 'suzhou' }" :aria-pressed="mapType === 'suzhou'" @click="selectMap('suzhou')">苏州</button>
<button type="button" class="tab" :class="{ active: mapType === 'national' }" :aria-pressed="mapType === 'national'" @click="selectMap('national')">全国</button>
</div>
<!-- <div style="font-size: 1.1vw; font-weight: bold; color: #fff;" v-if="mapType == 'suzhou'">校友分布</div> -->
</div>
@ -276,8 +278,7 @@ export default {
data() {
return {
displayDataState: 'loading',
displayCoursePage: 0,
displayCoursePageSize: 8,
displayCourseRowStyle: null,
displayCourseTimer: null,
displayMapTimer: null,
isFullscreen: false,
@ -465,11 +466,6 @@ export default {
if (!currentConfig || !currentConfig.courseTypes) return []
return currentConfig.courseTypes || []
},
visibleCourseTypes() {
if (!this.displayMode) return this.currentCourseTypes
const start = this.displayCoursePage * this.displayCoursePageSize
return this.currentCourseTypes.slice(start, start + this.displayCoursePageSize)
},
// 当前选中年份的累计数据
currentCourseTypesTotal() {
if (!this.yearConfigs || this.yearConfigs.length === 0) return null
@ -542,8 +538,8 @@ export default {
if (this.displayMode) {
document.addEventListener('fullscreenchange', this.onFullscreenChange)
document.addEventListener('webkitfullscreenchange', this.onFullscreenChange)
document.addEventListener('keydown', this.handleDisplayKeydown, true)
this.$refs.fullscreenButton.focus()
this.displayCourseTimer = setInterval(this.rotateDisplayCourses, 12000)
} else {
this.$store.dispatch('app/closeSideBar', { withoutAnimation: false })
}
@ -562,6 +558,7 @@ export default {
if (this.displayMode) {
document.removeEventListener('fullscreenchange', this.onFullscreenChange)
document.removeEventListener('webkitfullscreenchange', this.onFullscreenChange)
document.removeEventListener('keydown', this.handleDisplayKeydown, true)
clearInterval(this.displayCourseTimer)
clearInterval(this.displayMapTimer)
}
@ -610,7 +607,7 @@ export default {
this.isFullscreen = (document.fullscreenElement || document.webkitFullscreenElement) === this.$refs.dataScreen
this.$nextTick(() => {
this.handleResize()
if (this.$refs.fullscreenButton) this.$refs.fullscreenButton.focus()
this.focusDisplayControl()
})
},
async logoutDisplay() {
@ -619,14 +616,71 @@ export default {
this.$router.replace({ path: '/login', query: { redirect: '/display' } })
}
},
rotateDisplayCourses() {
if (!this.yearConfigs.length) return
if ((this.displayCoursePage + 1) * this.displayCoursePageSize < this.currentCourseTypes.length) {
this.displayCoursePage += 1
} else {
this.displayCoursePage = 0
this.switchYear((this.currentYearIndex + 1) % this.yearConfigs.length)
focusDisplayControl() {
const screen = this.$refs.dataScreen
const button = this.$refs.fullscreenButton || screen.querySelector('.year-button.active, .map-tabs .active')
if (button) button.focus()
},
handleDisplayKeydown(event) {
const screen = this.$refs.dataScreen
const focused = document.activeElement
const directions = {
ArrowLeft: [-1, 0], ArrowRight: [1, 0], ArrowUp: [0, -1], ArrowDown: [0, 1]
}
const legacyKeys = { 37: 'ArrowLeft', 38: 'ArrowUp', 39: 'ArrowRight', 40: 'ArrowDown' }
const direction = directions[event.key] || directions[legacyKeys[event.keyCode]]
if (['Enter', 'OK', 'Select'].includes(event.key) || event.keyCode === 13 || event.keyCode === 23) {
if (screen.contains(focused) && focused.tagName === 'BUTTON') {
event.preventDefault()
event.stopPropagation()
if (!event.repeat) focused.click()
}
return
}
if (!direction) return
event.preventDefault()
event.stopPropagation()
if (!screen.contains(focused) || focused.tagName !== 'BUTTON') {
this.focusDisplayControl()
return
}
const origin = focused.getBoundingClientRect()
const [horizontal, vertical] = direction
let nextButton = null
let nearestScore = Infinity
Array.from(screen.querySelectorAll('button:not(:disabled)')).forEach(button => {
if (button === focused || !button.getClientRects().length) return
const target = button.getBoundingClientRect()
const dx = target.left + target.width / 2 - (origin.left + origin.width / 2)
const dy = target.top + target.height / 2 - (origin.top + origin.height / 2)
const distance = dx * horizontal + dy * vertical
if (distance <= 0) return
const score = distance + 2 * Math.abs(dx * vertical + dy * horizontal)
if (score < nearestScore) {
nearestScore = score
nextButton = button
}
})
if (nextButton) nextButton.focus()
},
startDisplayCourseRotation() {
clearInterval(this.displayCourseTimer)
if (this.yearConfigs.length <= 1) return
this.displayCourseTimer = setInterval(() => {
this.switchYear((this.currentYearIndex + 1) % this.yearConfigs.length)
}, 12000)
},
selectMap(mapType) {
this.mapType = mapType
if (this.displayMode) this.startDisplayMapRotation()
},
startDisplayMapRotation() {
clearInterval(this.displayMapTimer)
this.displayMapTimer = setInterval(() => {
this.mapType = this.mapType === 'suzhou' ? 'national' : 'suzhou'
}, 12000)
},
async getThreeCoverage() {
try {
@ -821,13 +875,12 @@ export default {
}
if (this.displayMode) {
this.displayDataState = 'ready'
clearInterval(this.displayMapTimer)
this.displayMapTimer = setInterval(() => {
this.mapType = this.mapType === 'suzhou' ? 'national' : 'suzhou'
}, 12000)
this.startDisplayCourseRotation()
this.startDisplayMapRotation()
this.$nextTick(() => {
this.handleResize()
this.scrollToActiveButton()
if (this.isFullscreen && !this.$refs.dataScreen.contains(document.activeElement)) this.focusDisplayControl()
})
}
} catch (error) {
@ -893,20 +946,24 @@ export default {
const scale = Math.min(map.clientWidth / 534, map.clientHeight / 444)
this.suzhouMapFrame = { width: `${534 * scale}px`, height: `${444 * scale}px` }
}
const rows = this.$refs.courseTypeRows
const row = rows && rows.firstElementChild
if (row && row.offsetHeight) {
const pageSize = Math.max(1, Math.floor(rows.clientHeight / row.offsetHeight))
if (pageSize !== this.displayCoursePageSize) {
this.displayCoursePage = 0
this.displayCoursePageSize = pageSize
}
}
this.fitDisplayCourseRows()
}
// 全国地图跟随容器重绘
if (this.nationalMapInstance && this.nationalMapInstance.checkResize) this.nationalMapInstance.checkResize()
},
fitDisplayCourseRows() {
const body = this.$refs.courseTypeRows
if (!body || !this.currentCourseTypes.length) return
const available = body.getBoundingClientRect().height
if (!available) return
const rowHeight = Math.min(window.innerHeight * 0.03, available / this.currentCourseTypes.length)
this.displayCourseRowStyle = {
'--display-course-row-height': `${rowHeight}px`,
'--display-course-font-size': `${Math.min(window.innerWidth * 0.01, rowHeight * 0.72)}px`
}
},
// 初始化全国天地图
scheduleNationalMapInit() {
if (this.nationalMapInitTimer) clearTimeout(this.nationalMapInitTimer)
@ -1055,9 +1112,13 @@ export default {
}, 3000)
},
// 切换年份配置
switchYear(index) {
switchYear(index, manual = false) {
if (index < 0 || index >= this.yearConfigs.length) return
this.currentYearIndex = index
if (this.displayMode) {
if (manual) this.startDisplayCourseRotation()
this.$nextTick(this.fitDisplayCourseRows)
}
// 手动切换时,滚动到对应按钮位置
this.scrollToActiveButton()
},
@ -1065,7 +1126,7 @@ export default {
scrollToActiveButton() {
this.$nextTick(() => {
const buttonsContainer = this.$refs.yearButtons
if (!buttonsContainer) return
if (!buttonsContainer || (this.displayMode && buttonsContainer.contains(document.activeElement))) return
// 通过查询选择器找到激活的按钮
const activeButton = buttonsContainer.querySelector('.year-button.active')
@ -2213,6 +2274,21 @@ export default {
}
.course-system-container .table-body { overflow: hidden; }
.course-system-container .table-body .table-row {
height: var(--display-course-row-height, 2.7vh);
min-height: 0;
padding-top: 0;
padding-bottom: 0;
font-size: var(--display-course-font-size, 1vw);
line-height: 1.1;
}
::v-deep button:focus {
outline: 2px solid #ffe3a1;
outline-offset: -2px;
}
.course-system-container .table-cell {
overflow: hidden;
text-overflow: ellipsis;

Loading…
Cancel
Save