You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

199 lines
6.7 KiB

2 years ago
<template>
<LoginFormTitle v-show="getShow" class="enter-x" />
<Form class="p-4 enter-x" :model="formData" :rules="getFormRules" ref="formRef" v-show="getShow" @keypress.enter="handleLogin">
2 years ago
<FormItem name="tenantName" class="enter-x">
<Input
v-if="tenantEnable === 'true'"
size="large"
v-model:value="formData.tenantName"
:placeholder="t('sys.login.tenantName')"
class="fix-auto-fill"
/>
</FormItem>
<FormItem name="username" class="enter-x">
<Input size="large" v-model:value="formData.username" :placeholder="t('sys.login.userName')" class="fix-auto-fill" />
2 years ago
</FormItem>
<FormItem name="password" class="enter-x">
<InputPassword
size="large"
visibilityToggle
v-model:value="formData.password"
:placeholder="t('sys.login.password')"
class="fix-auto-fill"
/>
2 years ago
</FormItem>
2 years ago
<Row class="enter-x">
<Col :span="12">
2 years ago
<FormItem>
<!-- No logic, you need to deal with it yourself -->
<Checkbox v-model:checked="rememberMe" size="small">
{{ t('sys.login.rememberMe') }}
</Checkbox>
</FormItem>
2 years ago
</Col>
<Col :span="12">
2 years ago
<FormItem :style="{ 'text-align': 'right' }">
<!-- No logic, you need to deal with it yourself -->
<Button type="link" size="small" @click="setLoginState(LoginStateEnum.RESET_PASSWORD)">
{{ t('sys.login.forgetPassword') }}
</Button>
</FormItem>
2 years ago
</Col>
</Row>
2 years ago
<FormItem class="enter-x">
2 years ago
<Button type="primary" size="large" block @click="getCode" :loading="loading">
2 years ago
{{ t('sys.login.loginButton') }}
</Button>
<!-- <Button size="large" class="mt-4 enter-x" block @click="handleRegister">
{{ t('sys.login.registerButton') }}
</Button> -->
</FormItem>
2 years ago
<Row class="enter-x">
<Col :md="8" :xs="24">
2 years ago
<Button block @click="setLoginState(LoginStateEnum.MOBILE)">
{{ t('sys.login.mobileSignInFormTitle') }}
</Button>
2 years ago
</Col>
<Col :md="8" :xs="24" class="!my-2 !md:my-0 xs:mx-0 md:mx-2">
2 years ago
<Button block @click="setLoginState(LoginStateEnum.QR_CODE)">
{{ t('sys.login.qrSignInFormTitle') }}
</Button>
2 years ago
</Col>
<Col :md="6" :xs="24">
2 years ago
<a-button block @click="setLoginState(LoginStateEnum.REGISTER)">
2 years ago
{{ t('sys.login.registerButton') }}
2 years ago
</a-button>
2 years ago
</Col>
</Row>
2 years ago
<Divider class="enter-x">{{ t('sys.login.otherSignIn') }}</Divider>
<div class="flex justify-evenly enter-x" :class="`${prefixCls}-sign-in-way`">
<GithubFilled />
<WechatFilled />
<AlipayCircleFilled />
<!-- <GoogleCircleFilled /> -->
<!-- <TwitterCircleFilled /> -->
</div>
<!-- 萌新必读 -->
<Divider class="enter-x">萌新必读</Divider>
<div class="flex justify-evenly enter-x" :class="`${prefixCls}-sign-in-way`">
<Button href="https://doc.iocoder.cn/" target="_blank">📚开发指南</Button>
<Button href="https://doc.iocoder.cn/video/" target="_blank" style="padding-left: 10px">🔥视频教程</Button>
<Button href="https://www.iocoder.cn/Interview/good-collection/" target="_blank" style="padding-left: 10px">面试手册</Button>
<Button href="http://static.yudao.iocoder.cn/mp/xinyu370.jpeg" target="_blank" style="padding-left: 10px">🤝外包咨询</Button>
2 years ago
</div>
</Form>
2 years ago
<Verify ref="verify" mode="pop" :captchaType="captchaType" :imgSize="{ width: '400px', height: '200px' }" @success="handleLogin" />
2 years ago
</template>
<script lang="ts" setup>
import { reactive, ref, unref, computed } from 'vue'
import { Checkbox, Form, Input, Row, Col, Button, Divider } from 'ant-design-vue'
import { GithubFilled, WechatFilled, AlipayCircleFilled } from '@ant-design/icons-vue'
2 years ago
import LoginFormTitle from './LoginFormTitle.vue'
import { useI18n } from '@/hooks/web/useI18n'
import { useMessage } from '@/hooks/web/useMessage'
import { useUserStore } from '@/store/modules/user'
2 years ago
import { usePermissionStore } from '@/store/modules/permission'
2 years ago
import { LoginStateEnum, useLoginState, useFormRules, useFormValid } from './useLogin'
2 years ago
import { useGlobSetting } from '@/hooks/setting'
2 years ago
import { useDesign } from '@/hooks/web/useDesign'
2 years ago
import * as authUtil from '@/utils/auth'
import { Verify } from '@/components/Verifition'
import { getTenantIdByName } from '@/api/base/login'
2 years ago
const FormItem = Form.Item
const InputPassword = Input.Password
2 years ago
2 years ago
const { t } = useI18n()
const { notification, createErrorModal } = useMessage()
const { prefixCls } = useDesign('login')
const userStore = useUserStore()
2 years ago
const permissionStore = usePermissionStore()
const { tenantEnable, captchaEnable } = useGlobSetting()
2 years ago
const { setLoginState, getLoginState } = useLoginState()
const { getFormRules } = useFormRules()
const formRef = ref()
const loading = ref(false)
const rememberMe = ref(false)
2 years ago
const verify = ref()
const captchaType = ref('blockPuzzle') // blockPuzzle 滑块 clickWord 点击文字
2 years ago
const formData = reactive({
2 years ago
tenantName: '芋道源码',
username: 'admin',
password: 'admin123',
captchaVerification: ''
2 years ago
})
const { validForm } = useFormValid(formRef)
//onKeyStroke('Enter', handleLogin);
const getShow = computed(() => unref(getLoginState) === LoginStateEnum.LOGIN)
2 years ago
// 获取验证码
async function getCode() {
// 情况一,未开启:则直接登录
if (captchaEnable === 'false') {
await handleLogin({})
} else {
// 情况二,已开启:则展示验证码;只有完成验证码的情况,才进行登录
// 弹出验证码
verify.value.show()
}
}
//获取租户ID
async function getTenantId() {
if (tenantEnable === 'true') {
const res = await getTenantIdByName(formData.tenantName)
authUtil.setTenantId(res)
}
}
async function handleLogin(params) {
await getTenantId()
2 years ago
const data = await validForm()
if (!data) return
try {
loading.value = true
const userInfo = await userStore.login({
password: data.password,
2 years ago
username: data.username,
captchaVerification: params.captchaVerification,
2 years ago
mode: 'none' //不要默认的错误提示
})
if (userInfo) {
2 years ago
await permissionStore.changePermissionCode(userInfo.permissions)
2 years ago
notification.success({
message: t('sys.login.loginSuccessTitle'),
2 years ago
description: `${t('sys.login.loginSuccessDesc')}: ${userInfo.user.nickname}`,
2 years ago
duration: 3
})
}
} catch (error) {
createErrorModal({
title: t('sys.api.errorTip'),
content: (error as unknown as Error).message || t('sys.api.networkExceptionMsg'),
getContainer: () => document.body.querySelector(`.${prefixCls}`) || document.body
})
} finally {
loading.value = false
}
}
</script>