Browse Source

登录

master
zhangli 1 year ago
parent
commit
6179bd8acb
  1. 18
      src/api/login/index.ts
  2. 120
      src/views/Login/components/LoginForm.vue

18
src/api/login/index.ts

@ -62,3 +62,21 @@ export const getCode = (data) => {
export const reqCheck = (data) => { export const reqCheck = (data) => {
return request.postOriginal({ url: 'system/captcha/check', data }) return request.postOriginal({ url: 'system/captcha/check', data })
} }
// 获取验证码
export const getCodeImg = () => {
return request.get({
url: 'system/captcha/captchaImage', headers: {
isToken: false
}})
}
// export function getCodeImg() {
// return request({
// url: '/captchaImage',
// headers: {
// isToken: false
// },
// method: 'get',
// timeout: 20000
// })
// }

120
src/views/Login/components/LoginForm.vue

@ -1,14 +1,6 @@
<template> <template>
<el-form <el-form v-show="getShow" ref="formLogin" :model="loginData.loginForm" :rules="LoginRules" class="login-form"
v-show="getShow" label-position="top" label-width="120px" size="large">
ref="formLogin"
:model="loginData.loginForm"
:rules="LoginRules"
class="login-form"
label-position="top"
label-width="120px"
size="large"
>
<el-row style="margin-right: -10px; margin-left: -10px"> <el-row style="margin-right: -10px; margin-left: -10px">
<el-col :span="24" style="padding-right: 10px; padding-left: 10px"> <el-col :span="24" style="padding-right: 10px; padding-left: 10px">
<el-form-item> <el-form-item>
@ -17,40 +9,53 @@
</el-col> </el-col>
<el-col :span="24" style="padding-right: 10px; padding-left: 10px"> <el-col :span="24" style="padding-right: 10px; padding-left: 10px">
<el-form-item v-if="loginData.tenantEnable === 'true'" prop="tenantName"> <el-form-item v-if="loginData.tenantEnable === 'true'" prop="tenantName">
<el-input <el-input v-model="loginData.loginForm.tenantName" :placeholder="t('login.tenantNamePlaceholder')"
v-model="loginData.loginForm.tenantName" :prefix-icon="iconHouse" link type="primary" />
:placeholder="t('login.tenantNamePlaceholder')"
:prefix-icon="iconHouse"
link
type="primary"
/>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="24" style="padding-right: 10px; padding-left: 10px"> <el-col :span="24" style="padding-right: 10px; padding-left: 10px">
<el-form-item prop="username"> <el-form-item prop="username">
<el-input <el-input v-model="loginData.loginForm.username" :placeholder="t('login.usernamePlaceholder')"
v-model="loginData.loginForm.username" :prefix-icon="iconAvatar" />
:placeholder="t('login.usernamePlaceholder')"
:prefix-icon="iconAvatar"
/>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="24" style="padding-right: 10px; padding-left: 10px"> <el-col :span="24" style="padding-right: 10px; padding-left: 10px">
<el-form-item prop="password"> <el-form-item prop="password">
<el-input <el-input v-model="loginData.loginForm.password" :placeholder="t('login.passwordPlaceholder')"
v-model="loginData.loginForm.password" :prefix-icon="iconLock" show-password type="password" @keyup.enter="getCode()" />
:placeholder="t('login.passwordPlaceholder')"
:prefix-icon="iconLock"
show-password
type="password"
@keyup.enter="getCode()"
/>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col <!-- <el-col :span="24" style="padding-right: 10px; padding-left: 10px; margin-top: -20px; margin-bottom: -20px">
:span="24" <el-form-item prop="code" v-if="captchaEnabled">
style="padding-right: 10px; padding-left: 10px; margin-top: -20px; margin-bottom: -20px" <div class="label">
> <svg-icon icon-class="icon_safe" class="el-input__icon input-icon" />
<div>验证码</div>
</div>
<div>
<el-input v-model="loginData.loginForm.password" :placeholder="t('login.passwordPlaceholder')"
:prefix-icon="iconLock" show-password type="password" @keyup.enter="getCode()" />
<div class="login-code">
<img :src="codeUrl" @click="getCode" class="login-code-img" />
</div>
</div>
</el-form-item>
</el-col> -->
<el-col :span="24" style="padding-right: 10px; padding-left: 10px">
<el-form-item prop="code">
<div class="flex">
<el-input v-model="loginData.loginForm.code" placeholder="请输入验证码" style="width: 320px;"
:prefix-icon="iconLock" show-password type="password" @keyup.enter="getCode()"/>
<div class="login-code flex-1">
<img :src="codeUrl" @click="getCode" class="login-code-img" />
</div>
</div>
</el-form-item>
</el-col>
<el-col :span="24" style="padding-right: 10px; padding-left: 10px; margin-top: -20px; margin-bottom: -20px">
<el-form-item> <el-form-item>
<el-row justify="space-between" style="width: 100%"> <el-row justify="space-between" style="width: 100%">
<el-col :span="6"> <el-col :span="6">
@ -64,24 +69,20 @@
</el-row> </el-row>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="24" style="padding-right: 10px; padding-left: 10px"> <el-col :span="24" style="padding-right: 10px; padding-left: 10px">
<el-form-item> <el-form-item>
<XButton <XButton :loading="loginLoading" :title="t('login.login')" class="w-[100%]" type="primary"
:loading="loginLoading" @click="handleLogin()" />
:title="t('login.login')"
class="w-[100%]"
type="primary"
@click="getCode()"
/>
</el-form-item> </el-form-item>
</el-col> </el-col>
<Verify <!-- <Verify
ref="verify" ref="verify"
:captchaType="captchaType" :captchaType="captchaType"
:imgSize="{ width: '400px', height: '200px' }" :imgSize="{ width: '400px', height: '200px' }"
mode="pop" mode="pop"
@success="handleLogin" @success="handleLogin"
/> /> -->
</el-row> </el-row>
</el-form> </el-form>
</template> </template>
@ -96,6 +97,7 @@ import * as authUtil from '@/utils/auth'
import { usePermissionStore } from '@/store/modules/permission' import { usePermissionStore } from '@/store/modules/permission'
import * as LoginApi from '@/api/login' import * as LoginApi from '@/api/login'
import { LoginStateEnum, useFormValid, useLoginState } from './useLogin' import { LoginStateEnum, useFormValid, useLoginState } from './useLogin'
import { getCodeImg } from "@/api/login";
defineOptions({ name: 'LoginForm' }) defineOptions({ name: 'LoginForm' })
@ -115,6 +117,9 @@ const verify = ref()
const captchaType = ref('blockPuzzle') // blockPuzzle clickWord const captchaType = ref('blockPuzzle') // blockPuzzle clickWord
const getShow = computed(() => unref(getLoginState) === LoginStateEnum.LOGIN) const getShow = computed(() => unref(getLoginState) === LoginStateEnum.LOGIN)
//
const captchaEnabled = ref(true);
const codeUrl = ref("");
const LoginRules = { const LoginRules = {
tenantName: [required], tenantName: [required],
@ -130,7 +135,8 @@ const loginData = reactive({
username: 'admin', username: 'admin',
password: 'admin123', password: 'admin123',
captchaVerification: '', captchaVerification: '',
rememberMe: false rememberMe: false,
code:''
} }
}) })
@ -142,15 +148,24 @@ const socialList = [
] ]
// //
const getCode = async () => { // const getCode = async () => {
// // //
if (loginData.captchaEnable === 'false') { // if (loginData.captchaEnable === 'false') {
await handleLogin({}) // await handleLogin({})
} else { // } else {
// // //
// // //
verify.value.show() // verify.value.show()
// }
// }
function getCode() {
getCodeImg().then(res => {
captchaEnabled.value = res.captchaEnabled === undefined ? true : res.captchaEnabled;
if (captchaEnabled.value) {
codeUrl.value = "data:image/gif;base64," + res.img;
loginForm.value.uuid = res.uuid;
} }
});
} }
//ID //ID
const getTenantId = async () => { const getTenantId = async () => {
@ -243,6 +258,7 @@ watch(
} }
) )
onMounted(() => { onMounted(() => {
getCode();
getCookie() getCookie()
}) })
</script> </script>

Loading…
Cancel
Save