接入学生学习数据接口
This commit is contained in:
+31
-1
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user