chore: 以本地为准,上传全部并替换 GitHub

This commit is contained in:
卡若
2026-02-03 11:36:53 +08:00
parent 1219166526
commit b404bf546e
131 changed files with 37618 additions and 3930 deletions

View File

@@ -0,0 +1,77 @@
import { NextRequest, NextResponse } from "next/server"
/**
* 本地登录 API - 支持邮箱/手机号 + 密码
* 当未配置 NEXT_PUBLIC_API_BASE_URL 时使用
* 开发账号: zhiqun@qq.com / Zhiqun1984
*/
const MOCK_USERS: Record<string, { password: string }> = {
"zhiqun@qq.com": { password: "Zhiqun1984" },
}
function isEmail(value: string): boolean {
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value)
}
export async function POST(request: NextRequest) {
try {
const formData = await request.formData()
const account = (formData.get("email") || formData.get("phone") || "").toString().trim()
const password = (formData.get("password") || "").toString()
const verificationCode = formData.get("verificationCode")?.toString()
if (!account) {
return NextResponse.json(
{ code: 40001, message: "请输入邮箱或手机号" },
{ status: 200 }
)
}
// 验证码登录开发环境下任意6位验证码通过
if (verificationCode) {
if (verificationCode.length >= 4) {
const token = `mock_token_${Date.now()}_${account}`
return NextResponse.json({
code: 10000,
message: "登录成功",
data: { token },
})
}
return NextResponse.json(
{ code: 40002, message: "验证码错误" },
{ status: 200 }
)
}
// 密码登录
if (!password) {
return NextResponse.json(
{ code: 40003, message: "请输入密码" },
{ status: 200 }
)
}
const key = isEmail(account) ? account : account
const user = MOCK_USERS[key]
if (user && user.password === password) {
const token = `mock_token_${Date.now()}_${account}`
return NextResponse.json({
code: 10000,
message: "登录成功",
data: { token },
})
}
return NextResponse.json(
{ code: 40004, message: "邮箱/手机号或密码错误" },
{ status: 200 }
)
} catch (error) {
console.error("[auth/login]", error)
return NextResponse.json(
{ code: 50000, message: "服务器错误" },
{ status: 500 }
)
}
}

View File

@@ -0,0 +1,31 @@
import { NextRequest, NextResponse } from "next/server"
/**
* 本地验证码发送 API (mock)
* 开发环境下直接返回成功验证码可为任意4位以上
*/
export async function POST(request: NextRequest) {
try {
const formData = await request.formData()
const phone = (formData.get("phone") || "").toString().trim()
if (!phone) {
return NextResponse.json(
{ code: 40001, message: "请输入手机号" },
{ status: 200 }
)
}
// Mock: 模拟发送成功,开发时可用 123456 等作为验证码
return NextResponse.json({
code: 10000,
message: "验证码已发送开发模式可使用任意4位以上数字",
})
} catch (error) {
console.error("[auth/send-code]", error)
return NextResponse.json(
{ code: 50000, message: "服务器错误" },
{ status: 500 }
)
}
}