From 2af1fbd254995a0240afbd9bef3022e5bbbc603f Mon Sep 17 00:00:00 2001 From: fuliqi <fuliqi@qq.com> Date: 星期一, 04 三月 2024 09:39:56 +0800 Subject: [PATCH] 初始化 --- src/views/login.vue | 91 ++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 80 insertions(+), 11 deletions(-) diff --git a/src/views/login.vue b/src/views/login.vue index 95cff50..cf7c897 100644 --- a/src/views/login.vue +++ b/src/views/login.vue @@ -2,6 +2,7 @@ <div class="login"> <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form"> <h3 class="title">鑻ヤ緷鍚庡彴绠$悊绯荤粺</h3> + <el-form-item prop="username"> <el-input v-model="loginForm.username" @@ -54,21 +55,53 @@ </div> </el-form-item> </el-form> - <!-- 搴曢儴 --> - <div class="el-login-footer"> - <span>Copyright 漏 2018-2023 ruoyi.vip All Rights Reserved.</span> - </div> + + <el-dialog title="涓轰簡鎮ㄧ殑璐﹀彿瀹夊叏,棣栨鐧婚檰璇蜂慨鏀瑰瘑鐮�" :visible.sync="loginInfo.firstLogin==0?true:false"> + <el-form> + <el-form-item label="鏂板瘑鐮�"> + <el-input v-model="newPassword" autocomplete="off"></el-input> + </el-form-item> + <el-form-item label="璇风‘璁ゅ瘑鐮�"> + <el-input v-model="confirmPassword" autocomplete="off"></el-input> + </el-form-item> + </el-form> + <div slot="footer" class="dialog-footer"> + <el-button type="primary" @click="updatePwd">纭� 瀹�</el-button> + </div> + </el-dialog> </div> + + </template> <script> -import { getCodeImg } from "@/api/login"; +import { getCodeImg ,getInfo} from "@/api/login"; import Cookies from "js-cookie"; import { encrypt, decrypt } from '@/utils/jsencrypt' +import { updateUserPwd } from "@/api/system/user"; export default { + //鏂板瀵硅薄銆佸彉閲� name: "Login", data() { + const equalToPassword = (rule, value, callback) => { + if (this.newPassword !== value) { + callback(new Error("涓ゆ杈撳叆鐨勫瘑鐮佷笉涓�鑷�")); + } else { + callback(); + } + }; + const validatePassword = (rule, value, callback) => { + var regex = /(?=.*[0-9])(?=.*[A-Z])(?=.*[a-z])(?=.*[\W_])/; + if (value.length < 8 || value.length > 10) { + callback(new Error('璇疯緭鍏�8-10浣嶅ぇ鍐欏瓧姣�+灏忓啓瀛楁瘝+鏁板瓧+鐗规畩瀛楃')); + } + else if (!regex.test(value)) { + callback(new Error("璇疯緭鍏�8-10浣嶅ぇ鍐欏瓧姣�+灏忓啓瀛楁瘝+鏁板瓧+鐗规畩瀛楃")); + } else { + callback(); + } + }; return { codeUrl: "", loginForm: { @@ -78,6 +111,11 @@ code: "", uuid: "" }, + loginInfo: { + firstLogin: 1 + }, + newPassword: undefined, + confirmPassword: undefined, loginRules: { username: [ { required: true, trigger: "blur", message: "璇疯緭鍏ユ偍鐨勮处鍙�" } @@ -86,6 +124,16 @@ { required: true, trigger: "blur", message: "璇疯緭鍏ユ偍鐨勫瘑鐮�" } ], code: [{ required: true, trigger: "change", message: "璇疯緭鍏ラ獙璇佺爜" }] + }, + rules: { + newPassword: [ + { required: true, message: "鏂板瘑鐮佷笉鑳戒负绌�", trigger: "blur" }, + { required: true, validator: validatePassword, trigger: "blur" } + ], + confirmPassword: [ + { required: true, message: "纭瀵嗙爜涓嶈兘涓虹┖", trigger: "blur" }, + { required: true, validator: equalToPassword, trigger: "blur" } + ] }, loading: false, // 楠岃瘉鐮佸紑鍏� @@ -131,6 +179,7 @@ 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 }); @@ -140,19 +189,39 @@ Cookies.remove("password"); Cookies.remove('rememberMe'); } - this.$store.dispatch("Login", this.loginForm).then(() => { - this.$router.push({ path: this.redirect || "/" }).catch(()=>{}); + + this.$store.dispatch("Login", this.loginForm).then((res) => { + getInfo().then(loginInfo => { + this.loginInfo = loginInfo.user + //濡傛灉杩斿洖涓�1姝e父璺宠浆 + if(this.loginInfo.firstLogin == 1){ + this.$router.push({ path: this.redirect || "/" }).catch(()=>{}); + } else { + localStorage.setItem('firstLogin',0) + } + }).catch(()=>{}) }).catch(() => { this.loading = false; if (this.captchaEnabled) { this.getCode(); } }); + } + }); + }, + // 鏂板淇敼鏂规硶 + updatePwd(){ + updateUserPwd("", this.newPassword, 0).then(response => { + // 淇敼瀹屾垚灏唂irstLogin鏀逛负1 + localStorage.setItem('firstLogin', 1) + this.$modal.msgSuccess("淇敼鎴愬姛"); + this.$router.push({ path: this.redirect || "/" }).catch(() => {}); + }).catch((e) => { + console.info(e) + }); } - }); - } - } -}; + } + }; </script> <style rel="stylesheet/scss" lang="scss"> -- Gitblit v1.8.0