首页 > 其他分享 >React 简单登录平台Demo(2):使用Anti写登录框架

React 简单登录平台Demo(2):使用Anti写登录框架

时间:2024-04-19 17:12:31浏览次数:19  
标签:flex 登录 Demo next React Anti import useRouter

目录

前言

在适用了一下Anti之后发现,学起来成本实在太高了,先用Anti默认的目标凑合一下好了。反正我也就是一个普通的后端,能用React写就不错了,样式凑合凑合能用就行。但是tailwindcss是通用css,学了就一通百通的。而且Anti是自己包装的组件,想想也是一个黑盒。算了,先试试尽量用tailwindcss来解决代码。

参考登录页面

网上找了个图片凑合用一下

基础框架

layout.tsx

import "./globals.css";

export default function RootLayout({
    children,
}: Readonly<{
    children: React.ReactNode;
}>) {
    return (
        <html lang="en">
            <body>
                <main>
                    <div className="flex flex-col min-h-screen h-full ">
                        <div className="flex-none">head</div>
                        <div className="flex flex-1">{children}</div>
                        <div className="flex-none">bottom</div>
                    </div>
                </main>
            </body>
        </html>
    );
}


page.tsx

"use client";
import Image from "next/image";
import Link from "next/link";
import { useRouter } from "next/navigation";

export default function Home() {
    const router = useRouter();

    return (
        <>
            <div className="flex-grow  basis-3/4 bg-blue-200">
                <div>
                    <div>欢迎光临</div>
                    <div>详细描述:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</div>
                </div>
            </div>
            <div className="flex-grow  basis-1/4 bg-slate-400">
                <div className="">登录窗口</div>
            </div>
        </>
    );
}

丑还是挺丑的

TailWind 使用

好看的渐变颜色

tailwindcss的渐变色是从左到右的,凑合用用已经够了

bg-gradient-to-r //从左到右渐变
from-yellow-400 //起点颜色,必加
via-red-500 //中间颜色,可不加
to-pink-500 //终点颜色,必加

flex布局

填充布局

父节点使用flex,填充节点使用flex-1。即可填充剩余空间

<div className="flex">
  <div >head</div>
  <div className="flex-1">{children}</div>
  <div >bottom</div>
</div>

居中布局

<div
    className="flex items-center"
>
    <div >
        。。。。后面都是居中了
    </div>
</div>

显示效果

"use client";
import Image from "next/image";
import Link from "next/link";
import { useRouter } from "next/navigation";

export default function Home() {
    const router = useRouter();

    return (
        <>
            <div
                className="  basis-3/4 
                bg-gradient-to-r from-blue-400 to-blue-800 
                flex items-center"
            >
                <div className="flex flex-col items-center">
                    <div className="w-3/4">
                        <div className="text-white text-4xl">欢迎光临</div>
                        <div className="text-white mt-8 text-wrap w-1/2">
                            详细描述:
                            xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
                            xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
                        </div>
                    </div>
                </div>
            </div>
            <div className="flex flex-row items-center basis-1/4 bg-gray-100">
                <div className="w-full flex flex-col items-center">
                    <div className="text-4xl">欢迎回来</div>
                    <div className="m-5">第三方登录</div>
                    <div>
                        <button className="btn  bg-blue-900 border-0 h-16 m-1">
                            <div className="icon-[ri--facebook-fill] w-8 h-8 text-white "></div>
                        </button>
                        <button className="btn bg-blue-500 border-0 h-16 m-1">
                            <div className="icon-[mdi--twitter] w-8 h-8 text-white "></div>
                        </button>
                        <button className="btn bg-black border-0 h-16 m-1">
                            <div className="icon-[mdi--github] w-8 h-8 text-white "></div>
                        </button>
                    </div>
                    <div className="text-gray-400 m-5">使用电子邮箱登录</div>
                    <div>
                        <div className="m-2"> 电子邮箱</div>
                        <label className="input input-bordered flex items-center gap-2">
                            <span className="icon-[mdi--email]"></span>
                            <input
                                type="text"
                                className="grow"
                                placeholder="Email"
                            />
                        </label>
                    </div>
                    <div>
                        <div className="m-2">密码</div>
                        <label className="input input-bordered flex items-center gap-2">
                            <span className="icon-[material-symbols--key]"></span>
                            <input
                                type="text"
                                className="grow"
                                placeholder="Email"
                            />
                        </label>
                    </div>
                    <div className="flex flex-row w-3/4 m-3">
                        <div className="flex">
                            <input
                                type="checkbox"
                                checked={false}
                                className="checkbox mr-3"
                            />
                            <div>记住我</div>
                        </div>
                        <div className="flex flex-1"></div>
                        <div>
                            <div className="text-blue-500">忘记密码?</div>
                        </div>
                    </div>
                    <div className="w-3/4">
                        <button className="btn bg-gradient-to-t from-blue-500 to-purple-600 w-full text-white">
                            登录
                        </button>
                    </div>
                    <div className="flex flex-row">
                        <div>还没有账号?</div>
                        <div className="text-blue-500">立即注册</div>
                    </div>
                </div>
            </div>
        </>
    );
}

