From 06d52deb60040d968c3f69d625f9cd52ecbdac4c Mon Sep 17 00:00:00 2001 From: RuoYi <yzz_ivy@163.com> Date: 星期二, 22 四月 2025 11:48:56 +0800 Subject: [PATCH] 优化代码 --- src/views/login.vue | 55 +++++++++++++++++++++++++++++++++++++------------------ 1 files changed, 37 insertions(+), 18 deletions(-) diff --git a/src/views/login.vue b/src/views/login.vue index d69b165..e6856a0 100644 --- a/src/views/login.vue +++ b/src/views/login.vue @@ -1,11 +1,12 @@ <template> <div class="login"> <el-form ref="loginRef" :model="loginForm" :rules="loginRules" class="login-form"> - <h3 class="title">鑻ヤ緷鍚庡彴绠$悊绯荤粺</h3> + <h3 class="title">{{ title }}</h3> <el-form-item prop="username"> <el-input v-model="loginForm.username" type="text" + size="large" auto-complete="off" placeholder="璐﹀彿" > @@ -16,6 +17,7 @@ <el-input v-model="loginForm.password" type="password" + size="large" auto-complete="off" placeholder="瀵嗙爜" @keyup.enter="handleLogin" @@ -23,9 +25,10 @@ <template #prefix><svg-icon icon-class="password" class="el-input__icon input-icon" /></template> </el-input> </el-form-item> - <el-form-item prop="code" v-if="captchaOnOff"> + <el-form-item prop="code" v-if="captchaEnabled"> <el-input v-model="loginForm.code" + size="large" auto-complete="off" placeholder="楠岃瘉鐮�" style="width: 63%" @@ -41,7 +44,7 @@ <el-form-item style="width:100%;"> <el-button :loading="loading" - size="medium" + size="large" type="primary" style="width:100%;" @click.prevent="handleLogin" @@ -56,7 +59,7 @@ </el-form> <!-- 搴曢儴 --> <div class="el-login-footer"> - <span>Copyright 漏 2018-2021 ruoyi.vip All Rights Reserved.</span> + <span>Copyright 漏 2018-2025 ruoyi.vip All Rights Reserved.</span> </div> </div> </template> @@ -65,8 +68,11 @@ import { getCodeImg } from "@/api/login"; import Cookies from "js-cookie"; import { encrypt, decrypt } from "@/utils/jsencrypt"; +import useUserStore from '@/store/modules/user' -const store = useStore(); +const title = import.meta.env.VITE_APP_TITLE; +const userStore = useUserStore(); +const route = useRoute(); const router = useRouter(); const { proxy } = getCurrentInstance(); @@ -87,16 +93,20 @@ const codeUrl = ref(""); const loading = ref(false); // 楠岃瘉鐮佸紑鍏� -const captchaOnOff = ref(true); +const captchaEnabled = ref(true); // 娉ㄥ唽寮�鍏� const register = ref(false); const redirect = ref(undefined); + +watch(route, (newRoute) => { + redirect.value = newRoute.query && newRoute.query.redirect; +}, { immediate: true }); function handleLogin() { proxy.$refs.loginRef.validate(valid => { if (valid) { loading.value = true; - // 鍕鹃�変簡闇�瑕佽浣忓瘑鐮佽缃湪cookie涓缃浣忕敤鎴锋槑鍜屽悕鍛� + // 鍕鹃�変簡闇�瑕佽浣忓瘑鐮佽缃湪 cookie 涓缃浣忕敤鎴峰悕鍜屽瘑鐮� if (loginForm.value.rememberMe) { Cookies.set("username", loginForm.value.username, { expires: 30 }); Cookies.set("password", encrypt(loginForm.value.password), { expires: 30 }); @@ -108,12 +118,19 @@ Cookies.remove("rememberMe"); } // 璋冪敤action鐨勭櫥褰曟柟娉� - store.dispatch("Login", loginForm.value).then(() => { - router.push({ path: redirect.value || "/" }); + userStore.login(loginForm.value).then(() => { + const query = route.query; + const otherQueryParams = Object.keys(query).reduce((acc, cur) => { + if (cur !== "redirect") { + acc[cur] = query[cur]; + } + return acc; + }, {}); + router.push({ path: redirect.value || "/", query: otherQueryParams }); }).catch(() => { loading.value = false; // 閲嶆柊鑾峰彇楠岃瘉鐮� - if (captchaOnOff.value) { + if (captchaEnabled.value) { getCode(); } }); @@ -123,8 +140,8 @@ function getCode() { getCodeImg().then(res => { - captchaOnOff.value = res.captchaOnOff === undefined ? true : res.captchaOnOff; - if (captchaOnOff.value) { + captchaEnabled.value = res.captchaEnabled === undefined ? true : res.captchaEnabled; + if (captchaEnabled.value) { codeUrl.value = "data:image/gif;base64," + res.img; loginForm.value.uuid = res.uuid; } @@ -166,16 +183,17 @@ background: #ffffff; width: 400px; padding: 25px 25px 5px 25px; + z-index: 1; .el-input { - height: 38px; + height: 40px; input { - height: 38px; + height: 40px; } } .input-icon { height: 39px; width: 14px; - margin-left: 2px; + margin-left: 0px; } } .login-tip { @@ -185,7 +203,7 @@ } .login-code { width: 33%; - height: 38px; + height: 40px; float: right; img { cursor: pointer; @@ -205,6 +223,7 @@ letter-spacing: 1px; } .login-code-img { - height: 38px; + height: 40px; + padding-left: 12px; } -</style> \ No newline at end of file +</style> -- Gitblit v1.9.3