1 Star 0 Fork 1

金缕羽/visaulProduct-95

forked from xpzll/visaulProduct-95 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
login.html 6.94 KB
一键复制 编辑 原始数据 按行查看 历史
xpzll 提交于 2023-02-20 10:36 . 请求拦截加token响应拦截做剥离
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>登录</title>
<link rel="stylesheet" href="./bootstrap/bootstrap.min.css" />
<link rel="stylesheet" href="./bootstrap/bootstrap-icons.css" />
<link rel="stylesheet" href="./css/common.css" />
<link rel="stylesheet" href="./css/login.css" />
</head>
<body class="application application-offset">
<div class="container-fluid container-application">
<div class="main-content position-relative">
<!-- Page content -->
<div class="page-content">
<div class="min-vh-100 py-5 d-flex align-items-center">
<div class="w-100">
<div class="row justify-content-center">
<div class="col-sm-8 col-lg-4">
<div class="card shadow zindex-100 mb-0">
<div class="card-body px-md-5 py-5">
<div class="mb-5">
<h6 class="h3">传智教育-登录</h6>
</div>
<span class="clearfix"></span>
<form role="form" autocomplete="off">
<div class="form-group">
<label class="form-control-label">账号</label>
<div class="input-group input-group-merge">
<div class="input-group-prepend">
<span class="input-group-text"
><i class="bi bi-person"></i
></span>
</div>
<input
name="username"
type="text"
class="form-control"
id="input-email"
placeholder="请输入账号"
/>
</div>
</div>
<div class="form-group mb-4">
<div
class="d-flex align-items-center justify-content-between"
>
<div>
<label class="form-control-label">密码</label>
</div>
<div class="mb-2">
<a
href="javascript:;"
class="small text-muted text-underline--dashed border-primary"
>忘记密码</a
>
</div>
</div>
<div class="input-group input-group-merge">
<div class="input-group-prepend">
<span class="input-group-text"
><i class="bi bi-key"></i
></span>
</div>
<input
name="password"
type="password"
class="form-control"
id="input-password"
placeholder="请输入密码"
/>
<div class="input-group-append">
<span class="input-group-text">
<a
href="javascript:;"
data-toggle="password-text"
data-target="#input-password"
>
<i class="bi bi-eye-fill text-blue"></i>
</a>
</span>
</div>
</div>
</div>
<div class="mt-4">
<button
id="btn-login"
type="button"
class="btn btn-sm btn-info btn-icon btn-blue rounded-pill"
>
<span class="btn-inner--text">登录</span>
<span class="btn-inner--icon"
><i class="bi bi-arrow-right"></i
></span>
</button>
</div>
</form>
</div>
<div class="card-footer px-md-5">
<small>没有注册?</small>
<a
href="./register.html"
class="small font-weight-bold text-blue"
>创建账号</a
>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- toast -->
<div
class="position-fixed top-0 start-50 pt-4"
style="z-index: 999; transform: translateX(-50%)"
>
<div id="myToast" class="toast bg-rgba">
<div class="toast-body">提示消息</div>
</div>
</div>
<script src="./bootstrap/bootstrap.min.js"></script>
<script src="./lib/form-serialize.js"></script>
<script src="./lib/axios.js"></script>
<script src="./js/common.js"></script>
<script>
document
.querySelector('#btn-login')
.addEventListener('click', async function () {
// 获得表单里所有输入的内容
const data = serialize(document.querySelector('form'), { hash: true })
// 怎么判断没有输入账号?
// if (data.username === undefined) {
if (!data.username) {
return tip('请输入账号')
}
if (!data.password) {
return tip('请输入密码')
}
// 判断位数
if (data.username.length < 2 || data.username.length > 30) {
return tip('账号在2-30位之间')
}
if (data.password.length < 6 || data.password.length > 30) {
return tip('密码在6-30位之间')
}
try {
// 发请求去做登录
const res = await axios({
url: '/login',
method: 'post',
data
})
// 把token存到本地
localStorage.setItem('token', res.data.token)
// 把用户名顺便也存起来
localStorage.setItem('username', res.data.username)
tip('登录成功')
setTimeout(() => {
location.href = 'index.html'
}, 1500);
} catch (err) {
tip(err.response.data.message)
}
})
</script>
</body>
</html>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/jinlvyu/visaul-product-95.git
git@gitee.com:jinlvyu/visaul-product-95.git
jinlvyu
visaul-product-95
visaulProduct-95
master

搜索帮助