2026-02-25 15:22:12 +08:00
|
|
|
import axios from 'axios'
|
2026-02-24 17:57:25 +08:00
|
|
|
|
2026-02-25 15:22:12 +08:00
|
|
|
const API_BASE = '/api/v1'
|
2026-02-24 17:57:25 +08:00
|
|
|
|
|
|
|
|
// 创建 axios 实例
|
2026-02-25 15:22:12 +08:00
|
|
|
const api = axios.create({
|
|
|
|
|
baseURL: API_BASE,
|
|
|
|
|
timeout: 30000,
|
2026-02-24 17:57:25 +08:00
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
2026-02-25 15:22:12 +08:00
|
|
|
// 请求拦截器:添加 token
|
|
|
|
|
api.interceptors.request.use(
|
|
|
|
|
(config) => {
|
|
|
|
|
const token = localStorage.getItem('token')
|
|
|
|
|
if (token) {
|
2026-02-24 17:57:25 +08:00
|
|
|
config.headers.Authorization = `Bearer ${token}`
|
|
|
|
|
}
|
|
|
|
|
return config
|
|
|
|
|
},
|
2026-02-25 15:22:12 +08:00
|
|
|
(error) => {
|
2026-02-24 17:57:25 +08:00
|
|
|
return Promise.reject(error)
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
2026-02-25 15:22:12 +08:00
|
|
|
// 响应拦截器:处理错误
|
|
|
|
|
api.interceptors.response.use(
|
|
|
|
|
(response) => {
|
2026-02-24 17:57:25 +08:00
|
|
|
const { data } = response
|
|
|
|
|
if (data.code === 0) {
|
2026-02-25 15:22:12 +08:00
|
|
|
return data.data
|
2026-02-24 17:57:25 +08:00
|
|
|
}
|
2026-02-25 15:22:12 +08:00
|
|
|
return Promise.reject(new Error(data.message || '请求失败'))
|
2026-02-24 17:57:25 +08:00
|
|
|
},
|
2026-02-25 15:22:12 +08:00
|
|
|
(error) => {
|
|
|
|
|
const message = error.response?.data?.message || error.message || '网络错误'
|
|
|
|
|
return Promise.reject(new Error(message))
|
2026-02-24 17:57:25 +08:00
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
2026-02-25 15:22:12 +08:00
|
|
|
// ========== 认证 API ==========
|
|
|
|
|
export const authApi = {
|
|
|
|
|
login: (username: string, password: string) =>
|
|
|
|
|
api.post('/auth/login', { username, password }),
|
2026-02-24 17:57:25 +08:00
|
|
|
|
2026-02-25 15:22:12 +08:00
|
|
|
feishuLogin: (authCode: string, tenantKey: string) =>
|
|
|
|
|
api.post('/auth/feishu-login', { auth_code: authCode, tenant_key: tenantKey }),
|
|
|
|
|
}
|
2026-02-24 17:57:25 +08:00
|
|
|
|
2026-02-25 15:22:12 +08:00
|
|
|
// ========== 用户 API ==========
|
|
|
|
|
export const userApi = {
|
|
|
|
|
getInfo: () => api.get('/user/info'),
|
|
|
|
|
getMenu: () => api.get('/user/menu'),
|
|
|
|
|
getCompanies: () => api.get('/user/companies'),
|
|
|
|
|
switchCompany: (companyId: number) =>
|
|
|
|
|
api.post('/user/switch-company', { company_id: companyId }),
|
2026-02-24 17:57:25 +08:00
|
|
|
|
2026-02-25 15:22:12 +08:00
|
|
|
// 获取用户列表
|
|
|
|
|
getUsers: (params: { keyword?: string; page?: number; page_size?: number }) =>
|
|
|
|
|
api.get('/user/list', { params }),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ========== 出差申请 API ==========
|
|
|
|
|
export const businessTripApi = {
|
|
|
|
|
getList: (params: { type?: string; page?: number; page_size?: number }) =>
|
|
|
|
|
api.get('/business-trip/list', { params }),
|
|
|
|
|
|
|
|
|
|
getDetail: (id: number) => api.get(`/business-trip/detail/${id}`),
|
|
|
|
|
|
|
|
|
|
create: (data: any) => api.post('/business-trip/create', data),
|
|
|
|
|
|
|
|
|
|
update: (id: number, data: any) =>
|
|
|
|
|
api.post(`/business-trip/update/${id}`, data),
|
|
|
|
|
|
|
|
|
|
submit: (id: number, approvers: number[], ccUsers: number[] = []) =>
|
|
|
|
|
api.post(`/business-trip/submit/${id}`, {
|
|
|
|
|
approvers,
|
|
|
|
|
cc_users: ccUsers,
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
|
|
cancel: (id: number) => api.post(`/business-trip/cancel/${id}`),
|
2026-02-25 18:09:04 +08:00
|
|
|
|
|
|
|
|
deleteDraft: (id: number) => api.delete(`/business-trip/${id}`),
|
|
|
|
|
|
|
|
|
|
approve: (id: number, action: 'approve' | 'reject', comment?: string) =>
|
|
|
|
|
api.post(`/business-trip/approve/${id}`, { action, comment }),
|
2026-02-25 15:22:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ========== 审批 API ==========
|
|
|
|
|
export const approvalApi = {
|
|
|
|
|
getList: (params: { type?: string; page?: number; page_size?: number }) =>
|
|
|
|
|
api.get('/approval/list', { params }),
|
|
|
|
|
|
|
|
|
|
getDetail: (id: number) => api.get(`/approval/detail/${id}`),
|
|
|
|
|
|
|
|
|
|
approve: (id: number, comment?: string) =>
|
|
|
|
|
api.post(`/approval/approve/${id}`, { comment }),
|
|
|
|
|
|
|
|
|
|
reject: (id: number, comment?: string) =>
|
|
|
|
|
api.post(`/approval/reject/${id}`, { comment }),
|
|
|
|
|
|
|
|
|
|
cancel: (id: number) => api.post(`/approval/cancel/${id}`),
|
2026-02-24 17:57:25 +08:00
|
|
|
}
|
|
|
|
|
|
2026-02-25 15:22:12 +08:00
|
|
|
export default api
|