134 lines
5.1 KiB
HTML
134 lines
5.1 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="zh-CN">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<title>登录 - WeChatRobot管理后台</title>
|
||
<!-- 添加favicon -->
|
||
<link rel="icon" href="/static/favicon.ico" type="image/x-icon">
|
||
<link rel="shortcut icon" href="/static/favicon.ico" type="image/x-icon">
|
||
<!-- Element UI CSS -->
|
||
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
|
||
<!-- Vue.js -->
|
||
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
|
||
<!-- Element UI JS -->
|
||
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
|
||
<style>
|
||
body {
|
||
margin: 0;
|
||
padding: 0;
|
||
font-family: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", Arial, sans-serif;
|
||
background-color: #f5f7fa;
|
||
height: 100vh;
|
||
display: flex;
|
||
justify-content: center;
|
||
align-items: center;
|
||
}
|
||
.login-container {
|
||
width: 400px;
|
||
padding: 30px;
|
||
background-color: white;
|
||
border-radius: 4px;
|
||
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
|
||
}
|
||
.login-title {
|
||
text-align: center;
|
||
margin-bottom: 30px;
|
||
color: #409EFF;
|
||
}
|
||
.login-form {
|
||
margin-top: 20px;
|
||
}
|
||
.login-button {
|
||
width: 100%;
|
||
margin-top: 20px;
|
||
}
|
||
.error-message {
|
||
color: #F56C6C;
|
||
margin-top: 10px;
|
||
text-align: center;
|
||
}
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<div id="app">
|
||
<div class="login-container">
|
||
<h2 class="login-title">WeChatRobot管理后台</h2>
|
||
<el-form class="login-form" ref="loginForm" :model="loginForm" :rules="rules" label-width="0px">
|
||
<el-form-item prop="username">
|
||
<el-input v-model="loginForm.username" prefix-icon="el-icon-user" placeholder="用户名"></el-input>
|
||
</el-form-item>
|
||
<el-form-item prop="password">
|
||
<el-input v-model="loginForm.password" prefix-icon="el-icon-lock" placeholder="密码" type="password" @keyup.enter.native="submitForm"></el-input>
|
||
</el-form-item>
|
||
<el-form-item>
|
||
<el-button type="primary" class="login-button" @click="submitForm" :loading="loading">登录</el-button>
|
||
</el-form-item>
|
||
</el-form>
|
||
<div class="error-message" v-if="errorMessage">{{ errorMessage }}</div>
|
||
</div>
|
||
</div>
|
||
|
||
<script>
|
||
new Vue({
|
||
el: '#app',
|
||
data() {
|
||
return {
|
||
loginForm: {
|
||
username: '',
|
||
password: ''
|
||
},
|
||
rules: {
|
||
username: [
|
||
{ required: true, message: '请输入用户名', trigger: 'blur' }
|
||
],
|
||
password: [
|
||
{ required: true, message: '请输入密码', trigger: 'blur' }
|
||
]
|
||
},
|
||
loading: false,
|
||
errorMessage: ''
|
||
}
|
||
},
|
||
methods: {
|
||
submitForm() {
|
||
this.$refs.loginForm.validate((valid) => {
|
||
if (valid) {
|
||
this.loading = true;
|
||
// 创建表单数据
|
||
const formData = new FormData();
|
||
formData.append('username', this.loginForm.username);
|
||
formData.append('password', this.loginForm.password);
|
||
|
||
// 发送POST请求
|
||
fetch('/login', {
|
||
method: 'POST',
|
||
body: formData
|
||
})
|
||
.then(response => {
|
||
if (response.redirected) {
|
||
window.location.href = response.url;
|
||
} else {
|
||
return response.text();
|
||
}
|
||
})
|
||
.then(html => {
|
||
if (html) {
|
||
// 如果返回HTML,说明登录失败
|
||
this.errorMessage = '用户名或密码错误';
|
||
this.loading = false;
|
||
}
|
||
})
|
||
.catch(error => {
|
||
console.error('登录出错:', error);
|
||
this.errorMessage = '登录请求失败,请稍后重试';
|
||
this.loading = false;
|
||
});
|
||
}
|
||
});
|
||
}
|
||
}
|
||
});
|
||
</script>
|
||
</body>
|
||
</html> |