关闭验证码功能
This commit is contained in:
6
saiadmin-artd/src/types/api/api.d.ts
vendored
6
saiadmin-artd/src/types/api/api.d.ts
vendored
@@ -82,12 +82,12 @@ declare namespace Api {
|
||||
image: string
|
||||
}
|
||||
|
||||
/** 登录参数 */
|
||||
/** 登录参数(关闭验证码时可不传 code、uuid) */
|
||||
interface LoginParams {
|
||||
username: string
|
||||
password: string
|
||||
code: string
|
||||
uuid: string
|
||||
code?: string
|
||||
uuid?: string
|
||||
}
|
||||
|
||||
/** 登录响应 */
|
||||
|
||||
@@ -164,6 +164,8 @@ export interface EnvConfig {
|
||||
VITE_USE_GZIP?: string
|
||||
// 是否开启 CDN
|
||||
VITE_USE_CDN?: string
|
||||
// 登录页是否启用验证码,设为 false 或 0 关闭
|
||||
VITE_LOGIN_CAPTCHA_ENABLED?: string
|
||||
}
|
||||
|
||||
// 应用配置
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
show-password
|
||||
/>
|
||||
</ElFormItem>
|
||||
<ElFormItem prop="code">
|
||||
<ElFormItem v-if="captchaEnabled" prop="code">
|
||||
<ElInput
|
||||
class="custom-height"
|
||||
:placeholder="$t('login.placeholder.code')"
|
||||
@@ -115,6 +115,12 @@
|
||||
const systemName = AppConfig.systemInfo.name
|
||||
const formRef = ref<FormInstance>()
|
||||
|
||||
/** 是否启用登录验证码(与后端 LOGIN_CAPTCHA_ENABLE 保持一致) */
|
||||
const captchaEnabled = computed(() => {
|
||||
const v = import.meta.env.VITE_LOGIN_CAPTCHA_ENABLED
|
||||
return v !== 'false' && v !== '0'
|
||||
})
|
||||
|
||||
const formData = reactive({
|
||||
username: '',
|
||||
password: '',
|
||||
@@ -123,16 +129,21 @@
|
||||
rememberPassword: true
|
||||
})
|
||||
|
||||
const rules = computed<FormRules>(() => ({
|
||||
username: [{ required: true, message: t('login.placeholder.username'), trigger: 'blur' }],
|
||||
password: [{ required: true, message: t('login.placeholder.password'), trigger: 'blur' }],
|
||||
code: [{ required: true, message: t('login.placeholder.code'), trigger: 'blur' }]
|
||||
}))
|
||||
const rules = computed<FormRules>(() => {
|
||||
const r: FormRules = {
|
||||
username: [{ required: true, message: t('login.placeholder.username'), trigger: 'blur' }],
|
||||
password: [{ required: true, message: t('login.placeholder.password'), trigger: 'blur' }]
|
||||
}
|
||||
if (captchaEnabled.value) {
|
||||
r.code = [{ required: true, message: t('login.placeholder.code'), trigger: 'blur' }]
|
||||
}
|
||||
return r
|
||||
})
|
||||
|
||||
const loading = ref(false)
|
||||
|
||||
onMounted(() => {
|
||||
refreshCaptcha()
|
||||
if (captchaEnabled.value) refreshCaptcha()
|
||||
})
|
||||
|
||||
// 登录
|
||||
@@ -146,12 +157,11 @@
|
||||
|
||||
loading.value = true
|
||||
|
||||
// 登录请求
|
||||
// 登录请求(关闭验证码时不传 code/uuid)
|
||||
const { access_token, refresh_token } = await fetchLogin({
|
||||
username: formData.username,
|
||||
password: formData.password,
|
||||
code: formData.code,
|
||||
uuid: formData.uuid
|
||||
...(captchaEnabled.value ? { code: formData.code, uuid: formData.uuid } : {})
|
||||
})
|
||||
|
||||
// 验证token
|
||||
@@ -178,7 +188,7 @@
|
||||
console.error('[Login] Unexpected error:', error)
|
||||
}
|
||||
} finally {
|
||||
refreshCaptcha()
|
||||
if (captchaEnabled.value) refreshCaptcha()
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user