chore: establish V1.1 recovery baseline

This commit is contained in:
2026-09-09 22:05:00 +08:00
commit b46b48eb33
947 changed files with 155471 additions and 0 deletions
+46
View File
@@ -0,0 +1,46 @@
import axios from 'axios'
import { ElMessage } from 'element-plus'
import router from '@/router'
const client = axios.create({
baseURL: '/api/v1',
timeout: 10000,
})
client.interceptors.request.use((config) => {
const token = localStorage.getItem('accessToken')
if (token) {
config.headers.Authorization = `Bearer ${token}`
}
return config
})
client.interceptors.response.use(
(res) => res.data,
(err) => {
if (err.response?.status === 401) {
localStorage.removeItem('accessToken')
router.push('/login')
ElMessage.error('登录已过期,请重新登录')
} else if (err.response?.data?.message) {
ElMessage.error(err.response.data.message)
} else {
ElMessage.error('请求失败')
}
return Promise.reject(err)
}
)
export const get = (url: string, params?: Record<string, any>, headers?: Record<string, string>) =>
client.get(url, { params, headers })
export const post = (url: string, data?: any, headers?: Record<string, string>) =>
client.post(url, data, { headers })
export const put = (url: string, data?: any, headers?: Record<string, string>) =>
client.put(url, data, { headers })
export const del = (url: string, headers?: Record<string, string>) =>
client.delete(url, { headers })
export default client