136 lines
5.0 KiB
HTML
136 lines
5.0 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>登录 - 售后服务平台</title>
|
|
<link rel="stylesheet" href="https://unpkg.com/element-plus/dist/index.css">
|
|
<style>
|
|
body {
|
|
margin: 0;
|
|
padding: 0;
|
|
background-color: #f5f7fa;
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
min-height: 100vh;
|
|
}
|
|
.login-container {
|
|
width: 400px;
|
|
padding: 40px;
|
|
background: #fff;
|
|
border-radius: 8px;
|
|
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
|
|
}
|
|
.login-title {
|
|
text-align: center;
|
|
margin-bottom: 30px;
|
|
color: #303133;
|
|
font-size: 24px;
|
|
}
|
|
.captcha-container {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 10px;
|
|
}
|
|
.captcha-img {
|
|
height: 40px;
|
|
cursor: pointer;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div id="app">
|
|
<div class="login-container">
|
|
<h2 class="login-title">售后服务平台</h2>
|
|
<el-form :model="loginForm" :rules="rules" ref="loginFormRef">
|
|
<el-form-item prop="username">
|
|
<el-input v-model="loginForm.username" placeholder="请输入账号" prefix-icon="User"></el-input>
|
|
</el-form-item>
|
|
<el-form-item prop="password">
|
|
<el-input v-model="loginForm.password" type="password" placeholder="请输入密码" prefix-icon="Lock" show-password></el-input>
|
|
</el-form-item>
|
|
<el-form-item prop="captcha">
|
|
<div class="captcha-container">
|
|
<el-input v-model="loginForm.captcha" placeholder="请输入验证码" style="flex: 1;"></el-input>
|
|
<img :src="captchaUrl" class="captcha-img" @click="refreshCaptcha" alt="验证码">
|
|
</div>
|
|
</el-form-item>
|
|
<el-form-item>
|
|
<el-button type="primary" style="width: 100%" @click="handleLogin">登录</el-button>
|
|
</el-form-item>
|
|
</el-form>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
|
|
<script src="https://unpkg.com/element-plus"></script>
|
|
<script src="https://unpkg.com/@element-plus/icons-vue"></script>
|
|
<script>
|
|
const { createApp, ref } = Vue
|
|
const app = createApp({
|
|
setup() {
|
|
const loginFormRef = ref(null)
|
|
const loginForm = ref({
|
|
username: '',
|
|
password: '',
|
|
captcha: ''
|
|
})
|
|
const captchaUrl = ref('/api/captcha')
|
|
|
|
const rules = {
|
|
username: [{ required: true, message: '请输入账号', trigger: 'blur' }],
|
|
password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
|
|
captcha: [{ required: true, message: '请输入验证码', trigger: 'blur' }]
|
|
}
|
|
|
|
const refreshCaptcha = () => {
|
|
captchaUrl.value = `/api/captcha?t=${new Date().getTime()}`
|
|
}
|
|
|
|
const handleLogin = () => {
|
|
loginFormRef.value.validate((valid) => {
|
|
if (valid) {
|
|
fetch('/api/login', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify(loginForm.value)
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.code === 0) {
|
|
window.location.href = '/'
|
|
} else {
|
|
ElementPlus.ElMessage.error(data.message)
|
|
refreshCaptcha()
|
|
}
|
|
})
|
|
.catch(error => {
|
|
ElementPlus.ElMessage.error('登录失败,请稍后重试')
|
|
refreshCaptcha()
|
|
})
|
|
}
|
|
})
|
|
}
|
|
|
|
return {
|
|
loginFormRef,
|
|
loginForm,
|
|
rules,
|
|
captchaUrl,
|
|
handleLogin,
|
|
refreshCaptcha
|
|
}
|
|
}
|
|
})
|
|
|
|
app.use(ElementPlus)
|
|
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
|
|
app.component(key, component)
|
|
}
|
|
app.mount('#app')
|
|
</script>
|
|
</body>
|
|
</html> |