feat: initialize Evergreen Health mobile app

This commit is contained in:
fuenmao
2026-09-21 15:53:02 +08:00
commit 93e9bb604d
18 changed files with 2715 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
import axios from 'axios'
import { clearTokens, getToken } from './auth'
type UnifiedResult<T> = {
type?: string
message?: string
result?: T
errors?: unknown
}
const http = axios.create({
baseURL: '/',
timeout: 15000
})
http.interceptors.request.use((config) => {
const token = getToken()
if (token) config.headers.Authorization = `Bearer ${token}`
return config
})
http.interceptors.response.use(
((response: any) => {
const body = response.data as UnifiedResult<unknown>
if (body && typeof body === 'object' && 'result' in body) {
if (body.type && body.type !== 'success') {
return Promise.reject(new Error(body.message || '请求失败'))
}
return body.result
}
return body
}) as any,
(error) => {
if (error.response?.status === 401) clearTokens()
const body = error.response?.data as UnifiedResult<unknown> | undefined
const message = body?.message || error.message || '网络请求失败'
return Promise.reject(new Error(message))
}
)
export default http