根因:access_token每2小时过期,前端收到401直接清token跳登录,没有用refresh_token续期 后端修复: - adminauth模块新增 POST /admin/auth/refresh 接口 - Service 注入 JWTManager,支持 admin refresh token 换新 token pair - Refresh 方法验证 subjectType=admin + tokenType=refresh 前端修复: - 401 拦截器核心改造:收到401先调 refresh 接口续期 - 加 isRefreshing 锁 + pendingRequests 队列防止并发刷新 - refresh 用原生 axios.post 避免拦截器递归 - 成功则更新 localStorage + 重试原请求,失败才清 token 跳登录 - 排除 /auth/refresh 自身避免死循环 - 支持 /admin/ 请求独立 token 管理 - auth.ts/adminAuth.ts 新增手动 refreshUserToken/refreshAdminSession - 路由守卫给所有需登录路由添加 meta.requiresAuth - 守卫同时支持 PC 端 /login 和移动端 /m/login
53 lines
1.5 KiB
TypeScript
53 lines
1.5 KiB
TypeScript
import { apiClient } from './client'
|
|
|
|
import { type PaginatedResult } from './orders'
|
|
|
|
export interface Dispute {
|
|
id: number
|
|
order_id: number
|
|
order_no: string
|
|
title: string
|
|
initiator_id: number
|
|
target_user_id: number
|
|
type: string
|
|
status: string
|
|
description: string
|
|
evidence_urls?: string[]
|
|
arbitration_result: string
|
|
arbitration_remark: string
|
|
handled_by?: number
|
|
handled_at?: string
|
|
created_at: string
|
|
updated_at: string
|
|
}
|
|
|
|
interface ApiResponse<T> {
|
|
code: string
|
|
message: string
|
|
data: T
|
|
}
|
|
|
|
export async function createDispute(orderId: number, payload: { type: string; description: string; evidence_urls?: string[] }) {
|
|
const { data } = await apiClient.post<ApiResponse<Dispute>>(`/orders/${orderId}/dispute`, payload)
|
|
return data.data
|
|
}
|
|
|
|
export async function fetchDisputes(page = 1, pageSize = 20) {
|
|
const { data } = await apiClient.get<ApiResponse<PaginatedResult<Dispute>>>('/disputes', {
|
|
params: { page, page_size: pageSize },
|
|
})
|
|
return data.data
|
|
}
|
|
|
|
export async function fetchAdminDisputes(page = 1, pageSize = 20) {
|
|
const { data } = await apiClient.get<ApiResponse<PaginatedResult<Dispute>>>('/admin/disputes', {
|
|
params: { page, page_size: pageSize },
|
|
})
|
|
return data.data
|
|
}
|
|
|
|
export async function arbitrateDispute(id: number, payload: { result: string; remark: string; amount?: number }) {
|
|
const { data } = await apiClient.post<ApiResponse<Dispute>>(`/admin/disputes/${id}/arbitrate`, payload)
|
|
return data.data
|
|
}
|