总结

我只是写了TailWindcss的样式,但是Anti封装了大部分的React逻辑,后面还是要用Anti组件写代码,但是TailWindCss用起来确实还可以,基本就是原子级的CSS,记得多查官方文档,用多了就属性了。

标签:flex,登录,Demo,next,React,Anti,import,useRouter
From: https://www.cnblogs.com/gclove2000/p/18145763

相关文章

  • MySQL安全登录策略
    原文链接:https://blog.csdn.net/weixin_46106069/article/details/129183418今天看到了安装validate_password插件,查下是什么,学习下。MySQL密码复杂度策略设置:MySQL系统自带有validate_password插件,此插件可以验证密码强度,未达到规定强度的密码则不允许被设置。MySQL5.7......
  • 没 2 年 React Native 开发经验,你都遇不到这些坑
    ......
  • 用 React 结合 SAP UI5 Web Components 来开发 SAP Fiori 应用
    用React结合SAPUI5WebComponents来开发SAPFiori应用阿里云开发者​已认证账号​关注 6人赞同了该文章简介:用React结合SAPUI5WebComponents来开发SAPFiori应用在FioriFundamentals和SAPUI5WebComponent诞生之前,SA......
  • 106.React SSR(服务器端渲染)实践指南
    106.ReactSSR(服务器端渲染)实践指南极客前端探索者前沿技术的探索者,编码艺术的实践者​关注他 1人赞同了该文章随着前端技术的发展,单页应用(SPA)已经成为了前端开发的主流形式。然而,在某些场景下,如首屏加载速度、SEO优化等方面,SPA仍然存在着一些......
  • 如何快速启动KVM虚拟机并用自定义用户登录
    以ubuntu虚拟机为例,很多时候创建了KVM虚拟机之后,想ssh登录进去做一些操作,但是却不知道用户名和密码,最早的时候ubuntu的cloudimage内置了一个cirros的用户名,密码也是cirros,现在好像没有这个用户了,所以想ssh虚拟机的话,可以借助cloudinit来在启动时创建一个指定的用户。以下以u......
  • windows11 配置账户登录锁定策略
    原文链接:https://blog.csdn.net/weixin_46119529/article/details/134162164一、打开本地策略有两种方法,都可以!!1、搜索“组策略”,或者 2、Win键+R输入“secpol.msc” 二、打开配置界面1、如果是搜索“组策略”,按以下步骤:      2、如果是Win键+R输入“sec......
  • sqlnet现在ip地址登录
    由于业务需要,需要使用白名单限制用户登录数据库的地址,决定使用数据库白名单功能一般单实例数据库启动白名单只需要在sqlnet.ora中添加以下内容即可:TCP.VALIDNODE_CHECKING=yes(开启IP限制功能),TCP.INVITED_NODES=(192.168.1.103,ip2,ip3,..,..本地IP..)--白名单,必须本地IP,否......
  • React 简单登录平台Demo(1):Next.js配置
    目录前言体验Next.js中文文档路径问题创建项目启动报错测试TailWindCSS热重载如何添加路由第三方库引入tailwindcss配置相关链接布局新建布局布局也是嵌套影响的根节点layout配置路由跳转Link跳转Hook跳转简单的登录页面前言我之前的那个项目写到后面,发现还不如直接用Next.js呢......
  • 三角不等式/react ts 速查表
    三角不等式一般来说软件工程观察到了反三角不等式:要从A到C,通过先从A到B,然后从B到C比直接从A到C更快。如果你提一个拉请求,有帮助的是将它分成更小的部分。如果你重构某些东西,先引入一个新的工作拷贝然后分别淘汰旧代码,比原地更改这个东西要快。reactts速查表htt......
  • 如何在 Netlify 上手动部署 React 和 TypeScript 项目
    在本教程中,我将教你如何使用Vite在Netlify上手动部署React和TypeScript项目。我将向你展示一些快速简单的步骤,让你的项目能够立即运行。要跟着本教程操作,有几个先决条件:一个现有的React和TypeScript项目,使用Vite构建,并且你想要部署它。VisualStudioCode(VSCode......