| 城市 | +可用IP量 | +分配IP量 | +
|---|---|---|
| {item.city} | +{formatNumber(item.count)} | +{formatNumber(item.assigned)} | +
| 城市 | +节点数量 | +Hash | +标签 | +轮换顺位 | +
|---|---|---|---|---|
| {item.city} | ++ {item.count} + | +{item.hash} | ++ + {item.label} + + | +{item.offset} | +
暂无节点数据
++ 共找到 {totalItems} 个节点 + {idThreshold > 0 && ` (ID大于${idThreshold})`} +
+| ID | +MAC地址 | +城市 | +公网IP | +运营商 | +多IP节点 | +独享IP | +设备类型 | +在线时长 | +
|---|---|---|---|---|---|---|---|---|
| {item.id} | +{item.macaddr} | +{item.city} | +{item.public} | ++ + {item.isp} + + | ++ + {formatBoolean(item.single)} + + | ++ + {formatBoolean(item.sole)} + + | ++ + {item.arch} + + | ++ {formatOnlineTime(item.online)} + | +
查询和管理网关设备的配置信息
+正在查询网关配置信息...
+| MAC地址 | +城市 | +内部账号 | +IP地址 | +内网入口 | +配置更新 | +在线状态 | +
|---|---|---|---|---|---|---|
|
+
+ {item.edge}
+
+ |
+ + + {item.city} + + | ++ {item.user} + | +
+
+ {item.public}
+
+ |
+
+
+ {item.inner_ip}
+
+ |
+ + {getStatusBadge(item.ischange, '已更新', '未更新')} + | ++ {getOnlineStatus(item.isonline)} + | +
暂无数据,请输入MAC地址查询网关配置信息
++ 您可以通过上方的搜索框查询特定MAC地址的网关配置 +
+| MAC地址 | +内网IP | +配置版本 | +状态 | +
|---|---|---|---|
| + + | +{item.inner_ip} | +{item.setid} | ++ + {getStatusText(item.enable)} + + | +
+ {JSON.stringify(results, null, 2)}
+
+ dAMQaiH zm^r3v#$Q#2T=X>bsY#D%s!bhs^M9PMAcHbCc0FMHV{u-dwlL;a1eJ63v5U*?Q_8JO zT#50!RD619#j_Uf))0ooADz~*9&lN!bBDRUgE>Vud-i5ck%vT=r^yD*^?Mp@Q^v+V zG#-?gKlr}Eeqifb{|So?HM&g91P8|av8hQoCmQXkd?7wIJw b z_^v8bbg` SAn{I*4bH$u(RZ6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FaJlhyfcw{k^vvtGl`N9xSo**rDW4S}i zM9{fMPWo%4wYDG~BZ18BD+}h|GQKc-g^{++3MY>}W_uq7jGHx{mwE9fZiPCoxN$+7 zrODGGJrOkcPQUB(FD5aoS4g~7#6NR^ma7-!>mHuJfY5kTe6PpNNKC9GGRiu^L31uG z$7v`*JknQHsYB!Tm_W{a32TM099djW%5e+j0Ve_ct}IM>XLF1Ap+YvcrLV=|CKo6S zb+ 9Nl3_YdKP6%Cxy@6TxZ>;4&nTneadr z_ES90ydCev)LV!dN=#(*f}|ZORFdvkYBni^aLbUk>BajeWIOcmHP#8S)*2U~QKI%S zyrLmtPqb&TphJ;>yAxri#;{uyk`JJqODDw%(Z=2 `1uc}br^V%>j!gS)D*q*f_-qf8&D;W1dJgQMlaH5er zN2U<%Smb7==vE}dDI8K7cKz!vs^73o9f>2sgiTzWcwY|BMYHH5%Vn7#kiw&eItCqa zIkR2~Q}>X=Ar8W|^Ms41Fm8o6IB2_j60eOeBB1Br!boW7JnoeX6Gs)?7rW0^5psc- zjS16yb>dFn>KPOF;imD}e!enuIniFzv}n$m2#gCCv4jM#ArwlzZ$7@9&XkFxZ4n!V zj3dyiwW4Ki2QG{@i>yuZXQizw_OkZI^-3otXC{!(lUpJF33gI60ak;Uqitp74|B6I zgg{b=Iz}WkhCGj1M =hu4#Aw173YxIVbISaoc z-nLZC*6Tgivd5V`K%GxhBsp@SUU60-rfc$=wb>zdJzXS&-5(NRRodFk;Kxk!S( O(a0e7oY=E( zAyS;Ow?6Q&XA+cnkCb{28_1N8H#?J!*$MmIwLq^*T_9-z^&UE@A(z9oGYtFy6EZef LrJugUA?W`A8`#=m literal 0 HcmV?d00001 diff --git a/src/app/globals.css b/src/app/globals.css new file mode 100644 index 0000000..dc98be7 --- /dev/null +++ b/src/app/globals.css @@ -0,0 +1,122 @@ +@import "tailwindcss"; +@import "tw-animate-css"; + +@custom-variant dark (&:is(.dark *)); + +@theme inline { + --color-background: var(--background); + --color-foreground: var(--foreground); + --font-sans: var(--font-geist-sans); + --font-mono: var(--font-geist-mono); + --color-sidebar-ring: var(--sidebar-ring); + --color-sidebar-border: var(--sidebar-border); + --color-sidebar-accent-foreground: var(--sidebar-accent-foreground); + --color-sidebar-accent: var(--sidebar-accent); + --color-sidebar-primary-foreground: var(--sidebar-primary-foreground); + --color-sidebar-primary: var(--sidebar-primary); + --color-sidebar-foreground: var(--sidebar-foreground); + --color-sidebar: var(--sidebar); + --color-chart-5: var(--chart-5); + --color-chart-4: var(--chart-4); + --color-chart-3: var(--chart-3); + --color-chart-2: var(--chart-2); + --color-chart-1: var(--chart-1); + --color-ring: var(--ring); + --color-input: var(--input); + --color-border: var(--border); + --color-destructive: var(--destructive); + --color-accent-foreground: var(--accent-foreground); + --color-accent: var(--accent); + --color-muted-foreground: var(--muted-foreground); + --color-muted: var(--muted); + --color-secondary-foreground: var(--secondary-foreground); + --color-secondary: var(--secondary); + --color-primary-foreground: var(--primary-foreground); + --color-primary: var(--primary); + --color-popover-foreground: var(--popover-foreground); + --color-popover: var(--popover); + --color-card-foreground: var(--card-foreground); + --color-card: var(--card); + --radius-sm: calc(var(--radius) - 4px); + --radius-md: calc(var(--radius) - 2px); + --radius-lg: var(--radius); + --radius-xl: calc(var(--radius) + 4px); +} + +:root { + --radius: 0.625rem; + --background: oklch(1 0 0); + --foreground: oklch(0.145 0 0); + --card: oklch(1 0 0); + --card-foreground: oklch(0.145 0 0); + --popover: oklch(1 0 0); + --popover-foreground: oklch(0.145 0 0); + --primary: oklch(0.205 0 0); + --primary-foreground: oklch(0.985 0 0); + --secondary: oklch(0.97 0 0); + --secondary-foreground: oklch(0.205 0 0); + --muted: oklch(0.97 0 0); + --muted-foreground: oklch(0.556 0 0); + --accent: oklch(0.97 0 0); + --accent-foreground: oklch(0.205 0 0); + --destructive: oklch(0.577 0.245 27.325); + --border: oklch(0.922 0 0); + --input: oklch(0.922 0 0); + --ring: oklch(0.708 0 0); + --chart-1: oklch(0.646 0.222 41.116); + --chart-2: oklch(0.6 0.118 184.704); + --chart-3: oklch(0.398 0.07 227.392); + --chart-4: oklch(0.828 0.189 84.429); + --chart-5: oklch(0.769 0.188 70.08); + --sidebar: oklch(0.985 0 0); + --sidebar-foreground: oklch(0.145 0 0); + --sidebar-primary: oklch(0.205 0 0); + --sidebar-primary-foreground: oklch(0.985 0 0); + --sidebar-accent: oklch(0.97 0 0); + --sidebar-accent-foreground: oklch(0.205 0 0); + --sidebar-border: oklch(0.922 0 0); + --sidebar-ring: oklch(0.708 0 0); +} + +.dark { + --background: oklch(0.145 0 0); + --foreground: oklch(0.985 0 0); + --card: oklch(0.205 0 0); + --card-foreground: oklch(0.985 0 0); + --popover: oklch(0.205 0 0); + --popover-foreground: oklch(0.985 0 0); + --primary: oklch(0.922 0 0); + --primary-foreground: oklch(0.205 0 0); + --secondary: oklch(0.269 0 0); + --secondary-foreground: oklch(0.985 0 0); + --muted: oklch(0.269 0 0); + --muted-foreground: oklch(0.708 0 0); + --accent: oklch(0.269 0 0); + --accent-foreground: oklch(0.985 0 0); + --destructive: oklch(0.704 0.191 22.216); + --border: oklch(1 0 0 / 10%); + --input: oklch(1 0 0 / 15%); + --ring: oklch(0.556 0 0); + --chart-1: oklch(0.488 0.243 264.376); + --chart-2: oklch(0.696 0.17 162.48); + --chart-3: oklch(0.769 0.188 70.08); + --chart-4: oklch(0.627 0.265 303.9); + --chart-5: oklch(0.645 0.246 16.439); + --sidebar: oklch(0.205 0 0); + --sidebar-foreground: oklch(0.985 0 0); + --sidebar-primary: oklch(0.488 0.243 264.376); + --sidebar-primary-foreground: oklch(0.985 0 0); + --sidebar-accent: oklch(0.269 0 0); + --sidebar-accent-foreground: oklch(0.985 0 0); + --sidebar-border: oklch(1 0 0 / 10%); + --sidebar-ring: oklch(0.556 0 0); +} + +@layer base { + * { + @apply border-border outline-ring/50; + } + body { + @apply bg-background text-foreground; + } +} diff --git a/src/app/layout.tsx b/src/app/layout.tsx new file mode 100644 index 0000000..8f7d774 --- /dev/null +++ b/src/app/layout.tsx @@ -0,0 +1,39 @@ +import type { Metadata } from "next"; +import { Geist, Geist_Mono } from "next/font/google"; +import "./globals.css"; +import { Toaster } from "sonner"; +import { SessionProvider } from "next-auth/react"; + +const geistSans = Geist({ + variable: "--font-geist-sans", + subsets: ["latin"], +}); + +const geistMono = Geist_Mono({ + variable: "--font-geist-mono", + subsets: ["latin"], +}); + +export const metadata: Metadata = { + title: "Create Next App", + description: "Generated by create next app", +}; + +export default function RootLayout({ + children, +}: Readonly<{ + children: React.ReactNode; +}>) { + return ( + + + + {children} + + + + ); +} diff --git a/src/app/page.tsx b/src/app/page.tsx new file mode 100644 index 0000000..e12f9e5 --- /dev/null +++ b/src/app/page.tsx @@ -0,0 +1,13 @@ +import { PrismaClient } from '@prisma/client' + +export default async function Home() { + const prisma = new PrismaClient() + const data = await prisma.change.findMany({ take: 10 }) + + return ( ++ ++ ) +} \ No newline at end of file diff --git a/src/app/test.ts b/src/app/test.ts new file mode 100644 index 0000000..3ec0468 --- /dev/null +++ b/src/app/test.ts @@ -0,0 +1,20 @@ +import { PrismaClient } from '@prisma/client' + +const prisma = new PrismaClient() + +async function main() { + try { + // 测试查询 + const changes = await prisma.change.findMany({ + take: 5 + }) + console.log('✅ 数据库连接成功!') + console.log('获取到的数据:', changes) + } catch (error) { + console.error('❌ 连接失败:', error) + } finally { + await prisma.$disconnect() + } +} + +main() \ No newline at end of file diff --git a/src/components/ui/alert.tsx b/src/components/ui/alert.tsx new file mode 100644 index 0000000..1421354 --- /dev/null +++ b/src/components/ui/alert.tsx @@ -0,0 +1,66 @@ +import * as React from "react" +import { cva, type VariantProps } from "class-variance-authority" + +import { cn } from "@/lib/utils" + +const alertVariants = cva( + "relative w-full rounded-lg border px-4 py-3 text-sm grid has-[>svg]:grid-cols-[calc(var(--spacing)*4)_1fr] grid-cols-[0_1fr] has-[>svg]:gap-x-3 gap-y-0.5 items-start [&>svg]:size-4 [&>svg]:translate-y-0.5 [&>svg]:text-current", + { + variants: { + variant: { + default: "bg-card text-card-foreground", + destructive: + "text-destructive bg-card [&>svg]:text-current *:data-[slot=alert-description]:text-destructive/90", + }, + }, + defaultVariants: { + variant: "default", + }, + } +) + +function Alert({ + className, + variant, + ...props +}: React.ComponentProps<"div"> & VariantProps数据库连接成功!
+{JSON.stringify(data, null, 2)}+) { + return ( + + ) +} + +function AlertTitle({ className, ...props }: React.ComponentProps<"div">) { + return ( + + ) +} + +function AlertDescription({ + className, + ...props +}: React.ComponentProps<"div">) { + return ( + + ) +} + +export { Alert, AlertTitle, AlertDescription } diff --git a/src/components/ui/badge.tsx b/src/components/ui/badge.tsx new file mode 100644 index 0000000..0205413 --- /dev/null +++ b/src/components/ui/badge.tsx @@ -0,0 +1,46 @@ +import * as React from "react" +import { Slot } from "@radix-ui/react-slot" +import { cva, type VariantProps } from "class-variance-authority" + +import { cn } from "@/lib/utils" + +const badgeVariants = cva( + "inline-flex items-center justify-center rounded-md border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden", + { + variants: { + variant: { + default: + "border-transparent bg-primary text-primary-foreground [a&]:hover:bg-primary/90", + secondary: + "border-transparent bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90", + destructive: + "border-transparent bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60", + outline: + "text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground", + }, + }, + defaultVariants: { + variant: "default", + }, + } +) + +function Badge({ + className, + variant, + asChild = false, + ...props +}: React.ComponentProps<"span"> & + VariantProps & { asChild?: boolean }) { + const Comp = asChild ? Slot : "span" + + return ( + + ) +} + +export { Badge, badgeVariants } diff --git a/src/components/ui/button.tsx b/src/components/ui/button.tsx new file mode 100644 index 0000000..a2df8dc --- /dev/null +++ b/src/components/ui/button.tsx @@ -0,0 +1,59 @@ +import * as React from "react" +import { Slot } from "@radix-ui/react-slot" +import { cva, type VariantProps } from "class-variance-authority" + +import { cn } from "@/lib/utils" + +const buttonVariants = cva( + "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive", + { + variants: { + variant: { + default: + "bg-primary text-primary-foreground shadow-xs hover:bg-primary/90", + destructive: + "bg-destructive text-white shadow-xs hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60", + outline: + "border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50", + secondary: + "bg-secondary text-secondary-foreground shadow-xs hover:bg-secondary/80", + ghost: + "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50", + link: "text-primary underline-offset-4 hover:underline", + }, + size: { + default: "h-9 px-4 py-2 has-[>svg]:px-3", + sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5", + lg: "h-10 rounded-md px-6 has-[>svg]:px-4", + icon: "size-9", + }, + }, + defaultVariants: { + variant: "default", + size: "default", + }, + } +) + +function Button({ + className, + variant, + size, + asChild = false, + ...props +}: React.ComponentProps<"button"> & + VariantProps & { + asChild?: boolean + }) { + const Comp = asChild ? Slot : "button" + + return ( + + ) +} + +export { Button, buttonVariants } diff --git a/src/components/ui/card.tsx b/src/components/ui/card.tsx new file mode 100644 index 0000000..d05bbc6 --- /dev/null +++ b/src/components/ui/card.tsx @@ -0,0 +1,92 @@ +import * as React from "react" + +import { cn } from "@/lib/utils" + +function Card({ className, ...props }: React.ComponentProps<"div">) { + return ( + + ) +} + +function CardHeader({ className, ...props }: React.ComponentProps<"div">) { + return ( + + ) +} + +function CardTitle({ className, ...props }: React.ComponentProps<"div">) { + return ( + + ) +} + +function CardDescription({ className, ...props }: React.ComponentProps<"div">) { + return ( + + ) +} + +function CardAction({ className, ...props }: React.ComponentProps<"div">) { + return ( + + ) +} + +function CardContent({ className, ...props }: React.ComponentProps<"div">) { + return ( + + ) +} + +function CardFooter({ className, ...props }: React.ComponentProps<"div">) { + return ( + + ) +} + +export { + Card, + CardHeader, + CardFooter, + CardTitle, + CardAction, + CardDescription, + CardContent, +} diff --git a/src/components/ui/errorCard.tsx b/src/components/ui/errorCard.tsx new file mode 100644 index 0000000..9e0a489 --- /dev/null +++ b/src/components/ui/errorCard.tsx @@ -0,0 +1,22 @@ +export default function ErrorCard({ + title, + error, + onRetry +}: { + title: string + error: string + onRetry: () => void +}) { + return ( + ++ ) +} \ No newline at end of file diff --git a/src/components/ui/form.tsx b/src/components/ui/form.tsx new file mode 100644 index 0000000..524b986 --- /dev/null +++ b/src/components/ui/form.tsx @@ -0,0 +1,167 @@ +"use client" + +import * as React from "react" +import * as LabelPrimitive from "@radix-ui/react-label" +import { Slot } from "@radix-ui/react-slot" +import { + Controller, + FormProvider, + useFormContext, + useFormState, + type ControllerProps, + type FieldPath, + type FieldValues, +} from "react-hook-form" + +import { cn } from "@/lib/utils" +import { Label } from "@/components/ui/label" + +const Form = FormProvider + +type FormFieldContextValue< + TFieldValues extends FieldValues = FieldValues, + TName extends FieldPath{title}
+加载失败: {error}
+ += FieldPath , +> = { + name: TName +} + +const FormFieldContext = React.createContext ( + {} as FormFieldContextValue +) + +const FormField = < + TFieldValues extends FieldValues = FieldValues, + TName extends FieldPath = FieldPath , +>({ + ...props +}: ControllerProps ) => { + return ( + + + ) +} + +const useFormField = () => { + const fieldContext = React.useContext(FormFieldContext) + const itemContext = React.useContext(FormItemContext) + const { getFieldState } = useFormContext() + const formState = useFormState({ name: fieldContext.name }) + const fieldState = getFieldState(fieldContext.name, formState) + + if (!fieldContext) { + throw new Error("useFormField should be used within+ ") + } + + const { id } = itemContext + + return { + id, + name: fieldContext.name, + formItemId: `${id}-form-item`, + formDescriptionId: `${id}-form-item-description`, + formMessageId: `${id}-form-item-message`, + ...fieldState, + } +} + +type FormItemContextValue = { + id: string +} + +const FormItemContext = React.createContext ( + {} as FormItemContextValue +) + +function FormItem({ className, ...props }: React.ComponentProps<"div">) { + const id = React.useId() + + return ( + + + + ) +} + +function FormLabel({ + className, + ...props +}: React.ComponentProps) { + const { error, formItemId } = useFormField() + + return ( + + ) +} + +function FormControl({ ...props }: React.ComponentProps ) { + const { error, formItemId, formDescriptionId, formMessageId } = useFormField() + + return ( + + ) +} + +function FormDescription({ className, ...props }: React.ComponentProps<"p">) { + const { formDescriptionId } = useFormField() + + return ( + + ) +} + +function FormMessage({ className, ...props }: React.ComponentProps<"p">) { + const { error, formMessageId } = useFormField() + const body = error ? String(error?.message ?? "") : props.children + + if (!body) { + return null + } + + return ( + + {body} +
+ ) +} + +export { + useFormField, + Form, + FormItem, + FormLabel, + FormControl, + FormDescription, + FormMessage, + FormField, +} diff --git a/src/components/ui/input.tsx b/src/components/ui/input.tsx new file mode 100644 index 0000000..03295ca --- /dev/null +++ b/src/components/ui/input.tsx @@ -0,0 +1,21 @@ +import * as React from "react" + +import { cn } from "@/lib/utils" + +function Input({ className, type, ...props }: React.ComponentProps<"input">) { + return ( + + ) +} + +export { Input } diff --git a/src/components/ui/label.tsx b/src/components/ui/label.tsx new file mode 100644 index 0000000..fb5fbc3 --- /dev/null +++ b/src/components/ui/label.tsx @@ -0,0 +1,24 @@ +"use client" + +import * as React from "react" +import * as LabelPrimitive from "@radix-ui/react-label" + +import { cn } from "@/lib/utils" + +function Label({ + className, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +export { Label } diff --git a/src/components/ui/loadingCard.tsx b/src/components/ui/loadingCard.tsx new file mode 100644 index 0000000..b89198d --- /dev/null +++ b/src/components/ui/loadingCard.tsx @@ -0,0 +1,14 @@ +export default function LoadingCard({ title }: { title: string }) { + return ( + ++ ) +} \ No newline at end of file diff --git a/src/components/ui/pagination.tsx b/src/components/ui/pagination.tsx new file mode 100644 index 0000000..0d18541 --- /dev/null +++ b/src/components/ui/pagination.tsx @@ -0,0 +1,127 @@ +import * as React from "react" +import { + ChevronLeftIcon, + ChevronRightIcon, + MoreHorizontalIcon, +} from "lucide-react" + +import { cn } from "@/lib/utils" +import { Button, buttonVariants } from "@/components/ui/button" + +function Pagination({ className, ...props }: React.ComponentProps<"nav">) { + return ( + + ) +} + +function PaginationContent({ + className, + ...props +}: React.ComponentProps<"ul">) { + return ( ++ +++ + + +++ ) +} + +function PaginationItem({ ...props }: React.ComponentProps<"li">) { + return +} + +type PaginationLinkProps = { + isActive?: boolean +} & Pick
, "size"> & + React.ComponentProps<"a"> + +function PaginationLink({ + className, + isActive, + size = "icon", + ...props +}: PaginationLinkProps) { + return ( + + ) +} + +function PaginationPrevious({ + className, + ...props +}: React.ComponentProps ) { + return ( + + + ) +} + +function PaginationNext({ + className, + ...props +}: React.ComponentProps+ Previous + ) { + return ( + + Next + + ) +} + +function PaginationEllipsis({ + className, + ...props +}: React.ComponentProps<"span">) { + return ( + ++ + More pages + + ) +} + +export { + Pagination, + PaginationContent, + PaginationLink, + PaginationItem, + PaginationPrevious, + PaginationNext, + PaginationEllipsis, +} diff --git a/src/components/ui/select.tsx b/src/components/ui/select.tsx new file mode 100644 index 0000000..dcbbc0c --- /dev/null +++ b/src/components/ui/select.tsx @@ -0,0 +1,185 @@ +"use client" + +import * as React from "react" +import * as SelectPrimitive from "@radix-ui/react-select" +import { CheckIcon, ChevronDownIcon, ChevronUpIcon } from "lucide-react" + +import { cn } from "@/lib/utils" + +function Select({ + ...props +}: React.ComponentProps ) { + return +} + +function SelectGroup({ + ...props +}: React.ComponentProps ) { + return +} + +function SelectValue({ + ...props +}: React.ComponentProps ) { + return +} + +function SelectTrigger({ + className, + size = "default", + children, + ...props +}: React.ComponentProps & { + size?: "sm" | "default" +}) { + return ( + + {children} + + ) +} + +function SelectContent({ + className, + children, + position = "popper", + ...props +}: React.ComponentProps+ ++ ) { + return ( + + + ) +} + +function SelectLabel({ + className, + ...props +}: React.ComponentProps+ ++ + {children} + ++ ) { + return ( + + ) +} + +function SelectItem({ + className, + children, + ...props +}: React.ComponentProps ) { + return ( + + + + ) +} + +function SelectSeparator({ + className, + ...props +}: React.ComponentProps+ + ++ {children} +) { + return ( + + ) +} + +function SelectScrollUpButton({ + className, + ...props +}: React.ComponentProps ) { + return ( + + + ) +} + +function SelectScrollDownButton({ + className, + ...props +}: React.ComponentProps+ ) { + return ( + + + ) +} + +export { + Select, + SelectContent, + SelectGroup, + SelectItem, + SelectLabel, + SelectScrollDownButton, + SelectScrollUpButton, + SelectSeparator, + SelectTrigger, + SelectValue, +} diff --git a/src/components/ui/skeleton.tsx b/src/components/ui/skeleton.tsx new file mode 100644 index 0000000..32ea0ef --- /dev/null +++ b/src/components/ui/skeleton.tsx @@ -0,0 +1,13 @@ +import { cn } from "@/lib/utils" + +function Skeleton({ className, ...props }: React.ComponentProps<"div">) { + return ( + + ) +} + +export { Skeleton } diff --git a/src/components/ui/sonner.tsx b/src/components/ui/sonner.tsx new file mode 100644 index 0000000..957524e --- /dev/null +++ b/src/components/ui/sonner.tsx @@ -0,0 +1,25 @@ +"use client" + +import { useTheme } from "next-themes" +import { Toaster as Sonner, ToasterProps } from "sonner" + +const Toaster = ({ ...props }: ToasterProps) => { + const { theme = "system" } = useTheme() + + return ( ++ + ) +} + +export { Toaster } diff --git a/src/components/ui/table.tsx b/src/components/ui/table.tsx new file mode 100644 index 0000000..51b74dd --- /dev/null +++ b/src/components/ui/table.tsx @@ -0,0 +1,116 @@ +"use client" + +import * as React from "react" + +import { cn } from "@/lib/utils" + +function Table({ className, ...props }: React.ComponentProps<"table">) { + return ( + ++ ) +} + +function TableHeader({ className, ...props }: React.ComponentProps<"thead">) { + return ( + + ) +} + +function TableBody({ className, ...props }: React.ComponentProps<"tbody">) { + return ( + + ) +} + +function TableFooter({ className, ...props }: React.ComponentProps<"tfoot">) { + return ( + tr]:last:border-b-0", + className + )} + {...props} + /> + ) +} + +function TableRow({ className, ...props }: React.ComponentProps<"tr">) { + return ( ++
+ ) +} + +function TableHead({ className, ...props }: React.ComponentProps<"th">) { + return ( + [role=checkbox]]:translate-y-[2px]", + className + )} + {...props} + /> + ) +} + +function TableCell({ className, ...props }: React.ComponentProps<"td">) { + return ( + [role=checkbox]]:translate-y-[2px]", + className + )} + {...props} + /> + ) +} + +function TableCaption({ + className, + ...props +}: React.ComponentProps<"caption">) { + return ( + + ) +} + +export { + Table, + TableHeader, + TableBody, + TableFooter, + TableHead, + TableRow, + TableCell, + TableCaption, +} diff --git a/src/components/ui/tabs.tsx b/src/components/ui/tabs.tsx new file mode 100644 index 0000000..497ba5e --- /dev/null +++ b/src/components/ui/tabs.tsx @@ -0,0 +1,66 @@ +"use client" + +import * as React from "react" +import * as TabsPrimitive from "@radix-ui/react-tabs" + +import { cn } from "@/lib/utils" + +function Tabs({ + className, + ...props +}: React.ComponentProps ) { + return ( + + ) +} + +function TabsList({ + className, + ...props +}: React.ComponentProps ) { + return ( + + ) +} + +function TabsTrigger({ + className, + ...props +}: React.ComponentProps ) { + return ( + + ) +} + +function TabsContent({ + className, + ...props +}: React.ComponentProps ) { + return ( + + ) +} + +export { Tabs, TabsList, TabsTrigger, TabsContent } diff --git a/src/lib/auth.ts b/src/lib/auth.ts new file mode 100644 index 0000000..5467339 --- /dev/null +++ b/src/lib/auth.ts @@ -0,0 +1,8 @@ +import NextAuth from "next-auth" +import { PrismaAdapter } from "@next-auth/prisma-adapter" +import { prisma } from "./prisma" + +export const { handlers, auth, signIn, signOut } = NextAuth({ + adapter: PrismaAdapter(prisma), + providers: [], +}) \ No newline at end of file diff --git a/src/lib/db.ts b/src/lib/db.ts new file mode 100644 index 0000000..6220b63 --- /dev/null +++ b/src/lib/db.ts @@ -0,0 +1,8 @@ +// import { PrismaClient } from '@prisma/client' + +// const globalForPrisma = global as { prisma?: PrismaClient } + +// export const db = globalForPrisma.prisma || new PrismaClient() + +// if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = db +export { prisma as db } from './prisma' diff --git a/src/lib/definitions.ts b/src/lib/definitions.ts new file mode 100644 index 0000000..f7e0725 --- /dev/null +++ b/src/lib/definitions.ts @@ -0,0 +1,29 @@ +import { z } from 'zod' + +export const SignupFormSchema = z.object({ + name: z + .string() + .min(2, { message: 'Name must be at least 2 characters long.' }) + .trim(), + email: z.string().email({ message: 'Please enter a valid email.' }).trim(), + password: z + .string() + .min(8, { message: 'Be at least 8 characters long' }) + .regex(/[a-zA-Z]/, { message: 'Contain at least one letter.' }) + .regex(/[0-9]/, { message: 'Contain at least one number.' }) + .regex(/[^a-zA-Z0-9]/, { + message: 'Contain at least one special character.', + }) + .trim(), +}) + +export type FormState = + | { + errors?: { + name?: string[] + email?: string[] + password?: string[] + } + message?: string + } + | undefined \ No newline at end of file diff --git a/src/lib/formatters.ts b/src/lib/formatters.ts new file mode 100644 index 0000000..9e5bc2c --- /dev/null +++ b/src/lib/formatters.ts @@ -0,0 +1,26 @@ +// 数字格式化工具函数 +export const formatNumber = (num: number | string): string => { + const numberValue = typeof num === 'string' ? parseInt(num) || 0 : num + return numberValue.toLocaleString('zh-CN') +} + +export const formatLargeNumber = (num: number | string): string => { + const numberValue = typeof num === 'string' ? parseInt(num) || 0 : num + + if (numberValue > 1e9) return `${(numberValue / 1e9).toFixed(1)}亿` + if (numberValue > 1e6) return `${(numberValue / 1e6).toFixed(1)}百万` + if (numberValue > 1e4) return `${(numberValue / 1e4).toFixed(1)}万` + if (numberValue > 1e3) return `${(numberValue / 1e3).toFixed(1)}千` + + return numberValue.toLocaleString('zh-CN') +} + +// 数据验证函数 +export const validateNumber = (value: unknown): number => { + if (typeof value === 'number') return value + if (typeof value === 'string') { + const num = parseInt(value) + return isNaN(num) ? 0 : num + } + return 0 +} \ No newline at end of file diff --git a/src/lib/prisma.ts b/src/lib/prisma.ts new file mode 100644 index 0000000..5a5e41f --- /dev/null +++ b/src/lib/prisma.ts @@ -0,0 +1,13 @@ +import { PrismaClient } from '@prisma/client' + +const globalForPrisma = global as unknown as { + prisma: PrismaClient | undefined +} + +export const prisma = globalForPrisma.prisma ?? new PrismaClient() + +if (process.env.NODE_ENV !== 'production') { + globalForPrisma.prisma = prisma +} + +export default prisma \ No newline at end of file diff --git a/src/lib/utils.ts b/src/lib/utils.ts new file mode 100644 index 0000000..bd0c391 --- /dev/null +++ b/src/lib/utils.ts @@ -0,0 +1,6 @@ +import { clsx, type ClassValue } from "clsx" +import { twMerge } from "tailwind-merge" + +export function cn(...inputs: ClassValue[]) { + return twMerge(clsx(inputs)) +} diff --git a/src/middleware.ts b/src/middleware.ts new file mode 100644 index 0000000..3ac3e08 --- /dev/null +++ b/src/middleware.ts @@ -0,0 +1,29 @@ +import { NextResponse } from 'next/server' +import type { NextRequest } from 'next/server' + +export async function middleware(request: NextRequest) { + const session = request.cookies.get('session') + console.log(session, 'sessionsessionsession'); + + // 保护的路由需要验证会话 + if (request.nextUrl.pathname.startsWith('/dashboard')) { + if (!session?.value) { + return NextResponse.redirect(new URL('/login', request.url)) + } + } + + // 已登录用户重定向 + if (session?.value && ( + request.nextUrl.pathname === '/login' || + request.nextUrl.pathname === '/register' + )) { + console.log(session, 'sessionsessionsession'); + return NextResponse.redirect(new URL('/dashboard', request.url)) + } + + return NextResponse.next() +} + +export const config = { + matcher: ['/dashboard/:path*', '/login', '/register'] +} \ No newline at end of file diff --git a/src/store/auth.ts b/src/store/auth.ts new file mode 100644 index 0000000..c322e1b --- /dev/null +++ b/src/store/auth.ts @@ -0,0 +1,19 @@ +import { create } from 'zustand' +import { persist } from 'zustand/middleware' + +interface AuthState { + isAuthenticated: boolean + setAuth: (state: boolean) => void +} + +export const useAuthStore = create ()( + persist( + (set) => ({ + isAuthenticated: false, + setAuth: (state) => set({ isAuthenticated: state }), + }), + { + name: 'auth-storage', + } + ) +) diff --git a/src/types/auth.d.ts b/src/types/auth.d.ts new file mode 100644 index 0000000..7f5d47e --- /dev/null +++ b/src/types/auth.d.ts @@ -0,0 +1,27 @@ +export interface User { + id: number + phone: string + name?: string | null + verifiedPhone: boolean +} + +export interface Session { + id: string + userId: number + expires: Date +} + +export interface LoginResponse { + success: boolean + error?: string + user?: { + id: number + phone: string + name?: string | null + } +} + +export interface RegisterResponse { + success: boolean + error?: string +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..53d5beb --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,43 @@ +{ + "compilerOptions": { + "target": "ES2017", + "lib": [ + "dom", + "dom.iterable", + "esnext" + ], + "allowJs": true, + "skipLibCheck": true, + "strict": true, + "noEmit": true, + "esModuleInterop": true, + "module": "esnext", + "moduleResolution": "bundler", + "resolveJsonModule": true, + "isolatedModules": true, + "jsx": "preserve", + "incremental": true, + "plugins": [ + { + "name": "next" + } + ], + "paths": { + "@/*": [ + "./src/*" + ], + "@/lib/*": [ + "./src/lib/*" + ] + } + }, + "include": [ + "next-env.d.ts", + "**/*.ts", + "**/*.tsx", + ".next/types/**/*.ts" + ], + "exclude": [ + "node_modules" + ] +} \ No newline at end of file