import { useState, useEffect } from "react"; import type { MetaFunction, LoaderFunction } from "@remix-run/node"; import { json } from "@remix-run/node"; import { useLoaderData } from "@remix-run/react"; import { Button, Card, Typography, Space } from "antd"; import db from "~/db.server"; const { Title, Paragraph } = Typography; export const meta: MetaFunction = () => { return [ { title: "Remix 管理系统" }, { name: "description", content: "欢迎来到 Remix 管理系统!" }, ]; }; export const loader: LoaderFunction = async () => { const userCount = await db("users").count("* as count").first(); return json({ userCount: userCount?.count || 0 }); }; export default function Index() { const { userCount } = useLoaderData(); const [currentTime, setCurrentTime] = useState(new Date()); useEffect(() => { const timer = setInterval(() => setCurrentTime(new Date()), 1000); return () => clearInterval(timer); }, []); return (
欢迎来到 Remix 管理系统 当前时间:{currentTime.toLocaleString()} 系统中共有 {userCount} 个用户
); }