2025-11-10 09:40:14 +00:00
|
|
|
|
<template>
|
|
|
|
|
|
<div class="login">
|
|
|
|
|
|
<el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
|
|
|
|
|
|
<h3 class="title">{{title}}</h3>
|
|
|
|
|
|
<el-form-item prop="username">
|
|
|
|
|
|
<el-input
|
|
|
|
|
|
v-model="loginForm.username"
|
|
|
|
|
|
type="text"
|
|
|
|
|
|
auto-complete="off"
|
|
|
|
|
|
placeholder="账号"
|
|
|
|
|
|
>
|
|
|
|
|
|
<svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
|
|
|
|
|
|
</el-input>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item prop="password">
|
|
|
|
|
|
<el-input
|
|
|
|
|
|
v-model="loginForm.password"
|
|
|
|
|
|
type="password"
|
|
|
|
|
|
auto-complete="off"
|
|
|
|
|
|
placeholder="密码"
|
|
|
|
|
|
@keyup.enter.native="handleLogin"
|
|
|
|
|
|
>
|
|
|
|
|
|
<svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
|
|
|
|
|
|
</el-input>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item prop="code" v-if="captchaEnabled">
|
|
|
|
|
|
<el-input
|
|
|
|
|
|
v-model="loginForm.code"
|
|
|
|
|
|
auto-complete="off"
|
|
|
|
|
|
placeholder="验证码"
|
|
|
|
|
|
style="width: 63%"
|
|
|
|
|
|
@keyup.enter.native="handleLogin"
|
|
|
|
|
|
>
|
|
|
|
|
|
<svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" />
|
|
|
|
|
|
</el-input>
|
|
|
|
|
|
<div class="login-code">
|
|
|
|
|
|
<img :src="codeUrl" @click="getCode" class="login-code-img"/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 25px 0px;">记住密码</el-checkbox>
|
|
|
|
|
|
<el-form-item style="width:100%;">
|
|
|
|
|
|
<el-button
|
|
|
|
|
|
:loading="loading"
|
|
|
|
|
|
size="medium"
|
|
|
|
|
|
type="primary"
|
|
|
|
|
|
style="width:100%;"
|
|
|
|
|
|
@click.native.prevent="handleLogin"
|
|
|
|
|
|
>
|
|
|
|
|
|
<span v-if="!loading">登 录</span>
|
|
|
|
|
|
<span v-else>登 录 中...</span>
|
|
|
|
|
|
</el-button>
|
|
|
|
|
|
<div style="float: right;" v-if="register">
|
|
|
|
|
|
<router-link class="link-type" :to="'/register'">立即注册</router-link>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</el-form>
|
2026-05-20 21:31:47 +00:00
|
|
|
|
<el-dialog
|
|
|
|
|
|
title="修改密码"
|
|
|
|
|
|
:visible.sync="resetPwdOpen"
|
|
|
|
|
|
width="420px"
|
|
|
|
|
|
:close-on-click-modal="false"
|
|
|
|
|
|
:close-on-press-escape="false"
|
|
|
|
|
|
:show-close="false"
|
|
|
|
|
|
append-to-body
|
|
|
|
|
|
>
|
|
|
|
|
|
<el-form ref="resetPwdForm" :model="resetPwdForm" :rules="resetPwdRules" label-width="100px">
|
|
|
|
|
|
<el-form-item label="旧密码" prop="oldPassword">
|
|
|
|
|
|
<el-input v-model="resetPwdForm.oldPassword" type="password" placeholder="请输入旧密码" show-password />
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item label="新密码" prop="newPassword">
|
|
|
|
|
|
<el-input v-model="resetPwdForm.newPassword" type="password" placeholder="请输入新密码" show-password />
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item label="确认新密码" prop="confirmPassword">
|
|
|
|
|
|
<el-input v-model="resetPwdForm.confirmPassword" type="password" placeholder="请确认新密码" show-password />
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item label="邮箱验证码" prop="emailCode">
|
|
|
|
|
|
<el-input v-model="resetPwdForm.emailCode" placeholder="请输入邮箱验证码" maxlength="6" style="width: 190px" />
|
|
|
|
|
|
<el-button :loading="emailCodeLoading" :disabled="emailCodeCountdown > 0" @click="sendEmailCode">
|
|
|
|
|
|
{{ emailCodeCountdown > 0 ? emailCodeCountdown + '秒后重发' : '发送验证码' }}
|
|
|
|
|
|
</el-button>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<div class="password-tip">密码长度8-20位,需包含大小写字母、数字、特殊字符</div>
|
|
|
|
|
|
</el-form>
|
|
|
|
|
|
<div slot="footer" class="dialog-footer">
|
|
|
|
|
|
<el-button type="primary" :loading="resetPwdLoading" @click="submitResetPwd">提 交</el-button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</el-dialog>
|
2025-11-10 09:40:14 +00:00
|
|
|
|
<!-- 底部 -->
|
|
|
|
|
|
<div class="el-login-footer">
|
2025-11-20 08:23:07 +00:00
|
|
|
|
<span>Copyright © 2018-2025 unissense All Rights Reserved.</span>
|
2025-11-10 09:40:14 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
import Cookies from "js-cookie"
|
|
|
|
|
|
import { encrypt, decrypt } from '@/utils/jsencrypt'
|
2026-05-20 21:31:47 +00:00
|
|
|
|
import { resetLoginPwd, sendResetPwdEmailCode } from '@/api/login'
|
2025-11-10 09:40:14 +00:00
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
|
name: "Login",
|
|
|
|
|
|
data() {
|
|
|
|
|
|
return {
|
|
|
|
|
|
title: process.env.VUE_APP_TITLE,
|
|
|
|
|
|
codeUrl: "",
|
|
|
|
|
|
loginForm: {
|
2025-11-25 01:00:26 +00:00
|
|
|
|
username: "",
|
|
|
|
|
|
password: "",
|
2025-11-10 09:40:14 +00:00
|
|
|
|
rememberMe: false,
|
2025-11-11 07:41:07 +00:00
|
|
|
|
code: ""
|
2025-11-10 09:40:14 +00:00
|
|
|
|
},
|
2026-05-20 21:31:47 +00:00
|
|
|
|
resetPwdForm: {
|
|
|
|
|
|
username: "",
|
|
|
|
|
|
oldPassword: "",
|
|
|
|
|
|
newPassword: "",
|
|
|
|
|
|
confirmPassword: "",
|
|
|
|
|
|
emailCode: ""
|
|
|
|
|
|
},
|
|
|
|
|
|
resetPwdOpen: false,
|
|
|
|
|
|
resetPwdLoading: false,
|
|
|
|
|
|
emailCodeLoading: false,
|
|
|
|
|
|
emailCodeCountdown: 0,
|
|
|
|
|
|
emailCodeTimer: null,
|
|
|
|
|
|
resetPwdRules: {
|
|
|
|
|
|
oldPassword: [
|
|
|
|
|
|
{ required: true, trigger: "blur", message: "请输入旧密码" }
|
|
|
|
|
|
],
|
|
|
|
|
|
newPassword: [
|
|
|
|
|
|
{ required: true, trigger: "blur", message: "请输入新密码" },
|
|
|
|
|
|
{ min: 8, max: 20, trigger: "blur", message: "密码长度为8到20个字符" },
|
|
|
|
|
|
{ pattern: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^A-Za-z0-9]).{8,20}$/, trigger: "blur", message: "密码需包含大小写字母、数字、特殊字符" }
|
|
|
|
|
|
],
|
|
|
|
|
|
confirmPassword: [
|
|
|
|
|
|
{ required: true, trigger: "blur", message: "请确认新密码" },
|
|
|
|
|
|
{ validator: (rule, value, callback) => this.equalToNewPassword(rule, value, callback), trigger: "blur" }
|
|
|
|
|
|
],
|
|
|
|
|
|
emailCode: [
|
|
|
|
|
|
{ required: true, trigger: "blur", message: "请输入邮箱验证码" },
|
|
|
|
|
|
{ pattern: /^\d{6}$/, trigger: "blur", message: "邮箱验证码为6位数字" }
|
|
|
|
|
|
]
|
|
|
|
|
|
},
|
2025-11-10 09:40:14 +00:00
|
|
|
|
loginRules: {
|
|
|
|
|
|
username: [
|
|
|
|
|
|
{ required: true, trigger: "blur", message: "请输入您的账号" }
|
|
|
|
|
|
],
|
|
|
|
|
|
password: [
|
|
|
|
|
|
{ required: true, trigger: "blur", message: "请输入您的密码" }
|
|
|
|
|
|
],
|
|
|
|
|
|
code: [{ required: true, trigger: "change", message: "请输入验证码" }]
|
|
|
|
|
|
},
|
|
|
|
|
|
loading: false,
|
|
|
|
|
|
// 验证码开关
|
2025-11-24 03:36:14 +00:00
|
|
|
|
captchaEnabled: false,
|
2025-11-10 09:40:14 +00:00
|
|
|
|
// 注册开关
|
|
|
|
|
|
register: false,
|
|
|
|
|
|
redirect: undefined
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
watch: {
|
|
|
|
|
|
$route: {
|
|
|
|
|
|
handler: function(route) {
|
|
|
|
|
|
this.redirect = route.query && route.query.redirect
|
|
|
|
|
|
},
|
|
|
|
|
|
immediate: true
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
created() {
|
2026-05-20 21:31:47 +00:00
|
|
|
|
this.getCode()
|
2025-11-10 09:40:14 +00:00
|
|
|
|
this.getCookie()
|
|
|
|
|
|
},
|
2026-05-20 21:31:47 +00:00
|
|
|
|
beforeDestroy() {
|
|
|
|
|
|
this.clearEmailCodeTimer()
|
|
|
|
|
|
},
|
2025-11-10 09:40:14 +00:00
|
|
|
|
methods: {
|
|
|
|
|
|
getCode() {
|
2025-11-11 07:41:07 +00:00
|
|
|
|
// 基于 Session 认证,直接使用图片 URL,添加时间戳防止缓存
|
|
|
|
|
|
const timestamp = new Date().getTime()
|
|
|
|
|
|
this.codeUrl = `${process.env.VUE_APP_BASE_API}/captcha/captchaImage?type=math&s=${timestamp}`
|
|
|
|
|
|
this.captchaEnabled = true
|
2025-11-10 09:40:14 +00:00
|
|
|
|
},
|
|
|
|
|
|
getCookie() {
|
|
|
|
|
|
const username = Cookies.get("username")
|
|
|
|
|
|
const password = Cookies.get("password")
|
|
|
|
|
|
const rememberMe = Cookies.get('rememberMe')
|
|
|
|
|
|
this.loginForm = {
|
|
|
|
|
|
username: username === undefined ? this.loginForm.username : username,
|
|
|
|
|
|
password: password === undefined ? this.loginForm.password : decrypt(password),
|
2026-05-20 21:31:47 +00:00
|
|
|
|
rememberMe: rememberMe === undefined ? false : Boolean(rememberMe),
|
|
|
|
|
|
code: this.loginForm.code
|
2025-11-10 09:40:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
},
|
2026-05-20 21:31:47 +00:00
|
|
|
|
equalToNewPassword(rule, value, callback) {
|
|
|
|
|
|
if (this.resetPwdForm.newPassword !== value) {
|
|
|
|
|
|
callback(new Error("两次输入的密码不一致"))
|
|
|
|
|
|
} else {
|
|
|
|
|
|
callback()
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
openResetPwdDialog() {
|
|
|
|
|
|
this.resetPwdOpen = true
|
|
|
|
|
|
this.clearEmailCodeTimer()
|
|
|
|
|
|
this.resetPwdForm = {
|
|
|
|
|
|
username: this.loginForm.username,
|
|
|
|
|
|
oldPassword: "",
|
|
|
|
|
|
newPassword: "",
|
|
|
|
|
|
confirmPassword: "",
|
|
|
|
|
|
emailCode: ""
|
|
|
|
|
|
}
|
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
|
if (this.$refs.resetPwdForm) {
|
|
|
|
|
|
this.$refs.resetPwdForm.clearValidate()
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
sendEmailCode() {
|
|
|
|
|
|
if (!this.resetPwdForm.username) {
|
|
|
|
|
|
this.$modal.msgError("请输入用户名")
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
this.emailCodeLoading = true
|
|
|
|
|
|
sendResetPwdEmailCode(this.resetPwdForm.username).then(() => {
|
|
|
|
|
|
this.$modal.msgSuccess("验证码已发送")
|
|
|
|
|
|
this.startEmailCodeCountdown()
|
|
|
|
|
|
}).finally(() => {
|
|
|
|
|
|
this.emailCodeLoading = false
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
startEmailCodeCountdown() {
|
|
|
|
|
|
this.clearEmailCodeTimer()
|
|
|
|
|
|
this.emailCodeCountdown = 60
|
|
|
|
|
|
this.emailCodeTimer = setInterval(() => {
|
|
|
|
|
|
if (this.emailCodeCountdown <= 1) {
|
|
|
|
|
|
this.clearEmailCodeTimer()
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.emailCodeCountdown--
|
|
|
|
|
|
}
|
|
|
|
|
|
}, 1000)
|
|
|
|
|
|
},
|
|
|
|
|
|
clearEmailCodeTimer() {
|
|
|
|
|
|
if (this.emailCodeTimer) {
|
|
|
|
|
|
clearInterval(this.emailCodeTimer)
|
|
|
|
|
|
this.emailCodeTimer = null
|
|
|
|
|
|
}
|
|
|
|
|
|
this.emailCodeCountdown = 0
|
|
|
|
|
|
},
|
|
|
|
|
|
submitResetPwd() {
|
|
|
|
|
|
this.$refs.resetPwdForm.validate(valid => {
|
|
|
|
|
|
if (!valid) {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
this.resetPwdLoading = true
|
|
|
|
|
|
resetLoginPwd(this.resetPwdForm).then(() => {
|
|
|
|
|
|
this.$modal.msgSuccess("密码修改成功,请重新登录")
|
|
|
|
|
|
this.resetPwdOpen = false
|
|
|
|
|
|
this.$refs.loginForm.resetFields()
|
|
|
|
|
|
this.loginForm.password = ""
|
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
|
window.location.reload()
|
|
|
|
|
|
})
|
|
|
|
|
|
}).catch(() => {
|
|
|
|
|
|
}).finally(() => {
|
|
|
|
|
|
this.resetPwdLoading = false
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
2025-11-10 09:40:14 +00:00
|
|
|
|
handleLogin() {
|
|
|
|
|
|
this.$refs.loginForm.validate(valid => {
|
|
|
|
|
|
if (valid) {
|
|
|
|
|
|
this.loading = true
|
|
|
|
|
|
if (this.loginForm.rememberMe) {
|
|
|
|
|
|
Cookies.set("username", this.loginForm.username, { expires: 30 })
|
|
|
|
|
|
Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 })
|
|
|
|
|
|
Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 })
|
|
|
|
|
|
} else {
|
|
|
|
|
|
Cookies.remove("username")
|
|
|
|
|
|
Cookies.remove("password")
|
|
|
|
|
|
Cookies.remove('rememberMe')
|
|
|
|
|
|
}
|
2026-05-20 21:31:47 +00:00
|
|
|
|
this.$store.dispatch("Login", this.loginForm).then((res) => {
|
|
|
|
|
|
if (res && res.code === 301) {
|
|
|
|
|
|
this.resetPwdForm.username = this.loginForm.username
|
|
|
|
|
|
this.resetPwdForm.oldPassword = this.loginForm.password
|
|
|
|
|
|
this.resetPwdForm.newPassword = ""
|
|
|
|
|
|
this.resetPwdForm.confirmPassword = ""
|
|
|
|
|
|
this.resetPwdForm.emailCode = ""
|
|
|
|
|
|
this.clearEmailCodeTimer()
|
|
|
|
|
|
this.resetPwdOpen = true
|
|
|
|
|
|
this.loading = false
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
2025-11-10 09:40:14 +00:00
|
|
|
|
this.$router.push({ path: this.redirect || "/" }).catch(()=>{})
|
|
|
|
|
|
}).catch(() => {
|
|
|
|
|
|
this.loading = false
|
|
|
|
|
|
if (this.captchaEnabled) {
|
|
|
|
|
|
this.getCode()
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style rel="stylesheet/scss" lang="scss">
|
|
|
|
|
|
.login {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
justify-content: center;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
height: 100%;
|
|
|
|
|
|
background-image: url("../assets/images/login-background.jpg");
|
|
|
|
|
|
background-size: cover;
|
|
|
|
|
|
}
|
2026-05-20 21:31:47 +00:00
|
|
|
|
.password-tip {
|
|
|
|
|
|
margin-top: -5px;
|
|
|
|
|
|
margin-bottom: 15px;
|
|
|
|
|
|
color: #f56c6c;
|
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
|
line-height: 18px;
|
|
|
|
|
|
}
|
2025-11-10 09:40:14 +00:00
|
|
|
|
.title {
|
|
|
|
|
|
margin: 0px auto 30px auto;
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
color: #707070;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.login-form {
|
|
|
|
|
|
border-radius: 6px;
|
|
|
|
|
|
background: #ffffff;
|
|
|
|
|
|
width: 400px;
|
|
|
|
|
|
padding: 25px 25px 5px 25px;
|
|
|
|
|
|
z-index: 1;
|
|
|
|
|
|
.el-input {
|
|
|
|
|
|
height: 38px;
|
|
|
|
|
|
input {
|
|
|
|
|
|
height: 38px;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
.input-icon {
|
|
|
|
|
|
height: 39px;
|
|
|
|
|
|
width: 14px;
|
|
|
|
|
|
margin-left: 2px;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
.login-tip {
|
|
|
|
|
|
font-size: 13px;
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
color: #bfbfbf;
|
|
|
|
|
|
}
|
|
|
|
|
|
.login-code {
|
|
|
|
|
|
width: 33%;
|
|
|
|
|
|
height: 38px;
|
|
|
|
|
|
float: right;
|
|
|
|
|
|
img {
|
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
vertical-align: middle;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
.el-login-footer {
|
|
|
|
|
|
height: 40px;
|
|
|
|
|
|
line-height: 40px;
|
|
|
|
|
|
position: fixed;
|
|
|
|
|
|
bottom: 0;
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
color: #fff;
|
|
|
|
|
|
font-family: Arial;
|
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
|
letter-spacing: 1px;
|
|
|
|
|
|
}
|
|
|
|
|
|
.login-code-img {
|
|
|
|
|
|
height: 38px;
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|