Commit 6ff04972 authored by “yiyousong”'s avatar “yiyousong”

feat: 登录页添加修改密码功能

parent 05d0b025
...@@ -20,3 +20,7 @@ export function changePassword(params) { ...@@ -20,3 +20,7 @@ export function changePassword(params) {
export function editPassword(params) { export function editPassword(params) {
return http.post(`${baseURL}/zwfw/user/reset/password`, params); return http.post(`${baseURL}/zwfw/user/reset/password`, params);
} }
// 密码过期修改密码
export function changeForgotPassword(params) {
return http.post(`${baseURL}/zwfw/user/forgot/password`, params);
}
...@@ -59,7 +59,7 @@ axios.interceptors.response.use( ...@@ -59,7 +59,7 @@ axios.interceptors.response.use(
message.error({ message.error({
content: msg, content: msg,
maxCount: 1, maxCount: 1,
duration: 1, duration: 2,
}); });
store.commit("user/reset"); store.commit("user/reset");
router.push("/"); router.push("/");
......
...@@ -5,8 +5,16 @@ ...@@ -5,8 +5,16 @@
<p class="slogan-text slogan-text-1 mb-12">长江第一城</p> <p class="slogan-text slogan-text-1 mb-12">长江第一城</p>
<p class="slogan-text slogan-text-2">巴蜀醉宜宾</p> <p class="slogan-text slogan-text-2">巴蜀醉宜宾</p>
</div> </div>
<div class="w-[490px] h-[660px]">
<div class="swiper mySwiper">
<div class="swiper-wrapper">
<div class="swiper-slide">
<!-- 登录框 -->
<div class="login-box"> <div class="login-box">
<img class="w-[74px] mb-[20px]" src="@/assets/images/logo.png" /> <img
class="w-[74px] mb-[20px]"
src="@/assets/images/logo.png"
/>
<p class="login-text text-[40px] mb-[20px]">欢迎登录!</p> <p class="login-text text-[40px] mb-[20px]">欢迎登录!</p>
<p class="login-text text-[32px] mb-[30px]"> <p class="login-text text-[32px] mb-[30px]">
{{ sysName }} {{ sysName }}
...@@ -37,7 +45,7 @@ ...@@ -37,7 +45,7 @@
<a-form-model-item prop="password"> <a-form-model-item prop="password">
<a-input <a-input
placeholder="请输入密码" placeholder="请输入密码"
:type="iptType" :type="TypeForm.iptType"
v-model="form.password" v-model="form.password"
@pressEnter="handleSubmit" @pressEnter="handleSubmit"
> >
...@@ -51,14 +59,14 @@ ...@@ -51,14 +59,14 @@
src="@/assets/images/icon-close.png" src="@/assets/images/icon-close.png"
/> />
<i <i
v-if="iptType == 'password'" v-if="TypeForm.iptType == 'password'"
class="iconfont icon-hidden cursor-pointer" class="iconfont icon-hidden cursor-pointer"
@click="iptType = 'text'" @click="TypeForm.iptType = 'text'"
></i> ></i>
<i <i
v-else v-else
class="iconfont icon-show cursor-pointer" class="iconfont icon-show cursor-pointer"
@click="iptType = 'password'" @click="TypeForm.iptType = 'password'"
></i> ></i>
</a-space> </a-space>
</template> </template>
...@@ -83,24 +91,176 @@ ...@@ -83,24 +91,176 @@
</div> </div>
</a-form-model-item> </a-form-model-item>
<a-form-model-item> <a-form-model-item>
<a-button :loading="loading" class="login-btn" @click="handleSubmit" <a-button
:loading="loading"
class="login-btn"
@click="handleSubmit"
>登录</a-button >登录</a-button
> >
</a-form-model-item> </a-form-model-item>
</a-form-model> </a-form-model>
</div> </div>
</div> </div>
<div class="swiper-slide">
<!-- 修改密码框 -->
<div class="revamp-box">
<img
class="w-[74px] mb-[20px]"
src="@/assets/images/logo.png"
/>
<p class="login-text text-[40px] mb-[20px]">请修改密码</p>
<p class="login-text text-[32px] mb-[30px]">
密码有效期为三个月
</p>
<a-form-model
:model="changePwdForm"
ref="changePwdForm"
:rules="PwdFormRules"
:label-col="labelCol"
:wrapper-col="wrapperCol"
>
<a-form-model-item prop="loginName">
<a-input
placeholder="请输入用户名"
v-model="changePwdForm.loginName"
@pressEnter="changePwd"
>
<img slot="prefix" src="@/assets/images/icon-user.png" />
<img
slot="suffix"
v-show="changePwdForm.loginName"
class="cursor-pointer"
@click="changePwdForm.loginName = ''"
src="@/assets/images/icon-close.png"
/>
</a-input>
</a-form-model-item>
<a-form-model-item prop="oldPwd">
<a-input
placeholder="请输入原密码"
:type="TypeForm.oldType"
v-model="changePwdForm.oldPwd"
@pressEnter="changePwd"
>
<img slot="prefix" src="@/assets/images/icon-user.png" />
<template slot="suffix">
<a-space>
<img
v-show="changePwdForm.oldPwd"
class="cursor-pointer"
@click="changePwdForm.oldPwd = ''"
src="@/assets/images/icon-close.png"
/>
<i
v-if="TypeForm.oldType == 'password'"
class="iconfont icon-hidden cursor-pointer"
@click="TypeForm.oldType = 'text'"
></i>
<i
v-else
class="iconfont icon-show cursor-pointer"
@click="TypeForm.oldType = 'password'"
></i>
</a-space>
</template>
</a-input>
</a-form-model-item>
<a-form-model-item prop="newPwd">
<a-input
placeholder="请输入新密码"
:type="TypeForm.newType"
v-model="changePwdForm.newPwd"
@pressEnter="changePwd"
>
<img slot="prefix" src="@/assets/images/icon-user.png" />
<template slot="suffix">
<a-space>
<img
v-show="changePwdForm.newPwd"
class="cursor-pointer"
@click="changePwdForm.newPwd = ''"
src="@/assets/images/icon-close.png"
/>
<i
v-if="TypeForm.newType == 'password'"
class="iconfont icon-hidden cursor-pointer"
@click="TypeForm.newType = 'text'"
></i>
<i
v-else
class="iconfont icon-show cursor-pointer"
@click="TypeForm.newType = 'password'"
></i>
</a-space>
</template>
</a-input>
</a-form-model-item>
<a-form-model-item prop="newPwdAgain">
<a-input
placeholder="请再次输入新密码"
:type="TypeForm.newAgainType"
v-model="changePwdForm.newPwdAgain"
@pressEnter="changePwd"
>
<img slot="prefix" src="@/assets/images/icon-user.png" />
<template slot="suffix">
<a-space>
<img
v-show="changePwdForm.newPwdAgain"
class="cursor-pointer"
@click="changePwdForm.newPwdAgain = ''"
src="@/assets/images/icon-close.png"
/>
<i
v-if="TypeForm.newAgainType == 'password'"
class="iconfont icon-hidden cursor-pointer"
@click="TypeForm.newAgainType = 'text'"
></i>
<i
v-else
class="iconfont icon-show cursor-pointer"
@click="TypeForm.newAgainType = 'password'"
></i>
</a-space>
</template>
</a-input>
</a-form-model-item>
<a-form-model-item>
<a-button
:loading="changeloading"
class="login-btn"
@click="changePwd"
>确认</a-button
>
</a-form-model-item>
</a-form-model>
</div>
</div>
</div>
</div>
</div>
</div>
</div> </div>
</template> </template>
<script> <script>
import { LoginInterface } from "@/api/user.js"; import Swiper from "swiper";
import { LoginInterface, changeForgotPassword } from "@/api/user.js";
import { mapMutations, mapState } from "vuex"; import { mapMutations, mapState } from "vuex";
import { changeAccount } from "@/utils/js/validate"; import { changeAccount, changePassWord } from "@/utils/js/validate";
import { encrypt } from "@/utils"; import { encrypt } from "@/utils";
import storage from "@/utils/js/Storage"; import storage from "@/utils/js/Storage";
export default { export default {
data() { data() {
const changePwdAgain = (rule, value, callback) => {
if (!value) {
callback(new Error("请再次输入密码"));
} else if (value !== this.changePwdForm.newPwd) {
callback(new Error("两次密码输入不一致"));
} else {
callback();
}
};
return { return {
sysName: process.env.VUE_APP_systemName, sysName: process.env.VUE_APP_systemName,
labelCol: { span: 0 }, labelCol: { span: 0 },
...@@ -108,7 +268,13 @@ export default { ...@@ -108,7 +268,13 @@ export default {
api: process.env.VUE_APP_API_BASE_URL, api: process.env.VUE_APP_API_BASE_URL,
loading: false, loading: false,
imgCode: "", imgCode: "",
iptType: "password", changeloading: false,
TypeForm: {
iptType: "password", // 登录密码输入框切换
oldType: "password", // 原密码输入框切换
newType: "password", // 新密码输入框切换
newAgainType: "password", // 再次输入新密码输入框切换
},
form: { form: {
loginName: "", loginName: "",
password: "", password: "",
...@@ -116,6 +282,12 @@ export default { ...@@ -116,6 +282,12 @@ export default {
mark: "", mark: "",
type: 2, type: 2,
}, },
changePwdForm: {
loginName: "",
oldPwd: "", // 原密码
newPwd: "", // 新密码
newPwdAgain: "", // 新密码
},
rules: { rules: {
loginName: [ loginName: [
{ required: true, validator: changeAccount, trigger: "blur" }, { required: true, validator: changeAccount, trigger: "blur" },
...@@ -125,6 +297,20 @@ export default { ...@@ -125,6 +297,20 @@ export default {
{ required: true, message: "请输入验证码", trigger: "blur" }, { required: true, message: "请输入验证码", trigger: "blur" },
], ],
}, },
PwdFormRules: {
loginName: [
{ required: true, validator: changeAccount, trigger: "blur" },
],
oldPwd: [
{ required: true, validator: changePassWord, trigger: "blur" },
],
newPwd: [
{ required: true, validator: changePassWord, trigger: "blur" },
],
newPwdAgain: [
{ required: true, validator: changePwdAgain, trigger: "blur" },
],
},
}; };
}, },
computed: { computed: {
...@@ -136,8 +322,38 @@ export default { ...@@ -136,8 +322,38 @@ export default {
} }
this.createCode(); this.createCode();
}, },
mounted() {
this.initSwiper();
},
methods: { methods: {
...mapMutations("user", ["set_token", "SET_USERDATA", "set_siteList"]), ...mapMutations("user", ["set_token", "SET_USERDATA", "set_siteList"]),
initSwiper() {
this.mySwiper = new Swiper(".mySwiper", {
effect: "cube", // 方块动画
speed: 1000, // 时长
simulateTouch: false, //禁止鼠标滑动切换
grabCursor: false, // 手形鼠标
cubeEffect: {
shadow: false, // 取消盒子阴影
slideShadows: false, // 取消子项拖动时候的阴影
// shadowOffset: 20,
// shadowScale: 0.94,
},
on: {
slideChange: () => {
// 初始化密码框类型
Object.assign(this.TypeForm, this.$options.data().TypeForm);
this.loading = false;
this.changeloading = false;
this.$refs.changePwdForm.resetFields();
this.$refs.form.resetFields();
this.createCode();
},
},
});
this.mySwiper.init();
},
// 获取验证码 // 获取验证码
createCode() { createCode() {
// 加时间戳印记用于刷新gif // 加时间戳印记用于刷新gif
...@@ -155,7 +371,7 @@ export default { ...@@ -155,7 +371,7 @@ export default {
loginName: encrypt(this.form.loginName), loginName: encrypt(this.form.loginName),
password: encrypt(this.form.password), password: encrypt(this.form.password),
}); });
let { code, data } = res; let { code, data, msg } = res;
if (code == 1) { if (code == 1) {
let { siteList, user, token } = data; let { siteList, user, token } = data;
this.set_token(token); this.set_token(token);
...@@ -168,6 +384,11 @@ export default { ...@@ -168,6 +384,11 @@ export default {
setTimeout(() => { setTimeout(() => {
this.$router.push("/home"); this.$router.push("/home");
}, 20); }, 20);
} else if (code == 99998) {
this.$message.error(msg);
setTimeout(() => {
this.mySwiper.slideTo(1);
}, 500);
} else { } else {
this.createCode(); this.createCode();
} }
...@@ -175,6 +396,29 @@ export default { ...@@ -175,6 +396,29 @@ export default {
} }
}); });
}, },
// 修改密码
changePwd() {
this.$refs.changePwdForm.validate(async (valid) => {
if (valid) {
this.changeloading = true;
let obj = {
loginName: this.changePwdForm.loginName,
oldPwd: encrypt(this.changePwdForm.oldPwd),
newPwd: encrypt(this.changePwdForm.newPwd),
};
let res = await changeForgotPassword(obj);
this.changeloading = false;
let { msg, code } = res;
if (code == 1) {
this.$message.success(msg);
setTimeout(() => {
this.mySwiper.slideTo(0);
}, 500);
}
}
});
},
}, },
}; };
</script> </script>
...@@ -243,9 +487,14 @@ export default { ...@@ -243,9 +487,14 @@ export default {
margin-left: 1em; margin-left: 1em;
animation: var(--time) printText var(--time) steps(5) both; animation: var(--time) printText var(--time) steps(5) both;
} }
.login-box { .swiper {
width: 490px; width: 100%;
height: 660px; height: 100%;
}
.login-box,
.revamp-box {
width: 100%;
height: 100%;
padding: 60px 34px; padding: 60px 34px;
background: url("@/assets/images/login_box_bg.png") center; background: url("@/assets/images/login_box_bg.png") center;
background-size: 100% 100%; background-size: 100% 100%;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment