feat: 添加生产环境配置,重构 API 请求,更新部署脚本和配置
This commit is contained in:
@@ -9,6 +9,7 @@ import { LevelDialog } from '@/components/levels/level-dialog'
|
||||
import { Spinner } from '@/components/ui/spinner'
|
||||
import { Level, LevelFormData } from '@/types'
|
||||
import { Plus } from 'lucide-react'
|
||||
import { apiFetch } from '@/lib/api'
|
||||
|
||||
export default function LevelsPage() {
|
||||
const queryClient = useQueryClient()
|
||||
@@ -20,7 +21,7 @@ export default function LevelsPage() {
|
||||
const { data: levels, isLoading, error } = useQuery<Level[]>({
|
||||
queryKey: ['levels'],
|
||||
queryFn: async () => {
|
||||
const res = await fetch('/api/levels')
|
||||
const res = await apiFetch('/api/levels')
|
||||
if (!res.ok) throw new Error('Failed to fetch levels')
|
||||
return res.json()
|
||||
},
|
||||
@@ -29,7 +30,7 @@ export default function LevelsPage() {
|
||||
// Create level mutation
|
||||
const createMutation = useMutation({
|
||||
mutationFn: async (data: LevelFormData) => {
|
||||
const res = await fetch('/api/levels', {
|
||||
const res = await apiFetch('/api/levels', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data),
|
||||
@@ -48,7 +49,7 @@ export default function LevelsPage() {
|
||||
// Update level mutation
|
||||
const updateMutation = useMutation({
|
||||
mutationFn: async ({ id, data }: { id: string; data: LevelFormData }) => {
|
||||
const res = await fetch('/api/levels', {
|
||||
const res = await apiFetch('/api/levels', {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ id, ...data }),
|
||||
@@ -67,7 +68,7 @@ export default function LevelsPage() {
|
||||
// Delete level mutation
|
||||
const deleteMutation = useMutation({
|
||||
mutationFn: async (id: string) => {
|
||||
const res = await fetch(`/api/levels?id=${id}`, {
|
||||
const res = await apiFetch(`/api/levels?id=${id}`, {
|
||||
method: 'DELETE',
|
||||
})
|
||||
if (!res.ok) {
|
||||
@@ -85,7 +86,7 @@ export default function LevelsPage() {
|
||||
// Reorder mutation
|
||||
const reorderMutation = useMutation({
|
||||
mutationFn: async (orders: { id: string; sortOrder: number }[]) => {
|
||||
const res = await fetch('/api/levels/reorder', {
|
||||
const res = await apiFetch('/api/levels/reorder', {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ orders }),
|
||||
|
||||
Reference in New Issue
Block a user