|
|
@@ -1,392 +1,104 @@
|
|
|
<template>
|
|
|
- <div class="login">
|
|
|
- <div class="lg-logo"></div>
|
|
|
- <div class="right">
|
|
|
- <div class="lg-title"></div>
|
|
|
- <el-form ref="formLogin" :model="loginData.loginForm" :rules="LoginRules" class="login-form" auto-complete="on" label-position="left">
|
|
|
- <el-form-item prop="tenantName" v-if="false">
|
|
|
- <el-input
|
|
|
- style="height: 60px;width: 100%"
|
|
|
- v-model="loginData.loginForm.tenantName"
|
|
|
- :placeholder="t('login.tenantNamePlaceholder')"
|
|
|
- :prefix-icon="iconHouse"
|
|
|
- link
|
|
|
- type="primary"
|
|
|
- />
|
|
|
- </el-form-item>
|
|
|
- <el-form-item prop="username">
|
|
|
- <el-input
|
|
|
- class="input_item"
|
|
|
- v-model="loginData.loginForm.username"
|
|
|
- :placeholder="t('login.usernamePlaceholder')"
|
|
|
- :prefix-icon="iconAvatar"
|
|
|
- />
|
|
|
- </el-form-item>
|
|
|
- <el-form-item prop="password">
|
|
|
- <el-input
|
|
|
- class="input_item"
|
|
|
- v-model="loginData.loginForm.password"
|
|
|
- :placeholder="t('login.passwordPlaceholder')"
|
|
|
- :prefix-icon="iconLock"
|
|
|
- show-password
|
|
|
- type="password"
|
|
|
- />
|
|
|
- </el-form-item>
|
|
|
- <el-button :loading="loading" type="primary" style="margin-top: 30px" class="btn" @click="getCode()" >登录</el-button>
|
|
|
- <Verify
|
|
|
- ref="verify"
|
|
|
- :captchaType="captchaType"
|
|
|
- :imgSize="{ width: '400px', height: '200px' }"
|
|
|
- mode="pop"
|
|
|
- @success="handleLogin"
|
|
|
- />
|
|
|
- </el-form>
|
|
|
- </div>
|
|
|
- <div style="position:absolute; bottom:-150px;left:50%;transform: translateX(50%;); font-size:14px;z-index: 9;color: #999;">
|
|
|
+ <div
|
|
|
+ :class="prefixCls"
|
|
|
+ class="relative h-[100%] lt-md:px-10px lt-sm:px-10px lt-xl:px-10px lt-xl:px-10px"
|
|
|
+ >
|
|
|
+ <div class="relative mx-auto h-full flex">
|
|
|
+ <div
|
|
|
+ :class="`${prefixCls}__left flex-1 bg-gray-500 bg-opacity-20 relative p-30px lt-xl:hidden`"
|
|
|
+ >
|
|
|
+ <!-- 左上角的 logo + 系统标题 -->
|
|
|
+ <div class="relative flex items-center text-white">
|
|
|
+ <img alt="" class="mr-10px h-52px w-500px" src="@/assets/imgs/login/glogo.png" />
|
|
|
+<!-- <span class="text-20px font-bold">{{ underlineToHump(appStore.getTitle) }}</span>-->
|
|
|
+ </div>
|
|
|
+ <!-- 左边的背景图 + 欢迎语 -->
|
|
|
+ <div class="h-[calc(100%-60px)] flex items-center justify-center">
|
|
|
+ <TransitionGroup
|
|
|
+ appear
|
|
|
+ enter-active-class="animate__animated animate__bounceInLeft"
|
|
|
+ tag="div"
|
|
|
+ >
|
|
|
+ <img key="1" alt="" class="w-600px" src="@/assets/svgs/login-box-bg.svg" />
|
|
|
+ <div key="2" class="text-3xl">{{ t('login.welcome') }}</div>
|
|
|
+ <div key="3" class="mt-5 text-14px font-normal">
|
|
|
+ {{ t('login.message') }}
|
|
|
+ </div>
|
|
|
+ </TransitionGroup>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <div class="relative flex-1 p-30px dark:bg-[var(--login-bg-color)] lt-sm:p-10px">
|
|
|
+ <!-- 右上角的主题、语言选择 -->
|
|
|
+ <div
|
|
|
+ class="flex items-center justify-between text-white at-2xl:justify-end at-xl:justify-end"
|
|
|
+ >
|
|
|
+ <div class="flex items-center at-2xl:hidden at-xl:hidden">
|
|
|
+ <img alt="" class="mr-10px h-48px w-48px" src="@/assets/imgs/logo.png" />
|
|
|
+ <span class="text-20px font-bold">{{ underlineToHump(appStore.getTitle) }}</span>
|
|
|
+ </div>
|
|
|
+ <div class="flex items-center justify-end space-x-10px">
|
|
|
+ <ThemeSwitch />
|
|
|
+ <LocaleDropdown class="dark:text-white lt-xl:text-white" />
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <!-- 右边的登录界面 -->
|
|
|
+ <Transition appear enter-active-class="animate__animated animate__bounceInRight">
|
|
|
+ <div
|
|
|
+ class="m-auto h-full w-[100%] flex items-center at-2xl:max-w-500px at-lg:max-w-500px at-md:max-w-500px at-xl:max-w-500px"
|
|
|
+ >
|
|
|
+ <!-- 账号登录 -->
|
|
|
+ <LoginForm class="m-auto h-auto p-20px lt-xl:(rounded-3xl light:bg-white)" />
|
|
|
+ <!-- 手机登录 -->
|
|
|
+ <MobileForm class="m-auto h-auto p-20px lt-xl:(rounded-3xl light:bg-white)" />
|
|
|
+ <!-- 二维码登录 -->
|
|
|
+ <QrCodeForm class="m-auto h-auto p-20px lt-xl:(rounded-3xl light:bg-white)" />
|
|
|
+ <!-- 注册 -->
|
|
|
+ <RegisterForm class="m-auto h-auto p-20px lt-xl:(rounded-3xl light:bg-white)" />
|
|
|
+ <!-- 三方登录 -->
|
|
|
+ <SSOLoginVue class="m-auto h-auto p-20px lt-xl:(rounded-3xl light:bg-white)" />
|
|
|
+ </div>
|
|
|
+ </Transition>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
</div>
|
|
|
</template>
|
|
|
<script lang="ts" setup>
|
|
|
+ import { underlineToHump } from '@/utils'
|
|
|
|
|
|
import { useDesign } from '@/hooks/web/useDesign'
|
|
|
import { useAppStore } from '@/store/modules/app'
|
|
|
+ import { ThemeSwitch } from '@/layout/components/ThemeSwitch'
|
|
|
+ import { LocaleDropdown } from '@/layout/components/LocaleDropdown'
|
|
|
|
|
|
- import { ElLoading } from 'element-plus'
|
|
|
- import LoginFormTitle from './components/LoginFormTitle.vue'
|
|
|
- import type { RouteLocationNormalizedLoaded } from 'vue-router'
|
|
|
-
|
|
|
- import * as authUtil from '@/utils/auth'
|
|
|
- import { usePermissionStore } from '@/store/modules/permission'
|
|
|
- import * as LoginApi from '@/api/login'
|
|
|
- import { LoginStateEnum, useFormValid, useLoginState } from './components/useLogin'
|
|
|
-
|
|
|
- defineOptions({ name: 'LoginForm' })
|
|
|
+ import { LoginForm, MobileForm, QrCodeForm, RegisterForm, SSOLoginVue } from './components'
|
|
|
|
|
|
- import { useIcon } from '@/hooks/web/useIcon'
|
|
|
+ defineOptions({ name: 'Login' })
|
|
|
|
|
|
const { t } = useI18n()
|
|
|
- const message = useMessage()
|
|
|
- const iconHouse = useIcon({ icon: 'ep:house' })
|
|
|
- const iconAvatar = useIcon({ icon: 'ep:avatar' })
|
|
|
- const iconLock = useIcon({ icon: 'ep:lock' })
|
|
|
-
|
|
|
- const formLogin = ref()
|
|
|
- const { validForm } = useFormValid(formLogin)
|
|
|
- const { setLoginState, getLoginState } = useLoginState()
|
|
|
- const { currentRoute, push } = useRouter()
|
|
|
- const permissionStore = usePermissionStore()
|
|
|
- const redirect = ref<string>('')
|
|
|
- const loginLoading = ref(false)
|
|
|
- const verify = ref()
|
|
|
- const captchaType = ref('blockPuzzle') // blockPuzzle 滑块 clickWord 点击文字
|
|
|
-
|
|
|
- const getShow = computed(() => unref(getLoginState) === LoginStateEnum.LOGIN)
|
|
|
-
|
|
|
-
|
|
|
- const LoginRules = {
|
|
|
- // tenantName: [required],
|
|
|
- username: [required],
|
|
|
- password: [required]
|
|
|
- }
|
|
|
- const loginData = reactive({
|
|
|
- isShowPassword: false,
|
|
|
- captchaEnable: import.meta.env.VITE_APP_CAPTCHA_ENABLE,
|
|
|
- tenantEnable: import.meta.env.VITE_APP_TENANT_ENABLE,
|
|
|
- loginForm: {
|
|
|
- tenantName: '中康科',
|
|
|
- username: 'admin',
|
|
|
- password: 'admin123',
|
|
|
- captchaVerification: '',
|
|
|
- rememberMe: false // 默认不记录我
|
|
|
- }
|
|
|
- })
|
|
|
-
|
|
|
- // 获取验证码
|
|
|
- const getCode = async () => {
|
|
|
- // 情况一,未开启:则直接登录
|
|
|
- if (loginData.captchaEnable === 'false') {
|
|
|
- await handleLogin({})
|
|
|
- } else {
|
|
|
- // 情况二,已开启:则展示验证码;只有完成验证码的情况,才进行登录
|
|
|
- // 弹出验证码
|
|
|
- verify.value.show()
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 获取租户 ID
|
|
|
- const getTenantId = async () => {
|
|
|
- if (loginData.tenantEnable === 'true') {
|
|
|
- const res = await LoginApi.getTenantIdByName(loginData.loginForm.tenantName)
|
|
|
- authUtil.setTenantId(res)
|
|
|
- }
|
|
|
- }
|
|
|
- // 记住我
|
|
|
- const getLoginFormCache = () => {
|
|
|
- const loginForm = authUtil.getLoginForm()
|
|
|
- if (loginForm) {
|
|
|
- loginData.loginForm = {
|
|
|
- ...loginData.loginForm,
|
|
|
- username: loginForm.username ? loginForm.username : loginData.loginForm.username,
|
|
|
- password: loginForm.password ? loginForm.password : loginData.loginForm.password,
|
|
|
- rememberMe: loginForm.rememberMe,
|
|
|
- tenantName: loginForm.tenantName ? loginForm.tenantName : loginData.loginForm.tenantName
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- // 根据域名,获得租户信息
|
|
|
- const getTenantByWebsite = async () => {
|
|
|
- const website = location.host
|
|
|
- const res = await LoginApi.getTenantByWebsite(website)
|
|
|
- if (res) {
|
|
|
- loginData.loginForm.tenantName = res.name
|
|
|
- authUtil.setTenantId(res.id)
|
|
|
- }
|
|
|
- }
|
|
|
- const loading = ref() // ElLoading.service 返回的实例
|
|
|
- // 登录
|
|
|
- const handleLogin = async (params) => {
|
|
|
- loginLoading.value = true
|
|
|
- try {
|
|
|
- await getTenantId()
|
|
|
- const data = await validForm()
|
|
|
- if (!data) {
|
|
|
- return
|
|
|
- }
|
|
|
- loginData.loginForm.captchaVerification = params.captchaVerification
|
|
|
- const res = await LoginApi.login(loginData.loginForm)
|
|
|
- if (!res) {
|
|
|
- return
|
|
|
- }
|
|
|
- loading.value = ElLoading.service({
|
|
|
- lock: true,
|
|
|
- text: '正在加载系统中...',
|
|
|
- background: 'rgba(0, 0, 0, 0.7)'
|
|
|
- })
|
|
|
- if (loginData.loginForm.rememberMe) {
|
|
|
- authUtil.setLoginForm(loginData.loginForm)
|
|
|
- } else {
|
|
|
- authUtil.removeLoginForm()
|
|
|
- }
|
|
|
- authUtil.setToken(res)
|
|
|
- if (!redirect.value) {
|
|
|
- redirect.value = '/Navicate'
|
|
|
- }
|
|
|
- // 判断是否为SSO登录
|
|
|
- if (redirect.value.indexOf('sso') !== -1) {
|
|
|
- window.location.href = window.location.href.replace('/login?redirect=', '')
|
|
|
- } else {
|
|
|
- push({ path: redirect.value || permissionStore.addRouters[0].path })
|
|
|
- }
|
|
|
- } finally {
|
|
|
- loginLoading.value = false
|
|
|
- loading.value.close()
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 社交登录
|
|
|
- const doSocialLogin = async (type: number) => {
|
|
|
- if (type === 0) {
|
|
|
- message.error('此方式未配置')
|
|
|
- } else {
|
|
|
- loginLoading.value = true
|
|
|
- if (loginData.tenantEnable === 'true') {
|
|
|
- // 尝试先通过 tenantName 获取租户
|
|
|
- await getTenantId()
|
|
|
- // 如果获取不到,则需要弹出提示,进行处理
|
|
|
- if (!authUtil.getTenantId()) {
|
|
|
- try {
|
|
|
- const data = await message.prompt('请输入租户名称', t('common.reminder'))
|
|
|
- if (data?.action !== 'confirm') throw 'cancel'
|
|
|
- const res = await LoginApi.getTenantIdByName(data.value)
|
|
|
- authUtil.setTenantId(res)
|
|
|
- } catch (error) {
|
|
|
- if (error === 'cancel') return
|
|
|
- } finally {
|
|
|
- loginLoading.value = false
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- // 计算 redirectUri
|
|
|
- // tricky: type、redirect需要先encode一次,否则钉钉回调会丢失。
|
|
|
- // 配合 Login/SocialLogin.vue#getUrlValue() 使用
|
|
|
- const redirectUri =
|
|
|
- location.origin +
|
|
|
- '/social-login?' +
|
|
|
- encodeURIComponent(`type=${type}&redirect=${redirect.value || '/'}`)
|
|
|
-
|
|
|
- // 进行跳转
|
|
|
- const res = await LoginApi.socialAuthRedirect(type, encodeURIComponent(redirectUri))
|
|
|
- window.location.href = res
|
|
|
- }
|
|
|
- }
|
|
|
- watch(
|
|
|
- () => currentRoute.value,
|
|
|
- (route: RouteLocationNormalizedLoaded) => {
|
|
|
- redirect.value = route?.query?.redirect as string
|
|
|
- },
|
|
|
- {
|
|
|
- immediate: true
|
|
|
- }
|
|
|
- )
|
|
|
- onMounted(() => {
|
|
|
- getLoginFormCache()
|
|
|
- getTenantByWebsite()
|
|
|
- })
|
|
|
-
|
|
|
-
|
|
|
const appStore = useAppStore()
|
|
|
const { getPrefixCls } = useDesign()
|
|
|
const prefixCls = getPrefixCls('login')
|
|
|
-
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
- $bg: rgb(255, 255, 255);
|
|
|
- $light_gray: rgb(0, 0, 0);
|
|
|
- $cursor: rgb(0, 0, 0);
|
|
|
-
|
|
|
- .login {
|
|
|
- width: 100%;
|
|
|
- height: 100%;
|
|
|
- /* background-image: linear-gradient(to top left, #e5a8d5, #00efff, #e5a8d5); */
|
|
|
- background-image: url("/src/assets/imgs/login/gbg.png");
|
|
|
- /* 背景图垂直、水平均居中 */
|
|
|
- background-position: center center;
|
|
|
- /* 背景图不平铺 */
|
|
|
- background-repeat: no-repeat;
|
|
|
- // /* 当内容高度大于图片高度时,背景图像的位置相对于viewport固定 */
|
|
|
- // background-attachment: fixed;
|
|
|
- /* 让背景图基于容器大小伸缩 */
|
|
|
- background-size: cover;
|
|
|
-
|
|
|
- .lg-logo{
|
|
|
- width: 525px;
|
|
|
- height: 62px;
|
|
|
- position: absolute;
|
|
|
- top:115px;
|
|
|
- left:210px;
|
|
|
- background-image: url("/src/assets/imgs/login/glogo.png");
|
|
|
- }
|
|
|
-
|
|
|
- .right {
|
|
|
- width: 440px;
|
|
|
- height: 380px;
|
|
|
- position: absolute;
|
|
|
- top:220px;
|
|
|
- left:1190px;
|
|
|
- padding: 70px 40px 70px 40px;
|
|
|
- background-color: rgba(255, 255, 255, 0.8);
|
|
|
-
|
|
|
- .lg-title{
|
|
|
- width: 364px;
|
|
|
- height:34px;
|
|
|
- margin-left: 38px;
|
|
|
- margin-bottom: 20px;
|
|
|
- background-image: url("/src/assets/imgs/login/gtitle.png");
|
|
|
- }
|
|
|
-
|
|
|
- .item .el-form-item__content {
|
|
|
- display: flex;
|
|
|
- border-bottom: 2px solid #e3e3e3;
|
|
|
- align-items: center;
|
|
|
- text-align: justify; // width: 514px; // height: 60px;
|
|
|
- position: relative;
|
|
|
-
|
|
|
- .yzm {
|
|
|
- position: absolute;
|
|
|
- top: 3px;
|
|
|
- right: 0;
|
|
|
- height: 40px;
|
|
|
- }
|
|
|
+ $prefix-cls: #{$namespace}-login;
|
|
|
|
|
|
- .lock {
|
|
|
- width: 30px;
|
|
|
- margin-right: 30px;
|
|
|
- margin-top: 20px;
|
|
|
- }
|
|
|
+ .#{$prefix-cls} {
|
|
|
+ overflow: auto;
|
|
|
|
|
|
- }
|
|
|
-
|
|
|
- .input_item {
|
|
|
- height: 60px;
|
|
|
- width: 100%;
|
|
|
- margin-top: 30px;
|
|
|
- }
|
|
|
-
|
|
|
- .btn {
|
|
|
- border: none;
|
|
|
- width: 100%;
|
|
|
- // border-radius: 100px;
|
|
|
- height: 60px;
|
|
|
- margin: 20px auto 0;
|
|
|
- font-size: 20px;
|
|
|
- color: #ffffff;
|
|
|
- // line-height: 41px;
|
|
|
- // background: url("../../assets/login/login.png") no-repeat;
|
|
|
- background-color: #00734D;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- .wrapper {
|
|
|
- // width: 1216px;
|
|
|
- min-width: 65%;
|
|
|
- max-width: 75%;
|
|
|
- background: #ffffff;
|
|
|
- box-shadow: 0px 2px 15px 3px rgba(0, 0, 0, 0.26);
|
|
|
- margin: 0 auto;
|
|
|
- z-index: 9;
|
|
|
- top: 18%;
|
|
|
-
|
|
|
- position: absolute;
|
|
|
- left: 50%;
|
|
|
- transform: translateX(-50%);
|
|
|
- display: flex;
|
|
|
-
|
|
|
- .left {
|
|
|
- width: 50%;
|
|
|
-
|
|
|
- img {
|
|
|
+ &__left {
|
|
|
+ &::before {
|
|
|
+ position: absolute;
|
|
|
+ top: 0;
|
|
|
+ left: 0;
|
|
|
+ z-index: -1;
|
|
|
width: 100%;
|
|
|
height: 100%;
|
|
|
+ background-image: url('@/assets/svgs/login-bg.svg');
|
|
|
+ background-position: center;
|
|
|
+ background-repeat: no-repeat;
|
|
|
+ content: '';
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- }
|
|
|
- .bottom {
|
|
|
- width: 100%;
|
|
|
- position: absolute;
|
|
|
- top: 50%;
|
|
|
- height: 546px;
|
|
|
- background: #414969 linear-gradient(90deg, #7488f1 0%, #616dc7 0%, #3e4676 0%, #292e46 100%);
|
|
|
- z-index: 1;
|
|
|
- }
|
|
|
-
|
|
|
- .forget {
|
|
|
- display: flex;
|
|
|
- justify-content: center;
|
|
|
- align-items: center;
|
|
|
- margin-top: 10px;
|
|
|
- }
|
|
|
-
|
|
|
- .line {
|
|
|
- height: 18px;
|
|
|
- display: inline-block;
|
|
|
- width: 1px;
|
|
|
- margin: 0 30px;
|
|
|
- background-color: #b4b4b4;
|
|
|
- }
|
|
|
-
|
|
|
- @media screen and (min-width: 1600px) {
|
|
|
- .wrapper {
|
|
|
- top: 10%;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @media screen and (min-width: 1900px) {
|
|
|
- .wrapper {
|
|
|
- top: 0%;
|
|
|
- }
|
|
|
}
|
|
|
</style>
|