首页、学情、任务绑定接口

This commit is contained in:
hexi
2026-11-06 16:43:41 +08:00
parent af73453035
commit 4a19192d73
16 changed files with 965 additions and 236 deletions
+13 -2
View File
@@ -1,9 +1,12 @@
import type { StudentAlert, StudentHomeMetrics, StudentHomeProfile } from '../api/student'
type BoundStudentLike = { id: string, name: string, account: string, grade: string, school: string, className: string, avatar: string }
// 仅在本次登录会话内缓存首页学生资料,切换一级页面时不重复请求。
export const homeStudentProfile = ref<StudentHomeProfile | null>(null)
export const homeStudentMetrics = ref<StudentHomeMetrics | null>(null)
export const homeStudentAlerts = ref<StudentAlert[] | null>(null)
export const selectedStudentChangeVersion = ref(0)
export function setHomeStudentProfile(profile: StudentHomeProfile) {
const userInfo = uni.getStorageSync('userInfo') as { userId?: string } | null
@@ -23,7 +26,7 @@ export function setHomeStudentProfile(profile: StudentHomeProfile) {
}
}
export function saveSelectedStudent(student: { id: string, name: string, account: string, grade: string, school: string, className: string, avatar: string }) {
export function saveSelectedStudent(student: BoundStudentLike) {
const userInfo = uni.getStorageSync('userInfo') as { userId?: string } | null
if (userInfo?.userId) uni.setStorageSync(`selectedStudent_${userInfo.userId}`, student)
}
@@ -34,11 +37,19 @@ export function getSavedSelectedStudent(): { id: string, name: string, account:
return uni.getStorageSync(`selectedStudent_${userInfo.userId}`) as { id: string, name: string, account: string, grade: string, school: string, className: string, avatar: string } | null
}
export function applyBoundStudent(student: { id: string, name: string, account: string, grade: string, school: string, className: string, avatar: string }) {
export function applyBoundStudent(student: BoundStudentLike) {
const comprehensiveLevel = homeStudentProfile.value?.id === student.id ? homeStudentProfile.value.comprehensiveLevel : 'good'
setHomeStudentProfile({ ...student, comprehensiveLevel })
}
export function switchBoundStudent(student: BoundStudentLike) {
saveSelectedStudent(student)
applyBoundStudent(student)
homeStudentMetrics.value = null
homeStudentAlerts.value = null
selectedStudentChangeVersion.value++
}
export function setHomeStudentMetrics(metrics: StudentHomeMetrics) {
homeStudentMetrics.value = metrics
}