582f454a5a
- 将后端目录名从大写改为小写 (Controller->controller 等) - 将命名空间从 App\ 改为 app\ (符合 webman 官方规范) - 移除不必要的 bootstrap 目录 - 完善出差审批业务功能: - 添加删除草稿功能 - 添加审批操作功能(同意/拒绝) - 完善审批详情页,显示审批人和审批记录 - 前端优化: - 调整列表页行高 - 隐藏底部导航栏 - 仪表盘只显示3个快捷入口 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
108 lines
3.0 KiB
TypeScript
108 lines
3.0 KiB
TypeScript
import axios from 'axios'
|
|
|
|
const API_BASE = '/api/v1'
|
|
|
|
// 创建 axios 实例
|
|
const api = axios.create({
|
|
baseURL: API_BASE,
|
|
timeout: 30000,
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
})
|
|
|
|
// 请求拦截器:添加 token
|
|
api.interceptors.request.use(
|
|
(config) => {
|
|
const token = localStorage.getItem('token')
|
|
if (token) {
|
|
config.headers.Authorization = `Bearer ${token}`
|
|
}
|
|
return config
|
|
},
|
|
(error) => {
|
|
return Promise.reject(error)
|
|
}
|
|
)
|
|
|
|
// 响应拦截器:处理错误
|
|
api.interceptors.response.use(
|
|
(response) => {
|
|
const { data } = response
|
|
if (data.code === 0) {
|
|
return data.data
|
|
}
|
|
return Promise.reject(new Error(data.message || '请求失败'))
|
|
},
|
|
(error) => {
|
|
const message = error.response?.data?.message || error.message || '网络错误'
|
|
return Promise.reject(new Error(message))
|
|
}
|
|
)
|
|
|
|
// ========== 认证 API ==========
|
|
export const authApi = {
|
|
login: (username: string, password: string) =>
|
|
api.post('/auth/login', { username, password }),
|
|
|
|
feishuLogin: (authCode: string, tenantKey: string) =>
|
|
api.post('/auth/feishu-login', { auth_code: authCode, tenant_key: tenantKey }),
|
|
}
|
|
|
|
// ========== 用户 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 }),
|
|
|
|
// 获取用户列表
|
|
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}`),
|
|
|
|
deleteDraft: (id: number) => api.delete(`/business-trip/${id}`),
|
|
|
|
approve: (id: number, action: 'approve' | 'reject', comment?: string) =>
|
|
api.post(`/business-trip/approve/${id}`, { action, comment }),
|
|
}
|
|
|
|
// ========== 审批 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}`),
|
|
}
|
|
|
|
export default api
|