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,8 +4,8 @@ import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { Link } from 'react-router-dom'
|
||||
import { PieChart, Pie, Cell, ResponsiveContainer, Tooltip, RadialBarChart, RadialBar, PolarAngleAxis } from 'recharts'
|
||||
import { Users, AlertTriangle, CheckSquare, DollarSign, ArrowRight, RefreshCw, FileText, Calendar, TrendingUp, Briefcase, Calculator, Wallet, Building2, Receipt, Check, X, Clock, LayoutDashboard, ListTodo, ShieldAlert, UserPlus, AlertCircle, Download, ChevronRight, TrendingDown, ShieldCheck, Lightbulb, BookOpen, Sparkles, Repeat, XCircle, Loader2 } from 'lucide-react'
|
||||
import api from '../lib/api'
|
||||
import { dashboardApi, rosterApi } from '../lib/api-services'
|
||||
import { dashboardApi, rosterApi, workProcessApi } from '../lib/api-services'
|
||||
import { post as apiPost, patch as apiPatch } from '../lib/api-services-raw'
|
||||
import { useAuthStore } from '../store/authStore'
|
||||
import Card from '../components/ui/Card'
|
||||
import Button from '../components/ui/Button'
|
||||
@@ -50,10 +50,7 @@ export default function Dashboard() {
|
||||
const [dismissedExpiring, setDismissedExpiring] = useState(false)
|
||||
const { data, isLoading, refetch, isFetching } = useQuery<DashboardData>({
|
||||
queryKey: ['dashboard'],
|
||||
queryFn: async () => {
|
||||
const res = await api.get('/dashboard') as any
|
||||
return res.data
|
||||
},
|
||||
queryFn: () => dashboardApi.data(),
|
||||
})
|
||||
|
||||
const { data: expiringContracts } = useQuery<any>({
|
||||
@@ -65,10 +62,7 @@ export default function Dashboard() {
|
||||
|
||||
const { data: costAnalysis } = useQuery<any>({
|
||||
queryKey: ['cost-analysis', currentMonth],
|
||||
queryFn: async () => {
|
||||
const res = await api.get(`/dashboard/cost-analysis?month=${currentMonth}`) as any
|
||||
return res.data
|
||||
},
|
||||
queryFn: () => dashboardApi.costAnalysis(currentMonth),
|
||||
})
|
||||
|
||||
const { data: complianceScore } = useQuery<any>({
|
||||
@@ -82,17 +76,17 @@ export default function Dashboard() {
|
||||
})
|
||||
|
||||
const resolveMutation = useMutation({
|
||||
mutationFn: (id: string) => api.patch(`/dashboard/todos/${id}/resolve`),
|
||||
mutationFn: (id: string) => apiPatch(`/dashboard/todos/${id}/resolve`),
|
||||
onSuccess: () => queryClient.invalidateQueries({ queryKey: ['dashboard'] }),
|
||||
})
|
||||
|
||||
const ignoreMutation = useMutation({
|
||||
mutationFn: (id: string) => api.patch(`/dashboard/todos/${id}/ignore`),
|
||||
mutationFn: (id: string) => apiPatch(`/dashboard/todos/${id}/ignore`),
|
||||
onSuccess: () => queryClient.invalidateQueries({ queryKey: ['dashboard'] }),
|
||||
})
|
||||
|
||||
const batchResolveMutation = useMutation({
|
||||
mutationFn: (ids: string[]) => api.patch('/dashboard/todos/batch-resolve', { ids }),
|
||||
mutationFn: (ids: string[]) => apiPatch('/dashboard/todos/batch-resolve', { ids }),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['dashboard'] })
|
||||
setSelectedIds(new Set())
|
||||
@@ -100,7 +94,7 @@ export default function Dashboard() {
|
||||
})
|
||||
|
||||
const batchIgnoreMutation = useMutation({
|
||||
mutationFn: (ids: string[]) => api.patch('/dashboard/todos/batch-ignore', { ids }),
|
||||
mutationFn: (ids: string[]) => apiPatch('/dashboard/todos/batch-ignore', { ids }),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['dashboard'] })
|
||||
setSelectedIds(new Set())
|
||||
@@ -1066,7 +1060,7 @@ export default function Dashboard() {
|
||||
<div className="flex items-center gap-1">
|
||||
<button
|
||||
onClick={() => {
|
||||
api.post('/work-processes', {
|
||||
workProcessApi.create({
|
||||
type: 'RENEW',
|
||||
title: `合同续签-${c.employeeName}`,
|
||||
employeeId: c.employeeId,
|
||||
@@ -1075,7 +1069,7 @@ export default function Dashboard() {
|
||||
}).then(() => {
|
||||
toast.success(`已创建 ${c.employeeName} 的续签流程`)
|
||||
setShowExpiringModal(false)
|
||||
}).catch((err) => {
|
||||
}).catch((err: any) => {
|
||||
toast.error(err?.response?.data?.error?.message || '创建失败')
|
||||
})
|
||||
}}
|
||||
@@ -1085,7 +1079,7 @@ export default function Dashboard() {
|
||||
</button>
|
||||
<button
|
||||
onClick={() => {
|
||||
api.post('/work-processes', {
|
||||
workProcessApi.create({
|
||||
type: 'TERMINATE',
|
||||
title: `合同终止-${c.employeeName}`,
|
||||
employeeId: c.employeeId,
|
||||
@@ -1094,7 +1088,7 @@ export default function Dashboard() {
|
||||
}).then(() => {
|
||||
toast.success(`已创建 ${c.employeeName} 的终止流程`)
|
||||
setShowExpiringModal(false)
|
||||
}).catch((err) => {
|
||||
}).catch((err: any) => {
|
||||
toast.error(err?.response?.data?.error?.message || '创建失败')
|
||||
})
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user