chore(release): 1.3.3 发布并退役旧联动
This commit is contained in:
1 parent
b7cdc7c9ea
commit
c0ebf88138
184 files changed
+5450
-11705
No files matched your search
@@ -1,15 +1,12 @@
|
||||
import { computed, ref } from 'vue';
|
||||
import { defineStore } from 'pinia';
|
||||
import {
|
||||
DEFAULT_CLASSISLAND_NOTIFICATION_CHANNEL,
|
||||
STORAGE_KEYS,
|
||||
formatDate,
|
||||
type ClassIslandNotificationChannel,
|
||||
} from '@classhelper/shared';
|
||||
import { STORAGE_KEYS, formatDate } from '@classhelper/shared';
|
||||
import { pingHealth, setApiBaseUrl, setReachabilityReporter } from '../api/http.js';
|
||||
import { classChannelApi } from '../api/index.js';
|
||||
import { cacheClearAll, cacheStats, type CacheStoreStat } from '../cache/db.js';
|
||||
import { DEFAULT_SERVER, normalizeServerUrl } from '../config.js';
|
||||
import { dashboardApi } from '../api/index.js';
|
||||
import { fetchWithCache } from '../cache/index.js';
|
||||
import { getCacheScope, onCacheScopeChanged } from '../cache/scope.js';
|
||||
|
||||
type RecoveryHandler = () => void;
|
||||
|
||||
@@ -70,13 +67,26 @@ export const useAppStore = defineStore('app', () => {
|
||||
const currentWeek = ref(1);
|
||||
const maxWeek = ref(20);
|
||||
const initialized = ref(false);
|
||||
/**
|
||||
* 通知显示位置:这台教室机器把提醒弹在哪个端。
|
||||
*
|
||||
* 单一事实来源是**班级记录**(服务端),本地这份只是缓存:断网时也要能按上次的选择
|
||||
* 决定本机弹不弹,所以启动时先读本地配置、登录后再向服务器对齐一次。
|
||||
*/
|
||||
const notificationChannel = ref<ClassIslandNotificationChannel>(DEFAULT_CLASSISLAND_NOTIFICATION_CHANNEL);
|
||||
let termRequest = 0;
|
||||
onCacheScopeChanged(() => {
|
||||
currentWeek.value = 1;
|
||||
maxWeek.value = 20;
|
||||
termRequest += 1;
|
||||
clearOfflineSince();
|
||||
});
|
||||
|
||||
/** 当前教学周的单一写入入口,课表页与灵动岛共用。 */
|
||||
async function refreshTerm(classId?: string): Promise<void> {
|
||||
const request = ++termRequest;
|
||||
const scope = getCacheScope();
|
||||
const result = await fetchWithCache('classes', 'term', () => dashboardApi.term(classId), {
|
||||
currentWeek: 1,
|
||||
maxWeek: 20,
|
||||
});
|
||||
if (request !== termRequest || scope !== getCacheScope() || (result.error && !result.updatedAt)) return;
|
||||
currentWeek.value = result.data.currentWeek;
|
||||
maxWeek.value = result.data.maxWeek;
|
||||
}
|
||||
|
||||
const offline = computed(() => !serverReachable.value);
|
||||
const lastSyncText = computed(() => (lastSyncAt.value ? formatDate(lastSyncAt.value, true) : '尚未同步'));
|
||||
@@ -178,53 +188,6 @@ export const useAppStore = defineStore('app', () => {
|
||||
void refreshCacheStats();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ 通知显示位置 */
|
||||
|
||||
/** 启动时用本地配置兜底(此时可能还没登录/断网) */
|
||||
function applyLocalNotificationChannel(value: ClassIslandNotificationChannel): void {
|
||||
notificationChannel.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 向服务器对齐显示位置。
|
||||
* 登录后调用:以服务端为准(多台机器/老师改过之后,本地缓存可能已经过期)。
|
||||
*/
|
||||
async function loadNotificationChannel(classId: string | null): Promise<void> {
|
||||
if (!classId) return;
|
||||
try {
|
||||
const result = await classChannelApi.get(classId);
|
||||
notificationChannel.value = result.notificationChannel;
|
||||
await window.desktop?.saveConfig({ notificationChannel: result.notificationChannel });
|
||||
} catch {
|
||||
// 离线/无权限:保留本地值,不影响展示
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 改显示位置:先落本地(立刻生效),再写回班级记录。
|
||||
* 服务端写失败时返回 false,由设置页提示"已保存在本机,联网后请重试"。
|
||||
*/
|
||||
async function setNotificationChannel(
|
||||
classId: string | null,
|
||||
value: ClassIslandNotificationChannel,
|
||||
): Promise<boolean> {
|
||||
notificationChannel.value = value;
|
||||
await window.desktop?.saveConfig({ notificationChannel: value });
|
||||
if (!classId) return false;
|
||||
try {
|
||||
const result = await classChannelApi.set(classId, value);
|
||||
notificationChannel.value = result.notificationChannel;
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/** 本次提醒是否要在本机弹(弹窗 + 灵动岛);"只在 ClassIsland 上弹"时为 false */
|
||||
function shouldPopupLocally(): boolean {
|
||||
return notificationChannel.value !== 'classisland';
|
||||
}
|
||||
|
||||
return {
|
||||
serverUrl,
|
||||
serverReachable,
|
||||
@@ -236,17 +199,13 @@ export const useAppStore = defineStore('app', () => {
|
||||
currentWeek,
|
||||
maxWeek,
|
||||
initialized,
|
||||
notificationChannel,
|
||||
init,
|
||||
ping,
|
||||
applyServerUrl,
|
||||
applyLocalNotificationChannel,
|
||||
loadNotificationChannel,
|
||||
setNotificationChannel,
|
||||
shouldPopupLocally,
|
||||
refreshCacheStats,
|
||||
clearCache,
|
||||
markSynced,
|
||||
refreshTerm,
|
||||
onServerRecovered,
|
||||
offServerRecovered,
|
||||
stopHealthPolling,
|
||||
|
||||
Reference in new issue
Block a user