<template>
|
<div class="login-container">
|
<div class="project-name">WMS</div>
|
<div class="login-form">
|
<div class="form-user" @keypress="changePwdPress">
|
<div class="login-text">
|
<div>修改密码</div>
|
</div>
|
<div class="login-text-small">CHANGE PASSWORD</div>
|
|
<!-- 新增:用户名输入框 -->
|
<div class="item">
|
<div class="input-icon el-icon-user"></div>
|
<input
|
type="text"
|
v-focus
|
v-model="pwdForm.userName"
|
placeholder="请输入用户名"
|
/>
|
</div>
|
|
<!-- 旧密码 -->
|
<div class="item">
|
<div class="input-icon el-icon-lock"></div>
|
<input
|
type="password"
|
v-model="pwdForm.oldPwd"
|
placeholder="请输入旧密码"
|
/>
|
</div>
|
|
<!-- 新密码 -->
|
<div class="item">
|
<div class="input-icon el-icon-key"></div>
|
<input
|
type="password"
|
v-model="pwdForm.newPwd"
|
placeholder="请输入新密码"
|
/>
|
</div>
|
|
<!-- 确认新密码 -->
|
<div class="item">
|
<div class="input-icon el-icon-key"></div>
|
<input
|
type="password"
|
v-model="pwdForm.confirmPassword"
|
placeholder="请确认新密码"
|
/>
|
</div>
|
</div>
|
|
<!-- 提交按钮 -->
|
<div class="loging-btn">
|
<el-button
|
size="large"
|
:loading="loading"
|
color="#3a6cd1"
|
:dark="true"
|
@click="changePassword"
|
long
|
>
|
<span v-if="!loading">确认修改</span>
|
<span v-else>正在修改...</span>
|
</el-button>
|
</div>
|
|
<!-- 返回按钮 -->
|
<div class="back-login-btn">
|
<el-button
|
size="large"
|
type="text"
|
@click="goBack"
|
>
|
返回
|
</el-button>
|
</div>
|
</div>
|
|
<img class="login-bg" src="/static/login_bg.png" />
|
</div>
|
</template>
|
|
<script>
|
import {
|
defineComponent,
|
ref,
|
reactive,
|
getCurrentInstance,
|
} from "vue";
|
import { useRouter, useRoute } from "vue-router";
|
import store from "../store/index";
|
import http from "@/../src/api/http.js";
|
|
export default defineComponent({
|
setup(props, context) {
|
const loading = ref(false);
|
const router = useRouter();
|
|
// 密码表单(保留原有默认值,新增用户名双向绑定)
|
const pwdForm = reactive({
|
userName: store.state.userInfo?.userName || "", // 仍保留从store取值,可手动修改
|
oldPwd: "",
|
newPwd: "",
|
confirmPassword: "",
|
});
|
|
// 全局提示
|
let appContext = getCurrentInstance().appContext;
|
let $message = appContext.config.globalProperties.$message;
|
|
// 回车触发
|
const changePwdPress = (e) => {
|
if (e.keyCode === 13) {
|
changePassword();
|
}
|
};
|
|
// 返回上一页
|
const goBack = () => {
|
router.go(-1);
|
};
|
|
// 表单校验(新增:用户名非空校验)
|
const validateForm = () => {
|
if (!pwdForm.userName) return $message.error("请输入用户名"); // 新增
|
if (!pwdForm.oldPwd) return $message.error("请输入旧密码");
|
if (!pwdForm.newPwd) return $message.error("请输入新密码");
|
if (pwdForm.newPwd.length < 6) {
|
$message.error("新密码长度不能小于6位");
|
return false;
|
}
|
if (pwdForm.newPwd !== pwdForm.confirmPassword) {
|
$message.error("两次输入的新密码不一致");
|
return false;
|
}
|
if (pwdForm.oldPwd === pwdForm.newPwd) {
|
$message.error("新密码不能与旧密码相同");
|
return false;
|
}
|
return true;
|
};
|
|
// 修改密码(逻辑不变,userName已在表单中)
|
const changePassword = () => {
|
if (!validateForm()) return;
|
|
loading.value = true;
|
http.post("/api/User/ModifyUserNamePwd", {
|
userName: pwdForm.userName,
|
newPwd: pwdForm.newPwd,
|
oldPwd: pwdForm.oldPwd
|
}, "正在修改密码....").then((result) => {
|
loading.value = false;
|
if (!result.status) return $message.error(result.message);
|
|
$message.success("密码修改成功,请重新登录");
|
store.commit("clearUserInfo", "");
|
setTimeout(() => router.push("/login"), 1500);
|
}).catch((err) => {
|
loading.value = false;
|
$message.error("修改密码失败,请联系管理员");
|
});
|
};
|
|
return {
|
loading,
|
pwdForm,
|
changePassword,
|
changePwdPress,
|
goBack,
|
};
|
},
|
directives: {
|
focus: {
|
inserted: function (el) {
|
el.focus();
|
},
|
},
|
},
|
});
|
</script>
|
|
<style lang="less" scoped>
|
// 完全复用你登录页的样式,只新增少量按钮样式
|
.login-container {
|
display: flex;
|
width: 100%;
|
height: 100%;
|
background: rgb(246, 247, 252);
|
justify-content: flex-end;
|
align-items: center;
|
}
|
|
.login-form {
|
align-items: center;
|
width: 50%;
|
display: flex;
|
flex-direction: column;
|
z-index: 999;
|
|
.form-user {
|
.item {
|
border-radius: 5px;
|
border: 1px solid #ececec;
|
display: flex;
|
margin-bottom: 30px;
|
background: #ffff;
|
height: 45px;
|
padding-left: 20px;
|
align-items: center;
|
|
.input-icon {
|
color: #7a7a7a;
|
padding-right: 20px;
|
display: flex;
|
align-items: center;
|
}
|
}
|
}
|
|
input:-webkit-autofill {
|
box-shadow: 0 0 0px 1000px white inset;
|
-webkit-box-shadow: 0 0 0px 1000px white inset !important;
|
}
|
|
input {
|
background: white;
|
display: block;
|
box-sizing: border-box;
|
width: 100%;
|
min-width: 0;
|
margin: 0;
|
padding: 0;
|
color: #323233;
|
text-align: left;
|
border: 0;
|
outline: none;
|
font-size: 16px;
|
height: 100%;
|
line-height: normal;
|
}
|
}
|
|
.form-user,
|
.loging-btn {
|
width: 400px;
|
}
|
|
.loging-btn {
|
box-shadow: 2px 4px 11px #a4c2ff;
|
margin-top: 10px;
|
|
button {
|
padding: 21px;
|
font-size: 14px !important;
|
width: 100%;
|
}
|
}
|
|
// 仅新增:返回按钮样式
|
.back-login-btn {
|
width: 400px;
|
margin-top: 15px;
|
text-align: center;
|
|
button {
|
font-size: 13px;
|
color: #3a6cd1;
|
padding: 0;
|
|
&:hover {
|
color: #1850c1;
|
}
|
}
|
}
|
|
.login-text {
|
font-weight: bolder;
|
font-size: 20px;
|
letter-spacing: 2px;
|
position: relative;
|
display: flex;
|
}
|
|
.login-text-small {
|
margin-bottom: 20px;
|
font-size: 13px;
|
color: #7d7c7c;
|
}
|
|
.login-bg {
|
left: 0;
|
position: absolute;
|
height: 100%;
|
width: 50%;
|
z-index: 0;
|
}
|
|
.project-name {
|
position: absolute;
|
top: 40px;
|
left: 40px;
|
z-index: 9999;
|
font-weight: bolder;
|
background-image: linear-gradient(to right, #1850c1, #9c009c);
|
-webkit-background-clip: text;
|
color: transparent;
|
font-size: 25px;
|
}
|
|
// 响应式适配(复用你的逻辑)
|
@media screen and (max-width: 700px) {
|
.login-bg,
|
.project-name {
|
display: none;
|
}
|
|
.login-container {
|
padding: 2rem;
|
justify-content: center;
|
}
|
|
.login-form {
|
width: 100%;
|
}
|
|
.form-user,
|
.loging-btn,
|
.back-login-btn {
|
width: 100%;
|
}
|
}
|
</style>
|