| | |
| | | <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="账号"
|
| | | >
|
| | |
| | | <el-input
|
| | | v-model="loginForm.password"
|
| | | type="password"
|
| | | size="large"
|
| | | auto-complete="off"
|
| | | placeholder="密码"
|
| | | @keyup.enter="handleLogin"
|
| | |
| | | <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%"
|
| | |
| | | <el-form-item style="width:100%;">
|
| | | <el-button
|
| | | :loading="loading"
|
| | | size="medium"
|
| | | size="large"
|
| | | type="primary"
|
| | | style="width:100%;"
|
| | | @click.prevent="handleLogin"
|
| | |
| | | </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>
|
| | |
| | | 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();
|
| | |
|
| | |
| | | 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 });
|
| | |
| | | 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();
|
| | | }
|
| | | });
|
| | |
| | |
|
| | | 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;
|
| | | }
|
| | |
| | | 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 {
|
| | |
| | | }
|
| | | .login-code {
|
| | | width: 33%;
|
| | | height: 38px;
|
| | | height: 40px;
|
| | | float: right;
|
| | | img {
|
| | | cursor: pointer;
|
| | |
| | | letter-spacing: 1px;
|
| | | }
|
| | | .login-code-img {
|
| | | height: 38px;
|
| | | height: 40px;
|
| | | padding-left: 12px;
|
| | | }
|
| | | </style> |
| | | </style>
|