3 changed files with 70 additions and 1 deletions
@ -0,0 +1,57 @@
|
||||
<template> |
||||
<h1 style="text-align: center;">登录</h1> |
||||
<el-card style="display: flex; justify-content: center; align-items: center; height: 100vh;"> |
||||
<el-form :model="login"> |
||||
<el-form-item label="账号"> |
||||
<el-input v-model="login.account" placeholder="请输入手机号" clearable @input="inputCheck"></el-input> |
||||
</el-form-item> |
||||
<el-form-item label="密码"> |
||||
<el-container> |
||||
<el-input v-model="login.captcha" placeholder="请输入验证码" clearable @input="inputCheck"></el-input> |
||||
<el-button type="primary" @click="sendCaptcha">发送验证码</el-button> |
||||
</el-container> |
||||
</el-form-item> |
||||
<el-form-item> |
||||
<el-button type="primary" @click="loginIn" style="width: 100%;">登录</el-button> |
||||
</el-form-item> |
||||
</el-form> |
||||
</el-card> |
||||
</template> |
||||
|
||||
<script setup> |
||||
import { reactive } from 'vue' |
||||
import axios from 'axios' |
||||
import router from '../router' |
||||
|
||||
const login = reactive({ |
||||
account: '', |
||||
captcha: '' |
||||
}) |
||||
|
||||
const inputCheck = () => { |
||||
login.account = login.account.replace(/[^\d]/g, '') |
||||
login.captcha = login.captcha.replace(/[^\d]/g, '') |
||||
} |
||||
|
||||
const sendCaptcha = () => { |
||||
axios.post('/api/captcha', login, { headers: { 'Content-Type': 'application/json' } }).then(res => { |
||||
console.log(res) |
||||
login.captcha = res.data |
||||
}).catch(err => { |
||||
console.log(err) |
||||
}) |
||||
} |
||||
|
||||
const loginIn = () => { |
||||
axios.post('/api/login', login, { headers: { 'Content-Type': 'application/json' } }).then(res => { |
||||
console.log(res) |
||||
if (res.data === 200) { |
||||
sessionStorage.setItem('user', login.account) |
||||
router.push('/') |
||||
} |
||||
}).catch(err => { |
||||
console.log(err) |
||||
}) |
||||
} |
||||
|
||||
</script> |
||||
Loading…
Reference in new issue