generated from Leo_Ding/web-template
登录页面验证码
This commit is contained in:
parent
f34ecf2b58
commit
9a5ecf5d29
@ -5,5 +5,9 @@ export const getRegion = (params) => request.basic.get('/region', params)
|
|||||||
|
|
||||||
// 获取 验证码ID
|
// 获取 验证码ID
|
||||||
export const getCaptcha = (params) => request.basic.get('/api/v1/captcha/id', params)
|
export const getCaptcha = (params) => request.basic.get('/api/v1/captcha/id', params)
|
||||||
|
|
||||||
|
// 获取图片
|
||||||
|
export const getCaptchaImage = (params) => request.basic.get('/api/v1/captcha/image', params , { responseType: 'blob' })
|
||||||
|
|
||||||
//上传图片
|
//上传图片
|
||||||
export const uploadImg=(params)=>request.basic.post('/api/v1/upload',params,{Headers:{'Content-Type': 'multipart/form-data'}})
|
export const uploadImg=(params)=>request.basic.post('/api/v1/upload',params,{Headers:{'Content-Type': 'multipart/form-data'}})
|
||||||
@ -20,8 +20,7 @@ const options = {
|
|||||||
},
|
},
|
||||||
interceptorRequestCatch: () => {},
|
interceptorRequestCatch: () => {},
|
||||||
interceptorResponse: (response) => {
|
interceptorResponse: (response) => {
|
||||||
console.log('response',response)
|
const list = ['/api/v1/activity-details/export', '/api/v1/captcha/image']
|
||||||
const list=['/api/v1/activity-details/export']
|
|
||||||
// 错误处理
|
// 错误处理
|
||||||
const { success, msg = 'Network Error' } = response.data || {}
|
const { success, msg = 'Network Error' } = response.data || {}
|
||||||
if (![true].includes(success) && !list.includes(response.config.url)){
|
if (![true].includes(success) && !list.includes(response.config.url)){
|
||||||
|
|||||||
@ -2,17 +2,10 @@
|
|||||||
<div>
|
<div>
|
||||||
<a-tabs>
|
<a-tabs>
|
||||||
<!-- 账号登录 -->
|
<!-- 账号登录 -->
|
||||||
<a-tab-pane
|
<a-tab-pane key="account" :tab="$t('pages.login.accountLogin.tab')">
|
||||||
key="account"
|
<a-form :model="formData" :rules="formRules" ref="formRef">
|
||||||
:tab="$t('pages.login.accountLogin.tab')">
|
|
||||||
<a-form
|
|
||||||
:model="formData"
|
|
||||||
:rules="formRules"
|
|
||||||
ref="formRef">
|
|
||||||
<a-form-item name="username">
|
<a-form-item name="username">
|
||||||
<a-input
|
<a-input :placeholder="$t('pages.login.username.placeholder')" v-model:value="formData.username"
|
||||||
:placeholder="$t('pages.login.username.placeholder')"
|
|
||||||
v-model:value="formData.username"
|
|
||||||
size="large">
|
size="large">
|
||||||
<template #prefix>
|
<template #prefix>
|
||||||
<user-outlined></user-outlined>
|
<user-outlined></user-outlined>
|
||||||
@ -20,18 +13,14 @@
|
|||||||
</a-input>
|
</a-input>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
<a-form-item name="password">
|
<a-form-item name="password">
|
||||||
<a-input
|
<a-input v-model:value="formData.password" size="large" type="password"
|
||||||
v-model:value="formData.password"
|
:placeholder="$t('pages.login.password.placeholder')" @pressEnter="handleLogin">
|
||||||
size="large"
|
|
||||||
type="password"
|
|
||||||
:placeholder="$t('pages.login.password.placeholder')"
|
|
||||||
@pressEnter="handleLogin">
|
|
||||||
<template #prefix>
|
<template #prefix>
|
||||||
<lock-outlined></lock-outlined>
|
<lock-outlined></lock-outlined>
|
||||||
</template>
|
</template>
|
||||||
</a-input>
|
</a-input>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
<!-- <a-form-item name="captcha_code">
|
<a-form-item name="captcha_code">
|
||||||
<a-space>
|
<a-space>
|
||||||
<a-input
|
<a-input
|
||||||
v-model:value="formData.captcha_code"
|
v-model:value="formData.captcha_code"
|
||||||
@ -50,15 +39,10 @@
|
|||||||
:height="42"
|
:height="42"
|
||||||
:src="captcha_img" />
|
:src="captcha_img" />
|
||||||
</a-space>
|
</a-space>
|
||||||
</a-form-item> -->
|
</a-form-item>
|
||||||
<a-form-item>
|
<a-form-item>
|
||||||
<a-button
|
<a-button type="primary" size="large" block :loading="loading" @click="handleLogin">{{
|
||||||
type="primary"
|
$t('pages.login.submit') }}
|
||||||
size="large"
|
|
||||||
block
|
|
||||||
:loading="loading"
|
|
||||||
@click="handleLogin"
|
|
||||||
>{{ $t('pages.login.submit') }}
|
|
||||||
</a-button>
|
</a-button>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
</a-form>
|
</a-form>
|
||||||
@ -124,27 +108,33 @@ async function getCaptcha() {
|
|||||||
async function handleLogin() {
|
async function handleLogin() {
|
||||||
formRef.value.validate().then(async (values) => {
|
formRef.value.validate().then(async (values) => {
|
||||||
values.captcha_id = captcha_id.value
|
values.captcha_id = captcha_id.value
|
||||||
if (values.password === 'abc-123') values.password = md5(values.password)
|
if (values.password === 'abc-123') {
|
||||||
|
values.password = md5(values.password)
|
||||||
|
}
|
||||||
|
|
||||||
loading.value = true
|
loading.value = true
|
||||||
const { success } = await userStore
|
try {
|
||||||
.login({
|
const response = await userStore.login({ ...values })
|
||||||
...values,
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
loading.value = false
|
loading.value = false
|
||||||
getCaptcha()
|
if (config('http.code.success') === response.success) {
|
||||||
})
|
|
||||||
loading.value = false
|
|
||||||
if (config('http.code.success') === success) {
|
|
||||||
// 加载完成
|
|
||||||
if (appStore.complete) {
|
if (appStore.complete) {
|
||||||
goIndex()
|
goIndex()
|
||||||
} else {
|
} else {
|
||||||
await appStore.init()
|
await appStore.init()
|
||||||
goIndex()
|
goIndex()
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
message.error(t(response.msg))
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
loading.value = false
|
||||||
|
getCaptcha()
|
||||||
|
const msg = error.msg || error.message || '登录失败,请重试'
|
||||||
|
message.error(t(msg))
|
||||||
|
console.log("登录出错:", error)
|
||||||
|
}
|
||||||
|
}).catch(validationError => {
|
||||||
|
console.log('表单校验失败', validationError)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user