1
0
mirror of https://github.com/ZeroCatDev/Classworks.git synced 2025-12-07 21:13:11 +00:00

feat: 优化标题显示,添加设备名称和命名空间信息的加载逻辑

This commit is contained in:
SunWuyuan 2025-11-08 17:22:32 +08:00
parent 6eb9bbd79c
commit 670666aa41
No known key found for this signature in database
GPG Key ID: A6A54CF66F56BB64
2 changed files with 39 additions and 6 deletions

View File

@ -1,7 +1,7 @@
<template> <template>
<v-app-bar class="no-select"> <v-app-bar class="no-select">
<v-app-bar-title> <v-app-bar-title>
{{ state.classNumber }} - {{ titleText }} {{ titleText }}
</v-app-bar-title> </v-app-bar-title>
<v-spacer /> <v-spacer />
@ -672,6 +672,7 @@ import {
setSetting, setSetting,
settingsDefinitions, settingsDefinitions,
} from "@/utils/settings"; } from "@/utils/settings";
import { kvServerProvider } from "@/utils/providers/kvServerProvider";
import { useDisplay } from "vuetify"; import { useDisplay } from "vuetify";
import "../styles/index.scss"; import "../styles/index.scss";
import "../styles/transitions.scss"; import "../styles/transitions.scss";
@ -682,7 +683,6 @@ import { Base64 } from "js-base64";
import { import {
getSocket, getSocket,
on as socketOn, on as socketOn,
off as socketOff,
joinToken, joinToken,
leaveAll, leaveAll,
onConnect as onSocketConnect, onConnect as onSocketConnect,
@ -720,6 +720,9 @@ export default {
useDisplay: useDisplay, useDisplay: useDisplay,
state: { state: {
classNumber: "", classNumber: "",
// /
namespaceInfo: null,
deviceName: "",
studentList: [], studentList: [],
boardData: { boardData: {
homework: {}, homework: {},
@ -816,6 +819,12 @@ export default {
return useDisplay().mobile.value; return useDisplay().mobile.value;
}, },
titleText() { titleText() {
//
const deviceName =
this.state.namespaceInfo?.device?.name ||
this.state.classNumber ||
"高三八班";
const today = this.getToday(); const today = this.getToday();
const yesterday = new Date(today); const yesterday = new Date(today);
yesterday.setDate(yesterday.getDate() - 1); yesterday.setDate(yesterday.getDate() - 1);
@ -825,11 +834,11 @@ export default {
const yesterdayStr = this.formatDate(yesterday); const yesterdayStr = this.formatDate(yesterday);
if (currentDateStr === todayStr) { if (currentDateStr === todayStr) {
return "今天的作业"; return deviceName +" - 今天的作业";
} else if (currentDateStr === yesterdayStr) { } else if (currentDateStr === yesterdayStr) {
return "昨天的作业"; return deviceName + " - 昨天的作业";
} else { } else {
return `${currentDateStr}的作业`; return `${deviceName} - ${currentDateStr}的作业`;
} }
}, },
sortedItems() { sortedItems() {
@ -1048,6 +1057,8 @@ export default {
try { try {
this.updateBackendUrl(); this.updateBackendUrl();
await this.initializeData(); await this.initializeData();
// /
await this.loadDeviceInfo();
this.setupAutoRefresh(); this.setupAutoRefresh();
this.unwatchSettings = watchSettings(() => { this.unwatchSettings = watchSettings(() => {
this.updateSettings(); this.updateSettings();
@ -1143,6 +1154,26 @@ export default {
}, },
methods: { methods: {
// /
async loadDeviceInfo() {
try {
const provider = getSetting("server.provider");
const useServer = provider === "kv-server" || provider === "classworkscloud";
if (!useServer) return;
const res = await kvServerProvider.loadNamespaceInfo();
if (res && res.success === false) return; //
this.state.namespaceInfo = res || null;
//
this.state.deviceName =
res?.account?.deviceName ||
"";
} catch (e) {
console.warn("加载设备信息失败:", e);
}
},
// Token // Token
updateTokenDisplayInfo() { updateTokenDisplayInfo() {
const manager = this.$refs.studentNameManager const manager = this.$refs.studentNameManager
@ -1558,6 +1589,8 @@ export default {
this.state.contentStyle = { "font-size": `${this.state.fontSize}px` }; this.state.contentStyle = { "font-size": `${this.state.fontSize}px` };
this.setupAutoRefresh(); this.setupAutoRefresh();
this.updateBackendUrl(); this.updateBackendUrl();
// Token
this.loadDeviceInfo();
// shouldShowInit // shouldShowInit
this.settingsTick++; this.settingsTick++;
}, },