feat: 支持班级灵动岛云端配置与跨端同步
This commit is contained in:
1 parent
4449fbd0a1
commit
f6dd59aa25
40 files changed
+1208
-719
No files matched your search
@@ -136,11 +136,19 @@
|
||||
justify-content: center;
|
||||
min-width: 0;
|
||||
}
|
||||
.resident-card .layout-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: var(--ci-island-height);
|
||||
min-height: var(--ci-island-height);
|
||||
}
|
||||
.resident-card .row-components {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 0;
|
||||
height: var(--ci-island-height);
|
||||
min-height: var(--ci-island-height);
|
||||
}
|
||||
.resident-card .resident-compact .component-node:not(.container) {
|
||||
|
||||
@@ -226,13 +226,6 @@ if (!gotLock) {
|
||||
mainWindow.show();
|
||||
mainWindow.focus();
|
||||
});
|
||||
island.setEditLayoutHandler(() => {
|
||||
if (!mainWindow || mainWindow.isDestroyed()) return;
|
||||
if (mainWindow.isMinimized()) mainWindow.restore();
|
||||
mainWindow.show();
|
||||
mainWindow.focus();
|
||||
mainWindow.webContents.send('island:open-editor');
|
||||
});
|
||||
// 灵动岛点"标为已读":转交主窗口渲染进程调用接口并刷新通知中心
|
||||
island.setMarkReadHandler((id) => {
|
||||
if (!mainWindow || mainWindow.isDestroyed()) return;
|
||||
|
||||
@@ -11,7 +11,6 @@ import {
|
||||
type CoursewareTransfer,
|
||||
DEFAULT_ISLAND_APPEARANCE,
|
||||
CLASSISLAND_ISLAND_METRICS,
|
||||
normalizeIslandLayouts,
|
||||
ISLAND_POSITIONS,
|
||||
ISLAND_SHADOW_PAD,
|
||||
ISLAND_SIZE_DELTA,
|
||||
@@ -27,7 +26,7 @@ import {
|
||||
type IslandLessonReminder,
|
||||
} from '@classhelper/shared';
|
||||
import { logger } from './logger.js';
|
||||
import { getConfig, saveConfig } from './config.js';
|
||||
import { getConfig } from './config.js';
|
||||
import { LessonReminderTracker } from './lesson-reminder.js';
|
||||
|
||||
/** 生产环境的灵动岛页面地址(导航白名单的精确比对用) */
|
||||
@@ -175,7 +174,6 @@ class IslandController {
|
||||
if (this.customLayout && this.lessonCue?.kind === 'ending') return false;
|
||||
return Boolean(
|
||||
this.lessonCue &&
|
||||
!this.editingLayout &&
|
||||
!this.previewId &&
|
||||
!(
|
||||
this.state.active &&
|
||||
@@ -256,7 +254,6 @@ class IslandController {
|
||||
* 只有投影所需的 10px 留白,不再吞掉桌面点击。
|
||||
*/
|
||||
private touchMode = false;
|
||||
private editingLayout = false;
|
||||
private settlingLayout = false;
|
||||
private layoutSettleTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
private customSize = { width: 424, height: 80 };
|
||||
@@ -280,7 +277,7 @@ class IslandController {
|
||||
if (!this.win || this.win.isDestroyed() || process.platform !== 'win32') return;
|
||||
if (this.residentShapeTimer) clearTimeout(this.residentShapeTimer);
|
||||
this.residentShapeTimer = null;
|
||||
if (!this.residentEnabled || !this.touchMode || this.editingLayout) {
|
||||
if (!this.residentEnabled || !this.touchMode) {
|
||||
if (this.residentShaped) this.win.setShape([]);
|
||||
this.residentShaped = false;
|
||||
return;
|
||||
@@ -289,15 +286,7 @@ class IslandController {
|
||||
const apply = () => {
|
||||
this.residentShapeTimer = null;
|
||||
const r = this.hitRect;
|
||||
if (
|
||||
!r ||
|
||||
!this.win ||
|
||||
this.win.isDestroyed() ||
|
||||
!this.residentEnabled ||
|
||||
!this.touchMode ||
|
||||
this.editingLayout
|
||||
)
|
||||
return;
|
||||
if (!r || !this.win || this.win.isDestroyed() || !this.residentEnabled || !this.touchMode) return;
|
||||
this.win.setShape([
|
||||
{
|
||||
x: Math.max(0, Math.floor(r.x - 8)),
|
||||
@@ -315,9 +304,6 @@ class IslandController {
|
||||
);
|
||||
} else apply();
|
||||
}
|
||||
getEditingLayout(): boolean {
|
||||
return this.editingLayout;
|
||||
}
|
||||
syncCustomLayout(): void {
|
||||
this.refreshLessonReminder();
|
||||
if (this.residentEnabled !== this.residentWasEnabled) {
|
||||
@@ -355,13 +341,6 @@ class IslandController {
|
||||
this.syncWindow();
|
||||
}, 320);
|
||||
}
|
||||
private editLayoutHandler: (() => void) | null = null;
|
||||
setEditLayoutHandler(handler: () => void): void {
|
||||
this.editLayoutHandler = handler;
|
||||
}
|
||||
editLayout(enabled = true): void {
|
||||
if (enabled) this.editLayoutHandler?.();
|
||||
}
|
||||
reportCustomSize(value: { width: number; height: number }): void {
|
||||
if (
|
||||
!this.customLayout ||
|
||||
@@ -372,7 +351,6 @@ class IslandController {
|
||||
)
|
||||
return;
|
||||
this.customDesiredSize = { ...value };
|
||||
if (this.editingLayout) return;
|
||||
if (this.residentEnabled) {
|
||||
if (this.customTimer) clearTimeout(this.customTimer);
|
||||
this.customTimer = null;
|
||||
@@ -391,7 +369,7 @@ class IslandController {
|
||||
if (this.customTimer) clearTimeout(this.customTimer);
|
||||
this.customTimer = setTimeout(() => {
|
||||
this.customTimer = null;
|
||||
if (!this.win || !this.customLayout || this.editingLayout || this.residentEnabled) return;
|
||||
if (!this.win || !this.customLayout || this.residentEnabled) return;
|
||||
const area = screen.getDisplayNearestPoint(this.win.getBounds()).workArea;
|
||||
const current = this.win.getBounds();
|
||||
const width = Math.max(40, Math.min(Math.ceil(value.width), area.width - 2 * ISLAND_SHADOW_PAD));
|
||||
@@ -557,13 +535,12 @@ class IslandController {
|
||||
* 因此这里再用**指针位置**兜一层:指针还在岛上就绝不收起(详见 isCursorOnIsland)。
|
||||
*/
|
||||
win.on('resize', () => {
|
||||
if (this.customLayout && !this.editingLayout && this.ready && !win.isDestroyed()) {
|
||||
if (this.customLayout && this.ready && !win.isDestroyed()) {
|
||||
const { width, height } = win.getContentBounds();
|
||||
win.webContents.send('island:viewport', { width, height });
|
||||
}
|
||||
});
|
||||
win.on('blur', () => {
|
||||
if (this.editingLayout) return;
|
||||
// 冒烟里可以临时关掉"失焦收起",避免测试过程被无关的焦点变化打断(默认开启)
|
||||
if (!this.blurCollapseEnabled) return;
|
||||
if (this.state.mode !== 'expanded') return;
|
||||
@@ -576,7 +553,7 @@ class IslandController {
|
||||
}
|
||||
// 触摸屏上没有"指针"可依据(isCursorOnIsland 恒为 false),只能用更宽的宽限期覆盖
|
||||
// 上面实测到的 70~520ms 抖动区间,否则手指点开后约 0.5s 会莫名缩回胶囊。
|
||||
const grace = this.touchMode || this.editingLayout ? BLUR_GRACE_TOUCH_MS : BLUR_GRACE_MS;
|
||||
const grace = this.touchMode ? BLUR_GRACE_TOUCH_MS : BLUR_GRACE_MS;
|
||||
if (sinceActivated < grace) {
|
||||
logger.info(`灵动岛:忽略激活后 ${sinceActivated}ms 内的失焦(宽限期内不收起)`);
|
||||
return;
|
||||
@@ -1153,14 +1130,7 @@ class IslandController {
|
||||
if (this.customLayout)
|
||||
setTimeout(() => {
|
||||
// 提醒沿原路径收回后,隐藏窗口再缩回组件栏;时钟等普通组件继续显示。
|
||||
if (
|
||||
!this.win ||
|
||||
this.win.isDestroyed() ||
|
||||
!this.customLayout ||
|
||||
this.editingLayout ||
|
||||
this.state.mode !== 'hidden'
|
||||
)
|
||||
return;
|
||||
if (!this.win || this.win.isDestroyed() || !this.customLayout || this.state.mode !== 'hidden') return;
|
||||
this.win.hide();
|
||||
const area = screen.getDisplayNearestPoint(this.win.getBounds()).workArea;
|
||||
this.customSize = {
|
||||
@@ -1432,7 +1402,7 @@ class IslandController {
|
||||
*/
|
||||
private syncWindow(): void {
|
||||
if (!this.win || this.win.isDestroyed()) return;
|
||||
if (this.coursewareShowing && !this.editingLayout) {
|
||||
if (this.coursewareShowing) {
|
||||
this.cancelFade();
|
||||
if (!this.win.isVisible() || this.customLayout) this.applyWindowLayout();
|
||||
this.syncTouchLayout();
|
||||
@@ -1442,10 +1412,6 @@ class IslandController {
|
||||
this.setInteractive(false, '课件传输不遮挡桌面操作');
|
||||
return;
|
||||
}
|
||||
if (this.editingLayout) {
|
||||
this.setInteractive(true, '布局编辑');
|
||||
return;
|
||||
}
|
||||
if (this.customLayout) {
|
||||
if (this.settlingLayout) return;
|
||||
this.cancelFade();
|
||||
@@ -1613,7 +1579,6 @@ class IslandController {
|
||||
private applyWindowLayout(): void {
|
||||
if (!this.win || this.win.isDestroyed()) return;
|
||||
const next = this.windowBounds();
|
||||
if (this.editingLayout) return;
|
||||
const current = this.win.getBounds();
|
||||
if (
|
||||
current.x === next.x &&
|
||||
@@ -1677,7 +1642,6 @@ class IslandController {
|
||||
*/
|
||||
private applyFocusable(): void {
|
||||
if (!this.win || this.win.isDestroyed()) return;
|
||||
if (this.editingLayout) return;
|
||||
if (!this.win.isFocusable()) this.win.setFocusable(true);
|
||||
if (this.state.mode === 'expanded') {
|
||||
this.win.focus();
|
||||
@@ -1817,7 +1781,7 @@ class IslandController {
|
||||
const next =
|
||||
passthrough || this.residentFaded
|
||||
? false
|
||||
: this.touchMode || this.editingLayout || (this.customLayout && !this.residentEnabled)
|
||||
: this.touchMode || (this.customLayout && !this.residentEnabled)
|
||||
? true
|
||||
: interactive;
|
||||
if (this.interactive === next) return;
|
||||
@@ -1879,7 +1843,6 @@ class IslandController {
|
||||
const faded =
|
||||
this.residentEnabled &&
|
||||
settings.pointerFadeEnabled &&
|
||||
!this.editingLayout &&
|
||||
!this.lessonShowing &&
|
||||
Date.now() >= this.residentTouchUntil &&
|
||||
Date.now() >= this.residentMotionUntil &&
|
||||
@@ -2403,13 +2366,6 @@ export function registerIslandIpc(): void {
|
||||
event.sender === island.getWindow()?.webContents ? island.getTimePoints() : [],
|
||||
);
|
||||
ipcMain.handle('island:get-layout', () => getConfig().islandLayout);
|
||||
ipcMain.handle('island:save-layout', (_event, value: unknown) => {
|
||||
const result = saveConfig({ islandLayout: normalizeIslandLayouts(value) }).islandLayout;
|
||||
island.syncCustomLayout();
|
||||
return result;
|
||||
});
|
||||
ipcMain.handle('island:edit-layout', () => island.editLayout());
|
||||
ipcMain.handle('island:get-editing', () => island.getEditingLayout());
|
||||
ipcMain.handle(
|
||||
'island:get-visible',
|
||||
(event) => event.sender === island.getWindow()?.webContents && (island.getWindow()?.isVisible() ?? false),
|
||||
@@ -2420,7 +2376,6 @@ export function registerIslandIpc(): void {
|
||||
ipcMain.on('island:resident-touch', (event) => {
|
||||
if (event.sender === island.getWindow()?.webContents) island.noteResidentTouch();
|
||||
});
|
||||
ipcMain.handle('island:set-editing', (_event, value: unknown) => island.editLayout(value === true));
|
||||
ipcMain.on('island:content-size', (event, value) => {
|
||||
if (event.sender === island.getWindow()?.webContents) island.reportCustomSize(value);
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import fs from 'node:fs';
|
||||
import { BrowserWindow } from 'electron';
|
||||
import path from 'node:path';
|
||||
import { BrowserWindow } from 'electron';
|
||||
import { island } from './island.js';
|
||||
import { getConfig, saveConfig } from './config.js';
|
||||
import {
|
||||
@@ -11,22 +11,28 @@ import {
|
||||
} from '@classhelper/shared';
|
||||
import { getIslandWeather } from './island-weather.js';
|
||||
import { verifyResidentSmoke } from './smoke-resident.js';
|
||||
|
||||
/**
|
||||
* 自定义岛回归:班级端只运行服务端下发的方案,布局编辑器已迁到 Web 管理端。
|
||||
* 这里验证“无本地编辑入口 + 固定行高居中渲染 + 通知宿主 + 天气边界”。
|
||||
*/
|
||||
export async function verifyLayoutSmoke(
|
||||
check: (name: string, action: () => Promise<boolean | string> | boolean) => Promise<void>,
|
||||
) {
|
||||
): Promise<void> {
|
||||
const original = getConfig().islandLayout;
|
||||
await island.init(null);
|
||||
island.setTestInputPassthrough(true);
|
||||
const win = island.getWindow()!;
|
||||
const editor = BrowserWindow.getAllWindows().find(
|
||||
(w) => w !== win && !w.isDestroyed() && /\/index\.html(?:#|$)/.test(w.webContents.getURL()),
|
||||
const main = BrowserWindow.getAllWindows().find(
|
||||
(item) => item !== win && !item.isDestroyed() && /\/index\.html(?:#|$)/.test(item.webContents.getURL()),
|
||||
)!;
|
||||
let editingBounds = win.getBounds();
|
||||
const pause = () => new Promise<void>((r) => setTimeout(r, 400));
|
||||
const pause = (ms = 400) => new Promise<void>((resolve) => setTimeout(resolve, ms));
|
||||
|
||||
try {
|
||||
await pause();
|
||||
await check('默认 fixed 布局且尺寸上报不参与', async () => {
|
||||
saveConfig({ islandLayout: defaultIslandLayouts() });
|
||||
island.syncCustomLayout();
|
||||
const before = win.getBounds();
|
||||
island.reportCustomSize({ width: 900, height: 900 });
|
||||
await pause();
|
||||
@@ -37,193 +43,46 @@ export async function verifyLayoutSmoke(
|
||||
getConfig().islandLayout.layout === 'fixed'
|
||||
);
|
||||
});
|
||||
await check('自定义编辑模式可进入并添加组件行', async () => {
|
||||
saveConfig({ islandLayout: { ...defaultIslandLayouts(), layout: 'custom' } });
|
||||
|
||||
await check('班级端不再注册灵动岛布局编辑路由', async () => {
|
||||
await main.webContents.executeJavaScript(`location.hash = '#/settings/island/editor'`);
|
||||
await pause();
|
||||
return main.webContents.executeJavaScript(
|
||||
`!location.hash.includes('/settings/island/editor') && !document.querySelector('.island-editor-page')`,
|
||||
);
|
||||
});
|
||||
|
||||
await check('服务端自定义布局按 40px 行高居中渲染', async () => {
|
||||
const custom = defaultIslandLayouts();
|
||||
custom.layout = 'custom';
|
||||
custom.residentEnabled = true;
|
||||
saveConfig({ islandLayout: custom });
|
||||
island.syncCustomLayout();
|
||||
await pause();
|
||||
editingBounds = win.getBounds();
|
||||
await editor.webContents.executeJavaScript('window.__classhelperSmoke__.islandEditorSmoke(true)');
|
||||
await pause();
|
||||
if (process.env.ISLAND_SHOTS_DIR) {
|
||||
fs.mkdirSync(process.env.ISLAND_SHOTS_DIR, { recursive: true });
|
||||
const bounds = editor.getContentBounds();
|
||||
editor.setContentSize(1600, 1000);
|
||||
for (const theme of ['light', 'dark']) {
|
||||
await editor.webContents.executeJavaScript(
|
||||
`document.documentElement.classList.toggle('dark', ${theme === 'dark'})`,
|
||||
);
|
||||
await pause();
|
||||
fs.writeFileSync(
|
||||
path.join(process.env.ISLAND_SHOTS_DIR, `component-editor-${theme}.png`),
|
||||
(await editor.webContents.capturePage()).toPNG(),
|
||||
);
|
||||
}
|
||||
await editor.webContents.executeJavaScript(`document.documentElement.classList.remove('dark')`);
|
||||
editor.setContentSize(bounds.width, bounds.height);
|
||||
await pause();
|
||||
}
|
||||
return (
|
||||
(await editor.webContents.executeJavaScript(
|
||||
'location.hash.includes("/settings/island/editor") && Boolean(document.querySelector(".aside"))',
|
||||
)) &&
|
||||
editor.webContents.executeJavaScript(
|
||||
`(() => { const b=[...document.querySelectorAll('button')].find(b=>b.textContent.trim()==='新增行');b?.click();return document.querySelectorAll('.component-library > .component-options:first-of-type .library-item').length===11 && !document.querySelector('.layout-editor, iframe'); })()`,
|
||||
)
|
||||
await pause(650);
|
||||
const geometry = await win.webContents.executeJavaScript(`(() => {
|
||||
const card = document.querySelector('.resident-card');
|
||||
const source = card?.querySelector('.resident-compact');
|
||||
const rows = [...document.querySelectorAll('.resident-compact .layout-row')];
|
||||
if (!card || !source || !rows.length) return null;
|
||||
const r = card.getBoundingClientRect();
|
||||
const s = source.getBoundingClientRect();
|
||||
return {
|
||||
centered: Math.abs(r.left + r.width / 2 - s.left - s.width / 2) <= 2,
|
||||
contained:
|
||||
s.left >= ${ISLAND_SHADOW_PAD} - 1 &&
|
||||
s.right <= innerWidth - ${ISLAND_SHADOW_PAD} + 1 &&
|
||||
s.top >= ${ISLAND_SHADOW_PAD} - 1 &&
|
||||
s.bottom <= innerHeight - ${ISLAND_SHADOW_PAD} + 1,
|
||||
rowHeights: rows.map((row) => Math.round(row.getBoundingClientRect().height)),
|
||||
};
|
||||
})()`);
|
||||
return Boolean(
|
||||
geometry?.centered &&
|
||||
geometry.contained &&
|
||||
geometry.rowHeights.every((height: number) => Math.abs(height - 40) <= 1),
|
||||
);
|
||||
});
|
||||
await check('触摸拖动可跨行并持久化', async () => {
|
||||
await pause();
|
||||
const dragGeometry = await editor.webContents.executeJavaScript(`(() => {
|
||||
const handle=document.querySelector('.node-handle[data-kind=clock]');
|
||||
const row=document.querySelectorAll('[data-row]')[1]; if(!handle||!row)throw Error('缺少拖动目标');
|
||||
document.querySelector('.preview-canvas')?.scrollIntoView({block:'center'});
|
||||
const r=row.getBoundingClientRect(); const x=r.left+Math.min(20,r.width/2),y=r.top+r.height/2;
|
||||
handle.dispatchEvent(new PointerEvent('pointerdown',{bubbles:true,pointerId:19,pointerType:'touch',clientX:10,clientY:10}));
|
||||
handle.dispatchEvent(new PointerEvent('pointermove',{bubbles:true,pointerId:19,pointerType:'touch',clientX:x,clientY:y}));
|
||||
handle.dispatchEvent(new PointerEvent('pointerup',{bubbles:true,pointerId:19,pointerType:'touch',clientX:x,clientY:y}));
|
||||
return {row:r.toJSON(), point:{x,y}, hit:document.elementFromPoint(x,y)?.outerHTML.slice(0,600), canvas:document.querySelector('.preview-canvas')?.getBoundingClientRect().toJSON()};
|
||||
})()`);
|
||||
await pause();
|
||||
const moved =
|
||||
getConfig().islandLayout.schemes[0]?.rows[1]?.nodes.some((n) => n.kind === 'clock') === true;
|
||||
if (!moved) throw new Error(JSON.stringify(dragGeometry));
|
||||
return true;
|
||||
});
|
||||
await check('组件可以包裹进容器且设置独立保存', async () => {
|
||||
await editor.webContents.executeJavaScript(
|
||||
`document.querySelector('.node-handle[data-kind=clock]')?.click()`,
|
||||
);
|
||||
await pause();
|
||||
await editor.webContents.executeJavaScript(
|
||||
`document.querySelector('[data-action=wrap] .el-select__wrapper')?.click()`,
|
||||
);
|
||||
await pause();
|
||||
await editor.webContents.executeJavaScript(
|
||||
`(() => { const option=[...document.querySelectorAll('.el-select-dropdown__item')].find(e=>e.textContent.trim()==='分组容器'); if(!option)throw Error('容器菜单未出现');option.click(); })()`,
|
||||
);
|
||||
await pause();
|
||||
return (
|
||||
getConfig().islandLayout.schemes[0]?.rows.some((r) =>
|
||||
r.nodes.some((n) => n.kind === 'group' && n.children.some((c) => c.kind === 'clock')),
|
||||
) === true
|
||||
);
|
||||
});
|
||||
await check('组件设置按内容外观高级切换,整体外观单独显示', async () => {
|
||||
const initial = await editor.webContents.executeJavaScript(`(() => {
|
||||
const panel=[...document.querySelectorAll('.component-settings .el-tab-pane')].find(e=>getComputedStyle(e).display!=='none');
|
||||
return panel?.textContent.includes('排列方向') && !panel.textContent.includes('背景颜色');
|
||||
})()`);
|
||||
await editor.webContents.executeJavaScript(
|
||||
`document.querySelectorAll('.component-settings .el-tabs__item')[1].click()`,
|
||||
);
|
||||
await pause();
|
||||
const appearance = await editor.webContents.executeJavaScript(`(() => {
|
||||
const panel=[...document.querySelectorAll('.component-settings .el-tab-pane')].find(e=>getComputedStyle(e).display!=='none');
|
||||
return panel?.textContent.includes('正文字号') && !panel.textContent.includes('排列方向');
|
||||
})()`);
|
||||
await editor.webContents.executeJavaScript(
|
||||
`document.querySelectorAll('.component-settings .el-tabs__item')[2].click()`,
|
||||
);
|
||||
await pause();
|
||||
const advanced = await editor.webContents.executeJavaScript(`(() => {
|
||||
const panel=[...document.querySelectorAll('.component-settings .el-tab-pane')].find(e=>getComputedStyle(e).display!=='none');
|
||||
return panel?.textContent.includes('隐藏条件') && !panel.textContent.includes('背景颜色');
|
||||
})()`);
|
||||
await editor.webContents.executeJavaScript(
|
||||
`document.querySelectorAll('.component-settings .el-tabs__item')[0].click()`,
|
||||
);
|
||||
await pause();
|
||||
return initial && appearance && advanced;
|
||||
});
|
||||
await check('主窗口编辑器的预览完整适配画布且不遮挡缩放控件', async () => {
|
||||
await editor.webContents.executeJavaScript(
|
||||
`document.querySelector('.el-drawer__close-btn')?.click();document.querySelector('.surface-actions button:last-child')?.click()`,
|
||||
);
|
||||
await pause();
|
||||
return editor.webContents.executeJavaScript(`(() => {
|
||||
const canvas=document.querySelector('.preview-canvas')?.getBoundingClientRect();
|
||||
const footer=document.querySelector('.preview-toolbar')?.getBoundingClientRect();
|
||||
return Boolean(canvas&&footer&&canvas.bottom<=footer.top+1&&document.documentElement.scrollWidth<=innerWidth);
|
||||
})()`);
|
||||
});
|
||||
await check('原生编辑页使用客户端主题并兼容深色', async () => {
|
||||
return editor.webContents.executeJavaScript(`(() => {
|
||||
const root=document.documentElement, wasDark=root.classList.contains('dark');
|
||||
root.classList.add('dark');
|
||||
const page=document.querySelector('.island-editor-page'), style=getComputedStyle(page);
|
||||
const ok=style.getPropertyValue('--ch-text').trim() && !document.querySelector('.layout-editor, iframe') && document.querySelector('.component-library .library-title') && document.querySelector('.scheme-controls');
|
||||
root.classList.toggle('dark',wasDark);return Boolean(ok);
|
||||
})()`);
|
||||
});
|
||||
await check('从常驻组件库拖入容器,阻止将父组件放进自己的后代', async () => {
|
||||
await editor.webContents.executeJavaScript(
|
||||
`document.querySelector('.surface-actions button:last-child')?.click()`,
|
||||
);
|
||||
await pause();
|
||||
await editor.webContents.executeJavaScript(`(() => {
|
||||
const source=document.querySelector('[data-library-kind=text]'), target=document.querySelector('.editor-component.container');
|
||||
if(!source||!target)throw Error('缺少组件库或容器');
|
||||
const r=target.getBoundingClientRect(), x=r.left+r.width/2, y=r.top+r.height/2;
|
||||
source.dispatchEvent(new PointerEvent('pointerdown',{bubbles:true,pointerId:21,clientX:10,clientY:10}));
|
||||
source.dispatchEvent(new PointerEvent('pointermove',{bubbles:true,pointerId:21,clientX:x,clientY:y}));
|
||||
source.dispatchEvent(new PointerEvent('pointerup',{bubbles:true,pointerId:21,clientX:x,clientY:y}));
|
||||
})()`);
|
||||
await pause();
|
||||
const group = getConfig()
|
||||
.islandLayout.schemes[0]!.rows.flatMap((r) => r.nodes)
|
||||
.find((n) => n.kind === 'group');
|
||||
if (!group?.children.some((n) => n.kind === 'text')) throw Error('组件库内容没有进入容器');
|
||||
const before = JSON.stringify(getConfig().islandLayout);
|
||||
await editor.webContents.executeJavaScript(`(() => {
|
||||
const source=document.querySelector('.editor-component.container > .node-handle'), target=document.querySelector('.editor-component.container .container-children .node-handle');
|
||||
const r=target.getBoundingClientRect(), x=r.left+r.width/2, y=r.top+r.height/2;
|
||||
source.dispatchEvent(new PointerEvent('pointerdown',{bubbles:true,pointerId:22,clientX:10,clientY:10}));
|
||||
source.dispatchEvent(new PointerEvent('pointerup',{bubbles:true,pointerId:22,clientX:x,clientY:y}));
|
||||
})()`);
|
||||
await pause();
|
||||
return before === JSON.stringify(getConfig().islandLayout);
|
||||
});
|
||||
await check('常态与无通知展开内容分别保存,日期倒计时可配置并预览', async () => {
|
||||
const before = JSON.stringify(getConfig().islandLayout.schemes[0]!.rows);
|
||||
await editor.webContents.executeJavaScript(
|
||||
`document.querySelectorAll('.surface-tabs button')[1].click();document.querySelector('[data-library-kind=countdown]').click()`,
|
||||
);
|
||||
await pause();
|
||||
await editor.webContents.executeJavaScript(`(() => {
|
||||
const set=(input,value)=>{input.value=value;input.dispatchEvent(new Event('input',{bubbles:true}));input.dispatchEvent(new Event('change',{bubbles:true}));};
|
||||
const field=[...document.querySelectorAll('.component-settings .el-form-item')].find(e=>e.textContent.includes('目标名称'));
|
||||
set(field.querySelector('input'),'运动会');
|
||||
document.querySelector('.component-settings .el-date-editor input').focus();
|
||||
})()`);
|
||||
await pause();
|
||||
await editor.webContents.executeJavaScript(`(() => {
|
||||
const picker=document.querySelector('.component-settings .el-date-editor input');
|
||||
picker.value='2099-10-25';picker.dispatchEvent(new Event('input',{bubbles:true}));
|
||||
})()`);
|
||||
await pause();
|
||||
await editor.webContents.executeJavaScript(`(() => {
|
||||
const picker=document.querySelector('.component-settings .el-date-editor input');
|
||||
picker.dispatchEvent(new Event('change',{bubbles:true}));picker.dispatchEvent(new KeyboardEvent('keydown',{key:'Enter',code:'Enter',bubbles:true}));picker.blur();
|
||||
})()`);
|
||||
await pause();
|
||||
const added = getConfig()
|
||||
.islandLayout.schemes[0]!.expandedRows.flatMap((r) => r.nodes)
|
||||
.find((n) => n.kind === 'countdown');
|
||||
if (added?.settings.targetDate !== '2099-10-25' || added.settings.countdownTitle !== '运动会')
|
||||
throw Error(JSON.stringify(added?.settings));
|
||||
await editor.webContents.executeJavaScript(
|
||||
`document.querySelector('.el-drawer__close-btn')?.click();document.querySelector('.surface-actions button:last-child')?.click()`,
|
||||
);
|
||||
await pause();
|
||||
const preview = await editor.webContents.executeJavaScript(
|
||||
`document.querySelector('.island-preview .countdown')?.textContent.includes('距运动会')`,
|
||||
);
|
||||
await editor.webContents.executeJavaScript(
|
||||
`document.querySelectorAll('.surface-tabs button')[0].click()`,
|
||||
);
|
||||
await pause();
|
||||
return preview && JSON.stringify(getConfig().islandLayout.schemes[0]!.rows) === before;
|
||||
});
|
||||
|
||||
await check('天气坐标校验、并发合并与缓存使用 mock,不访问外网', async () => {
|
||||
let calls = 0;
|
||||
const request: typeof fetch = async (input) => {
|
||||
@@ -246,149 +105,23 @@ export async function verifyLayoutSmoke(
|
||||
} catch {
|
||||
invalid = true;
|
||||
}
|
||||
const weather = islandNode('weather', 'weather-test'),
|
||||
countdown = islandNode('countdown', 'countdown-test');
|
||||
weather.settings.latitude = NaN;
|
||||
const weather = islandNode('weather', 'weather-test');
|
||||
const countdown = islandNode('countdown', 'countdown-test');
|
||||
weather.settings.latitude = Number.NaN;
|
||||
countdown.settings.targetDate = '2026-02-31';
|
||||
const config = defaultIslandLayouts();
|
||||
config.schemes[0]!.rows[0]!.nodes = [weather, countdown];
|
||||
const normalized = normalizeIslandLayouts(config).schemes[0]!.rows[0]!.nodes;
|
||||
return (
|
||||
calls === 1 &&
|
||||
results.every((r) => r.temperature === 23.4 && !r.stale) &&
|
||||
results.every((result) => result.temperature === 23.4 && !result.stale) &&
|
||||
invalid &&
|
||||
normalized[0]!.settings.latitude === null &&
|
||||
normalized[1]!.settings.targetDate === ''
|
||||
);
|
||||
});
|
||||
await check('右上角新建、重置和删除方案均可保存并恢复原方案', async () => {
|
||||
await editor.webContents.executeJavaScript(`document.querySelector('[aria-label="新建方案"]').click()`);
|
||||
await pause();
|
||||
await editor.webContents.executeJavaScript(
|
||||
`(() => { const input=[...document.querySelectorAll('.el-message-box__input input')].filter(e=>e.getBoundingClientRect().width>0).at(-1); input.value='组件方案验收';input.dispatchEvent(new Event('input',{bubbles:true}));[...document.querySelectorAll('.el-message-box__btns .el-button--primary')].filter(e=>e.getBoundingClientRect().width>0).at(-1).click(); })()`,
|
||||
);
|
||||
await pause();
|
||||
if (getConfig().islandLayout.schemes.length !== 2) throw Error('新建方案没有保存');
|
||||
await editor.webContents.executeJavaScript(
|
||||
`document.querySelector('[aria-label="重置当前方案"]').click()`,
|
||||
);
|
||||
await pause();
|
||||
await editor.webContents.executeJavaScript(
|
||||
`[...document.querySelectorAll('.el-message-box__btns .el-button--primary')].filter(e=>e.getBoundingClientRect().width>0).at(-1).click()`,
|
||||
);
|
||||
await pause();
|
||||
await editor.webContents.executeJavaScript(`document.querySelector('[aria-label="管理方案"]').click()`);
|
||||
await pause();
|
||||
await editor.webContents.executeJavaScript(
|
||||
`[...document.querySelectorAll('.el-dropdown-menu__item')].find(e=>e.textContent.trim()==='删除方案').click()`,
|
||||
);
|
||||
await pause();
|
||||
await editor.webContents.executeJavaScript(
|
||||
`[...document.querySelectorAll('.el-message-box__btns .el-button--primary')].filter(e=>e.getBoundingClientRect().width>0).at(-1).click()`,
|
||||
);
|
||||
await pause();
|
||||
const restored =
|
||||
getConfig().islandLayout.schemes.length === 1 &&
|
||||
getConfig().islandLayout.activeSchemeId === 'default' &&
|
||||
getConfig().islandLayout.schemes[0]!.rows.length === 2;
|
||||
if (!restored)
|
||||
throw Error(
|
||||
'方案未恢复:' +
|
||||
JSON.stringify({
|
||||
active: getConfig().islandLayout.activeSchemeId,
|
||||
schemes: getConfig().islandLayout.schemes.map((s) => ({
|
||||
id: s.id,
|
||||
name: s.name,
|
||||
rows: s.rows.length,
|
||||
})),
|
||||
}),
|
||||
);
|
||||
return restored;
|
||||
});
|
||||
await check('方案 JSON 导入导出保留容器结构并重新生成标识', async () => {
|
||||
await editor.webContents.executeJavaScript(`document.querySelector('[aria-label="管理方案"]').click()`);
|
||||
await pause();
|
||||
const exported = await editor.webContents.executeJavaScript(`(async () => {
|
||||
let blob; const originalURL=URL.createObjectURL, originalClick=HTMLAnchorElement.prototype.click;
|
||||
try {
|
||||
URL.createObjectURL=value=>{blob=value;return 'blob:editor-smoke';};HTMLAnchorElement.prototype.click=()=>{};
|
||||
[...document.querySelectorAll('.el-dropdown-menu__item')].find(e=>e.textContent.trim()==='导出方案').click();
|
||||
} finally { URL.createObjectURL=originalURL;HTMLAnchorElement.prototype.click=originalClick; }
|
||||
const text=await blob.text(), parsed=JSON.parse(text);
|
||||
const input=document.querySelector('.island-editor-page input[type=file]'), transfer=new DataTransfer();
|
||||
transfer.items.add(new File([text],'组件方案.json',{type:'application/json'}));input.files=transfer.files;
|
||||
input.dispatchEvent(new Event('change',{bubbles:true}));return parsed;
|
||||
})()`);
|
||||
await pause();
|
||||
const layouts = getConfig().islandLayout;
|
||||
const imported = layouts.schemes.find((s) => s.id === layouts.activeSchemeId)!;
|
||||
const shape = (nodes: ReturnType<typeof islandNode>[]): string =>
|
||||
JSON.stringify(
|
||||
nodes.map((n) => ({ kind: n.kind, children: shape(n.children), settings: n.settings })),
|
||||
);
|
||||
const preserved =
|
||||
exported.format === 'classhelper-island-layout' &&
|
||||
imported.id !== exported.scheme.id &&
|
||||
imported.rows.every(
|
||||
(row, index) =>
|
||||
row.id !== exported.scheme.rows[index].id &&
|
||||
shape(row.nodes) === shape(exported.scheme.rows[index].nodes),
|
||||
);
|
||||
await editor.webContents.executeJavaScript(`document.querySelector('[aria-label="管理方案"]').click()`);
|
||||
await pause();
|
||||
await editor.webContents.executeJavaScript(
|
||||
`[...document.querySelectorAll('.el-dropdown-menu__item')].find(e=>e.textContent.trim()==='删除方案').click()`,
|
||||
);
|
||||
await pause();
|
||||
await editor.webContents.executeJavaScript(
|
||||
`[...document.querySelectorAll('.el-message-box__btns .el-button--primary')].filter(e=>e.getBoundingClientRect().width>0).at(-1).click()`,
|
||||
);
|
||||
await pause();
|
||||
if (!preserved || getConfig().islandLayout.schemes.length !== 1)
|
||||
throw Error(
|
||||
'方案导入或收尾不一致:' +
|
||||
JSON.stringify({
|
||||
preserved,
|
||||
schemes: getConfig().islandLayout.schemes.map((s) => ({
|
||||
id: s.id,
|
||||
name: s.name,
|
||||
rows: s.rows.length,
|
||||
})),
|
||||
}),
|
||||
);
|
||||
return true;
|
||||
});
|
||||
if (process.env.ISLAND_SHOTS_DIR) {
|
||||
await editor.webContents.executeJavaScript(`document.querySelector('.main').scrollTop=0`);
|
||||
fs.mkdirSync(process.env.ISLAND_SHOTS_DIR, { recursive: true });
|
||||
fs.writeFileSync(
|
||||
path.join(process.env.ISLAND_SHOTS_DIR, 'custom-editor.png'),
|
||||
(await editor.webContents.capturePage()).toPNG(),
|
||||
);
|
||||
}
|
||||
await check('退出编辑后配置可从 getConfig 读回', async () => {
|
||||
await editor.webContents.executeJavaScript(
|
||||
`[...document.querySelectorAll('button')].find(b=>b.textContent.trim()==='应用并返回')?.click()`,
|
||||
);
|
||||
await pause();
|
||||
return (
|
||||
!island.getEditingLayout() &&
|
||||
getConfig().islandLayout.schemes[0]!.rows.length === 2 &&
|
||||
!editor.webContents.getURL().includes('/editor') &&
|
||||
win.getBounds().width === editingBounds.width
|
||||
);
|
||||
});
|
||||
await editor.webContents.executeJavaScript('window.__classhelperSmoke__.islandEditorSmoke(false)');
|
||||
await check('自定义岛统一使用固定画布且常态组件居中适配', async () => {
|
||||
await pause();
|
||||
return win.webContents.executeJavaScript(`(() => {
|
||||
const card=document.querySelector('.resident-card'), source=card?.querySelector('.resident-compact');
|
||||
if(!card||!source)return false;
|
||||
const r=card.getBoundingClientRect(),s=source.getBoundingClientRect();
|
||||
return r.width<=innerWidth-${2 * ISLAND_SHADOW_PAD}&&r.height<=innerHeight-${2 * ISLAND_SHADOW_PAD}&&Math.abs(r.left+r.width/2-s.left-s.width/2)<=2;
|
||||
})()`);
|
||||
});
|
||||
await check('自定义岛紧急通知立即弹出并复用经典通知内容', async () => {
|
||||
|
||||
await check('班级端自定义岛仍可处理紧急通知', async () => {
|
||||
island.setClassState({ inClass: false, currentPeriodEnd: null, week: 1 });
|
||||
island.pushNotification({
|
||||
id: 'custom-smoke-alert',
|
||||
@@ -399,45 +132,41 @@ export async function verifyLayoutSmoke(
|
||||
teacherName: '临时教师',
|
||||
courseName: null,
|
||||
});
|
||||
await pause();
|
||||
await pause();
|
||||
await pause(800);
|
||||
const result = await win.webContents.executeJavaScript(`(() => {
|
||||
const card=document.querySelector('.resident-card'), content=card?.querySelector('.classic-notifications'),r=card?.getBoundingClientRect(),c=content?.getBoundingClientRect();
|
||||
const shape=card?.querySelectorAll('.shape').length;
|
||||
const radius=parseFloat(card ? getComputedStyle(card).borderTopLeftRadius : '0');
|
||||
const valid=Boolean(content&&content.textContent.includes('组件化提醒验收')&&shape===0&&radius>0&&c.left>=r.left-1&&c.right<=r.right+1&&c.bottom<=r.bottom+1);
|
||||
return {valid,card:r?.toJSON(),content:c?.toJSON(),shape,radius};
|
||||
const card = document.querySelector('.resident-card');
|
||||
const content = card?.querySelector('.classic-notifications');
|
||||
if (!card || !content) return false;
|
||||
const r = card.getBoundingClientRect();
|
||||
const c = content.getBoundingClientRect();
|
||||
return (
|
||||
content.textContent.includes('组件化提醒验收') &&
|
||||
c.left >= r.left - 1 &&
|
||||
c.right <= r.right + 1 &&
|
||||
c.bottom <= r.bottom + 1
|
||||
);
|
||||
})()`);
|
||||
if (!result.valid) throw Error(JSON.stringify(result));
|
||||
return island.getState().mode === 'expanded';
|
||||
if (process.env.ISLAND_SHOTS_DIR) {
|
||||
fs.mkdirSync(process.env.ISLAND_SHOTS_DIR, { recursive: true });
|
||||
fs.writeFileSync(
|
||||
path.join(process.env.ISLAND_SHOTS_DIR, 'custom-alert.png'),
|
||||
(await win.webContents.capturePage()).toPNG(),
|
||||
);
|
||||
}
|
||||
return Boolean(result) && island.getState().mode === 'expanded';
|
||||
});
|
||||
if (process.env.ISLAND_SHOTS_DIR)
|
||||
fs.writeFileSync(
|
||||
path.join(process.env.ISLAND_SHOTS_DIR, 'custom-alert.png'),
|
||||
(await win.webContents.capturePage()).toPNG(),
|
||||
);
|
||||
|
||||
await win.webContents.executeJavaScript(
|
||||
`document.querySelector('#custom-alert-host .solid-btn')?.click()`,
|
||||
);
|
||||
await pause();
|
||||
await pause();
|
||||
await pause();
|
||||
await check('提醒收回后缩回组件栏,保留时钟与可见状态', async () => {
|
||||
const content = await win.webContents.executeJavaScript(
|
||||
`Boolean(document.querySelector('.custom-card .clock'))`,
|
||||
);
|
||||
const visible = process.env.ELECTRON_SMOKE_MODE === 'visual' ? win.isVisible() : !win.isVisible();
|
||||
return content && visible && island.getState().mode === 'hidden';
|
||||
});
|
||||
await check('没有提醒时消息组件不占位', async () => {
|
||||
return win.webContents.executeJavaScript(
|
||||
`document.querySelectorAll('.custom-card .component-node.notification, .custom-card .component-node.homework, .custom-card .component-node.call').length === 0`,
|
||||
);
|
||||
await pause(900);
|
||||
await check('通知收回后保留常驻组件状态', async () => {
|
||||
const state = island.getState();
|
||||
return state.mode === 'hidden' && state.active === null;
|
||||
});
|
||||
|
||||
await verifyResidentSmoke(check);
|
||||
} finally {
|
||||
if (editor && !editor.isDestroyed())
|
||||
await editor.webContents.executeJavaScript('window.__classhelperSmoke__.islandEditorSmoke(false)');
|
||||
saveConfig({ islandLayout: original });
|
||||
island.syncCustomLayout();
|
||||
win.hide();
|
||||
|
||||
@@ -90,7 +90,6 @@ export async function runQuickSmoke(win: BrowserWindow): Promise<void> {
|
||||
);
|
||||
const shots = path.resolve(app.getAppPath(), '../../docs/screenshots/desktop-responsive');
|
||||
fs.mkdirSync(shots, { recursive: true });
|
||||
await win.webContents.executeJavaScript('window.__classhelperSmoke__.islandEditorSmoke(true)');
|
||||
try {
|
||||
for (const [width, height] of [
|
||||
[1000, 540],
|
||||
@@ -111,7 +110,6 @@ export async function runQuickSmoke(win: BrowserWindow): Promise<void> {
|
||||
'/settings/general',
|
||||
'/settings/appearance',
|
||||
'/settings/island',
|
||||
'/settings/island/editor',
|
||||
'/settings/reminder',
|
||||
'/settings/account',
|
||||
'/settings/about',
|
||||
@@ -130,7 +128,7 @@ export async function runQuickSmoke(win: BrowserWindow): Promise<void> {
|
||||
}
|
||||
} finally {
|
||||
await win.webContents.executeJavaScript(
|
||||
`document.documentElement.className=${JSON.stringify(appearance.className)};document.documentElement.setAttribute('style',${JSON.stringify(appearance.style || '')});window.__classhelperSmoke__.islandEditorSmoke(false)`,
|
||||
`document.documentElement.className=${JSON.stringify(appearance.className)};document.documentElement.setAttribute('style',${JSON.stringify(appearance.style || '')})`,
|
||||
);
|
||||
win.setContentSize(bounds.width, bounds.height);
|
||||
}
|
||||
|
||||
@@ -30,19 +30,17 @@ export async function verifyResidentSmoke(
|
||||
path.join(process.env.ISLAND_SHOTS_DIR, `${name}.png`),
|
||||
(
|
||||
await win.webContents.capturePage(
|
||||
island.getEditingLayout()
|
||||
? undefined
|
||||
: (() => {
|
||||
const r = island.getHitRect();
|
||||
return r
|
||||
? {
|
||||
x: Math.max(0, Math.floor(r.x - 8)),
|
||||
y: Math.max(0, Math.floor(r.y - 8)),
|
||||
width: Math.ceil(r.width + 16),
|
||||
height: Math.ceil(r.height + 16),
|
||||
}
|
||||
: undefined;
|
||||
})(),
|
||||
(() => {
|
||||
const r = island.getHitRect();
|
||||
return r
|
||||
? {
|
||||
x: Math.max(0, Math.floor(r.x - 8)),
|
||||
y: Math.max(0, Math.floor(r.y - 8)),
|
||||
width: Math.ceil(r.width + 16),
|
||||
height: Math.ceil(r.height + 16),
|
||||
}
|
||||
: undefined;
|
||||
})(),
|
||||
)
|
||||
).toPNG(),
|
||||
);
|
||||
@@ -875,21 +873,6 @@ export async function verifyResidentSmoke(
|
||||
island.setTouchMode(false);
|
||||
}
|
||||
});
|
||||
await check('编辑入口交给主窗口,浮岛不会变成额外的全屏编辑窗口', async () => {
|
||||
const before = win.getBounds();
|
||||
let opened = false;
|
||||
island.setEditLayoutHandler(() => {
|
||||
opened = true;
|
||||
});
|
||||
island.editLayout();
|
||||
await pause(100);
|
||||
return (
|
||||
opened &&
|
||||
!island.getEditingLayout() &&
|
||||
JSON.stringify(before) === JSON.stringify(win.getBounds()) &&
|
||||
!(await win.webContents.executeJavaScript('Boolean(document.querySelector(".layout-editor"))'))
|
||||
);
|
||||
});
|
||||
await check('通知、作业、叫人均使用不透明背景和原生窗口,收起后恢复常驻透明度', async () => {
|
||||
const appearance = island.getAppearance();
|
||||
try {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { island } from './island.js';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { Menu, Tray, app, nativeImage } from 'electron';
|
||||
@@ -39,7 +38,6 @@ export function createTray(handlers: TrayHandlers): Tray | null {
|
||||
tray.setContextMenu(
|
||||
Menu.buildFromTemplate([
|
||||
{ label: '显示主窗口', click: () => handlers.onShow() },
|
||||
{ label: '编辑灵动岛布局', click: () => island.editLayout() },
|
||||
{ label: '隐藏到托盘', click: () => handlers.onHide() },
|
||||
{ type: 'separator' },
|
||||
{ label: '退出 ClassHelper', click: () => handlers.onQuit() },
|
||||
|
||||
@@ -34,12 +34,6 @@ const bridge: DesktopBridge = {
|
||||
ipcRenderer.on('courseware:progress', listener);
|
||||
return () => ipcRenderer.removeListener('courseware:progress', listener);
|
||||
},
|
||||
islandEditLayout: () => ipcRenderer.invoke('island:edit-layout'),
|
||||
onIslandEditorOpen: (handler) => {
|
||||
const listener = () => handler();
|
||||
ipcRenderer.on('island:open-editor', listener);
|
||||
return () => ipcRenderer.removeListener('island:open-editor', listener);
|
||||
},
|
||||
smokeTest: process.env.ELECTRON_SMOKE_TEST === '1',
|
||||
// 冒烟凭据:只在冒烟模式下透传,供渲染进程的冒烟钩子构造测试数据用。
|
||||
// **不走代码字面量**——本文件与渲染产物都会进 app.asar,写死账号等于随安装包把教师口令发出去。
|
||||
|
||||
@@ -16,12 +16,9 @@ export interface IslandBridge {
|
||||
onTheme(handler: (theme: 'light' | 'dark') => void): void;
|
||||
getIslandWeather(coordinates: { latitude: number; longitude: number }): Promise<IslandWeather>;
|
||||
getLayout(): Promise<ContractIslandLayoutSettings>;
|
||||
saveLayout(value: ContractIslandLayoutSettings): Promise<ContractIslandLayoutSettings>;
|
||||
onLayout(handler: (value: ContractIslandLayoutSettings) => void): void;
|
||||
getEditing(): Promise<boolean>;
|
||||
getVisible(): Promise<boolean>;
|
||||
onVisibility(handler: (visible: boolean) => void): void;
|
||||
setEditing(value: boolean): Promise<void>;
|
||||
onEditing(handler: (value: boolean) => void): void;
|
||||
reportSize(value: { width: number; height: number }): void;
|
||||
reportResidentControl(value: { x: number; y: number; width: number; height: number } | null): void;
|
||||
@@ -70,16 +67,13 @@ const bridge: IslandBridge = {
|
||||
},
|
||||
getIslandWeather: (coordinates) => ipcRenderer.invoke('island:weather', coordinates),
|
||||
getLayout: () => ipcRenderer.invoke('island:get-layout'),
|
||||
saveLayout: (value) => ipcRenderer.invoke('island:save-layout', value),
|
||||
onLayout: (handler) => {
|
||||
ipcRenderer.on('island:layout', (_event, value) => handler(value));
|
||||
},
|
||||
getEditing: () => ipcRenderer.invoke('island:get-editing'),
|
||||
getVisible: () => ipcRenderer.invoke('island:get-visible'),
|
||||
onVisibility: (handler) => {
|
||||
ipcRenderer.on('island:visibility', (_event, value) => handler(value));
|
||||
},
|
||||
setEditing: (value) => ipcRenderer.invoke('island:set-editing', value),
|
||||
onEditing: (handler) => {
|
||||
ipcRenderer.on('island:editing', (_event, value) => handler(value));
|
||||
},
|
||||
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
API_PATHS,
|
||||
type ClassDetailDto,
|
||||
type ClassDto,
|
||||
type ClassIslandLayoutDto,
|
||||
type CourseDto,
|
||||
type ExamDto,
|
||||
type ExamRankingDto,
|
||||
@@ -46,6 +47,12 @@ export const classApi = {
|
||||
detail: (id: string): Promise<ClassDetailDto> => api.get(`${API_PATHS.classes}/${id}`),
|
||||
};
|
||||
|
||||
/** 班级级灵动岛:教室端只读本班方案,编辑入口只在 Web 管理端。 */
|
||||
export const classIslandLayoutApi = {
|
||||
get: (classId: string): Promise<ClassIslandLayoutDto> =>
|
||||
api.get(`${API_PATHS.classes}/${classId}/island-layout`),
|
||||
};
|
||||
|
||||
export const scheduleApi = {
|
||||
list: (params: { classId?: string; week?: number }): Promise<ScheduleDto[]> =>
|
||||
api.get(API_PATHS.schedules, params),
|
||||
|
||||
@@ -1294,48 +1294,9 @@ export async function islandScheduleSyncSelfTest(): Promise<SmokeCheckResult> {
|
||||
}
|
||||
}
|
||||
|
||||
let restoreIslandEditorSmoke: (() => Promise<void>) | undefined;
|
||||
/** 主窗口内编辑器验收使用纯本地 API 替身,结束后恢复登录态、路由与方法。 */
|
||||
async function islandEditorSmoke(open: boolean): Promise<void> {
|
||||
if (!open) {
|
||||
await restoreIslandEditorSmoke?.();
|
||||
restoreIslandEditorSmoke = undefined;
|
||||
return;
|
||||
}
|
||||
const [{ api }, { useAuthStore }, { router }] = await Promise.all([
|
||||
import('../api/http.js'),
|
||||
import('../stores/auth.js'),
|
||||
import('../router/index.js'),
|
||||
]);
|
||||
const auth = useAuthStore(),
|
||||
token = auth.token,
|
||||
path = router.currentRoute.value.fullPath,
|
||||
originalGet = api.get;
|
||||
const onboardingDone = (await window.desktop!.getConfig()).onboardingDone;
|
||||
await window.desktop!.saveConfig({ onboardingDone: true });
|
||||
api.get = (async (url: string) => {
|
||||
if (url.includes('unread-count')) return { count: 0 };
|
||||
if (url.includes('active-week')) return { days: [] };
|
||||
if (url.includes('term')) return { currentWeek: 1, maxWeek: 40 };
|
||||
return [];
|
||||
}) as typeof api.get;
|
||||
auth.applyToken('local-editor-smoke');
|
||||
const { useOnboardingStore } = await import('../stores/onboarding.js');
|
||||
useOnboardingStore().close();
|
||||
restoreIslandEditorSmoke = async () => {
|
||||
await router.push('/login');
|
||||
auth.applyToken(token);
|
||||
await router.push(path);
|
||||
api.get = originalGet;
|
||||
await window.desktop!.saveConfig({ onboardingDone });
|
||||
};
|
||||
await router.push('/settings/island/editor');
|
||||
}
|
||||
|
||||
/** 注册到 window,供主进程冒烟脚本调用 */
|
||||
export function registerSmokeHooks(): void {
|
||||
window.__classhelperSmoke__ = {
|
||||
islandEditorSmoke,
|
||||
islandScheduleSyncSelfTest,
|
||||
cacheSelfTest,
|
||||
cacheIsolationSelfTest,
|
||||
|
||||
@@ -1,310 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import {
|
||||
CLASSISLAND_TOKENS,
|
||||
ISLAND_COMPONENT_LABELS,
|
||||
type IslandComponentNode,
|
||||
type IslandComponentKind,
|
||||
} from '@classhelper/shared';
|
||||
const props = defineProps<{ node: IslandComponentNode }>();
|
||||
const emit = defineEmits<{ change: []; remove: []; duplicate: []; wrap: [kind: IslandComponentKind] }>();
|
||||
const node = computed(() => props.node),
|
||||
tab = ref('content');
|
||||
watch(
|
||||
() => props.node.id,
|
||||
() => {
|
||||
tab.value = 'content';
|
||||
},
|
||||
);
|
||||
const fonts = {
|
||||
secondaryFontSize: '辅助文字',
|
||||
bodyFontSize: '正文',
|
||||
emphasizedFontSize: '强调文字',
|
||||
largeFontSize: '大号文字',
|
||||
} as const;
|
||||
const containers = ['group', 'stack', 'slide', 'rolling'] as const;
|
||||
</script>
|
||||
<template>
|
||||
<div class="component-settings">
|
||||
<h3>{{ ISLAND_COMPONENT_LABELS[node.kind] }}</h3>
|
||||
<el-tabs v-model="tab" stretch>
|
||||
<el-tab-pane label="内容" name="content">
|
||||
<el-form label-position="top">
|
||||
<template v-if="node.kind === 'clock'">
|
||||
<el-form-item label="12 小时制">
|
||||
<el-switch v-model="node.settings.hour12" @change="emit('change')" />
|
||||
</el-form-item>
|
||||
<el-form-item label="显示秒">
|
||||
<el-switch v-model="node.settings.seconds" @change="emit('change')" />
|
||||
</el-form-item>
|
||||
</template>
|
||||
<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="目标日期">
|
||||
<ch-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')" />
|
||||
</el-form-item>
|
||||
<el-form-item label="启用模板变量">
|
||||
<el-switch v-model="node.settings.template" @change="emit('change')" />
|
||||
</el-form-item>
|
||||
<p class="hint">支持 {date} 日期、{time} 时间、{course} 当前课程。</p>
|
||||
</template>
|
||||
<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="next" />
|
||||
<el-option label="今日时间点" value="today" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<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-switch v-model="node.settings.showPeriod" @change="emit('change')" />
|
||||
</el-form-item>
|
||||
<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="排列方向">
|
||||
<el-select v-model="node.settings.direction" @change="emit('change')">
|
||||
<el-option label="横向" value="horizontal" />
|
||||
<el-option label="纵向" value="vertical" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="组件间距">
|
||||
<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
|
||||
v-model="node.settings.interval"
|
||||
:min="1"
|
||||
:max="300"
|
||||
@change="emit('change')"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="node.kind === 'rolling'" label="滚动速度">
|
||||
<el-input-number v-model="node.settings.speed" :min="1" :max="200" @change="emit('change')" />
|
||||
</el-form-item>
|
||||
</template>
|
||||
<p v-else class="hint">此组件使用实时数据。可在外观和高级设置中调整显示。</p>
|
||||
<el-divider />
|
||||
<el-form-item label="包裹到容器">
|
||||
<el-select
|
||||
data-action="wrap"
|
||||
model-value=""
|
||||
placeholder="选择容器类型"
|
||||
@change="(kind: IslandComponentKind) => emit('wrap', kind)"
|
||||
>
|
||||
<el-option
|
||||
v-for="kind in containers"
|
||||
:key="kind"
|
||||
:label="ISLAND_COMPONENT_LABELS[kind]"
|
||||
:value="kind"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<div class="actions">
|
||||
<el-button @click="emit('duplicate')">复制组件</el-button>
|
||||
<el-button type="danger" plain @click="emit('remove')">删除</el-button>
|
||||
</div>
|
||||
</el-form>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="外观" name="appearance">
|
||||
<el-form label-position="top">
|
||||
<el-form-item label="独立外观">
|
||||
<el-switch v-model="node.appearance.resourceOverridingEnabled" @change="emit('change')" />
|
||||
</el-form-item>
|
||||
<p class="hint">关闭时沿用灵动岛的整体外观。</p>
|
||||
<el-form-item v-for="(label, key) in fonts" :key="key" :label="`${label}字号`">
|
||||
<el-input-number
|
||||
v-model="node.appearance[key]"
|
||||
:disabled="!node.appearance.resourceOverridingEnabled"
|
||||
:min="CLASSISLAND_TOKENS.fontSizes.inputMin"
|
||||
:max="CLASSISLAND_TOKENS.fontSizes.inputMax"
|
||||
:step="CLASSISLAND_TOKENS.fontSizes.inputStep"
|
||||
@change="emit('change')"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="自定义文字颜色">
|
||||
<el-switch
|
||||
v-model="node.appearance.customForegroundEnabled"
|
||||
:disabled="!node.appearance.resourceOverridingEnabled"
|
||||
@change="emit('change')"
|
||||
/>
|
||||
<el-color-picker
|
||||
v-if="node.appearance.customForegroundEnabled"
|
||||
v-model="node.appearance.foreground"
|
||||
@change="emit('change')"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="自定义背景颜色">
|
||||
<el-switch
|
||||
v-model="node.appearance.customBackgroundEnabled"
|
||||
:disabled="!node.appearance.resourceOverridingEnabled"
|
||||
@change="emit('change')"
|
||||
/>
|
||||
<el-color-picker
|
||||
v-if="node.appearance.customBackgroundEnabled"
|
||||
v-model="node.appearance.background"
|
||||
@change="emit('change')"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="自定义背景透明度">
|
||||
<el-switch
|
||||
v-model="node.appearance.customBackgroundOpacityEnabled"
|
||||
:disabled="!node.appearance.resourceOverridingEnabled"
|
||||
@change="emit('change')"
|
||||
/>
|
||||
<el-input-number
|
||||
v-if="node.appearance.customBackgroundOpacityEnabled"
|
||||
v-model="node.appearance.backgroundOpacity"
|
||||
:min="0"
|
||||
:max="1"
|
||||
:step="0.05"
|
||||
@change="emit('change')"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="自定义圆角">
|
||||
<el-switch
|
||||
v-model="node.appearance.customCornerRadiusEnabled"
|
||||
:disabled="!node.appearance.resourceOverridingEnabled"
|
||||
@change="emit('change')"
|
||||
/>
|
||||
<el-input-number
|
||||
v-if="node.appearance.customCornerRadiusEnabled"
|
||||
v-model="node.appearance.cornerRadius"
|
||||
:min="0"
|
||||
:max="CLASSISLAND_TOKENS.radii.islandMax"
|
||||
:step="CLASSISLAND_TOKENS.radii.islandStep"
|
||||
@change="emit('change')"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="组件透明度">
|
||||
<el-slider
|
||||
v-model="node.appearance.opacity"
|
||||
:min="0"
|
||||
:max="1"
|
||||
:step="0.05"
|
||||
@change="emit('change')"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="高级" name="advanced">
|
||||
<el-form label-position="top">
|
||||
<el-form-item label="对齐方式">
|
||||
<el-select v-model="node.advanced.align" @change="emit('change')">
|
||||
<el-option
|
||||
v-for="(label, key) in { stretch: '拉伸', start: '起始', center: '居中', end: '末端' }"
|
||||
:key="key"
|
||||
:label="label"
|
||||
:value="key"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="固定宽度(px)">
|
||||
<el-input-number v-model="node.advanced.width" :min="0" :max="2000" @change="emit('change')" />
|
||||
</el-form-item>
|
||||
<el-form-item label="最大宽度(px)">
|
||||
<el-input-number v-model="node.advanced.maxWidth" :min="0" :max="2000" @change="emit('change')" />
|
||||
</el-form-item>
|
||||
<p class="hint">宽度为 0 时自适应;对齐在父容器设定宽度时生效。</p>
|
||||
<el-form-item label="隐藏条件">
|
||||
<el-checkbox-group v-model="node.advanced.hideRules" @change="emit('change')">
|
||||
<el-checkbox label="上课时" value="in-class" />
|
||||
<el-checkbox label="没有消息时" value="no-message" />
|
||||
<el-checkbox label="没有当前课程时" value="no-class" />
|
||||
</el-checkbox-group>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</div>
|
||||
</template>
|
||||
<style scoped>
|
||||
h3 {
|
||||
margin: 0 0 6px;
|
||||
}
|
||||
.hint {
|
||||
color: var(--ch-text-secondary);
|
||||
line-height: 1.6;
|
||||
font-size: 12px;
|
||||
}
|
||||
.actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.el-select {
|
||||
width: 100%;
|
||||
}
|
||||
.el-form-item :deep(.el-form-item__content) {
|
||||
gap: 10px;
|
||||
}
|
||||
.el-checkbox-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
</style>
|
||||
@@ -1,124 +0,0 @@
|
||||
<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: var(--ch-radius-control);
|
||||
}
|
||||
.component-chip {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
min-height: 36px;
|
||||
padding: 5px 9px;
|
||||
border: 1px solid var(--ch-border);
|
||||
border-radius: var(--ch-radius-control);
|
||||
background: var(--ch-surface);
|
||||
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>
|
||||
@@ -2,6 +2,7 @@ import type { ActiveClassPlanWeekDto as ContractActiveClassPlanWeekDto } from '@
|
||||
import { watch, type WatchStopHandle } from 'vue';
|
||||
import {
|
||||
SOCKET_EVENTS,
|
||||
defaultIslandLayouts,
|
||||
resolveClassStatus,
|
||||
type ClassPeriod,
|
||||
type HomeworkDto,
|
||||
@@ -10,7 +11,7 @@ import {
|
||||
type ScheduleDto,
|
||||
} from '@classhelper/shared';
|
||||
import { api } from '../api/http.js';
|
||||
import { notificationApi } from '../api/index.js';
|
||||
import { classIslandLayoutApi, notificationApi } from '../api/index.js';
|
||||
import { fetchWithCache } from '../cache/index.js';
|
||||
import { getCacheScope } from '../cache/scope.js';
|
||||
import { clearOfflineSince, readOfflineSince, useAppStore } from '../stores/app.js';
|
||||
@@ -40,6 +41,8 @@ let refreshTimer: ReturnType<typeof setInterval> | null = null;
|
||||
let stopWeekWatch: WatchStopHandle | null = null;
|
||||
let scheduleRequest = 0;
|
||||
let scheduleWeek = 1;
|
||||
let appliedIslandLayout = '';
|
||||
let islandLayoutRequest = 0;
|
||||
|
||||
/** 供通知投递时读取:当前是否上课 + 本节课结束时间 */
|
||||
export function getIslandClassContext(): { inClass: boolean; currentPeriodEnd: string | null } {
|
||||
@@ -135,6 +138,47 @@ export async function refreshIslandSchedules(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步 Web 管理端为当前班保存的灵动岛方案。
|
||||
*
|
||||
* 班级端没有编辑入口:这里只拉取、比较并写入本机配置,主进程收到 config 补丁后会重启岛布局。
|
||||
* 服务端返回 `null` 表示尚未配置,保留本机默认/兼容方案;切换班级后旧响应不得落到新班。
|
||||
*/
|
||||
export async function syncClassIslandLayout(): Promise<void> {
|
||||
const auth = useAuthStore();
|
||||
const classId = auth.classId;
|
||||
if (!auth.token || !classId || !window.desktop?.saveConfig) return;
|
||||
const request = ++islandLayoutRequest;
|
||||
try {
|
||||
const result = await classIslandLayoutApi.get(classId);
|
||||
const current = await window.desktop.getConfig();
|
||||
if (request !== islandLayoutRequest || useAuthStore().classId !== classId) return;
|
||||
const local = current?.islandLayout ?? defaultIslandLayouts();
|
||||
const next = result.layout
|
||||
? {
|
||||
...result.layout,
|
||||
// 提醒阈值与指针避让属于教室本机偏好,服务端只下发班级布局。
|
||||
pointerFadeEnabled: local.pointerFadeEnabled,
|
||||
pointerFadeReversed: local.pointerFadeReversed,
|
||||
lessonReminders: local.lessonReminders,
|
||||
}
|
||||
: {
|
||||
...defaultIslandLayouts(),
|
||||
pointerFadeEnabled: local.pointerFadeEnabled,
|
||||
pointerFadeReversed: local.pointerFadeReversed,
|
||||
lessonReminders: local.lessonReminders,
|
||||
};
|
||||
const key = JSON.stringify(next);
|
||||
if (key === appliedIslandLayout) return;
|
||||
if (JSON.stringify(current?.islandLayout) !== key) {
|
||||
await window.desktop.saveConfig({ islandLayout: next });
|
||||
}
|
||||
if (request === islandLayoutRequest && useAuthStore().classId === classId) appliedIslandLayout = key;
|
||||
} catch {
|
||||
// 离线时保留本机已缓存的班级方案;恢复连接后由 class:updated / 周期同步补取。
|
||||
}
|
||||
}
|
||||
|
||||
let sentDay = '';
|
||||
let sentTimePoints = '';
|
||||
function timePointsKey(): string {
|
||||
@@ -413,6 +457,11 @@ function onScheduleUpdated(): void {
|
||||
void refreshIslandSchedules().catch(() => undefined);
|
||||
}
|
||||
|
||||
/** 班级资料变化:布局下发也走 class:updated,收到后静默补取。 */
|
||||
function onClassUpdated(): void {
|
||||
void syncClassIslandLayout();
|
||||
}
|
||||
|
||||
export function startIslandBridge(): void {
|
||||
if (tickTimer) return;
|
||||
stopWeekWatch = watch(
|
||||
@@ -423,14 +472,17 @@ export function startIslandBridge(): void {
|
||||
);
|
||||
|
||||
onScheduleUpdated();
|
||||
void syncClassIslandLayout();
|
||||
useRealtimeStore().on('__connected__', onScheduleUpdated);
|
||||
|
||||
// 课表变更(教师改课)立即复算,避免"下课后不弹出"或"上课没隐藏"
|
||||
useRealtimeStore().on(SOCKET_EVENTS.scheduleUpdated, onScheduleUpdated);
|
||||
useRealtimeStore().on(SOCKET_EVENTS.classUpdated, onClassUpdated);
|
||||
|
||||
tickTimer = setInterval(() => recomputeClassState(), TICK_INTERVAL_MS);
|
||||
refreshTimer = setInterval(() => {
|
||||
onScheduleUpdated();
|
||||
void syncClassIslandLayout();
|
||||
}, REFRESH_INTERVAL_MS);
|
||||
}
|
||||
|
||||
@@ -448,10 +500,12 @@ export function stopIslandBridge(): void {
|
||||
tickTimer = null;
|
||||
refreshTimer = null;
|
||||
scheduleRequest += 1;
|
||||
islandLayoutRequest += 1;
|
||||
stopWeekWatch?.();
|
||||
stopWeekWatch = null;
|
||||
|
||||
useRealtimeStore().off(SOCKET_EVENTS.scheduleUpdated, onScheduleUpdated);
|
||||
useRealtimeStore().off(SOCKET_EVENTS.classUpdated, onClassUpdated);
|
||||
useRealtimeStore().off('__connected__', onScheduleUpdated);
|
||||
sentDay = '';
|
||||
sentTimePoints = '';
|
||||
@@ -459,6 +513,7 @@ export function stopIslandBridge(): void {
|
||||
dayTimePoints = [];
|
||||
currentPeriod = null;
|
||||
inClass = false;
|
||||
appliedIslandLayout = '';
|
||||
|
||||
// 把"不在上课"同步给主进程:否则主进程还记着上一个会话的"上课中",
|
||||
// 重新登录后若第一轮课表刷新失败(离线且无缓存),灵动岛会继续按上课态把通知压着不弹,
|
||||
|
||||
@@ -20,11 +20,6 @@ const auth = useAuthStore();
|
||||
const realtime = useRealtimeStore();
|
||||
const notifications = useNotificationStore();
|
||||
const ui = useUiStore();
|
||||
const stopEditorNavigation = window.desktop?.onIslandEditorOpen(
|
||||
() => void router.push('/settings/island/editor'),
|
||||
);
|
||||
onUnmounted(() => stopEditorNavigation?.());
|
||||
|
||||
/**
|
||||
* 主侧边栏。
|
||||
*
|
||||
|
||||
@@ -18,7 +18,12 @@ const routes: RouteRecordRaw[] = [
|
||||
component: () => import('../layouts/ClientLayout.vue'),
|
||||
redirect: '/schedule',
|
||||
children: [
|
||||
{ path: 'courseware', name: 'courseware', component: () => import('../views/CoursewareView.vue'), meta: { title: '课件' } },
|
||||
{
|
||||
path: 'courseware',
|
||||
name: 'courseware',
|
||||
component: () => import('../views/CoursewareView.vue'),
|
||||
meta: { title: '课件' },
|
||||
},
|
||||
{
|
||||
path: 'schedule',
|
||||
name: 'schedule',
|
||||
@@ -66,12 +71,6 @@ const routes: RouteRecordRaw[] = [
|
||||
component: () => import('../views/settings/IslandSettingsView.vue'),
|
||||
meta: { title: '灵动岛' },
|
||||
},
|
||||
{
|
||||
path: 'settings/island/editor',
|
||||
name: 'settings-island-editor',
|
||||
component: () => import('../views/settings/IslandEditorView.vue'),
|
||||
meta: { title: '自定义灵动岛' },
|
||||
},
|
||||
{
|
||||
path: 'settings/reminder',
|
||||
name: 'settings-reminder',
|
||||
|
||||
@@ -1,432 +0,0 @@
|
||||
.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(--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;
|
||||
}
|
||||
.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-surface);
|
||||
border-radius: var(--ch-radius-control);
|
||||
}
|
||||
.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: var(--ch-radius-control);
|
||||
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: var(--ch-radius-control);
|
||||
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: var(--ci-text-1);
|
||||
padding: var(--ci-island-pad-x);
|
||||
border-radius: var(--preview-radius);
|
||||
background: var(--preview-background);
|
||||
font-family: var(--ci-font-island);
|
||||
font-weight: var(--ci-font-weight);
|
||||
}
|
||||
.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: var(--ci-island-pad-x);
|
||||
background: var(--preview-background);
|
||||
}
|
||||
.empty-preview {
|
||||
color: var(--ci-text-2);
|
||||
background: transparent;
|
||||
border: var(--ci-stroke-island-w) dashed var(--ci-stroke-control);
|
||||
border-radius: var(--ci-radius-control);
|
||||
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;
|
||||
}
|
||||
.font-preview {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: calc(var(--ci-line-gap) * 2);
|
||||
margin: 0 0 18px;
|
||||
padding: var(--ci-popup-pad);
|
||||
border: var(--ci-stroke-island-w) solid var(--ci-stroke-island);
|
||||
border-radius: var(--ci-radius-card);
|
||||
background: var(--ci-island-bg-custom);
|
||||
line-height: var(--ci-line-height-body);
|
||||
overflow: auto;
|
||||
}
|
||||
.component-library {
|
||||
border-top: 1px solid var(--ch-border);
|
||||
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 var(--ch-border);
|
||||
border-radius: var(--ch-radius-control);
|
||||
background: var(--ch-surface);
|
||||
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;
|
||||
}
|
||||
.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;
|
||||
}
|
||||
:global(.island-inspector) {
|
||||
color: var(--ch-text);
|
||||
background: var(--ch-surface);
|
||||
}
|
||||
:global(.island-inspector .el-drawer__header) {
|
||||
color: var(--ch-text);
|
||||
}
|
||||
:global(.island-inspector .el-input-number),
|
||||
:global(.island-inspector .el-select) {
|
||||
width: 100%;
|
||||
}
|
||||
:global(.island-inspector .el-input__wrapper),
|
||||
:global(.island-inspector .el-select__wrapper) {
|
||||
background: var(--ch-surface);
|
||||
border-radius: var(--ch-radius-control);
|
||||
}
|
||||
.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%;
|
||||
}
|
||||
.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;
|
||||
}
|
||||
}
|
||||
@@ -1,997 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, onUnmounted, ref } from 'vue';
|
||||
import { onBeforeRouteLeave, useRouter } from 'vue-router';
|
||||
import { ElMessage, ElMessageBox } from 'element-plus';
|
||||
import {
|
||||
CLASSISLAND_ISLAND_METRICS as METRICS,
|
||||
CLASSISLAND_TOKENS,
|
||||
DEFAULT_ISLAND_APPEARANCE,
|
||||
ISLAND_COMPONENT_LABELS,
|
||||
defaultIslandLayouts,
|
||||
islandNode,
|
||||
normalizeIslandLayouts,
|
||||
type IslandComponentKind,
|
||||
type IslandComponentNode,
|
||||
type IslandLayoutRow,
|
||||
type IslandLayoutScheme,
|
||||
type IslandState,
|
||||
type IslandAppearance,
|
||||
} from '@classhelper/shared';
|
||||
import ComponentNode from '../../../island/ComponentNode.vue';
|
||||
import ComponentIcon from '../../../island/ComponentIcon.vue';
|
||||
import IslandEditorNode from '../../components/IslandEditorNode.vue';
|
||||
import IslandComponentSettings from '../../components/IslandComponentSettings.vue';
|
||||
import { getIslandSchedules, getIslandTimePoints } from '../../island/bridge.js';
|
||||
const router = useRouter();
|
||||
const settings = ref(defaultIslandLayouts()),
|
||||
appearance = ref<IslandAppearance>({ ...DEFAULT_ISLAND_APPEARANCE });
|
||||
const schedules = ref(getIslandSchedules()),
|
||||
timePoints = ref(getIslandTimePoints()),
|
||||
now = ref(Date.now()),
|
||||
ready = ref(false),
|
||||
error = ref(''),
|
||||
pending = ref(0),
|
||||
saved = ref(false);
|
||||
const surface = ref<'compact' | 'expanded'>('compact'),
|
||||
panel = ref<'scheme' | 'row' | 'component'>('scheme');
|
||||
const selectedId = ref(''),
|
||||
rowId = ref(''),
|
||||
inspectorOpen = ref(false),
|
||||
editMode = ref(false),
|
||||
zoom = ref(1),
|
||||
importInput = ref<HTMLInputElement>();
|
||||
const scheme = computed(() =>
|
||||
settings.value.schemes.find((item) => item.id === settings.value.activeSchemeId)!,
|
||||
);
|
||||
const rows = computed(() => (surface.value === 'expanded' ? scheme.value.expandedRows : scheme.value.rows));
|
||||
const activeRow = computed(() => rows.value.find((row) => row.id === rowId.value) ?? rows.value[0]!);
|
||||
const fontFields = [
|
||||
{ key: 'secondaryFontSize', label: '辅助文字' },
|
||||
{ key: 'bodyFontSize', label: '正文' },
|
||||
{ key: 'emphasizedFontSize', label: '强调文字' },
|
||||
{ key: 'largeFontSize', label: '大号文字' },
|
||||
] as const;
|
||||
const fontWeights = [
|
||||
{ value: CLASSISLAND_TOKENS.fontWeights.thin, label: '100 Thin' },
|
||||
{ value: CLASSISLAND_TOKENS.fontWeights.extraLight, label: '200 ExtraLight' },
|
||||
{ value: CLASSISLAND_TOKENS.fontWeights.light, label: '300 Light' },
|
||||
{ value: CLASSISLAND_TOKENS.fontWeights.normal, label: '400 Normal' },
|
||||
{ value: CLASSISLAND_TOKENS.fontWeights.medium, label: '500 Medium(默认)' },
|
||||
{ value: CLASSISLAND_TOKENS.fontWeights.semiBold, label: '600 SemiBold' },
|
||||
{ value: CLASSISLAND_TOKENS.fontWeights.bold, label: '700 Bold' },
|
||||
{ value: CLASSISLAND_TOKENS.fontWeights.extraBold, label: '800 ExtraBold' },
|
||||
{ value: CLASSISLAND_TOKENS.fontWeights.black, label: '900 Black' },
|
||||
] as const;
|
||||
function rowStyle(row: IslandLayoutRow): Record<string, string> {
|
||||
const style: Record<string, string> = {
|
||||
'--row-gap': `${row.gap}px`,
|
||||
opacity: String(row.opacity),
|
||||
};
|
||||
if (row.fontOverridesEnabled) {
|
||||
style['--ci-fs-secondary'] = `${row.secondaryFontSize}px`;
|
||||
style['--ci-fs-body'] = `${row.bodyFontSize}px`;
|
||||
style['--ci-fs-emphasized'] = `${row.emphasizedFontSize}px`;
|
||||
style['--ci-fs-large'] = `${row.largeFontSize}px`;
|
||||
}
|
||||
return style;
|
||||
}
|
||||
function previewStyle(): Record<string, string> {
|
||||
const foreground: Record<string, string> = scheme.value.customForegroundEnabled
|
||||
? {
|
||||
'--ci-text-1': scheme.value.foreground,
|
||||
'--ci-text-2': `color-mix(in srgb, ${scheme.value.foreground} 85.5%, transparent)`,
|
||||
'--ci-text-3': `color-mix(in srgb, ${scheme.value.foreground} 77.3%, transparent)`,
|
||||
'--ci-text-4': `color-mix(in srgb, ${scheme.value.foreground} 52.9%, transparent)`,
|
||||
'--ci-text-5': `color-mix(in srgb, ${scheme.value.foreground} 36.5%, transparent)`,
|
||||
}
|
||||
: {};
|
||||
return {
|
||||
zoom: String(scheme.value.scale * zoom.value),
|
||||
'--preview-gap': `${scheme.value.spacing}px`,
|
||||
'--preview-radius': `${scheme.value.radius}px`,
|
||||
'--preview-background': scheme.value.customBackgroundEnabled
|
||||
? `color-mix(in srgb, ${scheme.value.color} ${scheme.value.opacity * 100}%, transparent)`
|
||||
: 'var(--ci-bg-secondary)',
|
||||
'--ci-fs-secondary': `${scheme.value.secondaryFontSize}px`,
|
||||
'--ci-fs-body': `${scheme.value.bodyFontSize}px`,
|
||||
'--ci-fs-emphasized': `${scheme.value.emphasizedFontSize}px`,
|
||||
'--ci-fs-large': `${scheme.value.largeFontSize}px`,
|
||||
'--ci-font-weight': String(scheme.value.fontWeight),
|
||||
'--ci-accent': appearance.value.resolvedAccent ?? appearance.value.accent,
|
||||
fontSize: `${scheme.value.bodyFontSize}px`,
|
||||
...foreground,
|
||||
};
|
||||
}
|
||||
const state: IslandState = {
|
||||
mode: 'hidden',
|
||||
active: null,
|
||||
queued: [],
|
||||
inClass: false,
|
||||
currentPeriodEnd: null,
|
||||
reason: null,
|
||||
listExpanded: false,
|
||||
maxCardHeight: 1024,
|
||||
updatedAt: 0,
|
||||
};
|
||||
const library: { kind: IslandComponentKind; description: string }[] = [
|
||||
{ kind: 'text', description: '显示自定义文本。' },
|
||||
{ kind: 'separator', description: '显示一个分割线,视觉上对组件进行分组。' },
|
||||
{ kind: 'schedule', description: '显示当前的课程表信息。' },
|
||||
{ kind: 'date', description: '显示今天的日期和星期。' },
|
||||
{ kind: 'clock', description: '显示现在的时间,支持精确到秒。' },
|
||||
{ kind: 'weather', description: '显示指定地点的天气概况和天气提示。' },
|
||||
{ kind: 'countdown', description: '显示距离某一天的倒计时。' },
|
||||
{ kind: 'slide', description: '轮播多个组件。' },
|
||||
{ kind: 'rolling', description: '滚动显示组件内的内容。' },
|
||||
{ kind: 'group', description: '将多个组件组合到一个组件中显示。' },
|
||||
{ kind: 'stack', description: '将多个容器堆叠显示。' },
|
||||
];
|
||||
const containers: readonly string[] = ['group', 'stack', 'slide', 'rolling'];
|
||||
function id() {
|
||||
return crypto.randomUUID();
|
||||
}
|
||||
function all(nodes: IslandComponentNode[]): IslandComponentNode[] {
|
||||
return nodes.flatMap((node) => [node, ...all(node.children)]);
|
||||
}
|
||||
const selected = computed(() =>
|
||||
rows.value.flatMap((row) => all(row.nodes)).find((node) => node.id === selectedId.value),
|
||||
);
|
||||
let saveQueue = Promise.resolve(),
|
||||
revision = 0,
|
||||
clock: ReturnType<typeof setInterval>;
|
||||
function save() {
|
||||
if (!ready.value) return saveQueue;
|
||||
const snapshot = normalizeIslandLayouts(JSON.parse(JSON.stringify(settings.value)));
|
||||
const current = ++revision;
|
||||
pending.value++;
|
||||
saved.value = false;
|
||||
saveQueue = saveQueue.then(async () => {
|
||||
try {
|
||||
if (!window.desktop) throw new Error('请在桌面客户端中保存方案');
|
||||
await window.desktop.saveConfig({ islandLayout: snapshot });
|
||||
if (current === revision) {
|
||||
error.value = '';
|
||||
saved.value = true;
|
||||
}
|
||||
} catch (e) {
|
||||
error.value = e instanceof Error ? e.message : '保存失败,请重试';
|
||||
} finally {
|
||||
pending.value--;
|
||||
}
|
||||
});
|
||||
return saveQueue;
|
||||
}
|
||||
function selectNode(nodeId: string) {
|
||||
if (suppressClick) return;
|
||||
selectedId.value = nodeId;
|
||||
panel.value = 'component';
|
||||
rowId.value = rows.value.find((row) => all(row.nodes).some((node) => node.id === nodeId))?.id ?? '';
|
||||
inspectorOpen.value = true;
|
||||
}
|
||||
function selectRow(value: string) {
|
||||
rowId.value = value;
|
||||
selectedId.value = '';
|
||||
panel.value = 'row';
|
||||
inspectorOpen.value = true;
|
||||
}
|
||||
function resetSelection() {
|
||||
cancelDrag();
|
||||
selectedId.value = '';
|
||||
rowId.value = '';
|
||||
panel.value = 'scheme';
|
||||
inspectorOpen.value = false;
|
||||
}
|
||||
function switchScheme() {
|
||||
resetSelection();
|
||||
void save();
|
||||
}
|
||||
function add(kind: IslandComponentKind) {
|
||||
if (suppressClick || !capacity()) return;
|
||||
const target = selected.value && containers.includes(selected.value.kind) ? selected.value : undefined;
|
||||
if (target && depthOf(target.id) >= 6) {
|
||||
ElMessage.warning('最多嵌套 6 层容器');
|
||||
return;
|
||||
}
|
||||
const node = makeNode(kind);
|
||||
(target ? target.children : activeRow.value.nodes).push(node);
|
||||
selectNode(node.id);
|
||||
void save();
|
||||
}
|
||||
function addRow() {
|
||||
if (rows.value.length >= 12) {
|
||||
ElMessage.warning('每种内容最多添加 12 行');
|
||||
return;
|
||||
}
|
||||
const row: IslandLayoutRow = {
|
||||
id: id(),
|
||||
name: `组件行 ${rows.value.length + 1}`,
|
||||
main: false,
|
||||
allowNotifications: true,
|
||||
gap: 8,
|
||||
opacity: CLASSISLAND_TOKENS.opacity.line,
|
||||
fontOverridesEnabled: false,
|
||||
secondaryFontSize: CLASSISLAND_TOKENS.fontSizes.secondary,
|
||||
bodyFontSize: CLASSISLAND_TOKENS.fontSizes.body,
|
||||
emphasizedFontSize: CLASSISLAND_TOKENS.fontSizes.emphasized,
|
||||
largeFontSize: CLASSISLAND_TOKENS.fontSizes.large,
|
||||
nodes: [],
|
||||
};
|
||||
rows.value.push(row);
|
||||
rowId.value = row.id;
|
||||
selectedId.value = '';
|
||||
void save();
|
||||
}
|
||||
function findList(nodeId: string, nodes?: IslandComponentNode[]): IslandComponentNode[] | undefined {
|
||||
for (const list of nodes ? [nodes] : rows.value.map((row) => row.nodes)) {
|
||||
if (list.some((node) => node.id === nodeId)) return list;
|
||||
for (const node of list) {
|
||||
const found = findList(nodeId, node.children);
|
||||
if (found) return found;
|
||||
}
|
||||
}
|
||||
}
|
||||
function removeNode() {
|
||||
const list = findList(selectedId.value);
|
||||
if (list)
|
||||
list.splice(
|
||||
list.findIndex((node) => node.id === selectedId.value),
|
||||
1,
|
||||
);
|
||||
selectedId.value = '';
|
||||
panel.value = 'row';
|
||||
void save();
|
||||
}
|
||||
function copyNode() {
|
||||
if (!selected.value || !capacity(all([selected.value]).length)) return;
|
||||
const list = findList(selected.value.id)!;
|
||||
const copy: IslandComponentNode = JSON.parse(JSON.stringify(selected.value));
|
||||
all([copy]).forEach((node) => (node.id = id()));
|
||||
list.splice(list.indexOf(selected.value) + 1, 0, copy);
|
||||
selectNode(copy.id);
|
||||
void save();
|
||||
}
|
||||
function wrap(kind: IslandComponentKind) {
|
||||
if (!selected.value || !containers.includes(kind) || !capacity()) return;
|
||||
if (depthOf(selected.value.id) + height(selected.value) + 1 > 6) {
|
||||
ElMessage.warning('最多嵌套 6 层容器');
|
||||
return;
|
||||
}
|
||||
const list = findList(selected.value.id)!,
|
||||
container = islandNode(kind, id());
|
||||
container.children = [selected.value];
|
||||
list.splice(list.indexOf(selected.value), 1, container);
|
||||
selectNode(container.id);
|
||||
void save();
|
||||
}
|
||||
function removeRow() {
|
||||
if (rows.value.length < 2) return;
|
||||
const index = rows.value.indexOf(activeRow.value);
|
||||
rows.value.splice(index, 1);
|
||||
if (!rows.value.some((row) => row.main)) rows.value[0]!.main = true;
|
||||
resetSelection();
|
||||
void save();
|
||||
}
|
||||
function setMain() {
|
||||
rows.value.forEach((row) => (row.main = row.id === activeRow.value.id));
|
||||
void save();
|
||||
}
|
||||
function cloneScheme() {
|
||||
if (
|
||||
!schemeCapacity() ||
|
||||
!capacity([...scheme.value.rows, ...scheme.value.expandedRows].flatMap((row) => all(row.nodes)).length)
|
||||
)
|
||||
return;
|
||||
const copy = JSON.parse(JSON.stringify(scheme.value)) as typeof scheme.value;
|
||||
copy.id = id();
|
||||
copy.name = `${copy.name.slice(0, 61)} 副本`;
|
||||
[...copy.rows, ...copy.expandedRows].forEach((row) => {
|
||||
row.id = id();
|
||||
all(row.nodes).forEach((node) => (node.id = id()));
|
||||
});
|
||||
settings.value.schemes.push(copy);
|
||||
settings.value.activeSchemeId = copy.id;
|
||||
switchScheme();
|
||||
}
|
||||
async function deleteScheme() {
|
||||
if (settings.value.schemes.length < 2) return;
|
||||
try {
|
||||
await ElMessageBox.confirm(`删除方案「${scheme.value.name}」?`, '删除方案', {
|
||||
confirmButtonText: '删除',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning',
|
||||
});
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
settings.value.schemes = settings.value.schemes.filter((item) => item.id !== scheme.value.id);
|
||||
settings.value.activeSchemeId = settings.value.schemes[0]!.id;
|
||||
switchScheme();
|
||||
}
|
||||
function exportScheme() {
|
||||
const url = URL.createObjectURL(
|
||||
new Blob([JSON.stringify({ format: 'classhelper-island-layout', scheme: scheme.value }, null, 2)], {
|
||||
type: 'application/json',
|
||||
}),
|
||||
);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = `${scheme.value.name.replace(/[<>:"/\\|?*]/g, '_')}.json`;
|
||||
a.click();
|
||||
setTimeout(() => URL.revokeObjectURL(url), 1000);
|
||||
}
|
||||
async function importScheme(event: Event) {
|
||||
const input = event.target as HTMLInputElement;
|
||||
try {
|
||||
const file = input.files?.[0];
|
||||
if (!file || !schemeCapacity()) return;
|
||||
if (file.size > 1000000) throw new Error('方案文件不能超过 1 MB');
|
||||
const parsed = JSON.parse(await file.text());
|
||||
if (
|
||||
parsed?.format !== 'classhelper-island-layout' ||
|
||||
!Array.isArray(parsed.scheme?.rows) ||
|
||||
!parsed.scheme.rows.length
|
||||
)
|
||||
throw new Error('方案格式不正确');
|
||||
const imported = normalizeIslandLayouts({ schemes: [parsed.scheme], activeSchemeId: parsed.scheme.id })
|
||||
.schemes[0]!;
|
||||
if (!capacity([...imported.rows, ...imported.expandedRows].flatMap((row) => all(row.nodes)).length))
|
||||
return;
|
||||
imported.id = id();
|
||||
[...imported.rows, ...imported.expandedRows].forEach((row) => {
|
||||
row.id = id();
|
||||
all(row.nodes).forEach((node) => (node.id = id()));
|
||||
});
|
||||
settings.value.schemes.push(imported);
|
||||
settings.value.activeSchemeId = imported.id;
|
||||
switchScheme();
|
||||
ElMessage.success('方案已导入');
|
||||
} catch (e) {
|
||||
ElMessage.error(e instanceof Error ? e.message : '导入失败');
|
||||
} finally {
|
||||
input.value = '';
|
||||
}
|
||||
}
|
||||
async function apply() {
|
||||
if (!ready.value) return;
|
||||
settings.value.layout = 'custom';
|
||||
settings.value.residentEnabled = true;
|
||||
await save();
|
||||
if (!error.value) {
|
||||
ElMessage.success('自定义灵动岛已应用');
|
||||
await router.push('/settings/island');
|
||||
}
|
||||
}
|
||||
async function load() {
|
||||
try {
|
||||
const config = await window.desktop?.getConfig();
|
||||
if (!config) throw new Error('请在桌面客户端中打开组件编辑器');
|
||||
if (config) {
|
||||
settings.value = normalizeIslandLayouts(config.islandLayout);
|
||||
appearance.value = config.island;
|
||||
}
|
||||
ready.value = true;
|
||||
error.value = '';
|
||||
} catch (e) {
|
||||
error.value = String(e);
|
||||
}
|
||||
}
|
||||
onMounted(async () => {
|
||||
window.addEventListener('pointermove', moveDrag, { passive: false });
|
||||
window.addEventListener('pointerup', dropPreview);
|
||||
window.addEventListener('pointercancel', cancelDrag);
|
||||
window.addEventListener('blur', cancelDrag);
|
||||
await load();
|
||||
clock = setInterval(() => {
|
||||
now.value = Date.now();
|
||||
schedules.value = getIslandSchedules();
|
||||
timePoints.value = getIslandTimePoints();
|
||||
}, 1000);
|
||||
});
|
||||
onUnmounted(() => {
|
||||
clearInterval(clock);
|
||||
window.removeEventListener('pointermove', moveDrag);
|
||||
window.removeEventListener('pointerup', dropPreview);
|
||||
window.removeEventListener('pointercancel', cancelDrag);
|
||||
window.removeEventListener('blur', cancelDrag);
|
||||
});
|
||||
onBeforeRouteLeave(async () => {
|
||||
if (!ready.value) return true;
|
||||
await save();
|
||||
return !error.value;
|
||||
});
|
||||
function capacity(count = 1) {
|
||||
const total = settings.value.schemes.reduce(
|
||||
(sum, item) =>
|
||||
sum + [...item.rows, ...item.expandedRows].reduce((n, row) => n + all(row.nodes).length, 0),
|
||||
0,
|
||||
);
|
||||
if (total + count <= 200) return true;
|
||||
ElMessage.warning('组件总数已达上限,请先删除不用的组件或方案');
|
||||
return false;
|
||||
}
|
||||
function depthOf(nodeId: string, nodes = rows.value.flatMap((row) => row.nodes), level = 0): number {
|
||||
for (const node of nodes) {
|
||||
if (node.id === nodeId) return level;
|
||||
const found = depthOf(nodeId, node.children, level + 1);
|
||||
if (found >= 0) return found;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
function height(node: IslandComponentNode): number {
|
||||
return node.children.length ? 1 + Math.max(...node.children.map(height)) : 0;
|
||||
}
|
||||
function makeNode(kind: IslandComponentKind) {
|
||||
const node = islandNode(kind, id());
|
||||
if (kind === 'countdown') node.settings.target = 'date';
|
||||
return node;
|
||||
}
|
||||
function moveRow(direction: number) {
|
||||
const index = rows.value.indexOf(activeRow.value),
|
||||
next = index + direction;
|
||||
if (next < 0 || next >= rows.value.length) return;
|
||||
rows.value.splice(next, 0, rows.value.splice(index, 1)[0]!);
|
||||
void save();
|
||||
}
|
||||
function renewScheme(copy: IslandLayoutScheme) {
|
||||
copy.id = id();
|
||||
[...copy.rows, ...copy.expandedRows].forEach((row) => {
|
||||
row.id = id();
|
||||
all(row.nodes).forEach((node) => (node.id = id()));
|
||||
});
|
||||
return copy;
|
||||
}
|
||||
function schemeCapacity() {
|
||||
if (settings.value.schemes.length < 20) return true;
|
||||
ElMessage.warning('最多保存 20 个方案');
|
||||
return false;
|
||||
}
|
||||
async function newScheme() {
|
||||
if (!schemeCapacity()) return;
|
||||
try {
|
||||
const { value } = await ElMessageBox.prompt('为新的组件方案命名', '新建方案', {
|
||||
inputValue: '新方案',
|
||||
inputValidator: (value) => (!!value?.trim() && value.trim().length <= 64) || '请输入 1–64 个字符',
|
||||
confirmButtonText: '创建',
|
||||
cancelButtonText: '取消',
|
||||
});
|
||||
const copy = renewScheme(JSON.parse(JSON.stringify(defaultIslandLayouts().schemes[0]!)));
|
||||
if (!capacity([...copy.rows, ...copy.expandedRows].flatMap((row) => all(row.nodes)).length)) return;
|
||||
copy.name = value.trim();
|
||||
settings.value.schemes.push(copy);
|
||||
settings.value.activeSchemeId = copy.id;
|
||||
switchScheme();
|
||||
} catch {
|
||||
/* 取消输入 */
|
||||
}
|
||||
}
|
||||
async function resetScheme() {
|
||||
try {
|
||||
await ElMessageBox.confirm(`将「${scheme.value.name}」的组件和外观恢复为默认配置?`, '重置方案', {
|
||||
confirmButtonText: '重置',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning',
|
||||
});
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
const copy = renewScheme(JSON.parse(JSON.stringify(defaultIslandLayouts().schemes[0]!)));
|
||||
const count =
|
||||
[...copy.rows, ...copy.expandedRows].flatMap((row) => all(row.nodes)).length -
|
||||
[...scheme.value.rows, ...scheme.value.expandedRows].flatMap((row) => all(row.nodes)).length;
|
||||
if (!capacity(count)) return;
|
||||
copy.id = scheme.value.id;
|
||||
copy.name = scheme.value.name;
|
||||
settings.value.schemes.splice(settings.value.schemes.indexOf(scheme.value), 1, copy);
|
||||
switchScheme();
|
||||
}
|
||||
function schemeCommand(command: string) {
|
||||
if (command === 'import') importInput.value?.click();
|
||||
if (command === 'export') exportScheme();
|
||||
if (command === 'clone') cloneScheme();
|
||||
if (command === 'delete') void deleteScheme();
|
||||
if (command === 'settings') {
|
||||
panel.value = 'scheme';
|
||||
inspectorOpen.value = true;
|
||||
}
|
||||
}
|
||||
// 原生 Pointer Events 同时覆盖鼠标、触摸和笔;释放到画布外会取消。
|
||||
type Drag = {
|
||||
nodeId?: string;
|
||||
kind?: IslandComponentKind;
|
||||
rowId?: string;
|
||||
x: number;
|
||||
y: number;
|
||||
moved: boolean;
|
||||
label: string;
|
||||
};
|
||||
const dragging = ref<Drag | null>(null);
|
||||
const pointer = ref({ x: 0, y: 0 });
|
||||
type Drop = { row: IslandLayoutRow; node?: IslandComponentNode; position: 'before' | 'after' | 'inside' };
|
||||
const drop = ref<Drop | null>(null);
|
||||
let suppressClick = false;
|
||||
function beginDrag(event: PointerEvent, source: Omit<Drag, 'x' | 'y' | 'moved'>) {
|
||||
if (event.button !== 0 || !ready.value) return;
|
||||
dragging.value = { ...source, x: event.clientX, y: event.clientY, moved: false };
|
||||
pointer.value = { x: event.clientX, y: event.clientY };
|
||||
try {
|
||||
(event.currentTarget as HTMLElement).setPointerCapture(event.pointerId);
|
||||
} catch {
|
||||
/* 合成事件没有活动指针 */
|
||||
}
|
||||
}
|
||||
function startDrag(event: PointerEvent, nodeId: string) {
|
||||
const node = rows.value.flatMap((row) => all(row.nodes)).find((node) => node.id === nodeId);
|
||||
if (node) beginDrag(event, { nodeId, label: ISLAND_COMPONENT_LABELS[node.kind] });
|
||||
}
|
||||
function dragTarget(event: PointerEvent): Drop | null {
|
||||
const element = document.elementFromPoint(event.clientX, event.clientY);
|
||||
const row = rows.value.find((row) => row.id === element?.closest<HTMLElement>('[data-row]')?.dataset.row);
|
||||
if (!row) return null;
|
||||
const target = element?.closest<HTMLElement>('[data-node]');
|
||||
const node = all(row.nodes).find((node) => node.id === target?.dataset.node);
|
||||
if (!node || !target) return { row, position: 'inside' };
|
||||
const rect = target.getBoundingClientRect(),
|
||||
ratio = (event.clientX - rect.left) / Math.max(1, rect.width);
|
||||
return {
|
||||
row,
|
||||
node,
|
||||
position:
|
||||
containers.includes(node.kind) && ratio > 0.2 && ratio < 0.8
|
||||
? 'inside'
|
||||
: ratio > 0.5
|
||||
? 'after'
|
||||
: 'before',
|
||||
};
|
||||
}
|
||||
function moveDrag(event: PointerEvent) {
|
||||
const current = dragging.value;
|
||||
if (!current) return;
|
||||
if (Math.hypot(event.clientX - current.x, event.clientY - current.y) >= 6) current.moved = true;
|
||||
if (!current.moved) return;
|
||||
event.preventDefault();
|
||||
pointer.value = { x: event.clientX, y: event.clientY };
|
||||
drop.value = dragTarget(event);
|
||||
}
|
||||
function cancelDrag() {
|
||||
dragging.value = null;
|
||||
drop.value = null;
|
||||
}
|
||||
function dropPreview(event: PointerEvent) {
|
||||
const current = dragging.value;
|
||||
if (!current) return;
|
||||
const moved = current.moved || Math.hypot(event.clientX - current.x, event.clientY - current.y) >= 6;
|
||||
const target = moved ? dragTarget(event) : null;
|
||||
cancelDrag();
|
||||
if (!moved) return;
|
||||
suppressClick = true;
|
||||
setTimeout(() => (suppressClick = false), 0);
|
||||
if (!target) return;
|
||||
if (current.rowId) {
|
||||
const index = rows.value.findIndex((row) => row.id === current.rowId);
|
||||
if (index < 0 || target.row.id === current.rowId) return;
|
||||
const next = rows.value.indexOf(target.row);
|
||||
rows.value.splice(next, 0, rows.value.splice(index, 1)[0]!);
|
||||
void save();
|
||||
return;
|
||||
}
|
||||
const list = current.nodeId ? findList(current.nodeId) : undefined;
|
||||
const node =
|
||||
list?.find((node) => node.id === current.nodeId) ?? (current.kind ? makeNode(current.kind) : undefined);
|
||||
if (!node || (current.kind && !capacity())) return;
|
||||
if (all([node]).some((child) => child.id === target.node?.id)) return;
|
||||
const level = target.node ? depthOf(target.node.id) + (target.position === 'inside' ? 1 : 0) : 0;
|
||||
if (level + height(node) > 6) {
|
||||
ElMessage.warning('最多嵌套 6 层容器');
|
||||
return;
|
||||
}
|
||||
const destination = target.node
|
||||
? target.position === 'inside'
|
||||
? target.node.children
|
||||
: findList(target.node.id)!
|
||||
: target.row.nodes;
|
||||
list?.splice(list.indexOf(node), 1);
|
||||
const index =
|
||||
target.node && target.position !== 'inside'
|
||||
? destination.indexOf(target.node) + (target.position === 'after' ? 1 : 0)
|
||||
: destination.length;
|
||||
destination.splice(index, 0, node);
|
||||
selectedId.value = node.id;
|
||||
rowId.value = target.row.id;
|
||||
panel.value = 'component';
|
||||
void save();
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="page island-editor-page" aria-label="自定义灵动岛设置">
|
||||
<div class="editor-actions">
|
||||
<span class="save-status" :class="{ failed: error }" role="status">
|
||||
{{ error ? '保存失败' : pending ? '正在保存…' : saved ? '已自动保存' : '更改自动保存到本机' }}
|
||||
</span>
|
||||
<el-button text size="small" @click="router.push('/settings/island')">返回设置</el-button>
|
||||
<el-button type="primary" size="small" :loading="!!pending" :disabled="!ready" @click="apply">
|
||||
应用并返回
|
||||
</el-button>
|
||||
</div>
|
||||
<header class="page-header component-heading">
|
||||
<div class="heading-copy">
|
||||
<h2 class="page-title">组件</h2>
|
||||
<p>以下组件将显示在主界面上,从组件库拖动组件以添加组件。</p>
|
||||
</div>
|
||||
<div class="scheme-tools" :aria-busy="!ready">
|
||||
<label id="scheme-label">配置方案</label>
|
||||
<div class="scheme-controls">
|
||||
<el-select
|
||||
v-model="settings.activeSchemeId"
|
||||
aria-labelledby="scheme-label"
|
||||
aria-label="当前方案"
|
||||
:disabled="!ready"
|
||||
@change="switchScheme"
|
||||
>
|
||||
<el-option v-for="item in settings.schemes" :key="item.id" :label="item.name" :value="item.id" />
|
||||
</el-select>
|
||||
<el-button
|
||||
text
|
||||
class="icon-button"
|
||||
title="重置当前方案"
|
||||
aria-label="重置当前方案"
|
||||
:disabled="!ready"
|
||||
@click="resetScheme"
|
||||
>
|
||||
<el-icon><Refresh /></el-icon>
|
||||
</el-button>
|
||||
<el-button
|
||||
text
|
||||
class="icon-button"
|
||||
title="新建方案"
|
||||
aria-label="新建方案"
|
||||
:disabled="!ready"
|
||||
@click="newScheme"
|
||||
>
|
||||
<el-icon><Plus /></el-icon>
|
||||
</el-button>
|
||||
<el-dropdown trigger="click" :disabled="!ready" @command="schemeCommand">
|
||||
<el-button text class="icon-button" title="管理方案" aria-label="管理方案" :disabled="!ready">
|
||||
<el-icon><FolderOpened /></el-icon>
|
||||
</el-button>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item command="settings">方案设置</el-dropdown-item>
|
||||
<el-dropdown-item command="clone">复制方案</el-dropdown-item>
|
||||
<el-dropdown-item command="import" divided>导入方案</el-dropdown-item>
|
||||
<el-dropdown-item command="export">导出方案</el-dropdown-item>
|
||||
<el-dropdown-item command="delete" divided :disabled="settings.schemes.length < 2">
|
||||
删除方案
|
||||
</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<el-alert v-if="error" type="error" :closable="false" :title="error">
|
||||
<el-button link type="primary" @click="ready ? save() : load()">重试</el-button>
|
||||
</el-alert>
|
||||
<template v-if="ready">
|
||||
<div class="surface-toolbar">
|
||||
<div class="surface-tabs" role="tablist" aria-label="编辑内容">
|
||||
<button
|
||||
role="tab"
|
||||
:aria-selected="surface === 'compact'"
|
||||
:class="{ active: surface === 'compact' }"
|
||||
@click="
|
||||
surface = 'compact';
|
||||
resetSelection();
|
||||
"
|
||||
>
|
||||
常态内容
|
||||
</button>
|
||||
<button
|
||||
role="tab"
|
||||
:aria-selected="surface === 'expanded'"
|
||||
:class="{ active: surface === 'expanded' }"
|
||||
@click="
|
||||
surface = 'expanded';
|
||||
resetSelection();
|
||||
"
|
||||
>
|
||||
无通知展开内容
|
||||
</button>
|
||||
</div>
|
||||
<div class="surface-actions">
|
||||
<el-button text size="small" @click="addRow">新增行</el-button>
|
||||
<el-button
|
||||
text
|
||||
size="small"
|
||||
@click="
|
||||
panel = 'row';
|
||||
inspectorOpen = true;
|
||||
"
|
||||
>
|
||||
行设置
|
||||
</el-button>
|
||||
<el-button text size="small" :type="editMode ? 'primary' : 'default'" @click="editMode = !editMode">
|
||||
{{ editMode ? '退出编辑模式' : '进入编辑模式' }}
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="preview-canvas"
|
||||
:class="{ 'live-preview': editMode, 'is-dragging': dragging?.moved }"
|
||||
aria-label="组件排列画布"
|
||||
>
|
||||
<div v-if="!editMode" class="component-lines">
|
||||
<section
|
||||
v-for="row in rows"
|
||||
:key="row.id"
|
||||
class="component-line"
|
||||
:class="{
|
||||
'drop-row': drop?.row.id === row.id && !drop.node,
|
||||
'active-row': rows.length > 1 && activeRow.id === row.id,
|
||||
}"
|
||||
:data-row="row.id"
|
||||
>
|
||||
<button
|
||||
class="row-handle"
|
||||
:aria-label="`编辑${row.name}`"
|
||||
:title="`${row.name},拖动排序,点击设置`"
|
||||
@pointerdown="beginDrag($event, { rowId: row.id, label: row.name })"
|
||||
@click="!suppressClick && selectRow(row.id)"
|
||||
>
|
||||
<span aria-hidden="true">Ⅱ</span>
|
||||
</button>
|
||||
<div class="line-components" :style="{ gap: `${row.gap}px` }">
|
||||
<IslandEditorNode
|
||||
v-for="node in row.nodes"
|
||||
:key="node.id"
|
||||
:node="node"
|
||||
:selected-id="selectedId"
|
||||
:drop-id="drop?.node?.id"
|
||||
:drop-position="drop?.position"
|
||||
@select="selectNode"
|
||||
@drag="startDrag"
|
||||
/>
|
||||
<button v-if="!row.nodes.length" class="empty-line" @click="selectRow(row.id)">
|
||||
将组件拖到这里,或点击下方组件添加
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
<div v-else class="island-preview" :class="{ separated: scheme.separated }" :style="previewStyle()">
|
||||
<section
|
||||
v-for="row in rows"
|
||||
:key="row.id"
|
||||
class="preview-row"
|
||||
:class="{ 'drop-row': drop?.row.id === row.id && !drop.node }"
|
||||
:data-row="row.id"
|
||||
:style="rowStyle(row)"
|
||||
@click.self="selectRow(row.id)"
|
||||
>
|
||||
<ComponentNode
|
||||
v-for="node in row.nodes"
|
||||
:key="node.id"
|
||||
:node="node"
|
||||
:state="state"
|
||||
:now="now"
|
||||
:schedules="schedules"
|
||||
:time-points="timePoints"
|
||||
editing
|
||||
:selected-id="selectedId"
|
||||
alert-node-id=""
|
||||
@select="selectNode"
|
||||
@drag="startDrag"
|
||||
/>
|
||||
<button v-if="!row.nodes.length" class="empty-preview" @click="selectRow(row.id)">
|
||||
将组件拖到这里
|
||||
</button>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="editMode" class="preview-toolbar">
|
||||
<span>预览缩放</span>
|
||||
<el-slider
|
||||
v-model="zoom"
|
||||
:min="0.3"
|
||||
:max="1.5"
|
||||
:step="0.1"
|
||||
:format-tooltip="(v: number) => `${Math.round(v * 100)}%`"
|
||||
/>
|
||||
<el-button text size="small" @click="zoom = 1">重置缩放</el-button>
|
||||
<span class="hint">点选组件调整内容、外观和隐藏条件</span>
|
||||
</div>
|
||||
<section class="component-library" aria-labelledby="library-heading">
|
||||
<h3 id="library-heading" class="library-title">组件库</h3>
|
||||
<div class="component-options">
|
||||
<button
|
||||
v-for="item in library"
|
||||
:key="item.kind"
|
||||
class="library-item"
|
||||
:data-library-kind="item.kind"
|
||||
:aria-label="`添加${ISLAND_COMPONENT_LABELS[item.kind]}`"
|
||||
@pointerdown="beginDrag($event, { kind: item.kind, label: ISLAND_COMPONENT_LABELS[item.kind] })"
|
||||
@click="add(item.kind)"
|
||||
>
|
||||
<ComponentIcon :kind="item.kind" />
|
||||
<span>
|
||||
<strong>{{ ISLAND_COMPONENT_LABELS[item.kind] }}</strong>
|
||||
<span class="component-description">{{ item.description }}</span>
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
<el-skeleton v-else :rows="8" animated />
|
||||
<input ref="importInput" type="file" accept="application/json,.json" hidden @change="importScheme" />
|
||||
<div
|
||||
v-if="dragging?.moved"
|
||||
class="drag-ghost"
|
||||
:style="{ left: `${pointer.x + 16}px`, top: `${pointer.y + 16}px` }"
|
||||
>
|
||||
{{ dragging.label }}
|
||||
</div>
|
||||
<el-drawer
|
||||
v-model="inspectorOpen"
|
||||
class="island-inspector"
|
||||
title="组件设置"
|
||||
:size="'min(360px, 94vw)'"
|
||||
:modal="false"
|
||||
modal-penetrable
|
||||
:lock-scroll="false"
|
||||
append-to-body
|
||||
>
|
||||
<el-radio-group v-model="panel" size="small" class="inspector-tabs">
|
||||
<el-radio-button value="scheme">方案</el-radio-button>
|
||||
<el-radio-button value="row">行</el-radio-button>
|
||||
<el-radio-button value="component" :disabled="!selected">组件</el-radio-button>
|
||||
</el-radio-group>
|
||||
<IslandComponentSettings
|
||||
v-if="panel === 'component' && selected"
|
||||
:node="selected"
|
||||
@change="save"
|
||||
@remove="removeNode"
|
||||
@duplicate="copyNode"
|
||||
@wrap="wrap"
|
||||
/>
|
||||
<el-form v-else-if="panel === 'row'" label-position="top">
|
||||
<h3>组件行</h3>
|
||||
<el-form-item label="当前行">
|
||||
<el-select :model-value="activeRow.id" @change="selectRow">
|
||||
<el-option v-for="row in rows" :key="row.id" :value="row.id" :label="row.name" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="行名称">
|
||||
<el-input v-model="activeRow.name" :maxlength="64" @change="save" />
|
||||
</el-form-item>
|
||||
<el-form-item label="组件间距">
|
||||
<el-input-number v-model="activeRow.gap" :min="0" :max="64" @change="save" />
|
||||
</el-form-item>
|
||||
<el-form-item label="整行透明度">
|
||||
<el-slider
|
||||
v-model="activeRow.opacity"
|
||||
:min="0"
|
||||
:max="1"
|
||||
:step="0.05"
|
||||
:format-tooltip="(value: number) => value.toFixed(2)"
|
||||
@change="save"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="行级字号覆盖">
|
||||
<el-switch v-model="activeRow.fontOverridesEnabled" @change="save" />
|
||||
</el-form-item>
|
||||
<el-form-item v-for="field in fontFields" :key="field.key" :label="`${field.label}字号(px)`">
|
||||
<el-input-number
|
||||
v-model="activeRow[field.key]"
|
||||
:disabled="!activeRow.fontOverridesEnabled"
|
||||
:min="CLASSISLAND_TOKENS.fontSizes.inputMin"
|
||||
:max="CLASSISLAND_TOKENS.fontSizes.inputMax"
|
||||
:step="CLASSISLAND_TOKENS.fontSizes.inputStep"
|
||||
@change="save"
|
||||
/>
|
||||
</el-form-item>
|
||||
<p class="hint">行级字号只写到当前行根元素;关闭覆盖后回落到方案字号。</p>
|
||||
<el-form-item label="允许显示提醒">
|
||||
<el-switch v-model="activeRow.allowNotifications" @change="save" />
|
||||
</el-form-item>
|
||||
<el-button :disabled="activeRow.main" @click="setMain">
|
||||
{{ activeRow.main ? '已设为主要行' : '设为主要行' }}
|
||||
</el-button>
|
||||
<p class="hint">提醒优先使用主要行;关闭提醒后使用下一条允许提醒的行。</p>
|
||||
<div class="row-actions">
|
||||
<el-button :disabled="rows.indexOf(activeRow) === 0" @click="moveRow(-1)">上移</el-button>
|
||||
<el-button :disabled="rows.indexOf(activeRow) === rows.length - 1" @click="moveRow(1)">
|
||||
下移
|
||||
</el-button>
|
||||
<el-button type="danger" plain :disabled="rows.length < 2" @click="removeRow">删除此行</el-button>
|
||||
</div>
|
||||
</el-form>
|
||||
<el-form v-else label-position="top">
|
||||
<h3>方案设置</h3>
|
||||
<el-form-item label="方案名称">
|
||||
<el-input v-model="scheme.name" :maxlength="64" @change="save" />
|
||||
</el-form-item>
|
||||
<el-form-item label="界面缩放">
|
||||
<el-input-number
|
||||
v-model="scheme.scale"
|
||||
:min="METRICS.scaleMin"
|
||||
:max="METRICS.scaleMax"
|
||||
:step="CLASSISLAND_TOKENS.dpi.scaleStep"
|
||||
@change="save"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="字体字重">
|
||||
<el-select v-model="scheme.fontWeight" @change="save">
|
||||
<el-option
|
||||
v-for="weight in fontWeights"
|
||||
:key="weight.value"
|
||||
:label="weight.label"
|
||||
:value="weight.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item v-for="field in fontFields" :key="field.key" :label="`${field.label}字号(px)`">
|
||||
<el-input-number
|
||||
v-model="scheme[field.key]"
|
||||
:min="CLASSISLAND_TOKENS.fontSizes.inputMin"
|
||||
:max="CLASSISLAND_TOKENS.fontSizes.inputMax"
|
||||
:step="CLASSISLAND_TOKENS.fontSizes.inputStep"
|
||||
@change="save"
|
||||
/>
|
||||
</el-form-item>
|
||||
<div class="font-preview" aria-label="四档字号预览">
|
||||
<span class="l1" :style="{ fontSize: `${scheme.secondaryFontSize}px` }">辅助文字</span>
|
||||
<span class="l2" :style="{ fontSize: `${scheme.bodyFontSize}px` }">正文示例</span>
|
||||
<span
|
||||
class="l1"
|
||||
:style="{ fontSize: `${scheme.emphasizedFontSize}px`, fontWeight: scheme.fontWeight }"
|
||||
>
|
||||
强调文字
|
||||
</span>
|
||||
<span class="l1" :style="{ fontSize: `${scheme.largeFontSize}px`, fontWeight: scheme.fontWeight }">
|
||||
大号标题
|
||||
</span>
|
||||
</div>
|
||||
<el-form-item label="行间距">
|
||||
<el-slider v-model="scheme.spacing" :min="0" :max="METRICS.rowSpacingMax" @change="save" />
|
||||
</el-form-item>
|
||||
<el-form-item label="常态圆角">
|
||||
<el-slider
|
||||
v-model="scheme.radius"
|
||||
:min="0"
|
||||
:max="METRICS.radiusMax"
|
||||
:step="CLASSISLAND_TOKENS.radii.islandStep"
|
||||
@change="save"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="自定义背景色">
|
||||
<el-switch v-model="scheme.customBackgroundEnabled" @change="save" />
|
||||
<el-color-picker v-if="scheme.customBackgroundEnabled" v-model="scheme.color" @change="save" />
|
||||
</el-form-item>
|
||||
<el-form-item label="背景不透明度">
|
||||
<el-slider
|
||||
v-model="scheme.opacity"
|
||||
:min="0"
|
||||
:max="1"
|
||||
:step="0.05"
|
||||
:show-tooltip="true"
|
||||
:format-tooltip="(value: number) => value.toFixed(2)"
|
||||
@change="save"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="自定义前景色">
|
||||
<el-switch v-model="scheme.customForegroundEnabled" @change="save" />
|
||||
<el-color-picker v-if="scheme.customForegroundEnabled" v-model="scheme.foreground" @change="save" />
|
||||
</el-form-item>
|
||||
<p class="hint">
|
||||
关闭自定义前景色后回落当前亮/暗主题的五级文字色;开启后按 100% / 85.5% / 77.3% / 52.9% / 36.5%
|
||||
生成颜色 alpha。
|
||||
</p>
|
||||
<el-form-item label="各行分离显示">
|
||||
<el-switch v-model="scheme.separated" @change="save" />
|
||||
</el-form-item>
|
||||
<p class="hint">位置与动画与灵动岛共用设置。</p>
|
||||
<el-button link type="primary" @click="router.push('/settings/island')">前往灵动岛外观设置</el-button>
|
||||
</el-form>
|
||||
</el-drawer>
|
||||
</section>
|
||||
</template>
|
||||
<style scoped src="../../styles/island-editor.css"></style>
|
||||
@@ -2,7 +2,6 @@
|
||||
import { confirmAction } from '../../composables/confirm.js';
|
||||
import { computed, onMounted, onUnmounted, ref } from 'vue';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import { useRouter } from 'vue-router';
|
||||
import {
|
||||
CLASSISLAND_TOKENS,
|
||||
DEFAULT_ISLAND_APPEARANCE,
|
||||
@@ -28,38 +27,16 @@ import {
|
||||
*/
|
||||
const island = ref<IslandAppearance>({ ...DEFAULT_ISLAND_APPEARANCE });
|
||||
const savingIsland = ref(false);
|
||||
const router = useRouter();
|
||||
function editLayout() {
|
||||
layoutMode.value = 'custom';
|
||||
void router.push('/settings/island/editor');
|
||||
}
|
||||
const layoutMode = ref<'fixed' | 'custom'>('fixed');
|
||||
const layoutSettings = ref(defaultIslandLayouts());
|
||||
const layoutMode = computed(() => layoutSettings.value.layout);
|
||||
const activeScheme = computed(() =>
|
||||
layoutSettings.value.schemes.find((s) => s.id === layoutSettings.value.activeSchemeId)!,
|
||||
);
|
||||
const currentRadius = computed(() =>
|
||||
layoutMode.value === 'custom' ? activeScheme.value.radius : island.value.radius,
|
||||
);
|
||||
const residentEnabled = ref(false);
|
||||
const pointerFadeEnabled = ref(true);
|
||||
const pointerFadeReversed = ref(false);
|
||||
async function changeLayout() {
|
||||
const config = await window.desktop?.getConfig();
|
||||
if (config)
|
||||
await window.desktop?.saveConfig({
|
||||
islandLayout: {
|
||||
...config.islandLayout,
|
||||
layout: layoutMode.value,
|
||||
residentEnabled: residentEnabled.value,
|
||||
},
|
||||
});
|
||||
}
|
||||
async function chooseLayout(mode: 'fixed' | 'custom') {
|
||||
layoutMode.value = mode;
|
||||
residentEnabled.value = mode === 'custom';
|
||||
await changeLayout();
|
||||
}
|
||||
async function changePointerFade(
|
||||
key: 'pointerFadeEnabled' | 'pointerFadeReversed',
|
||||
value: boolean | string | number,
|
||||
@@ -77,8 +54,6 @@ async function changePointerFade(
|
||||
async function loadLayout() {
|
||||
const settings = (await window.desktop?.getConfig())?.islandLayout;
|
||||
if (settings) layoutSettings.value = settings;
|
||||
layoutMode.value = settings?.layout ?? 'fixed';
|
||||
residentEnabled.value = settings?.residentEnabled ?? false;
|
||||
pointerFadeEnabled.value = settings?.pointerFadeEnabled ?? true;
|
||||
pointerFadeReversed.value = settings?.pointerFadeReversed ?? false;
|
||||
}
|
||||
@@ -179,32 +154,15 @@ onMounted(async () => {
|
||||
|
||||
<el-card shadow="never" class="layout-mode-card">
|
||||
<template #header><span>岛内布局</span></template>
|
||||
<div class="layout-choices">
|
||||
<button
|
||||
class="layout-choice"
|
||||
:class="{ active: layoutMode === 'fixed' }"
|
||||
:aria-pressed="layoutMode === 'fixed'"
|
||||
@click="chooseLayout('fixed')"
|
||||
>
|
||||
<strong>经典灵动岛</strong>
|
||||
<span>显示课程进度、上下课提醒与班级消息</span>
|
||||
</button>
|
||||
<button
|
||||
class="layout-choice"
|
||||
:class="{ active: layoutMode === 'custom' }"
|
||||
:aria-pressed="layoutMode === 'custom'"
|
||||
@click="chooseLayout('custom')"
|
||||
>
|
||||
<strong>自定义灵动岛</strong>
|
||||
<span>ClassIsland 风格,常驻显示时钟、课程等组件</span>
|
||||
</button>
|
||||
</div>
|
||||
<div v-if="layoutMode === 'custom'" class="layout-edit-entry">
|
||||
<div class="layout-managed">
|
||||
<div>
|
||||
<strong>按你的习惯布置岛内内容</strong>
|
||||
<p>编辑常态内容与无通知展开内容;课前自动提示,通知操作与经典岛共用。</p>
|
||||
<strong>{{ layoutMode === 'custom' ? '班级自定义灵动岛' : '默认经典灵动岛' }}</strong>
|
||||
<p v-if="layoutMode === 'custom'">
|
||||
当前班使用网页管理端下发的组件方案;班级端只读并自动同步,不再提供本地编辑入口。
|
||||
</p>
|
||||
<p v-else>当前班尚未由网页管理端下发自定义方案,暂时使用默认经典灵动岛。</p>
|
||||
</div>
|
||||
<el-button type="primary" @click="editLayout">编辑岛内组件</el-button>
|
||||
<el-tag type="info" effect="plain">{{ layoutMode === 'custom' ? '服务端同步' : '默认方案' }}</el-tag>
|
||||
</div>
|
||||
<div v-if="layoutMode === 'custom'" class="resident-window-options">
|
||||
<div>
|
||||
@@ -522,19 +480,17 @@ onMounted(async () => {
|
||||
outline: 2px solid var(--el-color-primary);
|
||||
outline-offset: 3px;
|
||||
}
|
||||
.layout-edit-entry {
|
||||
.layout-managed {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 20px;
|
||||
margin-top: 20px;
|
||||
padding-top: 20px;
|
||||
border-top: 1px solid var(--el-border-color-lighter);
|
||||
padding: 4px 2px;
|
||||
}
|
||||
.layout-edit-entry strong {
|
||||
.layout-managed strong {
|
||||
font-size: 14px;
|
||||
}
|
||||
.layout-edit-entry p {
|
||||
.layout-managed p {
|
||||
margin: 8px 0 0;
|
||||
color: var(--el-text-color-secondary);
|
||||
font-size: 12px;
|
||||
@@ -544,9 +500,8 @@ onMounted(async () => {
|
||||
.layout-choices {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
.layout-edit-entry {
|
||||
.layout-managed {
|
||||
align-items: flex-start;
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -120,8 +120,6 @@ export interface DesktopBridge {
|
||||
onCoursewareTransfer(
|
||||
handler: (value: import('@classhelper/shared').CoursewareTransfer | null) => void,
|
||||
): () => void;
|
||||
islandEditLayout(): Promise<void>;
|
||||
onIslandEditorOpen(handler: () => void): () => void;
|
||||
getUpdateProgress(): Promise<ContractReleaseProgressDto>;
|
||||
onUpdateProgress(handler: (progress: ContractReleaseProgressDto) => void): () => void;
|
||||
/** 是否处于冒烟验证模式(由 ELECTRON_SMOKE_TEST=1 触发),同步可读 */
|
||||
@@ -243,7 +241,6 @@ declare global {
|
||||
island?: IslandRendererBridge;
|
||||
/** 冒烟验证钩子,仅在 ELECTRON_SMOKE_TEST=1 时由渲染进程注册 */
|
||||
__classhelperSmoke__?: {
|
||||
islandEditorSmoke(open: boolean): Promise<void>;
|
||||
islandScheduleSyncSelfTest(): Promise<{ ok: boolean; detail: string }>;
|
||||
cacheSelfTest(): Promise<{ ok: boolean; detail: string }>;
|
||||
cacheIsolationSelfTest(): Promise<{ ok: boolean; detail: string }>;
|
||||
|
||||
Reference in new issue
Block a user