2026-07-18 20:09:26 +08:00
|
|
|
import axios from 'axios'
|
|
|
|
|
|
|
|
|
|
const api = axios.create({
|
|
|
|
|
baseURL: '/admin/api',
|
2026-07-18 20:42:26 +08:00
|
|
|
timeout: 180000,
|
2026-07-18 20:09:26 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// 请求拦截器:自动添加 token
|
|
|
|
|
api.interceptors.request.use((config) => {
|
|
|
|
|
const token = localStorage.getItem('admin_token')
|
|
|
|
|
if (token) {
|
|
|
|
|
config.headers.Authorization = `Bearer ${token}`
|
|
|
|
|
}
|
|
|
|
|
return config
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// 响应拦截器:401 时清除 token
|
|
|
|
|
api.interceptors.response.use(
|
|
|
|
|
(response) => response,
|
|
|
|
|
(error) => {
|
|
|
|
|
if (error.response?.status === 401) {
|
|
|
|
|
localStorage.removeItem('admin_token')
|
|
|
|
|
// 触发重新检查登录状态(通过刷新页面)
|
|
|
|
|
window.location.reload()
|
|
|
|
|
}
|
|
|
|
|
return Promise.reject(error)
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Stats
|
|
|
|
|
export const getStats = () => api.get('/stats')
|
|
|
|
|
|
|
|
|
|
// Servers
|
|
|
|
|
export const getServers = () => api.get('/servers')
|
|
|
|
|
export const getServer = (id) => api.get(`/servers/${id}`)
|
|
|
|
|
export const createServer = (data) => api.post('/servers', data)
|
|
|
|
|
export const updateServer = (id, data) => api.put(`/servers/${id}`, data)
|
|
|
|
|
export const deleteServer = (id) => api.delete(`/servers/${id}`)
|
|
|
|
|
|
|
|
|
|
// Domains
|
|
|
|
|
export const getDomains = () => api.get('/domains')
|
|
|
|
|
export const getDomain = (id) => api.get(`/domains/${id}`)
|
|
|
|
|
export const createDomain = (data) => api.post('/domains', data)
|
|
|
|
|
export const updateDomain = (id, data) => api.put(`/domains/${id}`, data)
|
|
|
|
|
export const deleteDomain = (id) => api.delete(`/domains/${id}`)
|
|
|
|
|
|
|
|
|
|
// Logs
|
|
|
|
|
export const getLogs = (status) => api.get('/logs', { params: { status } })
|
|
|
|
|
|
|
|
|
|
// Script (通过管理接口获取脚本内容)
|
|
|
|
|
export const getScript = (domain, serverName) =>
|
2026-07-18 20:54:48 +08:00
|
|
|
axios.get('/api/script', { params: { domain, server_name: serverName } })
|
2026-07-18 20:09:26 +08:00
|
|
|
|
|
|
|
|
export default api
|