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:
@@ -2,7 +2,7 @@ import { useState } from 'react'
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { toast } from 'sonner'
|
||||
import { FileText, Plus, ChevronRight, CheckCircle, Clock, X } from 'lucide-react'
|
||||
import api from '../lib/api'
|
||||
import { policiesApi } from '../lib/api-services'
|
||||
import Card from '../components/ui/Card'
|
||||
import Button from '../components/ui/Button'
|
||||
import EmptyState from '../components/ui/EmptyState'
|
||||
@@ -30,21 +30,20 @@ export default function Policies() {
|
||||
const { data: listData, isLoading } = useQuery<any>({
|
||||
queryKey: ['policies', page, pageSize],
|
||||
queryFn: async () => {
|
||||
const res = await api.get('/policies', { params: { page, pageSize } }) as any
|
||||
return res.data
|
||||
return await policiesApi.list({ page, pageSize })
|
||||
},
|
||||
})
|
||||
const list = listData?.items || []
|
||||
const total = listData?.total || 0
|
||||
|
||||
const advanceMutation = useMutation({
|
||||
mutationFn: ({ id, step, note }: { id: string; step: number; note?: string }) => api.post(`/policies/${id}/advance-step`, { step, note }),
|
||||
mutationFn: ({ id, step, note }: { id: string; step: number; note?: string }) => policiesApi.advanceStep(id, step, note),
|
||||
onSuccess: () => {
|
||||
toast.success('流程步骤已推进')
|
||||
queryClient.invalidateQueries({ queryKey: ['policies'] })
|
||||
// 刷新选中制度详情
|
||||
if (selectedPolicy) {
|
||||
api.get(`/policies/${selectedPolicy.id}`).then((res: any) => setSelectedPolicy(res.data))
|
||||
policiesApi.detail(selectedPolicy.id).then((res: any) => setSelectedPolicy(res))
|
||||
}
|
||||
},
|
||||
onError: (err: any) => toast.error(err?.response?.data?.error?.message || '操作失败'),
|
||||
@@ -196,7 +195,7 @@ function CreatePolicyModal({ onClose, onSuccess }: { onClose: () => void; onSucc
|
||||
const [type, setType] = useState('RULES')
|
||||
|
||||
const createMutation = useMutation({
|
||||
mutationFn: () => api.post('/policies', { title, content, type }),
|
||||
mutationFn: () => policiesApi.create({ title, content, type }),
|
||||
onSuccess: () => { toast.success('制度已创建'); onSuccess() },
|
||||
onError: (err: any) => toast.error(err?.response?.data?.error?.message || '创建失败'),
|
||||
})
|
||||
@@ -243,8 +242,7 @@ function ReadStats({ policyId }: { policyId: string }) {
|
||||
const { data, isLoading } = useQuery<any>({
|
||||
queryKey: ['policy-read-stats', policyId],
|
||||
queryFn: async () => {
|
||||
const res = await api.get(`/policies/${policyId}/read-stats`) as any
|
||||
return res.data
|
||||
return await policiesApi.readStats(policyId)
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user