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 { FileText, Copy, X, ChevronRight, Download, BookOpen, HelpCircle, Plus, Edit, Trash2, Building2 } from 'lucide-react'
|
||||
import { toast } from 'sonner'
|
||||
import api from '../lib/api'
|
||||
import { templatesApi } from '../lib/api-services'
|
||||
import { useAuthStore } from '../store/authStore'
|
||||
import Card from '../components/ui/Card'
|
||||
import Button from '../components/ui/Button'
|
||||
@@ -110,17 +110,14 @@ function SystemTemplates() {
|
||||
const { data: list, isLoading } = useQuery<any>({
|
||||
queryKey: ['templates', category],
|
||||
queryFn: async () => {
|
||||
const params = category ? `?category=${category}` : ''
|
||||
const res = await api.get(`/templates${params}`) as any
|
||||
return res.data
|
||||
return await templatesApi.list(category || undefined)
|
||||
},
|
||||
})
|
||||
|
||||
const { data: detail } = useQuery<any>({
|
||||
queryKey: ['template-detail', selected?.id],
|
||||
queryFn: async () => {
|
||||
const res = await api.get(`/templates/${selected.id}`) as any
|
||||
return res.data
|
||||
return await templatesApi.detail(selected.id)
|
||||
},
|
||||
enabled: !!selected,
|
||||
})
|
||||
@@ -128,8 +125,8 @@ function SystemTemplates() {
|
||||
const handleRender = async () => {
|
||||
if (!selected) return
|
||||
try {
|
||||
const res = await api.post(`/templates/${selected.id}/render`, { variables }) as any
|
||||
setRendered(res.data.content)
|
||||
const res = await templatesApi.render(selected.id, variables) as any
|
||||
setRendered(res.content)
|
||||
} catch (err: any) {
|
||||
toast.error('渲染失败')
|
||||
}
|
||||
@@ -318,8 +315,7 @@ function EnterpriseTemplates() {
|
||||
queryFn: async () => {
|
||||
const params: any = { page, pageSize }
|
||||
if (category) params.category = category
|
||||
const res = await api.get('/enterprise-templates', { params }) as any
|
||||
return res.data
|
||||
return await templatesApi.enterpriseList({ page, pageSize, category: category || undefined } as any)
|
||||
},
|
||||
})
|
||||
const list = listData?.items || []
|
||||
@@ -328,8 +324,7 @@ function EnterpriseTemplates() {
|
||||
const { data: detail } = useQuery<any>({
|
||||
queryKey: ['enterprise-template-detail', selected?.id],
|
||||
queryFn: async () => {
|
||||
const res = await api.get(`/enterprise-templates/${selected.id}`) as any
|
||||
return res.data
|
||||
return await templatesApi.enterpriseDetail(selected.id)
|
||||
},
|
||||
enabled: !!selected,
|
||||
})
|
||||
@@ -337,11 +332,9 @@ function EnterpriseTemplates() {
|
||||
const saveMutation = useMutation({
|
||||
mutationFn: async (data: any) => {
|
||||
if (editItem) {
|
||||
const res = await api.put(`/enterprise-templates/${editItem.id}`, data) as any
|
||||
return res.data
|
||||
return await templatesApi.saveEnterprise(data, editItem.id)
|
||||
} else {
|
||||
const res = await api.post('/enterprise-templates', data) as any
|
||||
return res.data
|
||||
return await templatesApi.saveEnterprise(data)
|
||||
}
|
||||
},
|
||||
onSuccess: () => {
|
||||
@@ -356,7 +349,7 @@ function EnterpriseTemplates() {
|
||||
|
||||
const deleteMutation = useMutation({
|
||||
mutationFn: async (id: string) => {
|
||||
await api.delete(`/enterprise-templates/${id}`)
|
||||
await templatesApi.removeEnterprise(id)
|
||||
},
|
||||
onSuccess: () => {
|
||||
toast.success('已删除')
|
||||
@@ -368,8 +361,8 @@ function EnterpriseTemplates() {
|
||||
const handleRender = async () => {
|
||||
if (!selected) return
|
||||
try {
|
||||
const res = await api.post(`/enterprise-templates/${selected.id}/render`, { variables }) as any
|
||||
setRendered(res.data.content)
|
||||
const res = await templatesApi.renderEnterprise(selected.id, variables) as any
|
||||
setRendered(res.content)
|
||||
} catch {
|
||||
toast.error('渲染失败')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user