diff --git a/src/api/login/index.ts b/src/api/login/index.ts index b65a90cf6..613bc2d9e 100644 --- a/src/api/login/index.ts +++ b/src/api/login/index.ts @@ -62,3 +62,21 @@ export const getCode = (data) => { export const reqCheck = (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 +// }) +// } diff --git a/src/views/Login/components/LoginForm.vue b/src/views/Login/components/LoginForm.vue index 5db4dd919..2e7790cc0 100644 --- a/src/views/Login/components/LoginForm.vue +++ b/src/views/Login/components/LoginForm.vue @@ -1,56 +1,61 @@ @@ -96,6 +97,7 @@ import * as authUtil from '@/utils/auth' import { usePermissionStore } from '@/store/modules/permission' import * as LoginApi from '@/api/login' import { LoginStateEnum, useFormValid, useLoginState } from './useLogin' +import { getCodeImg } from "@/api/login"; defineOptions({ name: 'LoginForm' }) @@ -115,6 +117,9 @@ const verify = ref() const captchaType = ref('blockPuzzle') // blockPuzzle 滑块 clickWord 点击文字 const getShow = computed(() => unref(getLoginState) === LoginStateEnum.LOGIN) +// 验证码开关 +const captchaEnabled = ref(true); +const codeUrl = ref(""); const LoginRules = { tenantName: [required], @@ -130,7 +135,8 @@ const loginData = reactive({ username: 'admin', password: 'admin123', captchaVerification: '', - rememberMe: false + rememberMe: false, + code:'' } }) @@ -142,15 +148,24 @@ const socialList = [ ] // 获取验证码 -const getCode = async () => { - // 情况一,未开启:则直接登录 - if (loginData.captchaEnable === 'false') { - await handleLogin({}) - } else { - // 情况二,已开启:则展示验证码;只有完成验证码的情况,才进行登录 - // 弹出验证码 - verify.value.show() - } +// const getCode = async () => { +// // 情况一,未开启:则直接登录 +// if (loginData.captchaEnable === 'false') { +// await handleLogin({}) +// } else { +// // 情况二,已开启:则展示验证码;只有完成验证码的情况,才进行登录 +// // 弹出验证码 +// 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 const getTenantId = async () => { @@ -243,6 +258,7 @@ watch( } ) onMounted(() => { + getCode(); getCookie() })