接入学生学习数据接口

This commit is contained in:
tanxin
2026-11-05 11:01:12 +08:00
parent d1d44e250e
commit af73453035
15 changed files with 336 additions and 48 deletions
+31 -1
View File
@@ -6,7 +6,37 @@ export const homeStudentMetrics = ref<StudentHomeMetrics | null>(null)
export const homeStudentAlerts = ref<StudentAlert[] | null>(null)
export function setHomeStudentProfile(profile: StudentHomeProfile) {
homeStudentProfile.value = profile
const userInfo = uni.getStorageSync('userInfo') as { userId?: string } | null
const boundStudent = userInfo?.userId
? uni.getStorageSync(`selectedStudent_${userInfo.userId}`) as { id?: string, name?: string, account?: string, grade?: string, school?: string, className?: string, avatar?: string } | null
: null
const currentProfile = homeStudentProfile.value?.id === profile.id ? homeStudentProfile.value : null
const savedStudent = boundStudent?.id === profile.id ? boundStudent : null
homeStudentProfile.value = {
...profile,
name: savedStudent?.name ?? currentProfile?.name ?? profile.name,
account: savedStudent?.account ?? currentProfile?.account ?? profile.account,
grade: savedStudent?.grade ?? currentProfile?.grade ?? profile.grade,
school: savedStudent?.school ?? currentProfile?.school ?? profile.school,
className: savedStudent?.className ?? currentProfile?.className ?? profile.className,
avatar: savedStudent?.avatar ?? currentProfile?.avatar ?? profile.avatar
}
}
export function saveSelectedStudent(student: { id: string, name: string, account: string, grade: string, school: string, className: string, avatar: string }) {
const userInfo = uni.getStorageSync('userInfo') as { userId?: string } | null
if (userInfo?.userId) uni.setStorageSync(`selectedStudent_${userInfo.userId}`, student)
}
export function getSavedSelectedStudent(): { id: string, name: string, account: string, grade: string, school: string, className: string, avatar: string } | null {
const userInfo = uni.getStorageSync('userInfo') as { userId?: string } | null
if (!userInfo?.userId) return null
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 }) {
const comprehensiveLevel = homeStudentProfile.value?.id === student.id ? homeStudentProfile.value.comprehensiveLevel : 'good'
setHomeStudentProfile({ ...student, comprehensiveLevel })
}
export function setHomeStudentMetrics(metrics: StudentHomeMetrics) {