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:
selfrelease
2026-08-01 16:13:19 +08:00
parent fb924dea98
commit 16f22e6622
64 changed files with 1197 additions and 597 deletions
+43 -57
View File
@@ -4,7 +4,8 @@ import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
import { useConfirm } from '../hooks/useConfirm'
import { Calculator, Info, Check, Settings as SettingsIcon, Plus, History, Download, AlertCircle, Clock, MapPin, Sparkles, Upload, X, Shield } from 'lucide-react'
import { InlineAlert } from '../components/ui/InlineAlert'
import api from '../lib/api'
import { socialInsuranceApi, commercialInsuranceApi } from '../lib/api-services'
import { get as apiGet, post as apiPost, put as apiPut, del as apiDel } from '../lib/api-services-raw'
import { useAuthStore } from '../store/authStore'
import Card from '../components/ui/Card'
import Button from '../components/ui/Button'
@@ -54,31 +55,28 @@ export default function SocialInsurance() {
const { data: cities = [] } = useQuery<string[]>({
queryKey: ['social-config-cities'],
queryFn: async () => {
const res = await api.get('/social/config/cities') as any
return res.data
return await socialInsuranceApi.cities()
},
})
const { data: config, isLoading: configLoading } = useQuery<any>({
queryKey: ['social-config', city],
queryFn: async () => {
const res = await api.get('/social/config', { params: { city } }) as any
return res.data
return await socialInsuranceApi.config(city)
},
})
const { data: housingConfig, isLoading: housingLoading } = useQuery<any>({
queryKey: ['housing-config', city],
queryFn: async () => {
const res = await api.get('/social/housing-config', { params: { city } }) as any
return res.data
return await socialInsuranceApi.housingConfig(city)
},
})
const { data: housingAllAccounts } = useQuery<any[]>({
queryKey: ['housing-config-all-accounts', city],
queryFn: async () => {
const res = await api.get('/social/housing-config/versions', { params: { city } }) as any
const current = (res.data || []).filter((v: any) => v.isCurrent)
const res = await socialInsuranceApi.housingConfigVersions(city) as any
const current = (res || []).filter((v: any) => v.isCurrent)
return current
},
})
@@ -86,8 +84,7 @@ export default function SocialInsurance() {
const { data: versions } = useQuery<any[]>({
queryKey: ['social-config-versions', city],
queryFn: async () => {
const res = await api.get('/social/config/versions', { params: { city } }) as any
return res.data
return await socialInsuranceApi.configVersions(city)
},
enabled: showVersions && tab === 'social',
})
@@ -95,8 +92,7 @@ export default function SocialInsurance() {
const { data: housingVersions } = useQuery<any[]>({
queryKey: ['housing-config-versions'],
queryFn: async () => {
const res = await api.get('/social/housing-config/versions') as any
return res.data
return await socialInsuranceApi.housingConfigVersions()
},
enabled: showVersions && tab === 'housing',
})
@@ -105,8 +101,7 @@ export default function SocialInsurance() {
const { data: processedList, refetch: refetchProcessedList } = useQuery<any[]>({
queryKey: ['monthly-process-list'],
queryFn: async () => {
const res = await api.get('/social/monthly-process/list') as any
return res.data
return await socialInsuranceApi.monthlyProcessList()
},
enabled: tab === 'monthly',
})
@@ -114,8 +109,8 @@ export default function SocialInsurance() {
// 进入月度办理Tab时自动查询当前月状态
useEffect(() => {
if (tab === 'monthly') {
api.get('/social/monthly-process/status', { params: { month: monthlyMonth } }).then((res: any) => {
setProcessStatus(res.data)
socialInsuranceApi.monthlyProcessStatus(monthlyMonth).then((res: any) => {
setProcessStatus(res)
}).catch(() => {})
refetchProcessedList()
}
@@ -124,10 +119,10 @@ export default function SocialInsurance() {
const { mutateAsync: fetchMonthlyChanges, isPending: monthlyLoading, data: monthlyChanges } = useMutation<any>({
mutationFn: async () => {
const [socialRes, housingRes, socialActiveRes, housingActiveRes] = await Promise.all([
api.get('/social/monthly-changes', { params: { month: monthlyMonth } }) as any,
api.get('/social/housing/monthly-changes', { params: { month: monthlyMonth } }) as any,
api.get('/social/active-declaration', { params: { month: monthlyMonth } }) as any,
api.get('/social/housing/active-declaration', { params: { month: monthlyMonth } }) as any,
apiGet('/social/monthly-changes', { params: { month: monthlyMonth } }) as any,
apiGet('/social/housing/monthly-changes', { params: { month: monthlyMonth } }) as any,
apiGet('/social/active-declaration', { params: { month: monthlyMonth } }) as any,
apiGet('/social/housing/active-declaration', { params: { month: monthlyMonth } }) as any,
])
return {
social: socialRes.data,
@@ -143,8 +138,8 @@ export default function SocialInsurance() {
await fetchMonthlyChanges()
setMonthlyProcessed(true)
// 查询该月办理状态
const statusRes = await api.get('/social/monthly-process/status', { params: { month: monthlyMonth } }) as any
setProcessStatus(statusRes.data)
const statusRes = await socialInsuranceApi.monthlyProcessStatus(monthlyMonth) as any
setProcessStatus(statusRes)
} catch {
toast.error('获取月度办理数据失败')
}
@@ -154,7 +149,7 @@ export default function SocialInsurance() {
mutationFn: async (type: 'SOCIAL' | 'HOUSING') => {
const snapshot = type === 'SOCIAL' ? monthlyChanges.social : monthlyChanges.housing
const activeSnapshot = type === 'SOCIAL' ? monthlyChanges.socialActive : monthlyChanges.housingActive
const res = await api.post('/social/monthly-process/complete', {
const res = await socialInsuranceApi.completeMonthlyProcess({
month: monthlyMonth,
type,
snapshot: { changes: snapshot, active: activeSnapshot },
@@ -174,20 +169,18 @@ export default function SocialInsurance() {
const { data: result, mutate: calcMutate, isPending } = useMutation<any>({
mutationFn: async () => {
const res = await api.post('/social/calculate', { base, city }) as any
return res.data
return await socialInsuranceApi.calculate(base, city)
},
})
const { data: housingResult, mutate: calcHousingMutate, isPending: housingCalcPending } = useMutation<any>({
mutationFn: async () => {
const res = await api.post('/social/housing-calculate', { base, city }) as any
return res.data
return await socialInsuranceApi.housingCalculate(base, city)
},
})
const createVersionMutation = useMutation({
mutationFn: (data: any) => api.post('/social/config/versions', data),
mutationFn: (data: any) => socialInsuranceApi.createConfigVersion(data),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['social-config'] })
queryClient.invalidateQueries({ queryKey: ['social-config-versions'] })
@@ -197,7 +190,7 @@ export default function SocialInsurance() {
})
const createHousingVersionMutation = useMutation({
mutationFn: (data: any) => api.post('/social/housing-config/versions', data),
mutationFn: (data: any) => socialInsuranceApi.createHousingConfigVersion(data),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['housing-config'] })
queryClient.invalidateQueries({ queryKey: ['housing-config-versions'] })
@@ -208,8 +201,7 @@ export default function SocialInsurance() {
const aiSuggestMut = useMutation<any, any, { city: string; effectiveFrom: string; type: 'social' | 'housing' }>({
mutationFn: async (vars: { city: string; effectiveFrom: string; type: 'social' | 'housing' }) => {
const res = await api.post('/social/ai-suggest', vars) as any
return res.data
return await socialInsuranceApi.aiSuggest(vars)
},
onSuccess: (data) => {
if (isHousing) {
@@ -247,8 +239,7 @@ export default function SocialInsurance() {
const previewAdjustMutation = useMutation({
mutationFn: async () => {
const res = await api.get(`/social/config/${config?.id}/adjust-preview`) as any
return res.data
return await socialInsuranceApi.adjustPreview(config?.id)
},
onSuccess: (data) => {
setAdjustData(data)
@@ -258,8 +249,7 @@ export default function SocialInsurance() {
const previewHousingAdjustMutation = useMutation({
mutationFn: async () => {
const res = await api.get(`/social/housing-config/${housingConfig?.id}/adjust-preview`) as any
return res.data
return await socialInsuranceApi.housingAdjustPreview(housingConfig?.id)
},
onSuccess: (data) => {
setAdjustData(data)
@@ -269,7 +259,7 @@ export default function SocialInsurance() {
const applyAdjustMutation = useMutation({
mutationFn: (data: { items: { employeeId: string; newBase: number }[] }) =>
api.post(`/social/config/${config?.id}/adjust-apply`, data),
socialInsuranceApi.applyAdjust(config?.id, data),
onSuccess: (res: any) => {
queryClient.invalidateQueries({ queryKey: ['social-config'] })
queryClient.invalidateQueries({ queryKey: ['social-config-versions'] })
@@ -285,7 +275,7 @@ export default function SocialInsurance() {
const applyHousingAdjustMutation = useMutation({
mutationFn: (data: { items: { employeeId: string; newBase: number }[] }) =>
api.post(`/social/housing-config/${housingConfig?.id}/adjust-apply`, data),
socialInsuranceApi.applyHousingAdjust(housingConfig?.id, data),
onSuccess: (res: any) => {
queryClient.invalidateQueries({ queryKey: ['housing-config'] })
queryClient.invalidateQueries({ queryKey: ['housing-config-versions'] })
@@ -300,7 +290,7 @@ export default function SocialInsurance() {
})
const resetAdjustMutation = useMutation({
mutationFn: () => api.post(`/social/config/${config?.id}/reset-adjustment`, { city }),
mutationFn: () => socialInsuranceApi.resetAdjust(config?.id, city),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['social-config', city] })
queryClient.invalidateQueries({ queryKey: ['social-config-versions', city] })
@@ -309,7 +299,7 @@ export default function SocialInsurance() {
})
const resetHousingAdjustMutation = useMutation({
mutationFn: () => api.post(`/social/housing-config/${housingConfig?.id}/reset-adjustment`, { city }),
mutationFn: () => socialInsuranceApi.resetHousingAdjust(housingConfig?.id, city),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['housing-config', city] })
queryClient.invalidateQueries({ queryKey: ['housing-config-versions', city] })
@@ -1162,7 +1152,7 @@ function MonthlyRow({ item: i, type, onCorrected }: { item: any; type: 'add' | '
const d = i.detail
const correctMutation = useMutation({
mutationFn: (data: { base: number }) => api.put(`/social/records/social/${i.recordId}/correct`, data),
mutationFn: (data: { base: number }) => socialInsuranceApi.correctRecord('social', i.recordId, data),
onSuccess: () => {
setEditing(false)
toast.success('基数已修改')
@@ -1250,7 +1240,7 @@ function MonthlyHousingRow({ item: i, type, onCorrected }: { item: any; type: 'a
const d = i.detail
const correctMutation = useMutation({
mutationFn: (data: { base: number }) => api.put(`/social/records/housing/${i.recordId}/correct`, data),
mutationFn: (data: { base: number }) => socialInsuranceApi.correctRecord('housing', i.recordId, data),
onSuccess: () => {
setEditing(false)
toast.success('基数已修改')
@@ -1314,8 +1304,7 @@ function SpecialDeductionTab({ month, setMonth }: { month: string; setMonth: (m:
const { data: records = [], isLoading } = useQuery<any[]>({
queryKey: ['special-deduction', month],
queryFn: async () => {
const res = await api.get('/social/special-deduction/batch', { params: { month } }) as any
return res.data
return await socialInsuranceApi.specialDeductionBatch(month)
},
})
@@ -1323,8 +1312,8 @@ function SpecialDeductionTab({ month, setMonth }: { month: string; setMonth: (m:
const { data: employees = [] } = useQuery<any[]>({
queryKey: ['active-social-employees', month],
queryFn: async () => {
const res = await api.get('/social/active-declaration', { params: { month } }) as any
return (res.data?.items || []).map((item: any) => ({
const res = await socialInsuranceApi.activeDeclaration(month) as any
return (res?.items || []).map((item: any) => ({
id: item.employeeId,
name: item.name,
department: item.department,
@@ -1341,14 +1330,13 @@ function SpecialDeductionTab({ month, setMonth }: { month: string; setMonth: (m:
const { data: prevRecords = [] } = useQuery<any[]>({
queryKey: ['special-deduction', prevMonth],
queryFn: async () => {
const res = await api.get('/social/special-deduction/batch', { params: { month: prevMonth } }) as any
return res.data || []
return await socialInsuranceApi.specialDeductionBatch(prevMonth)
},
})
const prevRecordMap = new Map(prevRecords.map((r: any) => [r.employeeId, r]))
const saveMutation = useMutation({
mutationFn: (data: any) => api.post('/social/special-deduction', { ...data, month }),
mutationFn: (data: any) => socialInsuranceApi.saveSpecialDeduction({ ...data, month }),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['special-deduction'] })
setEditing(null)
@@ -1376,7 +1364,7 @@ function SpecialDeductionTab({ month, setMonth }: { month: string; setMonth: (m:
mutationFn: async () => {
let copied = 0
for (const prev of prevRecords) {
await api.post('/social/special-deduction', {
await socialInsuranceApi.saveSpecialDeduction({
employeeId: prev.employeeId,
month,
children: prev.children || 0,
@@ -1661,8 +1649,7 @@ function CommercialInsuranceTab() {
const { data: plans = [], isLoading } = useQuery<any[]>({
queryKey: ['commercial-insurance-plans'],
queryFn: async () => {
const res = await api.get('/commercial-insurance/plans') as any
return res.data || []
return await commercialInsuranceApi.plans()
},
})
@@ -1671,8 +1658,7 @@ function CommercialInsuranceTab() {
queryKey: ['commercial-insurance-enrollments', selectedPlanId],
queryFn: async () => {
if (!selectedPlanId) return []
const res = await api.get(`/commercial-insurance/plans/${selectedPlanId}/enrollments`) as any
return res.data || []
return await commercialInsuranceApi.enrollments(selectedPlanId)
},
enabled: !!selectedPlanId,
})
@@ -1681,9 +1667,9 @@ function CommercialInsuranceTab() {
const savePlanMutation = useMutation({
mutationFn: async (data: any) => {
if (editingPlan) {
return api.put(`/commercial-insurance/plans/${editingPlan.id}`, data) as any
return commercialInsuranceApi.savePlan(data, editingPlan.id) as any
}
return api.post('/commercial-insurance/plans', data) as any
return commercialInsuranceApi.savePlan(data) as any
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['commercial-insurance-plans'] })
@@ -1697,7 +1683,7 @@ function CommercialInsuranceTab() {
/** 删除商险方案 */
const deletePlanMutation = useMutation({
mutationFn: (id: string) => api.delete(`/commercial-insurance/plans/${id}`),
mutationFn: (id: string) => commercialInsuranceApi.removePlan(id),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['commercial-insurance-plans'] })
setSelectedPlanId(null)