首页、学情、任务绑定接口
This commit is contained in:
+11
-6
@@ -96,7 +96,7 @@ function requestInterceptor(config: RequestConfig): RequestConfig {
|
||||
/**
|
||||
* 响应拦截器 - 统一处理响应
|
||||
*/
|
||||
function responseInterceptor<T>(response: UniNamespace.RequestSuccessCallbackResult, config: RequestConfig): ApiResponse<T> | null {
|
||||
function responseInterceptor<T>(response: any, config: RequestConfig): ApiResponse<T> | null {
|
||||
// 隐藏Loading
|
||||
if (config.showLoading !== false) {
|
||||
hideLoading()
|
||||
@@ -108,8 +108,13 @@ function responseInterceptor<T>(response: UniNamespace.RequestSuccessCallbackRes
|
||||
return null
|
||||
}
|
||||
|
||||
// 解析响应数据
|
||||
const result = response.data as ApiResponse<T>
|
||||
// 解析响应数据,兼容后端 PascalCase 与前端 camelCase 两种包装格式。
|
||||
const rawResult = response.data as any
|
||||
const result: ApiResponse<T> = {
|
||||
code: Number(rawResult?.code ?? rawResult?.Code),
|
||||
message: String(rawResult?.message ?? rawResult?.Message ?? ''),
|
||||
data: (rawResult?.data ?? rawResult?.Data ?? null) as T | null
|
||||
}
|
||||
|
||||
// 业务状态码检查
|
||||
if (result.code !== 200) {
|
||||
@@ -210,10 +215,10 @@ function createMockResponse<T>(config: RequestConfig): ApiResponse<T> {
|
||||
const isSecondStudent = config.url.includes('studentId=test-student-002')
|
||||
data = isSecondStudent ? {
|
||||
studentId: 'test-student-002', onlineToday: true, checkedInToday: false, learningMinutesToday: 78,
|
||||
accuracyToday: 88, learningDaysThisWeek: 4, shouldStudyDaysThisWeek: 5, pendingHomeworkCount: 2, updatedAt: '2026-10-28T08:30:00+08:00'
|
||||
accuracyToday: 88, learningDaysThisWeek: 4, shouldStudyDaysThisWeek: 5, pendingPackCount: 2, updatedAt: '2026-10-28T08:30:00+08:00'
|
||||
} : {
|
||||
studentId: 'test-student-001', onlineToday: true, checkedInToday: true, learningMinutesToday: 155,
|
||||
accuracyToday: 92, learningDaysThisWeek: 5, shouldStudyDaysThisWeek: 5, pendingHomeworkCount: 1, updatedAt: '2026-10-28T08:30:00+08:00'
|
||||
accuracyToday: 92, learningDaysThisWeek: 5, shouldStudyDaysThisWeek: 5, pendingPackCount: 1, updatedAt: '2026-10-28T08:30:00+08:00'
|
||||
}
|
||||
} else if (config.url.includes('/api/parent/today-learning')) {
|
||||
const isSecondStudent = config.url.includes('studentId=test-student-002')
|
||||
@@ -385,7 +390,7 @@ export function request<T>(config: RequestConfig): Promise<ApiResponse<T> | null
|
||||
// 请求拦截
|
||||
const finalConfig = requestInterceptor(config)
|
||||
|
||||
if (USE_MOCK_API && !finalConfig.url.includes('/api/v1/Parents/')) {
|
||||
if (USE_MOCK_API && !finalConfig.url.includes('/api/v1/Parents/') && !finalConfig.url.includes('/api/v1/ParentStudentToday/') && !finalConfig.url.includes('/api/v1/ParentLearningWarning/') && !finalConfig.url.includes('/api/v1/ParentStudyPack/') && !finalConfig.url.includes('/api/v1/ParentLearningReport/')) {
|
||||
const delay = Math.floor(Math.random() * (MOCK_RESPONSE_MAX_DELAY + 1))
|
||||
setTimeout(() => {
|
||||
if (finalConfig.showLoading !== false) {
|
||||
|
||||
Reference in New Issue
Block a user