2026-09-11 22:46:31 +08:00
|
|
|
|
<script setup lang="ts">
|
2026-10-05 16:39:38 +08:00
|
|
|
|
import { h, onMounted, onUnmounted, ref } from 'vue';
|
2026-09-11 22:46:31 +08:00
|
|
|
|
import { useRouter } from 'vue-router';
|
2026-10-05 16:39:38 +08:00
|
|
|
|
import { ElButton, ElNotification } from 'element-plus';
|
|
|
|
|
|
import type { UpdateInfo } from '@classhelper/shared';
|
2026-10-02 00:25:10 +08:00
|
|
|
|
import {
|
|
|
|
|
|
startIslandBridge,
|
|
|
|
|
|
stopIslandBridge,
|
|
|
|
|
|
subscribeIslandMarkAllRead,
|
|
|
|
|
|
subscribeIslandMarkRead,
|
|
|
|
|
|
} from './island/bridge.js';
|
2026-10-02 11:18:47 +08:00
|
|
|
|
import OnboardingWelcome from './components/OnboardingWelcome.vue';
|
2026-09-11 22:46:31 +08:00
|
|
|
|
import { useAppStore } from './stores/app.js';
|
|
|
|
|
|
import { useAuthStore } from './stores/auth.js';
|
2026-10-02 11:18:47 +08:00
|
|
|
|
import { useOnboardingStore } from './stores/onboarding.js';
|
2026-09-11 22:46:31 +08:00
|
|
|
|
import { useRealtimeStore } from './stores/realtime.js';
|
2026-10-02 11:18:47 +08:00
|
|
|
|
import { useUiStore } from './stores/ui.js';
|
2026-09-11 22:46:31 +08:00
|
|
|
|
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
|
const appStore = useAppStore();
|
|
|
|
|
|
const auth = useAuthStore();
|
2026-10-02 11:18:47 +08:00
|
|
|
|
const onboarding = useOnboardingStore();
|
|
|
|
|
|
const ui = useUiStore();
|
2026-09-11 22:46:31 +08:00
|
|
|
|
const realtime = useRealtimeStore();
|
|
|
|
|
|
|
|
|
|
|
|
const booting = ref(true);
|
|
|
|
|
|
const bootText = ref('正在读取本地配置...');
|
|
|
|
|
|
|
2026-10-05 16:39:38 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 启动自动检查发现新版本时的提示(主进程查出后推过来,见 main/update.ts)。
|
|
|
|
|
|
*
|
|
|
|
|
|
* **为什么订阅放在 App.vue**:`onUpdateAvailable` 底层是 `ipcRenderer.on`,
|
|
|
|
|
|
* 桥接层没有对应的 off —— 挂在会随"登出 → 登录"反复挂载的 ClientLayout 里,
|
|
|
|
|
|
* 处理器会越堆越多(与灵动岛订阅同一个坑)。App.vue 整个应用生命周期只挂载一次。
|
|
|
|
|
|
*
|
|
|
|
|
|
* 提示是**一次性**且可永久消音:点「忽略此版本」写进 config.json,同一版本不再提示;
|
|
|
|
|
|
* 「关于」页里仍可随时手动检查。
|
|
|
|
|
|
*/
|
|
|
|
|
|
function showUpdateAvailable(info: UpdateInfo): void {
|
|
|
|
|
|
if (!info.latestVersion) return;
|
|
|
|
|
|
ElNotification({
|
|
|
|
|
|
title: `发现新版本 v${info.latestVersion}`,
|
|
|
|
|
|
type: 'info',
|
|
|
|
|
|
// 不自动消失:这是需要用户决定的事(去下载 / 忽略),滑过去就只能靠「关于」页再想起来
|
|
|
|
|
|
duration: 0,
|
|
|
|
|
|
message: h('div', { style: 'line-height: 1.7' }, [
|
|
|
|
|
|
h('p', { style: 'margin: 0 0 10px' }, `当前版本 ${info.currentVersion},可前往下载更新。`),
|
|
|
|
|
|
h('div', { style: 'display: flex; gap: 8px' }, [
|
|
|
|
|
|
h(
|
|
|
|
|
|
ElButton,
|
|
|
|
|
|
{
|
|
|
|
|
|
size: 'small',
|
|
|
|
|
|
type: 'primary',
|
|
|
|
|
|
onClick: () => {
|
|
|
|
|
|
void window.desktop?.openExternal(info.releaseUrl);
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
() => '前往下载',
|
|
|
|
|
|
),
|
|
|
|
|
|
h(
|
|
|
|
|
|
ElButton,
|
|
|
|
|
|
{
|
|
|
|
|
|
size: 'small',
|
|
|
|
|
|
onClick: () => {
|
|
|
|
|
|
void window.desktop?.ignoreUpdateVersion(info.latestVersion ?? '');
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
() => '忽略此版本',
|
|
|
|
|
|
),
|
|
|
|
|
|
]),
|
|
|
|
|
|
]),
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-09-11 22:46:31 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 启动流程:
|
|
|
|
|
|
* 1) 从主进程配置恢复服务器地址与登录令牌
|
|
|
|
|
|
* 2) 先用缓存资料渲染,再尝试向服务器刷新(不可达则进入离线会话)
|
|
|
|
|
|
* 3) 已登录则建立 Socket.IO 连接并进入主界面
|
|
|
|
|
|
*/
|
|
|
|
|
|
onMounted(async () => {
|
|
|
|
|
|
try {
|
2026-10-02 11:18:47 +08:00
|
|
|
|
bootText.value = '正在读取本地配置...';
|
|
|
|
|
|
// 主题与侧栏折叠最先恢复:在首屏渲染前挂好 html.dark,避免"先白后黑"闪一下
|
|
|
|
|
|
await ui.init();
|
|
|
|
|
|
|
2026-09-11 22:46:31 +08:00
|
|
|
|
bootText.value = '正在恢复登录状态...';
|
|
|
|
|
|
const session = await auth.restore();
|
|
|
|
|
|
|
2026-09-27 14:59:12 +08:00
|
|
|
|
// 通知显示位置:先用本地配置兜底(断网也要按上次的选择决定本机弹不弹),
|
|
|
|
|
|
// 登录态就绪后再向服务器对齐一次(服务端才是单一事实来源)
|
|
|
|
|
|
const storedConfig = await window.desktop?.getConfig?.();
|
|
|
|
|
|
if (storedConfig?.notificationChannel) {
|
|
|
|
|
|
appStore.applyLocalNotificationChannel(storedConfig.notificationChannel);
|
|
|
|
|
|
}
|
|
|
|
|
|
void appStore.loadNotificationChannel(auth.classId);
|
|
|
|
|
|
|
2026-09-11 22:46:31 +08:00
|
|
|
|
// 连通性探测与健康轮询放到后台,不阻塞进入界面(离线时也能立刻看到缓存数据)
|
|
|
|
|
|
void appStore.init(session.serverUrl);
|
|
|
|
|
|
|
|
|
|
|
|
if (auth.token) realtime.connect(appStore.serverUrl, auth.token);
|
|
|
|
|
|
|
2026-09-12 08:41:08 +08:00
|
|
|
|
// 灵动岛:开始按课表计算上课状态(上课隐藏、下课自动弹出)
|
|
|
|
|
|
if (auth.token) startIslandBridge();
|
|
|
|
|
|
|
2026-10-02 00:25:10 +08:00
|
|
|
|
// 灵动岛"标为已读" → 同步通知中心(未读红点);多条通知时是整批已读
|
2026-09-12 13:57:46 +08:00
|
|
|
|
subscribeIslandMarkRead();
|
2026-10-02 00:25:10 +08:00
|
|
|
|
subscribeIslandMarkAllRead();
|
2026-09-12 13:57:46 +08:00
|
|
|
|
|
2026-10-05 16:39:38 +08:00
|
|
|
|
// 启动自动检查发现新版本时由主进程推过来(订阅只挂一次,理由见 showUpdateAvailable)
|
|
|
|
|
|
window.desktop?.onUpdateAvailable?.(showUpdateAvailable);
|
|
|
|
|
|
|
2026-09-11 22:46:31 +08:00
|
|
|
|
if (auth.isAuthenticated) await router.replace('/schedule');
|
|
|
|
|
|
else await router.replace('/login');
|
2026-10-02 11:18:47 +08:00
|
|
|
|
|
|
|
|
|
|
// 初次启动引导:配置里没记「已看过」就自动弹一次(完成/跳过后由引导组件写入配置)。
|
|
|
|
|
|
// 稍等一拍再弹:让登录页/主界面先渲染完,避免和启动过渡的收尾抢帧。
|
|
|
|
|
|
window.setTimeout(() => {
|
|
|
|
|
|
void window.desktop
|
|
|
|
|
|
?.getConfig()
|
|
|
|
|
|
.then((config) => {
|
|
|
|
|
|
if (config.onboardingDone !== true) onboarding.open();
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch(() => undefined);
|
|
|
|
|
|
}, 400);
|
2026-09-11 22:46:31 +08:00
|
|
|
|
} finally {
|
|
|
|
|
|
booting.value = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2026-09-12 08:41:08 +08:00
|
|
|
|
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
|
|
|
stopIslandBridge();
|
|
|
|
|
|
});
|
2026-09-11 22:46:31 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
|
<div v-if="booting" class="boot-screen">
|
|
|
|
|
|
<el-icon :size="30" class="is-loading" color="#409eff"><Loading /></el-icon>
|
|
|
|
|
|
<p class="boot-title">班级小助手</p>
|
|
|
|
|
|
<p class="boot-text">{{ bootText }}</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<router-view v-else />
|
2026-10-02 11:18:47 +08:00
|
|
|
|
<!-- 初次启动引导:常驻挂载,由 onboarding store 控制显隐(登录页/主界面/设置页都能唤起) -->
|
|
|
|
|
|
<OnboardingWelcome v-if="!booting" />
|
2026-09-11 22:46:31 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
.boot-screen {
|
|
|
|
|
|
height: 100vh;
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: center;
|
|
|
|
|
|
gap: 10px;
|
|
|
|
|
|
background: linear-gradient(135deg, #1f2d3d 0%, #3a5169 60%, #409eff 100%);
|
|
|
|
|
|
color: #fff;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.boot-title {
|
|
|
|
|
|
margin: 6px 0 0;
|
|
|
|
|
|
font-size: 20px;
|
|
|
|
|
|
font-weight: 600;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.boot-text {
|
|
|
|
|
|
margin: 0;
|
|
|
|
|
|
font-size: 13px;
|
|
|
|
|
|
color: rgba(255, 255, 255, 0.75);
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|