app端优化
This commit is contained in:
1 parent
7994ed1ed3
commit
1e45ede5be
14 files changed
+357
-37
No files matched your search
@@ -13,6 +13,9 @@ interface WidgetPayload {
|
||||
scheduleDate: string
|
||||
schedule: WidgetItem[]
|
||||
exams: WidgetItem[]
|
||||
attendance: WidgetItem[]
|
||||
notifications: WidgetItem[]
|
||||
unreadNotificationCount: number
|
||||
updatedAt: string
|
||||
}
|
||||
|
||||
@@ -128,6 +131,26 @@ function examItems(exams: any[], now: Date): WidgetItem[] {
|
||||
}))
|
||||
}
|
||||
|
||||
function attendanceItems(activities: any[]): WidgetItem[] {
|
||||
return activities.slice(0, 3).map((activity: any) => ({
|
||||
title: String(activity.courseName ?? '待签到课程'),
|
||||
subtitle: [activity.courseCode, activity.sheetName].filter(Boolean).join(' · '),
|
||||
time: activity.checkInAt ? '已签到' : activity.checkInEndsAt
|
||||
? `截止 ${new Intl.DateTimeFormat('zh-CN', { hour: '2-digit', minute: '2-digit', hour12: false }).format(new Date(activity.checkInEndsAt))}`
|
||||
: '签到进行中',
|
||||
}))
|
||||
}
|
||||
|
||||
function notificationItems(notifications: any[]): WidgetItem[] {
|
||||
return notifications.filter((item: any) => !item.isRead).slice(0, 3).map((item: any) => ({
|
||||
title: String(item.title ?? '教务通知'),
|
||||
subtitle: String(item.senderName ?? '教务系统'),
|
||||
time: item.createdAt ? new Intl.DateTimeFormat('zh-CN', {
|
||||
month: 'numeric', day: 'numeric', hour: '2-digit', minute: '2-digit', hour12: false,
|
||||
}).format(new Date(item.createdAt)) : '未读',
|
||||
}))
|
||||
}
|
||||
|
||||
export async function clearNativeWidgets() {
|
||||
if (!native) return
|
||||
try {
|
||||
@@ -154,9 +177,13 @@ export async function syncNativeWidgets(force = false) {
|
||||
return
|
||||
}
|
||||
|
||||
const [timetableResult, examResult] = await Promise.allSettled([
|
||||
const [timetableResult, examResult, notificationResult, attendanceResult] = await Promise.allSettled([
|
||||
http.get('/timetables/mine'),
|
||||
http.get('/exams/my-schedule'),
|
||||
http.get('/notifications', { params: { page: 1, pageSize: 3, unreadOnly: true } }),
|
||||
roles.includes('Student')
|
||||
? http.get('/attendance/open-check-ins')
|
||||
: Promise.resolve({ data: [] }),
|
||||
])
|
||||
const now = new Date()
|
||||
const payload: WidgetPayload = {
|
||||
@@ -168,6 +195,15 @@ export async function syncNativeWidgets(force = false) {
|
||||
exams: examResult.status === 'fulfilled'
|
||||
? examItems(examResult.value.data, now)
|
||||
: [],
|
||||
attendance: attendanceResult.status === 'fulfilled'
|
||||
? attendanceItems(attendanceResult.value.data)
|
||||
: [],
|
||||
notifications: notificationResult.status === 'fulfilled'
|
||||
? notificationItems(notificationResult.value.data.items ?? [])
|
||||
: [],
|
||||
unreadNotificationCount: notificationResult.status === 'fulfilled'
|
||||
? Number(notificationResult.value.data.unreadCount ?? 0)
|
||||
: 0,
|
||||
updatedAt: now.toISOString(),
|
||||
}
|
||||
await NativeHome.updateWidgets({ payload })
|
||||
|
||||
Reference in new issue
Block a user