From 8022f7036945b75f82f2dfc43055623f81ed98f6 Mon Sep 17 00:00:00 2001 From: yxh <172933527@qq.com> Date: 星期五, 23 五月 2025 22:42:56 +0800 Subject: [PATCH] yxh --- src/views/login.vue | 164 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 135 insertions(+), 29 deletions(-) diff --git a/src/views/login.vue b/src/views/login.vue index 113f8c7..aac1184 100644 --- a/src/views/login.vue +++ b/src/views/login.vue @@ -1,25 +1,43 @@ <template> <div class="login"> - <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form"> + <el-form + ref="loginForm" + :model="loginForm" + :rules="loginRules" + class="login-form" + > <h3 class="title">娴欐睙鐪丱PO鏁板瓧鍖栫鐞嗗钩鍙�</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 + 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" + auto-complete="off" @focus="tip" placeholder="瀵嗙爜" @keyup.enter.native="handleLogin" > - <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" /> + <svg-icon + slot="prefix" + icon-class="password" + class="el-input__icon input-icon" + /> </el-input> </el-form-item> - <br> + <br /> <el-form-item prop="code" v-if="captchaOnOff"> <el-input v-model="loginForm.code" @@ -28,13 +46,21 @@ style="width: 63%" @keyup.enter.native="handleLogin" > - <svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" /> + <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"/> + <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-checkbox + v-model="loginForm.rememberMe" + style="margin:0px 0px 25px 0px;" + >璁颁綇瀵嗙爜</el-checkbox + > <el-form-item style="width:100%;"> <el-button :loading="loading" @@ -47,7 +73,9 @@ <span v-else>鐧� 褰� 涓�...</span> </el-button> <div style="float: right;" v-if="register"> - <router-link class="link-type" :to="'/register'">绔嬪嵆娉ㄥ唽</router-link> + <router-link class="link-type" :to="'/register'" + >绔嬪嵆娉ㄥ唽</router-link + > </div> </el-form-item> </el-form> @@ -61,13 +89,14 @@ <script> import { getCodeImg } from "@/api/login"; import Cookies from "js-cookie"; -import { encrypt, decrypt } from '@/utils/jsencrypt' +import { encrypt, decrypt } from "@/utils/jsencrypt"; export default { name: "Login", data() { return { codeUrl: "", + authCode: "", cookiePassword: "", loginForm: { username: "", @@ -81,13 +110,18 @@ { required: true, trigger: "blur", message: "璇疯緭鍏ユ偍鐨勮处鍙�" } ], password: [ - { required: true, trigger: "blur", message: "瀵嗙爜蹇呴』鍖呭惈澶у皬鍐欏瓧姣嶃�佹暟瀛椼�佺壒娈婂瓧绗︿腑鐨勮嚦灏戜笁绉嶄笖闀垮害澶т簬绛変簬8浣�" } - ], + { + required: true, + trigger: "blur", + message: + "瀵嗙爜蹇呴』鍖呭惈澶у皬鍐欏瓧姣嶃�佹暟瀛椼�佺壒娈婂瓧绗︿腑鐨勮嚦灏戜笁绉嶄笖闀垮害澶т簬绛変簬8浣�" + } + ] // code: [{ required: true, trigger: "change", message: "璇疯緭鍏ラ獙璇佺爜" }] }, loading: false, // 楠岃瘉鐮佸紑鍏� - captchaOnOff: false, + captchaOnOff: true, // 娉ㄥ唽寮�鍏� register: false, redirect: undefined @@ -104,27 +138,72 @@ created() { this.getCode(); this.getCookie(); + this.getAuthCode(); + // this.avoidLogin(); }, methods: { - tip(){ + tip() { //console.log('awdawd',鑱氱劍); }, getCode() { getCodeImg().then(res => { - this.captchaOnOff = res.captchaOnOff === undefined ? true : res.captchaOnOff; + this.captchaOnOff = + res.captchaOnOff === undefined ? true : res.captchaOnOff; if (this.captchaOnOff) { this.codeUrl = "data:image/gif;base64," + res.img; this.loginForm.uuid = res.uuid; } }); }, + getAuthCode() { + this.$dingtalk.runtime.permission.requestAuthCode({ + corpId: "dingd31f00f4fbc0ff5bf5bf40eda33b7ba0", + onSuccess: result => { + // 鍦ㄨ繖閲屽鐞嗘巿鏉冩垚鍔熷悗鐨勯�昏緫锛宺esult涓寘鍚巿鏉冪爜绛変俊鎭� + // this.authCode = result.codde; + this.$message.success("鎴愬姛鑾峰彇鎺堟潈鐮侊細" + result.code); + this.avoidLogin(result.code); + }, + onFail: err => { + // 鍦ㄨ繖閲屽鐞嗘巿鏉冨け璐ュ悗鐨勯�昏緫 + this.$message({ + type: "error", + message: err + }); + } + }); + }, + avoidLogin(authCode) { + this.loading = true; + // this.$message.error(authCode, "1鍙蜂綅"); + this.loginForm.authCode = authCode; + this.$store + .dispatch("Login", this.loginForm) + .then(res => { + if (this.$store.state.user.code == 200) { + this.$router.push({ path: this.redirect || "/" }).catch(() => {}); + } else { + this.loading = false; + // this.$message.error(this.$store.state.user.msg); + } + }) + .catch(err => { + console.log(err); + this.loading = false; + this.$message.error("鍏嶇櫥闄嗗け璐ヨ鎵嬪姩鎿嶄綔銆�"); + if (this.captchaOnOff) { + this.getCode(); + } + }); + }, getCookie() { const username = Cookies.get("username"); const password = Cookies.get("password"); - const rememberMe = Cookies.get('rememberMe') + const rememberMe = Cookies.get("rememberMe"); this.loginForm = { username: username === undefined ? this.loginForm.username : username, - password: password === undefined ? this.loginForm.password : decrypt(password), + password: + password === undefined ? this.loginForm.password : decrypt(password), rememberMe: rememberMe === undefined ? false : Boolean(rememberMe) }; }, @@ -134,21 +213,39 @@ 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 }); + 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'); + Cookies.remove("rememberMe"); } - this.$store.dispatch("Login", this.loginForm).then(() => { - this.$router.push({ path: this.redirect || "/" }).catch(()=>{}); - }).catch(() => { - this.loading = false; - if (this.captchaOnOff) { - this.getCode(); - } - }); + this.$store + .dispatch("Login", this.loginForm) + .then(res => { + console.log(this.$store.state.user.code, "44"); + console.log(this.$store.state.user.msg, "22"); + if (this.$store.state.user.code == 200) { + this.$router + .push({ path: this.redirect || "/" }) + .catch(() => {}); + } else { + this.loading = false; + this.$message.error(this.$store.state.user.msg); + } + }) + .catch(err => { + console.log(err); + this.loading = false; + // this.$message.error("鐧婚檰澶辫触璇烽噸璇曘��"); + if (this.captchaOnOff) { + this.getCode(); + } + }); } }); } @@ -162,6 +259,15 @@ justify-content: center; align-items: center; height: 100%; + background-position: center center; + /* 鑳屾櫙鍥句笉骞抽摵 */ + background-repeat: no-repeat; + /* 褰撳唴瀹归珮搴﹀ぇ浜庡浘鐗囬珮搴︽椂锛岃儗鏅浘鍍忕殑浣嶇疆鐩稿浜巚iewport鍥哄畾 */ + background-attachment: fixed; + /* 璁╄儗鏅浘鍩轰簬瀹瑰櫒澶у皬浼哥缉 */ + background-size: cover; + /* 璁剧疆鑳屾櫙棰滆壊锛岃儗鏅浘鍔犺浇杩囩▼涓細鏄剧ず鑳屾櫙鑹� */ + background-color: #464646; background-image: url("../assets/images/login-bgc.jpg"); background-size: cover; } -- Gitblit v1.9.3