Files
dashboard/frontend/src/utils/request.js
T
yangy fb1aad45af Add Luxsin curve API client and validation functionality
- Introduced a new module `curve_client.py` for interacting with the Luxsin curve API, including functions for custom Base64 decoding and parametric EQ validation.
- Implemented error handling for API responses and validation checks for curve data.
- Removed outdated test files to streamline the codebase.
- Updated brand creation and update logic in `brands.py` to ensure brand names are validated and checked for duplicates.
- Enhanced model handling in `models.py` with new validation and push-to-search functionality, integrating curve validation before pushing to Meilisearch.
- Updated frontend components to support new validation and push processes, including user feedback for validation results and progress tracking.
- Changed favicon to SVG format for better scalability and appearance.
2026-05-20 14:13:42 +08:00

67 lines
1.7 KiB
JavaScript

import axios from 'axios'
import { ElMessage } from 'element-plus'
import { getToken, clearToken } from '@/utils/auth'
// 创建 axios 实例
const request = axios.create({
baseURL: '/api',
timeout: 10000
})
// 请求拦截器
request.interceptors.request.use(
config => {
const token = getToken()
const url = config.url || ''
if (token && !url.includes('/auth/login')) {
config.headers.Authorization = `Bearer ${token}`
}
return config
},
error => {
console.error('请求错误:', error)
return Promise.reject(error)
}
)
// 响应拦截器
request.interceptors.response.use(
response => {
const res = response.data
// 如果响应码为 0,表示错误(可由调用方自行提示,如推送进度弹窗)
if (res.code === 0) {
if (!response.config.skipErrorToast) {
ElMessage.error(res.msg || '请求失败')
}
const err = new Error(res.msg || '请求失败')
err.responseData = res
return Promise.reject(err)
}
return res
},
error => {
const status = error.response?.status
if (status === 401) {
clearToken()
const detail = error.response?.data?.detail
if (detail) {
ElMessage.warning(typeof detail === 'string' ? detail : '登录已失效')
}
const path = window.location.pathname || ''
if (!path.startsWith('/login')) {
window.location.assign(
`/login?redirect=${encodeURIComponent(path + (window.location.search || ''))}`
)
}
return Promise.reject(error)
}
console.error('响应错误:', error)
ElMessage.error(error.message || '网络错误')
return Promise.reject(error)
}
)
export default request