fix: 培训/绩效/违纪列表页CRUD改用api实例(修复401鉴权失败)
This commit is contained in:
@@ -4,6 +4,7 @@ import { Link } from 'react-router-dom'
|
||||
import { Search, Plus, Edit2, Trash2, X } from 'lucide-react'
|
||||
import { toast } from 'sonner'
|
||||
import { rosterApi, employeeApi } from '../../lib/api-services'
|
||||
import api from '../../lib/api'
|
||||
import { usePageSize } from '../../hooks/usePageSize'
|
||||
import { Input, Label, Select } from '../../components/ui/Input'
|
||||
import Button from '../../components/ui/Button'
|
||||
@@ -43,14 +44,10 @@ export default function DisciplinaryRecords() {
|
||||
const isEdit = !!data.recordId
|
||||
const recordId = data.recordId
|
||||
delete data.recordId
|
||||
const url = isEdit
|
||||
? `/api/v1/roster/${empId}/disciplinary/${recordId}`
|
||||
: `/api/v1/roster/${empId}/disciplinary`
|
||||
return fetch(url, {
|
||||
method: isEdit ? 'PUT' : 'POST',
|
||||
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${localStorage.getItem('token')}` },
|
||||
body: JSON.stringify(data),
|
||||
}).then(r => r.json())
|
||||
if (isEdit) {
|
||||
return api.put(`/roster/${empId}/disciplinary/${recordId}`, data)
|
||||
}
|
||||
return api.post(`/roster/${empId}/disciplinary`, data)
|
||||
},
|
||||
onSuccess: () => {
|
||||
toast.success('违纪记录已保存')
|
||||
@@ -63,10 +60,7 @@ export default function DisciplinaryRecords() {
|
||||
|
||||
const deleteMut = useMutation({
|
||||
mutationFn: ({ employeeId, recordId }: { employeeId: string; recordId: string }) =>
|
||||
fetch(`/api/v1/roster/${employeeId}/disciplinary/${recordId}`, {
|
||||
method: 'DELETE',
|
||||
headers: { 'Authorization': `Bearer ${localStorage.getItem('token')}` },
|
||||
}).then(r => r.json()),
|
||||
api.delete(`/roster/${employeeId}/disciplinary/${recordId}`),
|
||||
onSuccess: () => {
|
||||
toast.success('记录已删除')
|
||||
queryClient.invalidateQueries({ queryKey: ['disciplinary-list'] })
|
||||
|
||||
@@ -4,6 +4,7 @@ import { Link } from 'react-router-dom'
|
||||
import { Search, Plus, Edit2, Trash2, X } from 'lucide-react'
|
||||
import { toast } from 'sonner'
|
||||
import { rosterApi, employeeApi } from '../../lib/api-services'
|
||||
import api from '../../lib/api'
|
||||
import { usePageSize } from '../../hooks/usePageSize'
|
||||
import { Input, Label, Select } from '../../components/ui/Input'
|
||||
import Button from '../../components/ui/Button'
|
||||
@@ -36,14 +37,10 @@ export default function PerformanceRecords() {
|
||||
const isEdit = !!data.recordId
|
||||
const recordId = data.recordId
|
||||
delete data.recordId
|
||||
const url = isEdit
|
||||
? `/api/v1/roster/${empId}/performance/${recordId}`
|
||||
: `/api/v1/roster/${empId}/performance`
|
||||
return fetch(url, {
|
||||
method: isEdit ? 'PUT' : 'POST',
|
||||
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${localStorage.getItem('token')}` },
|
||||
body: JSON.stringify(data),
|
||||
}).then(r => r.json())
|
||||
if (isEdit) {
|
||||
return api.put(`/roster/${empId}/performance/${recordId}`, data)
|
||||
}
|
||||
return api.post(`/roster/${empId}/performance`, data)
|
||||
},
|
||||
onSuccess: () => {
|
||||
toast.success('绩效记录已保存')
|
||||
@@ -56,10 +53,7 @@ export default function PerformanceRecords() {
|
||||
|
||||
const deleteMut = useMutation({
|
||||
mutationFn: ({ employeeId, recordId }: { employeeId: string; recordId: string }) =>
|
||||
fetch(`/api/v1/roster/${employeeId}/performance/${recordId}`, {
|
||||
method: 'DELETE',
|
||||
headers: { 'Authorization': `Bearer ${localStorage.getItem('token')}` },
|
||||
}).then(r => r.json()),
|
||||
api.delete(`/roster/${employeeId}/performance/${recordId}`),
|
||||
onSuccess: () => {
|
||||
toast.success('记录已删除')
|
||||
queryClient.invalidateQueries({ queryKey: ['performance-list'] })
|
||||
|
||||
@@ -4,6 +4,7 @@ import { Link } from 'react-router-dom'
|
||||
import { Search, Plus, Edit2, Trash2, X } from 'lucide-react'
|
||||
import { toast } from 'sonner'
|
||||
import { rosterApi, employeeApi } from '../../lib/api-services'
|
||||
import api from '../../lib/api'
|
||||
import { usePageSize } from '../../hooks/usePageSize'
|
||||
import { Input, Label, Select } from '../../components/ui/Input'
|
||||
import Button from '../../components/ui/Button'
|
||||
@@ -38,11 +39,7 @@ export default function TrainingRecords() {
|
||||
mutationFn: (data: any) => {
|
||||
const empId = data.employeeId
|
||||
delete data.employeeId
|
||||
return fetch(`/api/v1/roster/${empId}/training`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${localStorage.getItem('token')}` },
|
||||
body: JSON.stringify(data),
|
||||
}).then(r => r.json())
|
||||
return api.post(`/roster/${empId}/training`, data)
|
||||
},
|
||||
onSuccess: () => {
|
||||
toast.success('培训记录已添加')
|
||||
@@ -58,11 +55,7 @@ export default function TrainingRecords() {
|
||||
const recordId = data.recordId
|
||||
delete data.employeeId
|
||||
delete data.recordId
|
||||
return fetch(`/api/v1/roster/${empId}/training/${recordId}`, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${localStorage.getItem('token')}` },
|
||||
body: JSON.stringify(data),
|
||||
}).then(r => r.json())
|
||||
return api.put(`/roster/${empId}/training/${recordId}`, data)
|
||||
},
|
||||
onSuccess: () => {
|
||||
toast.success('培训记录已更新')
|
||||
@@ -74,10 +67,7 @@ export default function TrainingRecords() {
|
||||
|
||||
const deleteMut = useMutation({
|
||||
mutationFn: ({ employeeId, recordId }: { employeeId: string; recordId: string }) =>
|
||||
fetch(`/api/v1/roster/${employeeId}/training/${recordId}`, {
|
||||
method: 'DELETE',
|
||||
headers: { 'Authorization': `Bearer ${localStorage.getItem('token')}` },
|
||||
}).then(r => r.json()),
|
||||
api.delete(`/roster/${employeeId}/training/${recordId}`),
|
||||
onSuccess: () => {
|
||||
toast.success('记录已删除')
|
||||
queryClient.invalidateQueries({ queryKey: ['training-list'] })
|
||||
|
||||
Reference in New Issue
Block a user