feat: 周预览非工作时段淡灰, 本周无日程自动折叠, 折叠/展开按钮

- 8:00 前与 22:00 后的时段/hour-line 置淡灰背景
- 本周无日程时自动折叠周网格, 显示占位提示
- 工具栏新增折叠/展开切换按钮, 可强制展开空周
- 切换周时按是否有日程自动重置折叠状态
This commit is contained in:
zikai
2026-07-22 07:05:08 +00:00
parent 037b70deec
commit e64f9f4adf

View File

@@ -1,5 +1,5 @@
<script setup> <script setup>
import { computed } from 'vue' import { computed, ref, watch } from 'vue'
import { useCalendar } from '../composables/useCalendar.js' import { useCalendar } from '../composables/useCalendar.js'
import { expandOccurrences } from '../lib/recur.js' import { expandOccurrences } from '../lib/recur.js'
import { eventColor } from '../lib/colors.js' import { eventColor } from '../lib/colors.js'
@@ -14,6 +14,11 @@ const HOUR_HEIGHT = 48 // 每小时像素高度
const headers = DOW.slice(1).concat(DOW[0]) // 周一..周日 const headers = DOW.slice(1).concat(DOW[0]) // 周一..周日
const hours = Array.from({ length: 24 }, function (_, i) { return i }) const hours = Array.from({ length: 24 }, function (_, i) { return i })
// 非工作时段: 8:00 前 (0-7) 与 22:00 后 (22-23) 置淡灰
function isOffHour(h) {
return h < 8 || h >= 22
}
// 当前周的 7 天日期 (周一~周日) // 当前周的 7 天日期 (周一~周日)
const weekDays = computed(function () { const weekDays = computed(function () {
const ws = startOfWeek(state.previewDate) const ws = startOfWeek(state.previewDate)
@@ -82,6 +87,25 @@ const laidOutByDate = computed(function () {
return result return result
}) })
// 本周是否有任何日程
const hasEvents = computed(function () {
for (const items of laidOutByDate.value.values()) {
if (items.length > 0) return true
}
return false
})
// 折叠状态: 本周无日程时自动折叠; 按钮可强制切换
const collapsed = ref(false)
watch(weekLabel, function () {
// 切换周时, 若新周无日程则自动折叠
collapsed.value = !hasEvents.value
}, { immediate: true })
function toggleCollapse() {
collapsed.value = !collapsed.value
}
function eventStyle(occ) { function eventStyle(occ) {
const c = eventColor(occ.event.uid) const c = eventColor(occ.event.uid)
const top = occ.startMin * (HOUR_HEIGHT / 60) const top = occ.startMin * (HOUR_HEIGHT / 60)
@@ -114,13 +138,23 @@ function tooltip(ev) {
<span class="week-label">{{ weekLabel }}</span> <span class="week-label">{{ weekLabel }}</span>
<button class="nav-btn" @click="nextWeek">下一周</button> <button class="nav-btn" @click="nextWeek">下一周</button>
<button class="nav-btn today-btn" @click="goToToday">回到今日</button> <button class="nav-btn today-btn" @click="goToToday">回到今日</button>
<button class="nav-btn collapse-btn" @click="toggleCollapse">
{{ collapsed ? '展开' : '折叠' }}
</button>
<span v-if="!hasEvents" class="empty-hint">本周无日程</span>
</div> </div>
<div class="week-grid-wrapper"> <div v-show="!collapsed" class="week-grid-wrapper">
<div class="week-grid"> <div class="week-grid">
<!-- 左侧时间标签列 --> <!-- 左侧时间标签列 -->
<div class="time-col"> <div class="time-col">
<div class="time-spacer"></div> <div class="time-spacer"></div>
<div v-for="h in hours" :key="h" class="time-slot" :style="{ height: HOUR_HEIGHT + 'px' }"> <div
v-for="h in hours"
:key="h"
class="time-slot"
:class="{ 'off-hour': isOffHour(h) }"
:style="{ height: HOUR_HEIGHT + 'px' }"
>
{{ String(h).padStart(2, '0') }}:00 {{ String(h).padStart(2, '0') }}:00
</div> </div>
</div> </div>
@@ -135,6 +169,7 @@ function tooltip(ev) {
v-for="h in hours" v-for="h in hours"
:key="h" :key="h"
class="hour-line" class="hour-line"
:class="{ 'off-hour': isOffHour(h) }"
:style="{ top: h * HOUR_HEIGHT + 'px', height: HOUR_HEIGHT + 'px' }" :style="{ top: h * HOUR_HEIGHT + 'px', height: HOUR_HEIGHT + 'px' }"
></div> ></div>
<div <div
@@ -151,6 +186,10 @@ function tooltip(ev) {
</div> </div>
</div> </div>
</div> </div>
<div v-if="collapsed" class="collapsed-placeholder">
<span v-if="!hasEvents">本周无日程</span>
<span v-else>本周视图已折叠</span>
</div>
</div> </div>
</template> </template>
@@ -180,6 +219,13 @@ function tooltip(ev) {
.nav-btn:hover { background: #ecf0f1; } .nav-btn:hover { background: #ecf0f1; }
.today-btn { border-color: #3498db; color: #3498db; font-weight: 600; } .today-btn { border-color: #3498db; color: #3498db; font-weight: 600; }
.today-btn:hover { background: #eaf4fc; } .today-btn:hover { background: #eaf4fc; }
.collapse-btn { border-color: #9b59b6; color: #9b59b6; font-weight: 600; }
.collapse-btn:hover { background: #f4ecf7; }
.empty-hint {
font-size: 13px;
color: #95a5a6;
font-style: italic;
}
.week-label { .week-label {
font-size: 16px; font-size: 16px;
font-weight: 600; font-weight: 600;
@@ -213,6 +259,11 @@ function tooltip(ev) {
padding-right: 6px; padding-right: 6px;
border-bottom: 1px solid #f0f0f0; border-bottom: 1px solid #f0f0f0;
} }
/* 非工作时段 (8:00 前 / 22:00 后) 淡灰 */
.time-slot.off-hour {
color: #c4ccd0;
background: #f7f8f9;
}
.day-col { .day-col {
flex: 1; flex: 1;
min-width: 0; min-width: 0;
@@ -248,6 +299,19 @@ function tooltip(ev) {
right: 0; right: 0;
border-bottom: 1px solid #f0f0f0; border-bottom: 1px solid #f0f0f0;
} }
.hour-line.off-hour {
background: #f7f8f9;
}
.collapsed-placeholder {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
color: #95a5a6;
font-size: 14px;
font-style: italic;
padding: 40px;
}
.event-block { .event-block {
position: absolute; position: absolute;
border-radius: 4px; border-radius: 4px;