fix: modify
parent
7fb547ea62
commit
ce41faacc5
|
@ -26,14 +26,13 @@
|
||||||
</a-input-password>
|
</a-input-password>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
</a-tooltip>
|
</a-tooltip>
|
||||||
<a-form-item class="login-form-item" name="verify" :rules="[{ ...required, message: '请输入验证码' }]">
|
<a-form-item v-if="needSmsVerify" class="login-form-item" name="verify" :rules="[{ ...required, message: '请输入验证码' }]">
|
||||||
<a-input placeholder="请输入验证码" autocomplete="off" v-model:value="loginForm.verify" style="width: 67%; vertical-align: middle">
|
<a-input placeholder="请输入验证码" autocomplete="off" v-model:value="loginForm.verify" style="width: 67%; vertical-align: middle">
|
||||||
<template #prefix>
|
<template #prefix>
|
||||||
<LockOutlined />
|
<LockOutlined />
|
||||||
</template>
|
</template>
|
||||||
</a-input>
|
</a-input>
|
||||||
<div class="login-code" v-if="identifyCode"></div>
|
<a-button style="height: 60px; width: 31%; margin-left: 2%" @click="getVertify" :loading="verifyLoading" :disabled="isCountingDown || !loginForm.account.trim()">
|
||||||
<a-button v-else style="height: 60px; width: 31%; margin-left: 2%" @click="getVertify" :loading="verifyLoading" :disabled="isCountingDown || !loginForm.account.trim()">
|
|
||||||
{{ isCountingDown ? `${countdown}s后重新获取` : '获取验证码' }}
|
{{ isCountingDown ? `${countdown}s后重新获取` : '获取验证码' }}
|
||||||
</a-button>
|
</a-button>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
|
@ -56,13 +55,14 @@
|
||||||
<script>
|
<script>
|
||||||
import { decrypt, encrypt } from 'utils/crypto'
|
import { decrypt, encrypt } from 'utils/crypto'
|
||||||
import { login } from 'services'
|
import { login } from 'services'
|
||||||
import { reactive, toRefs, ref, computed } from 'vue'
|
import { reactive, toRefs, ref, computed, watch } from 'vue'
|
||||||
import { UserOutlined, LockOutlined } from '@ant-design/icons-vue'
|
import { UserOutlined, LockOutlined } from '@ant-design/icons-vue'
|
||||||
import { useStore } from 'vuex'
|
import { useStore } from 'vuex'
|
||||||
import { useRouter, useRoute } from 'vue-router'
|
import { useRouter, useRoute } from 'vue-router'
|
||||||
import setLoginData from './tools'
|
import setLoginData from './tools'
|
||||||
import { required } from '@/validate'
|
import { required } from '@/validate'
|
||||||
import { getVertifyCode } from '@/services'
|
import { getVertifyCode } from '@/services'
|
||||||
|
import { message } from 'ant-design-vue'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: { UserOutlined, LockOutlined },
|
components: { UserOutlined, LockOutlined },
|
||||||
|
@ -77,9 +77,9 @@ export default {
|
||||||
capsTooltip: false,
|
capsTooltip: false,
|
||||||
verifyLoading: false,
|
verifyLoading: false,
|
||||||
countdown: 0,
|
countdown: 0,
|
||||||
isCountingDown: false
|
isCountingDown: false,
|
||||||
|
needSmsVerify: true
|
||||||
})
|
})
|
||||||
|
|
||||||
const store = useStore()
|
const store = useStore()
|
||||||
const configs = computed(() => store.getters.pageConfig)
|
const configs = computed(() => store.getters.pageConfig)
|
||||||
const loginFormRef = ref(null)
|
const loginFormRef = ref(null)
|
||||||
|
@ -120,6 +120,15 @@ export default {
|
||||||
init()
|
init()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
|
|
||||||
|
// 监听account变化,如果清空则重置needSmsVerify
|
||||||
|
watch(() => state.loginForm.account, (newAccount) => {
|
||||||
|
if (!newAccount.trim()) {
|
||||||
|
state.needSmsVerify = true
|
||||||
|
resetCountdown() // 同时重置倒计时
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
const getVertify = () => {
|
const getVertify = () => {
|
||||||
if (state.isCountingDown) return // 如果正在倒计时,不允许重复点击
|
if (state.isCountingDown) return // 如果正在倒计时,不允许重复点击
|
||||||
if (!state.loginForm.account.trim()) {
|
if (!state.loginForm.account.trim()) {
|
||||||
|
@ -133,8 +142,14 @@ export default {
|
||||||
if (res.success) {
|
if (res.success) {
|
||||||
state.verifyLoading = false
|
state.verifyLoading = false
|
||||||
state.hasVertify = res.data
|
state.hasVertify = res.data
|
||||||
state.identifyCode = res.data
|
message.success(res.message)
|
||||||
startCountdown() // 开始倒计时
|
// 检查是否需要短信验证码
|
||||||
|
if (res.message && res.message.includes('无需短信验证码校验')) {
|
||||||
|
state.needSmsVerify = false
|
||||||
|
} else {
|
||||||
|
state.needSmsVerify = true
|
||||||
|
startCountdown() // 开始倒计时
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
|
@ -163,12 +178,16 @@ export default {
|
||||||
state.loading = true
|
state.loading = true
|
||||||
const values = await loginFormRef.value.validate()
|
const values = await loginFormRef.value.validate()
|
||||||
const { account, password, verify } = values
|
const { account, password, verify } = values
|
||||||
const res = await login({
|
const loginData = {
|
||||||
account,
|
account,
|
||||||
password: encrypt(password),
|
password: encrypt(password),
|
||||||
isManager: true,
|
isManager: true
|
||||||
code: verify
|
}
|
||||||
})
|
// 只有需要验证码时才添加code字段
|
||||||
|
if (state.needSmsVerify) {
|
||||||
|
loginData.code = verify
|
||||||
|
}
|
||||||
|
const res = await login(loginData)
|
||||||
if (res.success) {
|
if (res.success) {
|
||||||
goLogin(res.data)
|
goLogin(res.data)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue