接入学生学习数据接口

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
+19
View File
@@ -66,7 +66,9 @@
<script setup lang="ts">
import { apiLogin } from '../../api/auth'
import { apiGetBoundStudents, type BoundStudentSummary } from '../../api/student'
import { setUserInfo, saveRememberInfo, getRememberInfo } from '../../store/user'
import { applyBoundStudent, saveSelectedStudent } from '../../store/home'
type LoginForm = {
phone: string
@@ -111,6 +113,7 @@
if (res && res.data) {
// 保存用户信息
setUserInfo(res.data)
await restoreSelectedStudent(res.data.userId)
// 保存记住密码信息
saveRememberInfo(form.phone, form.password, form.remember)
@@ -129,6 +132,22 @@
}
}
/**
* 登录后加载家长绑定的学生,并恢复或初始化当前学生。
*/
async function restoreSelectedStudent(userId: string) {
const res = await apiGetBoundStudents()
if (!res || !res.data || res.data.students.length === 0) return
const savedStudent = uni.getStorageSync(`selectedStudent_${userId}`) as BoundStudentSummary | null
const selectedStudent = savedStudent && res.data.students.some((item) => item.id === savedStudent.id)
? res.data.students.find((item) => item.id === savedStudent.id)!
: res.data.students[0]
saveSelectedStudent(selectedStudent)
applyBoundStudent(selectedStudent)
}
/**
* 忘记密码
*/