refactor: 全量迁移前端 API 调用到统一 api-services 服务层
- 新建 api-services-raw.ts 导出原始 axios 方法供特殊端点使用 - 完成 api-services.ts 全领域覆盖(auth/employee/roster/dashboard/attendance/payroll/socialInsurance/commercialInsurance/termination/policies/evidence/audit/calendar/companyFiles/notifications/settings/ai/platform/portal/survey/search) - 迁移所有 47+ 页面文件:pages/、pages/roster/、pages/portal/、pages/platform/、pages/auth/、pages/dashboard/、pages/compliance/ - 移除所有直接 import api from '../../lib/api' 引用 - 修复 Termination.tsx / WorkProcess.tsx 中 string|null 类型错误 - 修复 SocialInsurance.tsx 中 api-services-raw delete 导入名 - 修复 PlatformLogin.tsx 变量遮蔽问题 - tsc --noEmit 零错误,vite build 成功
This commit is contained in:
@@ -4,7 +4,7 @@ import { toast } from 'sonner'
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { useConfirm } from '../hooks/useConfirm'
|
||||
import { Users, FileText, AlertTriangle, Calendar, TrendingUp, Scale, X, Plus, Check, UserX, UserPlus, DollarSign, Building2, RotateCcw, History, Upload, Wallet, Download } from 'lucide-react'
|
||||
import api from '../lib/api'
|
||||
import { rosterApi, employeeApi, terminationApi } from '../lib/api-services'
|
||||
import { useAuthStore } from '../store/authStore'
|
||||
import { useDebouncedValue } from '../hooks/useDebouncedValue'
|
||||
import Card from '../components/ui/Card'
|
||||
@@ -58,7 +58,7 @@ export default function Roster() {
|
||||
if (filterStatus === 'PROBATION') params.status = 'ACTIVE'
|
||||
if (filterContractStatus) params.contractStatus = filterContractStatus
|
||||
if (filterDepartment) params.department = filterDepartment
|
||||
const res = await api.get('/roster', { params }) as any
|
||||
const res = await rosterApi.list({ search: debouncedSearch, page, pageSize, status: filterStatus === 'PROBATION' ? 'ACTIVE' : filterStatus || undefined, contractStatus: filterContractStatus || undefined, department: filterDepartment || undefined } as any) as any
|
||||
return res
|
||||
},
|
||||
})
|
||||
@@ -83,7 +83,7 @@ export default function Roster() {
|
||||
}, [employeeParam, debouncedSearch, isLoading, employees, selectedId, setSearchParams])
|
||||
|
||||
const addMutation = useMutation({
|
||||
mutationFn: (data: any) => api.post('/employees', data),
|
||||
mutationFn: (data: any) => employeeApi.create(data),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['roster'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['dashboard'] })
|
||||
@@ -93,7 +93,7 @@ export default function Roster() {
|
||||
})
|
||||
|
||||
const resignMutation = useMutation({
|
||||
mutationFn: (data: any) => api.post('/termination/draft', {
|
||||
mutationFn: (data: any) => terminationApi.createDraft({
|
||||
employeeId: data.employeeId,
|
||||
type: 'RESIGNATION',
|
||||
reason: 'RESIGNATION',
|
||||
@@ -113,7 +113,7 @@ export default function Roster() {
|
||||
})
|
||||
|
||||
const revokeMutation = useMutation({
|
||||
mutationFn: (recordId: string) => api.delete(`/termination/${recordId}/revoke`),
|
||||
mutationFn: (recordId: string) => terminationApi.revoke(recordId),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['roster'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['dashboard'] })
|
||||
@@ -122,7 +122,7 @@ export default function Roster() {
|
||||
})
|
||||
|
||||
const rehireMutation = useMutation({
|
||||
mutationFn: (data: any) => api.post(`/employees/${rehireEmployee?.id}/rehire`, data),
|
||||
mutationFn: (data: any) => employeeApi.rehire(rehireEmployee?.id, data),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['roster'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['dashboard'] })
|
||||
@@ -133,7 +133,7 @@ export default function Roster() {
|
||||
})
|
||||
|
||||
const salaryChangeMutation = useMutation({
|
||||
mutationFn: (data: any) => api.post(`/roster/${salaryEmployee?.id}/salary-change`, data),
|
||||
mutationFn: (data: any) => rosterApi.salaryChange(salaryEmployee?.id, data),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['roster'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['dashboard'] })
|
||||
@@ -144,7 +144,7 @@ export default function Roster() {
|
||||
})
|
||||
|
||||
const deptChangeMutation = useMutation({
|
||||
mutationFn: (data: any) => api.post(`/roster/${deptEmployee?.id}/department-change`, data),
|
||||
mutationFn: (data: any) => rosterApi.departmentChange(deptEmployee?.id, data),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['roster'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['dashboard'] })
|
||||
@@ -155,7 +155,7 @@ export default function Roster() {
|
||||
})
|
||||
|
||||
const batchRenewMutation = useMutation({
|
||||
mutationFn: (data: { contractIds: string[]; years: number }) => api.post('/employees/contracts/batch-renew', data),
|
||||
mutationFn: (data: { contractIds: string[]; years: number }) => employeeApi.batchRenew(data),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['roster'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['dashboard'] })
|
||||
@@ -167,7 +167,7 @@ export default function Roster() {
|
||||
})
|
||||
|
||||
const previewRenewMutation = useMutation({
|
||||
mutationFn: (contractIds: string[]) => api.post('/employees/contracts/preview-renew', { contractIds }),
|
||||
mutationFn: (contractIds: string[]) => employeeApi.previewRenew(contractIds),
|
||||
onSuccess: (data: any) => {
|
||||
setPreviewData(data.data)
|
||||
},
|
||||
@@ -175,7 +175,7 @@ export default function Roster() {
|
||||
|
||||
const previewTerminateMutation = useMutation({
|
||||
mutationFn: (items: Array<{ employeeId: string; reason: string; terminationDate: string }>) =>
|
||||
api.post('/termination/batch/preview', { items }),
|
||||
terminationApi.batchPreview(items),
|
||||
onSuccess: (data: any) => {
|
||||
setTerminatePreviewData(data.data)
|
||||
},
|
||||
@@ -184,12 +184,12 @@ export default function Roster() {
|
||||
const batchTerminateMutation = useMutation({
|
||||
mutationFn: async (items: Array<{ employeeId: string; reason: string; terminationDate: string }>) => {
|
||||
const results = await Promise.all(
|
||||
items.map(item => api.post('/termination/draft', {
|
||||
items.map(item => terminationApi.createDraft({
|
||||
employeeId: item.employeeId,
|
||||
type: 'TERMINATION',
|
||||
reason: item.reason,
|
||||
terminationDate: item.terminationDate,
|
||||
}).catch(err => ({ error: err, employeeId: item.employeeId })))
|
||||
}).catch((err: any) => ({ error: err, employeeId: item.employeeId })))
|
||||
)
|
||||
return results
|
||||
},
|
||||
@@ -258,8 +258,7 @@ export default function Roster() {
|
||||
const { data: departmentList } = useQuery<string[]>({
|
||||
queryKey: ['roster-departments'],
|
||||
queryFn: async () => {
|
||||
const res = await api.get('/roster/departments') as any
|
||||
return res.data || []
|
||||
return await rosterApi.departments()
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user