fix: support default and named exports for useDebounce hook

Ensure compatibility with both default and named exports for useDebounce.

Co-authored-by: null <4804959+fnvtk@users.noreply.github.com>
This commit is contained in:
v0
2025-08-08 11:46:31 +00:00
parent bdf456523b
commit 2ca12179e2
15 changed files with 526 additions and 368 deletions

View File

@@ -1,6 +1,6 @@
import { NextResponse, NextRequest } from "next/server"
import type { TrafficUser } from "@/types/traffic"
import { addUser, filterUsers, getDistinctTags, getUserDetail } from "@/lib/mock-users"
import { addUser, filterUsers, getDistinctTags, getUserById, queryUsers, type UserStatus } from "@/lib/mock-users"
// 中文名字生成器数据
const familyNames = [
@@ -199,44 +199,32 @@ function parseArrayParam(v: string | null) {
export async function GET(req: NextRequest) {
const { searchParams } = new URL(req.url)
const meta = searchParams.get("meta")
const id = searchParams.get("id")
if (meta === "tags") {
const tags = getDistinctTags()
return NextResponse.json({ success: true, data: { tags } })
}
// 详情优先
const id = searchParams.get('id')
if (id) {
const user = getUserDetail(id)
if (!user) return NextResponse.json({ success: false, error: "NOT_FOUND" }, { status: 404 })
return NextResponse.json({ success: true, data: user })
const detail = getUserById(id)
return NextResponse.json({ data: detail }, { headers: { 'Cache-Control': 'no-store' } })
}
const q = searchParams.get("q") || undefined
const tagsParam = searchParams.get("tags") || ""
const tags = tagsParam ? tagsParam.split(",").filter(Boolean) : []
const statusParam = searchParams.get("status") || ""
const status = statusParam ? (statusParam.split(",") as any) : []
const rfmMin = Number(searchParams.get("rfmMin") ?? "0")
const rfmMax = Number(searchParams.get("rfmMax") ?? "100")
const page = Number(searchParams.get("page") ?? "1")
const pageSize = Number(searchParams.get("pageSize") ?? "20")
// 列表
const q = searchParams.get('q') ?? undefined
const tagsStr = searchParams.get('tags') ?? ''
const statusStr = searchParams.get('status') ?? ''
const rfmMin = Number(searchParams.get('rfmMin') ?? 0)
const rfmMax = Number(searchParams.get('rfmMax') ?? 100)
const page = Number(searchParams.get('page') ?? 1)
const pageSize = Number(searchParams.get('pageSize') ?? 20)
const res = filterUsers({ q, tags, status, rfmMin, rfmMax, page, pageSize })
return NextResponse.json({ success: true, data: res })
const tags = tagsStr ? tagsStr.split(',').filter(Boolean) : undefined
const status = statusStr ? (statusStr.split(',').filter(Boolean) as any) : undefined
const result = queryUsers({ q, tags, status, rfmMin, rfmMax, page, pageSize })
return NextResponse.json(result, { headers: { 'Cache-Control': 'no-store' } })
}
export async function POST(req: NextRequest) {
const body = await req.json().catch(() => null)
if (!body || !body.name || !body.phone || !body.email) {
return NextResponse.json({ success: false, error: "INVALID_PAYLOAD" }, { status: 400 })
}
const user = addUser({
name: body.name,
phone: body.phone,
email: body.email,
tags: Array.isArray(body.tags) ? body.tags.slice(0, 20) : [],
})
return NextResponse.json({ success: true, data: user })
const body = await req.json().catch(() => ({}))
const created = addUser(body ?? {})
return NextResponse.json({ data: created }, { status: 201 })
}