feat: 重做灵动岛编辑器与课表档案时间表编辑

灵动岛
- 重构自定义方案编辑器:组件库常驻、拖拽添加与排序、方案切换/新建/复制/删除、编辑模式预览与缩放,容器在编辑时展开全部子组件。
- 新增天气简报组件:主进程固定请求 Open-Meteo,只接受数值经纬度,失败退避并保留本次运行缓存;冒烟模式不访问外网。
- 倒计时支持目标名称与日期;课程表组件新增「今日时间点」,按时间点类型折叠/展开,课中不再常驻倒计时。
- preload 暴露 getIslandWeather 与时间点订阅,契约同步 desktop.d.ts。

课表档案
- 时间点默认课程:布局返回 defaultCourse,日课表没有条目时回退;新增 apply-default 覆盖所有引用课表;全校时间表不携带默认课程。
- 新增 ClassIsland 式时间表编辑器(列表/时间轴视图、拖动把柄、按类型添加、默认时长与缩放)与「课表信息」表单。
- 课表页默认进入单表编辑,底部保留列表/周/月视图;时间表支持新路由删除。
- 「课间」统一改称「课间休息」。

验证
- pnpm typecheck、pnpm lint 通过。
- verify:e2e 隔离验收 248/248 项通过(含默认课程回退、覆盖写入与时间表删除)。
- ui-smoke 覆盖单表编辑、课表信息与时间轴视图,并更新回归截图。
This commit is contained in:
LoveChengke committed 2026-10-25 16:41:29 +08:00
1 parent 938285bb9c
commit 682818dd4a
41 files changed
+4349 -1095

No files matched your search

