fix: 修改接口
This commit is contained in:
+27
-3
@@ -1,6 +1,6 @@
|
||||
import { API_BASE_URL, ApiRequestError } from './auth'
|
||||
import type { DimensionScore, EvaluationDetail, ScoreDetail } from './assessment'
|
||||
import type { ScoreType } from './session'
|
||||
import { FASTAPI_BASE_URL, type ScoreType } from './session'
|
||||
|
||||
type QueryValue = string | number | boolean | null | undefined
|
||||
|
||||
@@ -133,7 +133,7 @@ export function fetchCompetencyMetrics() {
|
||||
}
|
||||
|
||||
export async function fetchEvaluationList(query: EvaluationListQuery = {}) {
|
||||
const payload = await serverRequest<unknown>('/v1/evaluations', {
|
||||
const payload = await fastapiRequest<unknown>('/evaluations', {
|
||||
page: query.page,
|
||||
page_size: query.page_size
|
||||
})
|
||||
@@ -141,7 +141,7 @@ export async function fetchEvaluationList(query: EvaluationListQuery = {}) {
|
||||
}
|
||||
|
||||
export async function fetchServerEvaluationDetail(evaluationId: number) {
|
||||
const payload = await serverRequest<unknown>(`/v1/evaluations/${encodeURIComponent(String(evaluationId))}`)
|
||||
const payload = await fastapiRequest<unknown>(`/evaluations/${encodeURIComponent(String(evaluationId))}`)
|
||||
const data = unwrapServerData<Record<string, unknown>>(payload)
|
||||
return normalizeEvaluationDetail(data, evaluationId)
|
||||
}
|
||||
@@ -170,6 +170,30 @@ function serverRequest<T>(path: string, query?: Record<string, QueryValue>): Pro
|
||||
})
|
||||
}
|
||||
|
||||
function fastapiRequest<T>(path: string, query?: Record<string, QueryValue>): Promise<T> {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.request({
|
||||
url: `${FASTAPI_BASE_URL}${withQuery(path, query)}`,
|
||||
method: 'GET',
|
||||
timeout: 10000,
|
||||
header: createAuthHeaders(),
|
||||
success: response => {
|
||||
if (response.statusCode >= 200 && response.statusCode < 300) {
|
||||
resolve(response.data as T)
|
||||
return
|
||||
}
|
||||
|
||||
const payload = response.data as Record<string, unknown> | undefined
|
||||
const code = typeof payload?.code === 'string' ? payload.code : undefined
|
||||
reject(new ApiRequestError(readErrorMessage(response.data, `请求失败(${response.statusCode})`), code, response.statusCode))
|
||||
},
|
||||
fail: error => {
|
||||
reject(new ApiRequestError(error.errMsg || '无法连接服务'))
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function createAuthHeaders() {
|
||||
const headers: Record<string, string> = {
|
||||
'Content-Type': 'application/json',
|
||||
|
||||
Reference in New Issue
Block a user