新增 Web 浏览端(Go+Vue 报表系统)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
fish
2026-05-03 14:34:50 +08:00
parent bf8f578761
commit 750584e619
47 changed files with 2557 additions and 18 deletions

View File

@@ -0,0 +1,34 @@
import axios, { type AxiosInstance } from 'axios'
import { ElMessage } from 'element-plus'
import { useAuthStore } from '@/stores/auth'
import router from '@/router'
const baseURL = import.meta.env.VITE_API_BASE || '/api'
const client: AxiosInstance = axios.create({ baseURL, timeout: 15_000 })
client.interceptors.request.use((cfg) => {
const auth = useAuthStore()
if (auth.token) {
cfg.headers = cfg.headers ?? {}
cfg.headers.Authorization = `Bearer ${auth.token}`
}
return cfg
})
client.interceptors.response.use(
(resp) => resp,
(err) => {
const status = err?.response?.status
if (status === 401) {
const auth = useAuthStore()
auth.logout()
router.replace({ path: '/login', query: { redirect: router.currentRoute.value.fullPath } })
}
const msg = err?.response?.data?.error || err.message || '请求失败'
if (status !== 401) ElMessage.error(msg)
return Promise.reject(err)
},
)
export default client