<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title></title>
<link rel="stylesheet" href="./css/index.css" />
<script src="https://unpkg.com/vue@3"></script>
</head>
<body>
<div id="app"></div>
<template id="root">
<div class="box">
<!-- 左侧背景 -->
<div class="left_bg"></div>
<!-- 右侧内容 -->
<div class="right">
<div class="right_header">
<!-- logo -->
<div class="logo">
<img src="https://s1.ax1x.com/2023/04/14/ppzXmFI.png" alt="" />
<span>小米账号</span>
</div>
<!-- 右侧选项 -->
<div class="r_option">
<a href="javascript:;">用户协议</a>
<a href="javascript:;">隐私政策</a>
<a href="javascript:;">帮助中心</a>
<select name="" id="">
<option value="">中文(简体)</option>
<option value="">中文(繁体)</option>
<option value="">English</option>
</select>
</div>
</div>
<div class="right_body">
<div>
<img v-if="isSao" @click="changeStaue" class="img" src="https://s1.ax1x.com/2023/04/16/p99rIpt.jpg" alt="" srcset="">
<img v-else @click="changeStaue" class="img" src="https://s1.ax1x.com/2023/04/16/p99siBF.jpg" alt="" srcset="">
</div>
<!-- 账号登录 -->
<div v-if="isSao">
<div class="log_reg">
<a :class="isActice?['isActice']:[]" @click="login">登录</a>
<a :class="isActice?[]:['isActice']" @click="register">注册</a>
</div>
<!-- 登录 -->
<div class="login_content" v-if="isActice">
<form action="">
<div class="uname">
<input type="text" placeholder="邮箱/手机号码/小米ID" class="ipt" v-model="username" />
</div>
<div class="pwd">
<input type="password" placeholder="密码" class="ipt" v-model="password" />
</div>
<div class="change">
<input type="checkbox" v-model="isChecked" @click="l_change" />
<span>已阅读并同意小米账号<a href="javascript:;">用户协议</a>和
<a href="javascript:;">隐私政策</a>
</span>
</div>
</form>
<button class="log_btn" @click="goLogin">登录</button>
<div class="forget">
<a href="javascript:;">忘记密码?</a>
<a href="javascript:;">手机号登录</a>
</div>
<div class="other">其他方式登录</div>
<div class="other_content">
<img :src="item.path" alt="" v-for="item in otherLogin" :key="item.key" />
</div>
</div>
<!-- 注册 -->
<div class="register_content" v-else>
<form action="">
<div>
<select class="ipt" v-model="cityvalue">
<option :value="item.value" v-for="item in city">{{ item.text }}</option>
</select>
</div>
<div>
<input type="text" placeholder="手机号" class="ipt" v-model.number="phone" />
</div>
<div class="yzm">
<!-- <input type="password" placeholder="密码" class="ipt" v-model.trim="r_password" /> -->
<input type="text" placeholder="请输入验证码" class="ipt" maxlength="4" v-model.number="yzm" />
<span v-if="isSend" @click="changeVuale">获取验证码</span>
<span v-else>{{second}}s重新发送</span>
</div>
<div class="change">
<input type="checkbox" v-model="isChecked1" @click="r_change" />
<span>已阅读并同意小米账号<a href="javascript:;">用户协议</a>和
<a href="javascript:;">隐私政策</a>
</span>
</div>
<!-- <input type="submit" class="reg_btn" @click="goRegister" value="注册" /> -->
</form>
<button class="reg_btn" @click="goRegister">注册</button>
<div class="Unavailable">收不到验证码?</div>
<div class="other">其他方式登录</div>
<div class="other_content">
<img :src="item.path" alt="" v-for="item in otherLogin" :key="item.key" />
</div>
</div>
</div>
<!-- 扫码登录 -->
<div v-else>
<!-- 文字 -->
<h1>扫码登录 安全快捷</h1>
<div style="display: flex;justify-content: center;align-items: center;height: 300px;">
<img class="erweima" src="https://s1.ax1x.com/2023/04/16/p99sQBD.jpg" alt="" srcset="">
</div>
<view class="font">请使用小米手机/米家等小米旗下APP扫码登录</view>
<view class="font1">支持扫码登录的App</view>
<view style="display:flex;justify-content:space-around;padding: 80px;">
<img src="https://s1.ax1x.com/2023/04/16/p99sIUJ.jpg" alt="" srcset="" class="image">
<img src="https://s1.ax1x.com/2023/04/16/p99s7CR.jpg" alt="" srcset="" class="image">
<img src="https://s1.ax1x.com/2023/04/16/p99sH81.jpg" alt="" srcset="" class="image">
</view>
</div>
</div>
</div>
</div>
</template>
<script>
Vue.createApp({
template: '#root',
data() {
return {
isActice: true,
username: '',
password: '',
yzm: '',
phone: '',
isSend: true,
isSao:true,
second: 30,
isChecked: false,
isChecked1: false,
userList: [],
cityvalue: 'China',
city: [
{ value: 'China', text: '中国' },
{ value: 'mg', text: '美国' },
{ value: 'other', text: '其他' }
],
otherLogin: [
{
id: 1,
name: '支付宝',
path: 'https://s1.ax1x.com/2023/04/14/p9SEuQJ.png'
},
{
id: 2,
name: '微信',
path: 'https://s1.ax1x.com/2023/04/14/p9SEGFK.png'
},
{
id: 3,
name: 'QQ',
path: 'https://s1.ax1x.com/2023/04/14/p9SEJJO.png'
},
{
id: 4,
name: '微博',
path: 'https://s1.ax1x.com/2023/04/14/p9SEUQH.png'
}
]
}
},
methods: {
// 登录注册切换
login() {
this.isActice = !this.isActice
},
register() {
this.isActice = !this.isActice
},
// 用户条款勾选
l_change() {
this.isChecked = !this.isChecked
},
r_change() {
this.isChecked1 = !this.isChecked1
},
// 验证码
changeVuale() {
this.isSend = false
var interval = setInterval(() => {
let times = --this.second
this.second = times < 10 ? '0' + times : times //小于10秒补 0
}, 1000)
setTimeout(() => {
clearInterval(interval)
this.second = 30
this.isSend = true
}, 30000)
},
// 扫码
changeStaue() {
this.isSao = !this.isSao;
},
// 登录
goLogin() {
if (this.username == '' || this.password == '') {
alert('账号或密码为空,请输入')
} else {
if (!this.isChecked) {
alert('请同意用户条款')
} else {
console.log(JSON.parse(localStorage.getItem('user')));
console.log(this.userList);
this.userList.forEach(item => {
if (item.phone == this.username && item.yzm == this.password) {
alert('登录成功')
} else {
alert('登录失败')
}
})
}
}
},
// 注册
goRegister() {
if (this.phone == '' || this.yzm == '') {
alert('输入不能为空')
} else {
if (!this.isChecked1) {
alert('请同意用户条款')
} else {
const regCN = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/
if (!regCN.test(this.phone)) {
alert('请输入正确的手机号')
} else {
if (this.yzm === 1234) {
let isRegister
this.userList.forEach(item => {
if (item.phone == this.phone) {
isRegister = true
} else {
isRegister = false
}
})
if (isRegister) {
alert('用户名已存在')
} else {
let data = {
id: +new Date(),
phone: this.phone,
yzm: this.yzm,
city: this.cityvalue
}
this.userList.push(data)
localStorage.setItem('user',JSON.stringify(data))
alert('注册成功')
console.log(this.userList)
this.phone = ''
this.yzm = ''
}
}
else {
alert('验证码输入错误!')
}
}
}
}
}
}
}).mount('#app')
</script>
</body>
</html>
CSS
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
a{
text-decoration: none;
color: #838383;
}
.box {
display: flex;
justify-content: space-between;
}
.left_bg {
width: 25%;
height: 100vh;
background-image: url(https://cdn.web-global.fds.api.mi-img.com/mcfe--mi-account/static/static/media/banner.92c693b4..jpg);
background-size: 100%;
/* background-color: pink; */
}
.right {
display: flex;
flex-direction: column;
align-items: center;
width: 75%;
height: 100vh;
background-color: #fff;
/* background-color: lightblue; */
}
.right_header {
display: flex;
justify-content: space-between;
align-items: center;
width: 100%;
height: 80px;
padding: 0 30px;
/* background-color: pink; */
}
.logo{
display: flex;
align-items: center;
height: 100%;
}
.logo span{
font-size: 26px;
color: #333;
margin-left: 10px;
}
.r_option{
display: flex;
align-items: center;
height: 100%;
}
.r_option a{
font-size: 14px;
margin: 0 10px;
}
.r_option a:hover{
color: orange;
}
select{
color: #838383;
border: 0;
}
.right_body {
width: 35%;
height: 75%;
margin-top: 3%;
padding-bottom: 15px;
border: 1px solid #eee;
box-shadow: 2px 3px 5px #eee;
}
.log_reg{
width: 100%;
height: 50px;
line-height: 50px;
margin: 30px;
/* background-color: pink; */
}
.log_reg a{
font-size: 22px;
margin: 0 10px;
padding: 5px 0;
cursor: pointer;
}
.isActice{
color: #000;
font-weight: 400;
border-bottom: 3px solid rgb(255,92,0);
}
/* 扫码 */
.img{
width: 80px;
height: 80px;
position: absolute;
margin-left: 420px;
/* margin-top: 0px; */
}
.login_content,
.register_content{
width: 100%;
text-align: center;
margin-top: 20px;
}
form{
width: 100%;
text-align: center;
/* background-color: pink; */
}
.ipt{
width: 80%;
height: 60px;
border: none;
outline: none;
padding: 0 20px;
margin: 10px 0;
font-size: 17px;
background-color: #f9f9f9;
}
.change{
width: 80%;
margin: 0 auto;
text-align: left;
font-size: 14px;
color: #838383;
margin-top: 10px;
}
.change input{
vertical-align: middle;
margin-right: 5px;
}
.change a{
color: #000;
margin: 0 5px;
}
.log_btn,
.reg_btn{
width: 80%;
height: 50px;
margin-top: 20px;
margin-bottom: 10px;
border: none;
color: #fff;
font-size: 14px;
font-weight: 500;
border-radius: 5px;
outline: none;
background-color: #ff5c00;
}
.forget{
width: 80%;
margin: 0 auto;
display: flex;
justify-content: space-between;
}
.forget a{
font-size: 17px;
color: #ff5c00;
}
.other{
color: #aaa;
font-size: 17px;
font-weight: 400;
line-height: 40px;
text-align: center;
}
.other_content{
width: 100%;
/* background-color: pink; */
}
.other_content img{
width: 10%;
margin: 10px 10px 0;
}
/* 注册 */
.register_content{
margin-top: 10px;
}
.yzm{
position: relative;
}
.yzm .span{
position: absolute;
right: 0;
}
.yzm span{
position: absolute;
right: 12%;
top: 50%;
transform: translateY(-50%);
color: orange;
font-size: 14px;
z-index: 99;
cursor: pointer;
}
.Unavailable{
width: 80%;
margin: 0 auto;
text-align: left;
font-size: 17px;
color: #ff5c00;
/* background-color: pink; */
}
/* 扫码内容 */
h1{
/* background-color: #000; */
text-align: center;
margin-top: 50px;
}
.erweima{
width: 200px;
height: 200px;
}
.font{
margin-left: 90px;
}
.font1{
color: #ccc;
font-size: 20px;
margin-left: 160px;
position: relative;
top: 50px;
}
.image{
width: 70px;
height: 70px;
}
效果图