_index.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { useState, useEffect } from "react";
  2. import type { MetaFunction, LoaderFunction } from "@remix-run/node";
  3. import { json } from "@remix-run/node";
  4. import { useLoaderData } from "@remix-run/react";
  5. import { Button, Card, Typography, Space } from "antd";
  6. import db from "~/db.server";
  7. const { Title, Paragraph } = Typography;
  8. export const meta: MetaFunction = () => {
  9. return [
  10. { title: "Remix 管理系统" },
  11. { name: "description", content: "欢迎来到 Remix 管理系统!" },
  12. ];
  13. };
  14. export const loader: LoaderFunction = async () => {
  15. const userCount = await db("users").count("* as count").first();
  16. return json({ userCount: userCount?.count || 0 });
  17. };
  18. export default function Index() {
  19. const { userCount } = useLoaderData<typeof loader>();
  20. const [currentTime, setCurrentTime] = useState(new Date());
  21. useEffect(() => {
  22. const timer = setInterval(() => setCurrentTime(new Date()), 1000);
  23. return () => clearInterval(timer);
  24. }, []);
  25. return (
  26. <div className="min-h-screen bg-gray-100 flex items-center justify-center">
  27. <Card className="w-full max-w-md shadow-lg">
  28. <Title level={2} className="text-center mb-6">欢迎来到 Remix 管理系统</Title>
  29. <Paragraph className="text-center mb-4">
  30. 当前时间:{currentTime.toLocaleString()}
  31. </Paragraph>
  32. <Paragraph className="text-center mb-6">
  33. 系统中共有 {userCount} 个用户
  34. </Paragraph>
  35. <Space direction="vertical" size="middle" className="w-full">
  36. <Button type="primary" block>
  37. 登录系统
  38. </Button>
  39. <Button block>
  40. 查看用户列表
  41. </Button>
  42. </Space>
  43. </Card>
  44. </div>
  45. );
  46. }