技术标签: react.js typescript web站点
大家好,我是yma16,本期给大家分享next项目搭建卡通风的登录注册。
该系列的往期文章
博客搭建_初始化next项目
登录注册的交互效果如下:
背景图为卡通的动画,符合六一的风格!
React 函数组件是一个简单的 React 组件,是一个纯 JavaScript 函数,用于定义组件的结构和行为。相比于 Class 组件,函数组件的代码量更少,结构更清晰,也更易于测试和维护。下面是一些函数组件的风格介绍:
const MyComponent = () => {
return <div>Hello World</div>;
}
const MyComponent = (props) => {
return <div>Hello {
props.name}</div>;
}
// 使用组件时传递 props
<MyComponent name="World" />
const MyComponent = ({
name }) => {
return <div>Hello {
name}</div>;
}
// 使用组件时传递 props
<MyComponent name="World" />
import React, {
useState } from "react";
const MyComponent = () => {
const [count, setCount] = useState(0);
return (
<div>
<p>Count: {
count}</p>
<button onClick={
() => setCount(count + 1)}>Increment</button>
</div>
);
}
import React, {
useState, useEffect } from "react";
const MyComponent = () => {
const [count, setCount] = useState(0);
useEffect(() => {
document.title = `Count: ${
count}`;
}, [count]);
return (
<div>
<p>Count: {
count}</p>
<button onClick={
() => setCount(count + 1)}>Increment</button>
</div>
);
}
这些风格可以帮助您更加简洁和有效地编写 React 函数组件。
页面元素:
定义onSubmit 提交事件去校验输入框的内容,jumpAction的函数跳转到注册页面,添加reset重置form表单的方法
代码实现如下:
import React from 'react';
import {
Form, Input, Button, MessagePlugin,Link } from 'tdesign-react';
import {
DesktopIcon, LockOnIcon } from 'tdesign-icons-react';
import {
loginAction} from "../../service/user/userApi"
import {
useRouter } from 'next/router'
const {
FormItem } = Form;
export default function BaseForm() {
const router = useRouter()
const rules=[
{
required: true, message: '不能为空', type: 'warning' }
]
const onSubmit = (e:any) => {
console.log(e);
if (e.validateResult === true) {
loginAction({
name:e.fields?.account,
password:e.fields?.password
}).then(res=>{
console.log('res',res)
MessagePlugin.info('登录成功');
}).catch(r=>{
MessagePlugin.error('登录失败\n'+JSON.stringify(r));
})
}
};
const jumpAction=()=>{
router.push('/views/sys/register')
}
const onReset = (e) => {
console.log(e);
MessagePlugin.info('重置成功');
};
return (
<div className={
"login-box"}>
<div className={
"login-container"}>
<div style={
{
width:'100%',textAlign:'center',marginBottom:'20px',fontWeight:'bold'}}>
登录
</div>
<div style={
{
width: 350 }}>
<Form statusIcon={
true} onSubmit={
onSubmit} onReset={
onReset} colon={
true} labelWidth={
0}>
<FormItem name="account" rules={
rules}>
<Input clearable={
true} prefixIcon={
<DesktopIcon />} placeholder="请输入账户名" />
</FormItem>
<FormItem name="password" rules={
rules}>
<Input type="password" prefixIcon={
<LockOnIcon />} clearable={
true} placeholder="请输入密码"
/>
</FormItem>
<FormItem>
<Button theme="primary" type="submit" block>
登录
</Button>
</FormItem>
</Form>
<div style={
{
width:'100%',textAlign:'center',marginTop:'10px'}} onClick={
jumpAction}>
没有账号?<Link theme="primary">前往注册</Link>
</div>
</div>
</div>
</div>
);
}
思路分解
页面元素:
registerAction注册对接后端的接口,jumpAction跳转到登录的方法,reset重置表单的方法。
注册页面的代码如下:
import React from 'react';
import {
Form, Input, Button, MessagePlugin,Link } from 'tdesign-react';
import {
DesktopIcon, LockOnIcon } from 'tdesign-icons-react';
import {
registerAction} from "../../service/user/userApi"
import {
useRouter } from 'next/router'
const {
FormItem } = Form;
export default function BaseForm() {
const [form]=Form.useForm()
const router = useRouter()
const rules=[
{
required: true, message: '不能为空', type: 'warning' }
]
const pwdRules=[
{
required: true, message: '不能为空', type: 'warning' },
{
validator: asyncValidatePwd, message: '密码不一致', type: 'warning', trigger: 'blur' },
]
function asyncValidatePwd(val) {
// 密码不一致的校验
return new Promise((resolve) => {
setTimeout(() => {
if (val === form.getFieldValue('password')) {
resolve(true);
} else {
resolve(false);
}
}, 1000);
});
}
const onSubmit = (e:any) => {
console.log(e);
if (e.validateResult === true) {
registerAction({
name:e.fields?.account,
password:e.fields?.password
}).then(res=>{
console.log('res',res)
if(res.data.code){
MessagePlugin.info('注册成功');
}
else{
MessagePlugin.error('注册失败\n'+res.data.msg);
}
}).catch(r=>{
MessagePlugin.error('注册失败\n'+JSON.stringify(r));
})
}
};
const jumpAction=()=>{
router.push('/views/sys/login')
}
const onReset = (e) => {
console.log(e);
MessagePlugin.info('重置成功');
};
return (
<div className={
"login-box"}>
<div className={
"login-container"}>
<div style={
{
width:'100%',textAlign:'center',marginBottom:'20px',fontWeight:'bold'}}>
注册
</div>
<div style={
{
width: 350 }}>
<Form statusIcon={
true} onSubmit={
onSubmit} onReset={
onReset} colon={
true} labelWidth={
0} form={
form}>
<FormItem name="account" rules={
rules}>
<Input clearable={
true} prefixIcon={
<DesktopIcon />} placeholder="请输入账户名" />
</FormItem>
<FormItem name="password" rules={
rules}>
<Input type="password" prefixIcon={
<LockOnIcon />} clearable={
true} placeholder="请输入密码"
/>
</FormItem>
<FormItem name="confirmPwd" rules={
pwdRules}>
<Input type="confirmPwd" prefixIcon={
<LockOnIcon />} clearable={
true} placeholder="请确认密码"
/>
</FormItem>
<FormItem>
<Button theme="primary" type="submit" block>
注册
</Button>
</FormItem>
</Form>
<div style={
{
width:'100%',textAlign:'center',marginTop:'10px'}} onClick={
jumpAction}>
已有账号?<Link theme="primary">前往登录</Link>
</div>
</div>
</div>
</div>
);
}
博客的卡通风格登录注册到这结束,如有不足欢迎指出!
感谢你的阅读
我们下篇博客见!
文章浏览阅读1k次。在高并发处理图片的时候出现这个错误。18:29:37.993 [pool-9-thread-8] ERROR cn.bywin.cbvsp.service.ImageSevice - 切图出错!!javax.imageio.IIOException: Can't create cache file!at javax.imageio.ImageIO.createImageOutputStream(I..._filesystemexception 打开的文件过多
文章浏览阅读176次。BookmarksBookmarks 书签栏 姿态识别 2D3D姿态识别 IT网站-首页 TVM (99+ 封私信) TVM源码解析 - 搜索结果 - 知乎 TVM整体结构,TVM代码的基本构成 - 综合技术交流 - 电子技术论坛 - 广受欢迎的专业电子论坛! 源码研习 — T..._nvdla compiler
文章浏览阅读1.2w次。前言关于 QPS、TPS、PV、UV、GMV、IP、RPS 这些词语,看起来好像挺专业。但实际上,我认为是这是每个程序员必懂的知识点了,你可以搞不懂它们怎么计算的,但是你最少要了解它们分别代表什么意思。QPSQueries Per Second,每秒查询数。每秒能够响应的查询次数。QPS 是对一个特定的查询服务器在规定时间内所处理流量多少的衡量标准,在因特网上,作为域名系统服务器的机器的..._qpsvr
文章浏览阅读2.3k次。在DOS下SQL> startup;ORA-00119: invalid specification for system parameter LOCAL_LISTENERORA-00132: syntax error or unresolved network name 'LISTENER_ORCL'解决方法:1.SQL> create pfile from spf..._ora-00132
文章浏览阅读650次。今天给大家分享学习两个函数:quick_exit函数和ctime函数。quick_exitquick_exit()函数是在定义STDLIB头文件。quick_exit()函数用于正常终止进程而不完全清除资源。如果val为零或EXIT_SUCCESS,则表明程序成功终止。如果该值不为零或EXIT_FAILURE,则表明该程序未成功终止。这些函数以那里调用的相反顺序被调用。句法:void quick_exit(int val);参数:此方法采用单个参数val,它是表示程序退出状态_quick_exit
文章浏览阅读60次。 一转眼接触ORACLE已经一年了,在这一年中收获多多,感慨多多,我记得是2004年11月底开始学习ORACLE的,当时选择方向也是几经波折,还好现在的处境不是非常的艰难,前途似乎还有想象中的光明。 毕业已经两年半,开始半年主要是接触Sybase,当时公司后台使用的Sybase SQL 11,由于人手比较少,管理也不很严格,所以我经常有机会光顾他,在那里我学会了怎样备份,恢复数..._李小龙语录一拳就是一拳一脚就是一脚
文章浏览阅读5.9k次,点赞4次,收藏17次。我们都知道做投资最难的地方在于投资逻辑是否准确,如何验证逻辑的准确性是一门工程,从工科思维考虑就是通过历史数据做回测验证,以检验投资逻辑在历史中的表现,从而衡量投资逻辑的有效性。本文从华泰期货研报《20170925-华泰期货-CTA量化策略因子系列(二):动量因子》入手,去论证动量因子是否有效。一、准备巧妇难为无米之炊,首先我们需要准备成交量、动量和收益率的数据,收益率我们采用每天的涨跌幅来计..._华泰期货cta量化策略因子
文章浏览阅读503次,点赞9次,收藏7次。在软件开发过程中,文档资料是非常关键的一部分,它们帮助团队成员理解项目需求、设计、实施、测试、验收等各个环节,确保项目的顺利进行。以下是针对您提到的各个阶段的文档资料概述:
文章浏览阅读64次。1.建立一个添加页面,在这个页面上可以选择增加节点。add.php<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3....
文章浏览阅读266次。1.通过 `tenant_info `表的 customer_id(对应`custom_info`表的主键id)来l获取每个租户的 id 2.拿着id到 `custom_info`表获取具体的客户对象 3.通过获取到的客户对象拿到具体的客户名,具体实现如下: @AutoLog(value = "tenant_info-分页列表查询") @ApiOperation(value = "tenant_info-分页列表查询", notes = "tenant_info-分页列表查..._pagelist.getrecords().stream().foreach
文章浏览阅读3.2k次。请求头header中很重要的两个参数: Accept:text/html 只在响应中存在,表示当前请求希望服务器将来返回的数据类型是text/html Content-Type:application/json 既可以出现在请求中,也可以出现在响应中,例如 响应中代表服务器响应的是什么数据类型 响应中response.setContentType("text/html;charset=utf-8"); 请求中代表客户端所携带的参数是什么类型consumes 指定处理请求的提交内_consumes属性
文章浏览阅读288次,点赞6次,收藏5次。地址管理:用户收货地址管理,添加 修改 删除地址 可以添加多个。商品管理:查看 修改 删除 添加活动,添加商品分类,添加商品。订单管理:查询用户未发货 待收货 已完成订单,可对未发货商品。对完成订单的商品可以评论 评论后,可以在对应的商品详情页下方。用户订单管理:查看自己下单信息 未完成 已完成订单,下单后结算金额时,会判断是否享有活动,计算实付金额。活动管理:添加活动,每个商品可以对应活动。用户购买-->后台发货-用户收货-订单完成。用户管理:用户列表 可删除用户。