feat: Airwallex 发卡管理后台完整实现
- 后端: FastAPI + SQLAlchemy + SQLite, JWT认证, 代理支持的AirwallexClient - 前端: React 18 + Vite + Ant Design 5, 中文界面 - 功能: 卡片管理, 持卡人管理, 交易记录, API令牌, 系统设置, 审计日志 - 第三方API: X-API-Key认证, 权限控制 - Docker部署: docker-compose编排前后端
This commit is contained in:
84
frontend/src/services/api.ts
Normal file
84
frontend/src/services/api.ts
Normal file
@@ -0,0 +1,84 @@
|
||||
import axios from 'axios'
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: '/api',
|
||||
timeout: 30000,
|
||||
})
|
||||
|
||||
api.interceptors.request.use((config) => {
|
||||
const token = localStorage.getItem('token')
|
||||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}`
|
||||
}
|
||||
return config
|
||||
})
|
||||
|
||||
api.interceptors.response.use(
|
||||
(response) => response,
|
||||
(error) => {
|
||||
if (error.response?.status === 401) {
|
||||
localStorage.removeItem('token')
|
||||
localStorage.removeItem('username')
|
||||
window.location.href = '/login'
|
||||
}
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
|
||||
export const authApi = {
|
||||
login: (username: string, password: string) =>
|
||||
api.post('/auth/login', { username, password }),
|
||||
}
|
||||
|
||||
export const dashboardApi = {
|
||||
getDashboard: () => api.get('/dashboard'),
|
||||
}
|
||||
|
||||
export const cardsApi = {
|
||||
getCards: (params?: Record<string, unknown>) => api.get('/cards', { params }),
|
||||
createCard: (data: Record<string, unknown>) => api.post('/cards', data),
|
||||
getCard: (id: string) => api.get(`/cards/${id}`),
|
||||
getCardDetails: (id: string) => api.get(`/cards/${id}/details`),
|
||||
updateCard: (id: string, data: Record<string, unknown>) => api.put(`/cards/${id}`, data),
|
||||
}
|
||||
|
||||
export const cardholdersApi = {
|
||||
getCardholders: (params?: Record<string, unknown>) => api.get('/cardholders', { params }),
|
||||
createCardholder: (data: Record<string, unknown>) => api.post('/cardholders', data),
|
||||
}
|
||||
|
||||
export const transactionsApi = {
|
||||
getTransactions: (params?: Record<string, unknown>) => api.get('/transactions', { params }),
|
||||
}
|
||||
|
||||
export const authorizationsApi = {
|
||||
getAuthorizations: (params?: Record<string, unknown>) => api.get('/authorizations', { params }),
|
||||
}
|
||||
|
||||
export const tokensApi = {
|
||||
getTokens: () => api.get('/tokens'),
|
||||
createToken: (data: Record<string, unknown>) => api.post('/tokens', data),
|
||||
deleteToken: (id: string) => api.delete(`/tokens/${id}`),
|
||||
}
|
||||
|
||||
// Alias for components that import cardholderApi (singular)
|
||||
export const cardholderApi = {
|
||||
list: (params?: Record<string, unknown>) => api.get('/cardholders', { params }),
|
||||
create: (data: Record<string, unknown>) => api.post('/cardholders', data),
|
||||
}
|
||||
|
||||
export const settingsApi = {
|
||||
getSettings: () => api.get('/settings'),
|
||||
updateSettings: (data: { key: string; value: string }[]) => api.put('/settings', data),
|
||||
testConnection: () => api.post('/settings/test-connection'),
|
||||
}
|
||||
|
||||
export const cardLogsApi = {
|
||||
getCardLogs: (params?: Record<string, unknown>) => api.get('/card-logs', { params }),
|
||||
}
|
||||
|
||||
export const auditLogsApi = {
|
||||
getAuditLogs: (params?: Record<string, unknown>) => api.get('/audit-logs', { params }),
|
||||
}
|
||||
|
||||
export default api
|
||||
Reference in New Issue
Block a user