2021-11-19 23:55:14 +08:00
|
|
|
|
<template>
|
2022-05-08 13:06:12 +08:00
|
|
|
|
<div class="login-container">
|
2023-10-30 07:43:50 +08:00
|
|
|
|
<!-- 顶部 -->
|
2023-11-05 17:17:28 +08:00
|
|
|
|
<div class="absolute top-0 flex items-center justify-end px-5 h-20 w-full">
|
2023-10-30 07:43:50 +08:00
|
|
|
|
<el-switch
|
|
|
|
|
|
v-model="isDark"
|
|
|
|
|
|
inline-prompt
|
|
|
|
|
|
:active-icon="IconEpMoon"
|
|
|
|
|
|
:inactive-icon="IconEpSunny"
|
|
|
|
|
|
active-color="var(--el-fill-color-dark)"
|
|
|
|
|
|
inactive-color="var(--el-color-primary)"
|
2023-11-05 10:52:36 +08:00
|
|
|
|
@change="handleThemeChange"
|
2023-10-30 07:43:50 +08:00
|
|
|
|
/>
|
2023-11-05 17:17:28 +08:00
|
|
|
|
<lang-select class="ml-2 cursor-pointer" />
|
2023-10-30 07:43:50 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<!-- 登录表单 -->
|
|
|
|
|
|
<el-card
|
|
|
|
|
|
class="z-1 !border-none w-100 !bg-transparent !rounded-4% <sm:w-83"
|
2023-03-25 01:17:59 +08:00
|
|
|
|
>
|
2023-11-05 17:17:28 +08:00
|
|
|
|
<div class="text-center relative">
|
2023-11-16 22:46:28 +08:00
|
|
|
|
<h2>{{ title }}</h2>
|
|
|
|
|
|
<el-tag class="ml-2 absolute top-0 right-0">{{ version }}</el-tag>
|
2023-11-05 17:17:28 +08:00
|
|
|
|
</div>
|
2023-10-30 07:43:50 +08:00
|
|
|
|
<el-form
|
|
|
|
|
|
ref="loginFormRef"
|
|
|
|
|
|
:model="loginData"
|
|
|
|
|
|
:rules="loginRules"
|
|
|
|
|
|
class="login-form"
|
2023-03-25 01:17:59 +08:00
|
|
|
|
>
|
2023-10-30 07:43:50 +08:00
|
|
|
|
<el-form-item prop="username">
|
|
|
|
|
|
<div class="p-2">
|
|
|
|
|
|
<svg-icon icon-class="user" />
|
|
|
|
|
|
</div>
|
2023-03-25 01:17:59 +08:00
|
|
|
|
<el-input
|
2023-10-30 07:43:50 +08:00
|
|
|
|
ref="username"
|
|
|
|
|
|
v-model="loginData.username"
|
2023-05-16 01:05:37 +08:00
|
|
|
|
class="flex-1"
|
2023-03-25 01:17:59 +08:00
|
|
|
|
size="large"
|
2023-10-30 07:43:50 +08:00
|
|
|
|
:placeholder="$t('login.username')"
|
|
|
|
|
|
name="username"
|
2023-03-25 01:17:59 +08:00
|
|
|
|
/>
|
2022-05-08 13:06:12 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
2023-10-30 07:43:50 +08:00
|
|
|
|
<el-tooltip
|
|
|
|
|
|
:disabled="isCapslock === false"
|
|
|
|
|
|
content="Caps lock is On"
|
|
|
|
|
|
placement="right"
|
|
|
|
|
|
>
|
|
|
|
|
|
<el-form-item prop="password">
|
|
|
|
|
|
<span class="p-2">
|
|
|
|
|
|
<svg-icon icon-class="password" />
|
|
|
|
|
|
</span>
|
|
|
|
|
|
<el-input
|
|
|
|
|
|
v-model="loginData.password"
|
|
|
|
|
|
class="flex-1"
|
|
|
|
|
|
:placeholder="$t('login.password')"
|
|
|
|
|
|
:type="passwordVisible === false ? 'password' : 'input'"
|
|
|
|
|
|
size="large"
|
|
|
|
|
|
name="password"
|
|
|
|
|
|
@keyup="checkCapslock"
|
|
|
|
|
|
@keyup.enter="handleLogin"
|
|
|
|
|
|
/>
|
|
|
|
|
|
<span class="mr-2" @click="passwordVisible = !passwordVisible">
|
|
|
|
|
|
<svg-icon
|
|
|
|
|
|
:icon-class="passwordVisible === false ? 'eye' : 'eye-open'"
|
|
|
|
|
|
class="cursor-pointer"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</span>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</el-tooltip>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 验证码 -->
|
|
|
|
|
|
<el-form-item prop="verifyCode">
|
|
|
|
|
|
<span class="p-2">
|
|
|
|
|
|
<svg-icon icon-class="verify-code" />
|
|
|
|
|
|
</span>
|
2023-03-24 22:40:29 +08:00
|
|
|
|
|
2023-10-30 07:43:50 +08:00
|
|
|
|
<el-input
|
|
|
|
|
|
v-model="loginData.verifyCode"
|
|
|
|
|
|
auto-complete="off"
|
|
|
|
|
|
:placeholder="$t('login.verifyCode')"
|
|
|
|
|
|
class="w-[60%]"
|
|
|
|
|
|
@keyup.enter="handleLogin"
|
|
|
|
|
|
/>
|
2023-03-24 22:40:29 +08:00
|
|
|
|
|
2023-10-30 07:43:50 +08:00
|
|
|
|
<div class="captcha">
|
2023-11-03 17:27:09 +08:00
|
|
|
|
<el-image
|
|
|
|
|
|
:src="captchaBase64"
|
|
|
|
|
|
@click="getCaptcha"
|
|
|
|
|
|
class="w-[120px] h-[48px] cursor-pointer"
|
|
|
|
|
|
>
|
|
|
|
|
|
<template #error>
|
|
|
|
|
|
<div class="image-slot">
|
|
|
|
|
|
<i-ep-picture />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-image>
|
2023-10-30 07:43:50 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</el-form-item>
|
2022-05-08 13:06:12 +08:00
|
|
|
|
|
2023-10-30 07:43:50 +08:00
|
|
|
|
<el-button
|
|
|
|
|
|
:loading="loading"
|
|
|
|
|
|
type="primary"
|
|
|
|
|
|
class="w-full"
|
|
|
|
|
|
@click.prevent="handleLogin"
|
|
|
|
|
|
>{{ $t("login.login") }}
|
|
|
|
|
|
</el-button>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 账号密码提示 -->
|
|
|
|
|
|
<div class="mt-10 text-sm">
|
|
|
|
|
|
<span>{{ $t("login.username") }}: admin</span>
|
|
|
|
|
|
<span class="ml-4"> {{ $t("login.password") }}: 123456</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</el-form>
|
|
|
|
|
|
</el-card>
|
2023-11-02 23:33:09 +08:00
|
|
|
|
|
|
|
|
|
|
<!-- ICP备案 -->
|
2023-11-10 08:13:14 +08:00
|
|
|
|
<div
|
|
|
|
|
|
class="absolute bottom-1 text-[10px] text-center"
|
|
|
|
|
|
v-show="useAppStore().device == 'desktop'"
|
|
|
|
|
|
>
|
2023-11-02 23:33:09 +08:00
|
|
|
|
<p>
|
|
|
|
|
|
Copyright © 2021 - 2023 youlai.tech All Rights Reserved. 有来技术
|
|
|
|
|
|
版权所有
|
|
|
|
|
|
</p>
|
2023-11-10 08:13:14 +08:00
|
|
|
|
<p>皖ICP备20006496号-3</p>
|
2023-11-02 23:33:09 +08:00
|
|
|
|
</div>
|
2022-05-08 13:06:12 +08:00
|
|
|
|
</div>
|
2021-11-19 23:55:14 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
2022-02-27 01:08:09 +08:00
|
|
|
|
<script setup lang="ts">
|
2023-09-26 18:24:04 +08:00
|
|
|
|
import { useI18n } from "vue-i18n";
|
2023-04-15 23:51:27 +08:00
|
|
|
|
import router from "@/router";
|
|
|
|
|
|
import LangSelect from "@/components/LangSelect/index.vue";
|
|
|
|
|
|
import SvgIcon from "@/components/SvgIcon/index.vue";
|
2023-10-30 07:43:50 +08:00
|
|
|
|
import IconEpSunny from "~icons/ep/sunny";
|
|
|
|
|
|
import IconEpMoon from "~icons/ep/moon";
|
2023-11-05 10:52:36 +08:00
|
|
|
|
import { useSettingsStore } from "@/store/modules/settings";
|
2022-03-01 23:41:26 +08:00
|
|
|
|
|
|
|
|
|
|
// 状态管理依赖
|
2023-04-15 23:51:27 +08:00
|
|
|
|
import { useUserStore } from "@/store/modules/user";
|
2023-09-26 18:24:04 +08:00
|
|
|
|
import { useAppStore } from "@/store/modules/app";
|
2022-02-27 01:08:09 +08:00
|
|
|
|
|
|
|
|
|
|
// API依赖
|
2023-04-15 23:51:27 +08:00
|
|
|
|
import { LocationQuery, LocationQueryValue, useRoute } from "vue-router";
|
|
|
|
|
|
import { getCaptchaApi } from "@/api/auth";
|
|
|
|
|
|
import { LoginData } from "@/api/auth/types";
|
2022-02-27 01:08:09 +08:00
|
|
|
|
|
2023-11-16 22:46:28 +08:00
|
|
|
|
const settingsStore = useSettingsStore();
|
|
|
|
|
|
|
|
|
|
|
|
const { title, version } = settingsStore;
|
2023-11-10 08:13:14 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 明亮/暗黑主题切换
|
|
|
|
|
|
*/
|
2023-11-05 17:17:28 +08:00
|
|
|
|
const isDark = ref<boolean>(settingsStore.theme === "dark");
|
2023-11-10 08:13:14 +08:00
|
|
|
|
const handleThemeChange = (isDark: any) => {
|
2023-11-05 17:17:28 +08:00
|
|
|
|
useToggle(isDark);
|
|
|
|
|
|
settingsStore.changeSetting({
|
2023-11-05 10:52:36 +08:00
|
|
|
|
key: "theme",
|
2023-11-05 17:17:28 +08:00
|
|
|
|
value: isDark ? "dark" : "light",
|
2023-11-05 10:52:36 +08:00
|
|
|
|
});
|
2023-11-08 22:22:38 +08:00
|
|
|
|
};
|
2023-11-05 10:52:36 +08:00
|
|
|
|
|
2023-03-25 09:28:48 +08:00
|
|
|
|
/**
|
2023-11-10 08:13:14 +08:00
|
|
|
|
* 根据屏幕宽度切换设备模式
|
2023-03-25 09:28:48 +08:00
|
|
|
|
*/
|
2023-11-10 08:13:14 +08:00
|
|
|
|
const appStore = useAppStore();
|
|
|
|
|
|
const WIDTH = 992; // 响应式布局容器固定宽度 大屏(>=1200px) 中屏(>=992px) 小屏(>=768px)
|
|
|
|
|
|
const { width } = useWindowSize();
|
|
|
|
|
|
watchEffect(() => {
|
|
|
|
|
|
if (width.value < WIDTH) {
|
|
|
|
|
|
appStore.toggleDevice("mobile");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
appStore.toggleDevice("desktop");
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2023-03-25 09:28:48 +08:00
|
|
|
|
|
2023-11-10 08:13:14 +08:00
|
|
|
|
const loading = ref(false); // 按钮loading
|
|
|
|
|
|
const isCapslock = ref(false); // 是否大写锁定
|
|
|
|
|
|
const passwordVisible = ref(false); // 密码是否可见
|
|
|
|
|
|
const captchaBase64 = ref(); // 验证码图片Base64字符串
|
|
|
|
|
|
const loginFormRef = ref(ElForm); // 登录表单ref
|
2022-02-27 01:08:09 +08:00
|
|
|
|
|
2023-03-01 00:55:41 +08:00
|
|
|
|
const loginData = ref<LoginData>({
|
2023-04-15 23:51:27 +08:00
|
|
|
|
username: "admin",
|
|
|
|
|
|
password: "123456",
|
2022-03-11 00:07:34 +08:00
|
|
|
|
});
|
2022-02-27 01:08:09 +08:00
|
|
|
|
|
2023-09-26 18:24:04 +08:00
|
|
|
|
const { t } = useI18n();
|
|
|
|
|
|
const loginRules = computed(() => {
|
|
|
|
|
|
const prefix = appStore.language === "en" ? "Please enter " : "请输入";
|
|
|
|
|
|
return {
|
|
|
|
|
|
username: [
|
|
|
|
|
|
{
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
trigger: "blur",
|
|
|
|
|
|
message: `${prefix}${t("login.username")}`,
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
|
|
|
|
|
password: [
|
|
|
|
|
|
{
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
trigger: "blur",
|
2023-11-10 08:13:14 +08:00
|
|
|
|
validator: (rule: any, value: any, callback: any) => {
|
|
|
|
|
|
if (value.length < 6) {
|
|
|
|
|
|
callback(new Error("The password can not be less than 6 digits"));
|
|
|
|
|
|
} else {
|
|
|
|
|
|
callback();
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2023-09-26 18:24:04 +08:00
|
|
|
|
message: `${prefix}${t("login.password")}`,
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
|
|
|
|
|
verifyCode: [
|
|
|
|
|
|
{
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
trigger: "blur",
|
|
|
|
|
|
message: `${prefix}${t("login.verifyCode")}`,
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
|
|
|
|
|
};
|
|
|
|
|
|
});
|
2023-02-06 01:07:35 +08:00
|
|
|
|
|
2023-03-25 09:28:48 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 检查输入大小写状态
|
|
|
|
|
|
*/
|
2022-02-27 01:08:09 +08:00
|
|
|
|
function checkCapslock(e: any) {
|
2022-05-08 13:06:12 +08:00
|
|
|
|
const { key } = e;
|
2023-04-15 23:51:27 +08:00
|
|
|
|
isCapslock.value = key && key.length === 1 && key >= "A" && key <= "Z";
|
2022-02-27 01:08:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-09-13 07:44:55 +08:00
|
|
|
|
/**
|
2023-03-25 09:28:48 +08:00
|
|
|
|
* 获取验证码
|
2023-03-24 22:40:29 +08:00
|
|
|
|
*/
|
|
|
|
|
|
function getCaptcha() {
|
|
|
|
|
|
getCaptchaApi().then(({ data }) => {
|
2023-11-05 10:52:36 +08:00
|
|
|
|
const { captchaImgBase64, verifyCodeKey } = data;
|
2023-03-24 22:40:29 +08:00
|
|
|
|
loginData.value.verifyCodeKey = verifyCodeKey;
|
2023-11-05 10:52:36 +08:00
|
|
|
|
captchaBase64.value = captchaImgBase64;
|
2023-03-24 22:40:29 +08:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 登录
|
2022-09-13 07:44:55 +08:00
|
|
|
|
*/
|
2023-11-10 08:13:14 +08:00
|
|
|
|
const route = useRoute();
|
|
|
|
|
|
const userStore = useUserStore();
|
2022-02-27 01:08:09 +08:00
|
|
|
|
function handleLogin() {
|
2022-05-08 13:06:12 +08:00
|
|
|
|
loginFormRef.value.validate((valid: boolean) => {
|
|
|
|
|
|
if (valid) {
|
2023-02-06 01:07:35 +08:00
|
|
|
|
loading.value = true;
|
2022-12-18 15:27:53 +08:00
|
|
|
|
userStore
|
2023-02-06 01:07:35 +08:00
|
|
|
|
.login(loginData.value)
|
2022-05-08 13:06:12 +08:00
|
|
|
|
.then(() => {
|
2023-02-06 01:07:35 +08:00
|
|
|
|
const query: LocationQuery = route.query;
|
|
|
|
|
|
|
2023-04-15 23:51:27 +08:00
|
|
|
|
const redirect = (query.redirect as LocationQueryValue) ?? "/";
|
2023-02-06 01:07:35 +08:00
|
|
|
|
|
|
|
|
|
|
const otherQueryParams = Object.keys(query).reduce(
|
|
|
|
|
|
(acc: any, cur: string) => {
|
2023-04-15 23:51:27 +08:00
|
|
|
|
if (cur !== "redirect") {
|
2023-02-06 01:07:35 +08:00
|
|
|
|
acc[cur] = query[cur];
|
|
|
|
|
|
}
|
|
|
|
|
|
return acc;
|
|
|
|
|
|
},
|
|
|
|
|
|
{}
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
router.push({ path: redirect, query: otherQueryParams });
|
2022-05-08 13:06:12 +08:00
|
|
|
|
})
|
2023-03-25 09:28:48 +08:00
|
|
|
|
.catch(() => {
|
|
|
|
|
|
// 验证失败,重新生成验证码
|
|
|
|
|
|
getCaptcha();
|
|
|
|
|
|
})
|
2023-02-06 01:07:35 +08:00
|
|
|
|
.finally(() => {
|
|
|
|
|
|
loading.value = false;
|
2022-05-08 13:06:12 +08:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2022-02-27 01:08:09 +08:00
|
|
|
|
}
|
2023-03-24 22:40:29 +08:00
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
|
getCaptcha();
|
2023-11-03 14:29:03 +08:00
|
|
|
|
|
|
|
|
|
|
// 主题初始化
|
|
|
|
|
|
const theme = useSettingsStore().theme;
|
|
|
|
|
|
useSettingsStore().changeSetting({ key: "theme", value: theme });
|
|
|
|
|
|
if (theme == "dark") {
|
|
|
|
|
|
document.documentElement.classList.add("dark");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
document.documentElement.classList.remove("dark");
|
|
|
|
|
|
}
|
2023-03-24 22:40:29 +08:00
|
|
|
|
});
|
2021-11-19 23:55:14 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2023-11-02 23:33:09 +08:00
|
|
|
|
.dark .login-container {
|
|
|
|
|
|
background: url("@/assets/images/login-bg-dark.jpg") no-repeat center right;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-11-19 23:55:14 +08:00
|
|
|
|
.login-container {
|
2023-11-02 23:33:09 +08:00
|
|
|
|
@apply w-full h-full flex-center;
|
|
|
|
|
|
|
2023-11-03 14:29:03 +08:00
|
|
|
|
overflow-y: auto;
|
2023-11-02 23:33:09 +08:00
|
|
|
|
background: url("@/assets/images/login-bg.jpg") no-repeat center right;
|
2023-07-21 18:18:37 +08:00
|
|
|
|
|
2023-03-16 23:49:36 +08:00
|
|
|
|
.login-form {
|
2023-10-30 07:43:50 +08:00
|
|
|
|
padding: 30px 10px;
|
2023-03-25 09:28:48 +08:00
|
|
|
|
|
|
|
|
|
|
.captcha {
|
|
|
|
|
|
position: absolute;
|
|
|
|
|
|
top: 0;
|
2023-04-15 23:51:27 +08:00
|
|
|
|
right: 0;
|
2023-03-25 09:28:48 +08:00
|
|
|
|
|
2023-11-03 17:27:09 +08:00
|
|
|
|
.image-slot {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: right;
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
height: 100%;
|
|
|
|
|
|
font-size: 18px;
|
|
|
|
|
|
color: var(--el-text-color-secondary);
|
|
|
|
|
|
background: var(--el-fill-color-light);
|
|
|
|
|
|
|
|
|
|
|
|
svg {
|
|
|
|
|
|
margin-right: 10px;
|
|
|
|
|
|
}
|
2023-03-25 09:28:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-03-16 23:49:36 +08:00
|
|
|
|
}
|
2021-11-19 23:55:14 +08:00
|
|
|
|
}
|
2023-03-24 22:40:29 +08:00
|
|
|
|
|
2023-02-06 01:07:35 +08:00
|
|
|
|
.el-form-item {
|
2023-10-30 07:43:50 +08:00
|
|
|
|
background: var(--el-input-bg-color);
|
|
|
|
|
|
border: 1px solid var(--el-border-color);
|
2023-02-06 01:07:35 +08:00
|
|
|
|
border-radius: 5px;
|
2022-08-31 23:56:31 +08:00
|
|
|
|
}
|
2023-02-21 00:12:39 +08:00
|
|
|
|
|
2023-10-30 07:43:50 +08:00
|
|
|
|
:deep(.el-input) {
|
|
|
|
|
|
.el-input__wrapper {
|
2023-02-06 01:07:35 +08:00
|
|
|
|
padding: 0;
|
2023-11-02 23:33:09 +08:00
|
|
|
|
background-color: transparent;
|
2023-02-06 01:07:35 +08:00
|
|
|
|
box-shadow: none;
|
2023-03-24 22:40:29 +08:00
|
|
|
|
|
2023-11-05 10:52:36 +08:00
|
|
|
|
&.is-focus,
|
|
|
|
|
|
&:hover {
|
|
|
|
|
|
box-shadow: none !important;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-10-30 07:43:50 +08:00
|
|
|
|
input:-webkit-autofill {
|
2023-11-10 08:13:14 +08:00
|
|
|
|
transition: background-color 1000s ease-in-out 0s; /* 通过延时渲染背景色变相去除背景颜色 */
|
2023-02-06 01:07:35 +08:00
|
|
|
|
}
|
2022-08-31 23:56:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-11-19 23:55:14 +08:00
|
|
|
|
</style>
|