@@ -37,14 +37,63 @@ const containers = ['group', 'stack', 'slide', 'rolling'] as const;
<el-switch v-model="node.settings.seconds" @change="emit('change')" />
</el-form-item>
</template>
<el-form-item v-else-if="node.kind === 'countdown'" label="倒计时目标">
<el-select v-model="node.settings.target" @change="emit('change')">
<el-option label="自动:距上课 / 下课" value="auto" />
<el-option label="下一节课" value="next" />
<el-option label="本节下课" value="end" />
<el-option label="放学" value="school" />
</el-select>
</el-form-item>
<template v-else-if="node.kind === 'countdown'">
<el-form-item label="倒计时目标">
<el-select v-model="node.settings.target" @change="emit('change')">
<el-option label="自动:距上课 / 下课" value="auto" />
<el-option label="下一节课" value="next" />
<el-option label="本节下课" value="end" />
<el-option label="放学" value="school" />
<el-option label="指定日期" value="date" />
</el-select>
</el-form-item>
<template v-if="node.settings.target === 'date'">
<el-form-item label="目标名称">
<el-input v-model="node.settings.countdownTitle" :maxlength="64" @change="emit('change')" />
</el-form-item>
<el-form-item label="目标日期">
<el-date-picker
v-model="node.settings.targetDate"
type="date"
value-format="YYYY-MM-DD"
placeholder="选择日期"
@change="emit('change')"
/>
</el-form-item>
</template>
</template>
<template v-else-if="node.kind === 'weather'">
<el-form-item label="地点名称">
<el-input
v-model="node.settings.locationName"
placeholder="例如:学校"
:maxlength="64"
@change="emit('change')"
/>
</el-form-item>
<el-form-item label="纬度">
<el-input-number
v-model="node.settings.latitude"
:min="-90"
:max="90"
:precision="4"
@change="emit('change')"
/>
</el-form-item>
<el-form-item label="经度">
<el-input-number
v-model="node.settings.longitude"
:min="-180"
:max="180"
:precision="4"
@change="emit('change')"
/>
</el-form-item>
<p class="hint">
填写地点坐标后每 15 分钟更新天气。数据来自
Open-Meteo,断网时显示本次运行的缓存;天气提示不作为官方预警。
</p>
</template>
<template v-else-if="node.kind === 'text'">
<el-form-item label="文字内容">
<el-input v-model="node.settings.text" type="textarea" :rows="3" @change="emit('change')" />
@@ -57,20 +106,24 @@ const containers = ['group', 'stack', 'slide', 'rolling'] as const;
<template v-else-if="node.kind === 'schedule'">
<el-form-item label="显示课程">
<el-select v-model="node.settings.display" @change="emit('change')">
<el-option label="当前课程" value="current" />
<el-option label="当前时间点" value="current" />
<el-option label="下一节课" value="next" />
<el-option label="今日课表" value="today" />
<el-option label="今日时间点" value="today" />
</el-select>
</el-form-item>
<el-form-item v-if="node.settings.display === 'today'" label="显示节数">
<el-form-item v-if="node.settings.display === 'today'" label="显示时间点数">
<el-input-number v-model="node.settings.count" :min="1" :max="30" @change="emit('change')" />
</el-form-item>
<el-form-item label="显示课程时间">
<el-form-item label="当前时间点显示起止时间">
<el-switch v-model="node.settings.showPeriod" @change="emit('change')" />
</el-form-item>
<el-form-item label="显示上课进度">
<el-form-item label="当前课程显示进度">
<el-switch v-model="node.settings.showProgress" @change="emit('change')" />
</el-form-item>
<p class="hint">
今日时间点只展开当前项并显示时间段;课间休息与默认隐藏的时间点折叠时完全隐藏,轮到时才展开。
下课前一分钟的倒计时由「提醒」设置里的下课提醒负责。
</p>
</template>
<template v-else-if="containers.includes(node.kind as (typeof containers)[number])">
<el-form-item label="排列方向">
@@ -80,7 +133,7 @@ const containers = ['group', 'stack', 'slide', 'rolling'] as const;
</el-select>
</el-form-item>
<el-form-item label="组件间距">
<el-input-number v-model="node.settings.gap" :min="0" :max="80" @change="emit('change')" />
<el-input-number v-model="node.settings.gap" :min="0" :max="64" @change="emit('change')" />
</el-form-item>
<el-form-item v-if="node.kind === 'slide'" label="切换间隔(秒)">
<el-input-number
@@ -0,0 +1,124 @@
<script setup lang="ts">
import { computed } from 'vue';
import { ISLAND_COMPONENT_LABELS, type IslandComponentNode } from '@classhelper/shared';
import ComponentIcon from '../../island/ComponentIcon.vue';
const props = defineProps<{
node: IslandComponentNode;
selectedId: string;
dropId?: string;
dropPosition?: string;
}>();
const emit = defineEmits<{ select: [id: string]; drag: [event: PointerEvent, id: string] }>();
const container = computed(() => ['group', 'stack', 'slide', 'rolling'].includes(props.node.kind));
</script>
<template>
<div
class="editor-component"
:class="{
container,
selected: selectedId === node.id,
'drop-before': dropId === node.id && dropPosition === 'before',
'drop-after': dropId === node.id && dropPosition === 'after',
'drop-inside': dropId === node.id && dropPosition === 'inside',
}"
:data-node="node.id"
>
<button
class="component-chip node-handle"
:data-kind="node.kind"
:aria-label="`编辑${ISLAND_COMPONENT_LABELS[node.kind]}`"
@pointerdown="emit('drag', $event, node.id)"
@click.stop="emit('select', node.id)"
>
<ComponentIcon :kind="node.kind" />
<span>{{ ISLAND_COMPONENT_LABELS[node.kind] }}</span>
</button>
<div v-if="container" class="container-children">
<IslandEditorNode
v-for="child in node.children"
:key="child.id"
:node="child"
:selected-id="selectedId"
:drop-id="dropId"
:drop-position="dropPosition"
@select="emit('select', $event)"
@drag="(event, id) => emit('drag', event, id)"
/>
<span v-if="!node.children.length" class="container-empty">拖入组件</span>
</div>
</div>
</template>
<style scoped>
.editor-component {
position: relative;
display: flex;
align-items: center;
flex-shrink: 0;
border-radius: 5px;
}
.component-chip {
display: flex;
align-items: center;
gap: 5px;
min-height: 36px;
padding: 5px 9px;
border: 1px solid transparent;
border-radius: 5px;
background: transparent;
color: inherit;
font: inherit;
white-space: nowrap;
cursor: grab;
touch-action: none;
}
.component-chip svg {
width: 18px;
height: 18px;
flex-shrink: 0;
}
.component-chip:hover {
background: var(--ch-hover-soft);
}
.component-chip:focus-visible {
outline: 2px solid var(--ch-accent);
outline-offset: 2px;
}
.selected > .component-chip {
background: var(--ch-accent-soft);
border-color: var(--ch-accent);
}
.container {
border: 1px dashed var(--ch-border-strong);
padding: 3px;
gap: 3px;
}
.container-children {
display: flex;
align-items: center;
gap: 3px;
min-width: 60px;
min-height: 34px;
}
.container-empty {
color: var(--ch-text-tertiary);
font-size: 12px;
padding: 0 10px;
}
.drop-inside {
background: var(--ch-accent-soft);
outline: 2px solid var(--ch-accent);
}
.drop-before::before,
.drop-after::after {
content: '';
position: absolute;
inset: 3px auto 3px -4px;
width: 3px;
border-radius: 3px;
background: var(--ch-accent);
}
.drop-after::after {
left: auto;
right: -4px;
}
</style>
@@ -5,6 +5,7 @@ import {
resolveClassStatus,
type ClassPeriod,
type HomeworkDto,
type IslandTimePointDto,
type NotificationDto,
type ScheduleDto,
} from '@classhelper/shared';
@@ -30,6 +31,8 @@ const TICK_INTERVAL_MS = 1_000;
const REFRESH_INTERVAL_MS = 30_000;
let schedules: ScheduleDto[] = [];
/** 今天的完整时间点(含课间/分割线/默认隐藏),自定义岛的课程表组件使用。 */
let dayTimePoints: IslandTimePointDto[] = [];
let currentPeriod: ClassPeriod | null = null;
let inClass = false;
let tickTimer: ReturnType<typeof setInterval> | null = null;
@@ -47,6 +50,51 @@ export function getIslandSchedules(): ScheduleDto[] {
return schedules;
}
export function getIslandTimePoints(): IslandTimePointDto[] {
return dayTimePoints;
}
/** 从 active-week 的今天取完整时间点;课程名优先条目、没有条目才回退默认课程。 */
function buildDayTimePoints(days: ContractActiveClassPlanWeekDto['days']): IslandTimePointDto[] {
const weekday = new Date().getDay() || 7;
const day = days.find((item) => item.weekday === weekday);
const points = day?.timeLayout?.points ?? [];
if (!points.length) return [];
const entries = day?.classPlan?.entries ?? [];
return points.map((point) => {
const entry = entries.find((item) => item.timeLayoutItemId === point.id);
return {
id: point.id,
timeType: point.timeType,
name: point.breakName || point.name || '',
courseName: entry
? entry.isEnabled
? (entry.course?.name ?? null)
: null
: (point.defaultCourse?.name ?? null),
startTime: point.startTime,
endTime: point.endTime,
isHideDefault: point.isHideDefault,
};
});
}
/** 离线/旧服务端只有课表条目时退化成只有上课时间点。 */
function timePointsFromSchedules(list: ScheduleDto[]): IslandTimePointDto[] {
const weekday = new Date().getDay() || 7;
return list
.filter((item) => item.dayOfWeek === weekday)
.map((item) => ({
id: item.id,
timeType: 'LESSON' as const,
name: '',
courseName: item.course?.name ?? null,
startTime: item.startTime,
endTime: item.endTime,
isHideDefault: false,
}));
}
/** 主动刷新课表(课表变更事件触发) */
export async function refreshIslandSchedules(): Promise<void> {
const appStore = useAppStore();
@@ -61,13 +109,16 @@ export async function refreshIslandSchedules(): Promise<void> {
'schedules',
`week:${week}`,
async () => {
const data = (
await api.get<ContractActiveClassPlanWeekDto>('/schedules/active-week', { classId, week })
).days.flatMap((day) => day.schedules);
const payload = await api.get<ContractActiveClassPlanWeekDto>('/schedules/active-week', {
classId,
week,
});
const data = payload.days.flatMap((day) => day.schedules);
// 网络结果先上岛,IndexedDB 写入不再挡住可见内容;旧请求与切换账号的结果不得回写。
if (scope !== getCacheScope() || request !== scheduleRequest || !auth.token)
throw new Error('课表刷新已被新请求替代');
schedules = data;
dayTimePoints = buildDayTimePoints(payload.days);
scheduleWeek = week;
recomputeClassState(true);
return data;
@@ -78,12 +129,22 @@ export async function refreshIslandSchedules(): Promise<void> {
if (result.error && !result.updatedAt) return;
if (result.fromCache) {
schedules = result.data;
dayTimePoints = timePointsFromSchedules(result.data);
scheduleWeek = week;
recomputeClassState(true);
}
}
let sentDay = '';
let sentTimePoints = '';
function timePointsKey(): string {
return dayTimePoints
.map(
(point) =>
`${point.id}|${point.timeType}|${point.startTime}|${point.endTime}|${point.name}|${point.courseName ?? ''}|${point.isHideDefault ? 1 : 0}`,
)
.join(',');
}
function recomputeClassState(force = false): void {
const day = new Date().toDateString();
const appStore = useAppStore();
@@ -94,15 +155,19 @@ function recomputeClassState(force = false): void {
currentPeriod?.endTime === status.current?.endTime;
currentPeriod = status.current;
if (!force && day === sentDay && nextInClass === inClass && samePeriod) return;
const pointsKey = timePointsKey();
if (!force && day === sentDay && nextInClass === inClass && samePeriod && pointsKey === sentTimePoints)
return;
sentDay = day;
inClass = nextInClass;
sentTimePoints = pointsKey;
window.desktop?.islandSetClassState({
inClass,
currentPeriodEnd: currentPeriod?.endTime ?? null,
week: appStore.currentWeek,
schedules: schedules.filter((s) => s.dayOfWeek === (new Date().getDay() || 7)),
timePoints: dayTimePoints,
});
}
@@ -389,7 +454,9 @@ export function stopIslandBridge(): void {
useRealtimeStore().off(SOCKET_EVENTS.scheduleUpdated, onScheduleUpdated);
useRealtimeStore().off('__connected__', onScheduleUpdated);
sentDay = '';
sentTimePoints = '';
schedules = [];
dayTimePoints = [];
currentPeriod = null;
inClass = false;
@@ -401,5 +468,6 @@ export function stopIslandBridge(): void {
currentPeriodEnd: null,
week: useAppStore().currentWeek,
schedules: [],
timePoints: [],
});
}
@@ -0,0 +1,453 @@
.island-editor-page {
display: flex;
flex-direction: column;
flex: 1 0 auto;
min-height: 0;
min-width: 0;
color: var(--ch-text);
padding: 12px 24px 16px;
background: var(--editor-background, var(--ch-bg));
}
:global(.main:has(> .island-editor-page)) {
display: flex;
flex-direction: column;
}
:global(.main:has(> .island-editor-page) > .offline-banner),
.island-editor-page > * {
flex-shrink: 0;
}
:global(html.dark) .island-editor-page {
--editor-background: #262626;
--editor-divider: #3a3a3a;
--editor-card: #2c2c2c;
}
.editor-actions {
display: flex;
align-items: center;
justify-content: flex-end;
gap: 8px;
min-height: 30px;
margin-bottom: 4px;
}
.save-status {
color: var(--ch-text-tertiary);
font-size: 12px;
margin-right: 8px;
}
.save-status.failed {
color: var(--el-color-danger);
}
.component-heading {
align-items: flex-end;
gap: 24px;
margin-bottom: 20px;
}
.heading-copy {
flex: 1 1 380px;
}
.component-heading .page-title {
font-size: calc(34px * var(--ch-font-scale));
font-weight: 600;
line-height: 1.4;
margin-bottom: 20px;
}
.heading-copy p {
font-size: calc(16px * var(--ch-font-scale));
margin: 0;
line-height: 1.6;
}
.scheme-tools {
flex: 0 1 348px;
min-width: 300px;
}
.scheme-tools label {
display: block;
margin-bottom: 6px;
font-size: 14px;
font-weight: 600;
}
.scheme-controls {
display: flex;
gap: 6px;
align-items: center;
}
.scheme-controls .el-select {
min-width: 140px;
flex: 1;
}
.scheme-controls :deep(.el-select__wrapper) {
min-height: 38px;
background: var(--ch-card-subtle);
}
.icon-button {
width: 34px;
height: 36px;
padding: 8px;
margin: 0;
flex-shrink: 0;
font-size: 19px;
}
.surface-toolbar {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
flex-wrap: wrap;
}
.surface-tabs,
.surface-actions {
display: flex;
gap: 12px;
align-items: center;
}
.surface-actions {
gap: 0;
}
.surface-tabs button {
position: relative;
border: 0;
background: transparent;
color: var(--ch-text-secondary);
font: inherit;
font-size: 12px;
padding: 6px 0 9px;
cursor: pointer;
}
.surface-tabs button.active {
color: var(--ch-text);
}
.surface-tabs button.active::after {
content: '';
position: absolute;
bottom: 0;
left: 10%;
right: 10%;
height: 2px;
background: var(--ch-accent);
border-radius: 2px;
}
.preview-canvas {
min-height: 80px;
overflow: auto;
padding: 10px 0 20px;
}
.component-lines {
min-width: 100%;
width: max-content;
}
.component-line {
display: flex;
align-items: center;
min-height: 54px;
border-radius: 6px;
gap: 12px;
padding: 4px;
border: 1px solid transparent;
}
.component-line + .component-line {
margin-top: 6px;
}
.component-line.active-row {
border-color: var(--ch-border-strong);
}
.row-handle {
align-self: stretch;
width: 24px;
flex-shrink: 0;
padding: 0;
border: 0;
background: transparent;
color: var(--ch-text-secondary);
font: inherit;
font-size: 20px;
cursor: grab;
touch-action: none;
}
.row-handle:hover {
color: var(--ch-accent);
background: var(--ch-hover-soft);
}
.line-components {
display: flex;
justify-content: center;
align-items: center;
flex: 1;
padding: 0 28px 0 0;
min-height: 38px;
}
.empty-line {
border: 1px dashed var(--ch-border-strong);
background: transparent;
color: var(--ch-text-tertiary);
padding: 10px 24px;
border-radius: 5px;
font: inherit;
font-size: 12px;
cursor: pointer;
}
.preview-canvas.live-preview {
display: grid;
place-items: center;
min-height: 160px;
padding: 24px;
background: var(--ch-layer-alt);
border-radius: 6px;
margin-top: 8px;
}
.island-preview {
display: flex;
flex-direction: column;
gap: var(--preview-gap);
width: max-content;
color: #ffffffeb;
padding: 12px;
border-radius: var(--preview-radius);
background: #202024;
}
.preview-row {
display: flex;
align-items: center;
min-width: 120px;
min-height: 44px;
border-radius: var(--preview-radius);
}
.island-preview.separated {
background: transparent;
padding: 0;
}
.separated .preview-row {
padding: 12px;
background: #202024;
}
.empty-preview {
color: #ffffffb8;
background: transparent;
border: 1px dashed #ffffff60;
border-radius: 5px;
padding: 10px 20px;
cursor: pointer;
font: inherit;
font-size: 13px;
}
.drop-row {
outline: 2px dashed var(--ch-accent);
outline-offset: -2px;
background: var(--ch-accent-soft);
}
.preview-toolbar {
display: flex;
align-items: center;
gap: 14px;
padding: 6px 0 12px;
color: var(--ch-text-secondary);
font-size: 12px;
}
.preview-toolbar .el-slider {
width: 130px;
}
.hint {
color: var(--ch-text-secondary);
line-height: 1.6;
font-size: 12px;
}
.component-library {
border-top: 6px solid var(--editor-divider, var(--ch-divider));
margin: 0 -24px;
padding: 14px 24px 24px;
flex: 1 0 auto;
}
.library-title {
position: relative;
width: max-content;
font-size: 17px;
font-weight: 600;
margin: 0 0 12px;
padding: 0 0 7px;
}
.library-title::after {
content: '';
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 3px;
border-radius: 3px;
background: var(--ch-accent);
}
.component-options {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 12px 20px;
}
.library-item {
min-width: 0;
width: 100%;
display: flex;
gap: 12px;
align-items: center;
text-align: left;
min-height: 76px;
padding: 10px 8px;
border: 1px solid transparent;
border-radius: 6px;
background: transparent;
color: inherit;
font: inherit;
cursor: grab;
touch-action: none;
transition:
background var(--ch-dur-fast) var(--ch-ease-out),
border-color var(--ch-dur-fast) var(--ch-ease-out);
}
.library-item:hover {
background: var(--ch-hover-soft);
border-color: var(--ch-border);
}
.library-item:active {
background: var(--ch-accent-soft);
}
.library-item:focus-visible,
.row-handle:focus-visible,
.surface-tabs button:focus-visible {
outline: 2px solid var(--ch-accent);
outline-offset: 2px;
}
.library-item > svg {
width: 36px;
height: 36px;
flex: 0 0 36px;
}
.library-item > span {
min-width: 0;
}
.library-item strong {
display: block;
font-size: calc(18px * var(--ch-font-scale));
font-weight: 500;
line-height: 1.5;
}
.component-description {
display: block;
color: var(--ch-text-secondary);
font-size: calc(14px * var(--ch-font-scale));
line-height: 1.5;
}
.message-library-title {
color: var(--ch-text-tertiary);
font-size: 12px;
font-weight: 400;
margin: 20px 8px 4px;
}
.message-options .library-item {
min-height: 64px;
}
.message-options .library-item strong {
font-size: 15px;
}
.message-options .library-item > svg {
width: 26px;
height: 26px;
flex-basis: 26px;
}
.editor-tip {
display: flex;
align-items: center;
gap: 14px;
padding: 12px 16px;
min-height: 60px;
border: 1px solid var(--ch-border-strong);
border-radius: 5px;
background: var(--editor-card, var(--ch-card-subtle));
font-size: 14px;
}
.editor-tip > span {
flex: 1;
line-height: 1.6;
}
.tip-icon {
color: var(--ch-accent);
font-size: 22px;
}
.dismiss-tip {
border: 0;
color: var(--ch-text);
background: transparent;
font-size: 26px;
cursor: pointer;
margin-left: auto;
padding: 0 8px;
}
.drag-ghost {
position: fixed;
z-index: 10000;
pointer-events: none;
padding: 10px 16px;
background: var(--ch-layer-solid);
border: 1px solid var(--ch-accent);
border-radius: 6px;
box-shadow: var(--ch-shadow-flyout);
color: var(--ch-text);
font-size: 14px;
}
.inspector-tabs {
margin-bottom: 20px;
}
.row-actions {
display: flex;
gap: 6px;
flex-wrap: wrap;
margin-top: 20px;
}
.row-actions .el-button {
margin: 0;
}
@media (max-width: 1150px) {
.component-options {
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 8px;
}
.component-heading {
gap: 16px;
}
.heading-copy {
flex-basis: 300px;
}
.scheme-tools {
flex-basis: 300px;
}
}
@media (max-width: 800px) {
.component-options {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.component-heading .page-title {
margin-bottom: 10px;
}
.scheme-tools {
flex: 1 1 100%;
}
.editor-tip {
flex-wrap: wrap;
}
.preview-toolbar .hint {
display: none;
}
}
@media (max-width: 520px) {
.component-options {
grid-template-columns: 1fr;
}
.island-editor-page {
padding-right: 16px;
padding-left: 16px;
}
.component-library {
margin-right: -16px;
margin-left: -16px;
padding-right: 16px;
padding-left: 16px;
}
.save-status {
display: none;
}
}
File diff suppressed because it is too large. Load diff