From 348006af285393016f36a8bd643cd99b8e21fead Mon Sep 17 00:00:00 2001 From: yangyin <1850366751@qq.com> Date: 星期五, 26 七月 2024 17:10:35 +0800 Subject: [PATCH] fix: 修改验证码登录 --- src/api/ai/chat.ts | 3 + src/api/ai/user.ts | 15 +++++++ src/layout/component/sidebar/components/MenuList.vue | 57 +++++++++++++++++++++------- 3 files changed, 59 insertions(+), 16 deletions(-) diff --git a/src/api/ai/chat.ts b/src/api/ai/chat.ts index 2d8f11e..0db2c88 100644 --- a/src/api/ai/chat.ts +++ b/src/api/ai/chat.ts @@ -2,7 +2,8 @@ import { toFormData } from '/@/utils/util'; const GET_SECTION_SAMPLE_API = '/section/get_section_sample'; const GET_SECTION_A_LIST_API = '/section/get_section_a_list'; -export const NO_AUTH_API_LIST = [GET_SECTION_SAMPLE_API, GET_SECTION_A_LIST_API]; +export const Get_LOGIN_SMS = '/login_sms'; +export const NO_AUTH_API_LIST = [GET_SECTION_SAMPLE_API, GET_SECTION_A_LIST_API, Get_LOGIN_SMS]; //#region ====================== knowledge ====================== diff --git a/src/api/ai/user.ts b/src/api/ai/user.ts index 8ab839c..9c28874 100644 --- a/src/api/ai/user.ts +++ b/src/api/ai/user.ts @@ -1,3 +1,4 @@ +import { Get_LOGIN_SMS } from './chat'; import request from '/@/utils/request'; export const LOGIN_URL = '/login'; export const TEL_LOGIN_URL = '/send_login_sms'; @@ -25,10 +26,22 @@ }); }; +//鍙戦�佺煭淇¢獙璇佺爜 +export const loginVerifyMessage = async (params, req: any = request) => { + return req({ + url: TEL_LOGIN_URL, + method: 'POST', + data: params, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + }); +}; + //鍙戦�佺煭淇¢獙璇佺爜鐧诲綍 export const loginMessageUser = async (params, req: any = request) => { return req({ - url: TEL_LOGIN_URL, + url: Get_LOGIN_SMS, method: 'POST', data: params, headers: { diff --git a/src/layout/component/sidebar/components/MenuList.vue b/src/layout/component/sidebar/components/MenuList.vue index e9e438f..e841cf2 100644 --- a/src/layout/component/sidebar/components/MenuList.vue +++ b/src/layout/component/sidebar/components/MenuList.vue @@ -48,7 +48,7 @@ ref="loginFormRef" :model="state.loginForm" :rules="loginRules" - class="demo-ruleForm mt-[24px] min-h-[126px]" + class="demo-ruleForm mt-[24px] min-h-[140px]" size="large" > <el-form-item label="璐﹀彿" prop="account"> @@ -65,8 +65,7 @@ :rules="loginPhoneRules" :model="state.loginPhoneForm" size="large" - label-width="67px" - class="mt-[24px] min-h-[126px]" + class="mt-[24px] min-h-[140px]" > <el-form-item label="鎵嬫満鍙�" prop="phoneUser"> <el-input v-model="state.loginPhoneForm.phoneUser" placeholder="璇疯緭鍏ユ墜鏈哄彿鐮�" clearable> @@ -76,7 +75,9 @@ <el-form-item prop="verifyCode" label="楠岃瘉鐮�"> <el-input v-model="state.loginPhoneForm.verifyCode" placeholder="璇疯緭鍏ュ洓浣嶉獙璇佺爜" maxlength="6" clearable> <template #append> - <el-button type="primary" @click="handleSendVerifyCode">鑾峰彇楠岃瘉鐮�</el-button> + <el-button type="primary" @click="handleSendVerifyCode" :disabled="countdown > 0">{{ + countdown > 0 ? `${countdown}绉掑悗閲嶈瘯` : '鑾峰彇楠岃瘉鐮�' + }}</el-button> </template> </el-input> </el-form-item> @@ -95,7 +96,7 @@ <script setup lang="ts"> import type { FormInstance } from 'element-plus'; import { computed, onMounted, reactive, ref, watchEffect } from 'vue'; -import { PostLogin, loginMessageUser } from '/@/api/ai/user'; +import { PostLogin, loginMessageUser, loginVerifyMessage } from '/@/api/ai/user'; import router from '/@/router'; import emitter from '/@/utils/mitt'; import { accessSessionKey, userNameKey } from '/@/utils/request'; @@ -105,6 +106,7 @@ const formPhoneRef = ref(); //鎵嬫満鍙风櫥褰� const isLoginStatus = ref(!!Local.get(accessSessionKey)); const userName = ref(''); +const countdown = ref(0); const firstUserCharacter = computed(() => userName.value?.[0]?.toUpperCase()); watchEffect(() => { if (!isLoginStatus.value) return; @@ -157,6 +159,7 @@ { required: true, message: '璇疯緭鍏ユ墜鏈哄彿鐮�', trigger: 'blur' }, { pattern: /^1\d{10}$/, message: '璇疯緭鍏ユ纭殑鎵嬫満鍙风爜', trigger: 'blur' }, ], + verifyCode: [{ required: true, message: '璇疯緭鍏ラ獙璇佺爜', trigger: 'blur' }], }; const handleClick = (item) => { gotoRoute({ name: item.routerName }); @@ -170,14 +173,27 @@ }; //鐧诲綍 const onSubmit = async () => { - const isValid = await loginFormRef.value.validate().catch(() => {}); - if (!isValid) return; - const res = await PostLogin({ - user: state.loginForm.account, - pass: state.loginForm.pwd, - }); + if (state.activeLoginName === 'accountUser') { + //璐︽埛瀵嗙爜鐧诲綍 + const isValid = await loginFormRef.value.validate().catch(() => {}); + if (!isValid) return; + const res = await PostLogin({ + user: state.loginForm.account, + pass: state.loginForm.pwd, + }); - LoginInfo.set(res.hswatersession, state.loginForm.account); + LoginInfo.set(res.hswatersession, state.loginForm.account); + } else if (state.activeLoginName === 'phoneUser') { + //鎵嬫満鐧诲綍 + const isValid = await formPhoneRef.value.validate().catch(() => {}); + if (!isValid) return; + const res = await loginMessageUser({ + phone: state.loginPhoneForm.phoneUser, + code: state.loginPhoneForm.verifyCode, + }); + + LoginInfo.set(res.hswatersession, state.loginPhoneForm.phoneUser); + } state.isShowLogin = false; isLoginStatus.value = true; window.location.reload(); @@ -212,10 +228,20 @@ const handleSendVerifyCode = async () => { formPhoneRef.value.validateField('phoneUser', async (valid: boolean) => { if (valid) { - const res = await loginMessageUser({ + const res = await loginVerifyMessage({ phone: state.loginPhoneForm.phoneUser, }); - console.log('馃殌 ~ res:', res); + if (res.json_ok) { + countdown.value = 60; //寮�鍚�掕鏃� + // 鍊掕鏃堕�昏緫 + const intervalId = setInterval(() => { + if (countdown.value > 0) { + countdown.value--; + } else { + clearInterval(intervalId); + } + }, 1000); + } } }); }; @@ -466,6 +492,9 @@ background-color: #fff; border-radius: 5px; } + :deep(.el-form-item--large .el-form-item__error) { + padding: unset !important; + } } .set-pwd { text-align: right; -- Gitblit v1.9.3