首次提交
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import axios from 'axios'
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: '/admin/api',
|
||||
timeout: 10000,
|
||||
})
|
||||
|
||||
// 请求拦截器:自动添加 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) =>
|
||||
axios.get(`/api/script/${domain}`, { params: { server_name: serverName } })
|
||||
|
||||
export default api
|
||||
Reference in New Issue
Block a user