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:
@@ -5,8 +5,7 @@ import { AlertTriangle, Check, ChevronRight, ChevronLeft, Shield, Info, Calculat
|
||||
import { Stepper } from '../components/ui/Stepper'
|
||||
import { InlineAlert } from '../components/ui/InlineAlert'
|
||||
import jsPDF from 'jspdf'
|
||||
import api from '../lib/api'
|
||||
import { rosterApi } from '../lib/api-services'
|
||||
import { rosterApi, terminationApi } from '../lib/api-services'
|
||||
import { useAuthStore } from '../store/authStore'
|
||||
import Card from '../components/ui/Card'
|
||||
import Button from '../components/ui/Button'
|
||||
@@ -236,8 +235,7 @@ export default function Termination() {
|
||||
const { data: profile } = useQuery<EmployeeProfile>({
|
||||
queryKey: ['employee-profile', employeeId],
|
||||
queryFn: async () => {
|
||||
const res = await api.get(`/roster/${employeeId}/profile`) as any
|
||||
return res.data
|
||||
return await rosterApi.profile(employeeId)
|
||||
},
|
||||
enabled: !!employeeId,
|
||||
})
|
||||
@@ -305,8 +303,7 @@ export default function Termination() {
|
||||
}[]>({
|
||||
queryKey: ['checklist', reason, employeeId],
|
||||
queryFn: async () => {
|
||||
const res = await api.get(`/termination/checklist/${reason}`, { params: { employeeId } }) as any
|
||||
return res.data
|
||||
return await terminationApi.checklist(reason, employeeId)
|
||||
},
|
||||
enabled: !!reason && !!employeeId && step >= 2,
|
||||
})
|
||||
@@ -326,14 +323,13 @@ export default function Termination() {
|
||||
const { data: riskAssessment } = useQuery<{ level: string; warnings: string[] }>({
|
||||
queryKey: ['assess', employeeId, reason],
|
||||
queryFn: async () => {
|
||||
const res = await api.get(`/termination/assess/${employeeId}`, { params: { reason } }) as any
|
||||
return res.data
|
||||
return await terminationApi.assess(employeeId, reason)
|
||||
},
|
||||
enabled: !!employeeId && !!reason && step >= 1,
|
||||
})
|
||||
|
||||
const saveMutation = useMutation({
|
||||
mutationFn: (data: any) => api.post('/termination', data),
|
||||
mutationFn: (data: any) => terminationApi.create(data),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['dashboard'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['employees'] })
|
||||
@@ -352,8 +348,7 @@ export default function Termination() {
|
||||
if (filterStatus) params.status = filterStatus
|
||||
if (filterDepartment) params.department = filterDepartment
|
||||
if (searchTerm) params.search = searchTerm
|
||||
const res = await api.get('/termination/drafts', { params }) as any
|
||||
return res.data
|
||||
return await terminationApi.drafts(params)
|
||||
},
|
||||
enabled: view === 'list',
|
||||
})
|
||||
@@ -364,8 +359,7 @@ export default function Termination() {
|
||||
const { data: draftDetail } = useQuery({
|
||||
queryKey: ['termination-detail', draftId],
|
||||
queryFn: async () => {
|
||||
const res = await api.get(`/termination/detail/${draftId}`) as any
|
||||
return res.data
|
||||
return await terminationApi.detail(draftId!)
|
||||
},
|
||||
enabled: !!draftId && view === 'detail',
|
||||
})
|
||||
@@ -373,8 +367,8 @@ export default function Termination() {
|
||||
// 保存草稿
|
||||
const saveDraftMutation = useMutation({
|
||||
mutationFn: (data: any) => draftId
|
||||
? api.put(`/termination/draft/${draftId}`, data)
|
||||
: api.post('/termination/draft', data),
|
||||
? terminationApi.updateDraft(draftId!, data)
|
||||
: terminationApi.createDraft(data),
|
||||
onSuccess: (res: any) => {
|
||||
const newId = draftId || res?.data?.id
|
||||
setDraftId(newId)
|
||||
@@ -386,7 +380,7 @@ export default function Termination() {
|
||||
|
||||
// 提交审批
|
||||
const submitMutation = useMutation({
|
||||
mutationFn: () => api.post(`/termination/draft/${draftId}/submit`),
|
||||
mutationFn: () => terminationApi.submit(draftId!),
|
||||
onSuccess: () => {
|
||||
toast.success('已提交审批')
|
||||
queryClient.invalidateQueries({ queryKey: ['termination-drafts'] })
|
||||
@@ -398,7 +392,7 @@ export default function Termination() {
|
||||
|
||||
// 审批通过
|
||||
const approveMutation = useMutation({
|
||||
mutationFn: (comment: string) => api.post(`/termination/draft/${draftId}/approve`, { comment }),
|
||||
mutationFn: (comment: string) => terminationApi.approve(draftId!, comment),
|
||||
onSuccess: () => {
|
||||
toast.success('审批通过')
|
||||
queryClient.invalidateQueries({ queryKey: ['termination-drafts'] })
|
||||
@@ -409,7 +403,7 @@ export default function Termination() {
|
||||
|
||||
// 审批驳回
|
||||
const rejectMutation = useMutation({
|
||||
mutationFn: (comment: string) => api.post(`/termination/draft/${draftId}/reject`, { comment }),
|
||||
mutationFn: (comment: string) => terminationApi.reject(draftId!, comment),
|
||||
onSuccess: () => {
|
||||
toast.success('已驳回')
|
||||
queryClient.invalidateQueries({ queryKey: ['termination-drafts'] })
|
||||
@@ -420,7 +414,7 @@ export default function Termination() {
|
||||
|
||||
// 执行解聘
|
||||
const executeMutation = useMutation({
|
||||
mutationFn: () => api.post(`/termination/draft/${draftId}/execute`),
|
||||
mutationFn: () => terminationApi.execute(draftId!),
|
||||
onSuccess: () => {
|
||||
toast.success('解聘已执行')
|
||||
queryClient.invalidateQueries({ queryKey: ['termination-drafts'] })
|
||||
@@ -436,7 +430,7 @@ export default function Termination() {
|
||||
|
||||
// 撤销
|
||||
const cancelMutation = useMutation({
|
||||
mutationFn: () => api.post(`/termination/draft/${draftId}/cancel`),
|
||||
mutationFn: () => terminationApi.cancel(draftId!),
|
||||
onSuccess: () => {
|
||||
toast.success('已撤销')
|
||||
queryClient.invalidateQueries({ queryKey: ['termination-drafts'] })
|
||||
@@ -451,8 +445,7 @@ export default function Termination() {
|
||||
const { data: evidenceChain } = useQuery({
|
||||
queryKey: ['evidence-chain', employeeId],
|
||||
queryFn: async () => {
|
||||
const res = await api.get(`/roster/${employeeId}/evidence-chain`) as any
|
||||
return res.data
|
||||
return await rosterApi.evidenceChain(employeeId)
|
||||
},
|
||||
enabled: !!employeeId && step === 5 && saveMutation.isSuccess,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user