新增接单平台第一期闭环

This commit is contained in:
yml2213
2026-07-25 13:58:53 +08:00
parent 06decc51ff
commit f6d3f00f21
27 changed files with 3987 additions and 0 deletions
+35
View File
@@ -1,5 +1,6 @@
import axios from 'axios'
import { clearAdminSession, getAdminToken } from '@/utils/admin-auth'
import { clearWorkerSession, getWorkerToken } from '@/utils/worker-auth'
export interface ApiEnvelope<T> {
code: number
@@ -66,6 +67,22 @@ http.interceptors.response.use(
}
}
if (error?.config?.url && String(error.config.url).startsWith('/api/v1/worker')) {
const status = Number(error?.response?.status || 0)
const errorCode = String(error?.response?.data?.errorCode || '').trim()
if (status === 401 && shouldClearWorkerSession(errorCode)) {
clearWorkerSession()
if (
window.location.hash.startsWith('#/worker') &&
!window.location.hash.startsWith('#/worker/login')
) {
window.location.hash = '#/worker/login'
}
}
}
return Promise.reject(normalizedError)
},
)
@@ -79,6 +96,14 @@ http.interceptors.request.use((config) => {
}
}
if (String(config.url || '').startsWith('/api/v1/worker')) {
const token = getWorkerToken()
if (token) {
config.headers.Authorization = `Bearer ${token}`
}
}
return config
})
@@ -110,6 +135,16 @@ function shouldClearAdminSession(errorCode: string) {
].includes(errorCode)
}
function shouldClearWorkerSession(errorCode: string) {
return [
'worker_auth_required',
'worker_auth_invalid',
'worker_auth_expired',
'worker_auth_user_invalid',
'worker_auth_stale',
].includes(errorCode)
}
function request<T>(config: Parameters<typeof http.request<ApiEnvelope<T>>>[0]) {
return http.request<ApiEnvelope<T>, ApiEnvelope<T>>(config)
}