Bladeren bron

登录页添加log

Xiao_123 1 maand geleden
bovenliggende
commit
70bce03dbb
2 gewijzigde bestanden met toevoegingen van 47 en 10 verwijderingen
  1. 3 7
      src/views/login/components/passwordPage.vue
  2. 44 3
      src/views/login/index.vue

+ 3 - 7
src/views/login/components/passwordPage.vue

@@ -41,13 +41,13 @@
       :type="passwordType ? 'text' : 'password'"
       @click:append-inner="passwordType = !passwordType"
       :rules="[v=> !!v || $t('login.enterPassword'), validPassword]"
-      @keyup.enter="handleEnter"
+      @keyup.enter="emits('handleEnter')"
     ></v-text-field>
   </v-form>
 </template>
 
 <script setup name="passwordPage">
-import { ref, reactive, computed } from 'vue'
+import { ref, reactive, computed, onMounted, watch, nextTick } from 'vue'
 defineOptions({ name: 'password-form' })
 import { checkCompanyEmail } from '@/utils/validate'
 import { useI18n } from '@/hooks/web/useI18n'
@@ -57,6 +57,7 @@ const props = defineProps({ phoneDisabled: Boolean, placeholder: String, validEm
 const passwordType = ref(false)
 const emits = defineEmits(['handleEnter'])
 
+const passwordForm = ref()
 const phoneRules = ref([]) // 区分企业邮箱和手机号2种方式登录校验
 
 if (props.validEmail) {
@@ -113,11 +114,6 @@ if (window.location.hostname === 'localhost' || window.location.hostname === '19
   loginData.password = 'Citu123456'
 }
 
-const passwordForm = ref()
-
-const handleEnter = () => {
-  emits('handleEnter')
-}
 defineExpose({
   loginData,
   passwordForm

+ 44 - 3
src/views/login/index.vue

@@ -24,7 +24,13 @@
             <v-tabs v-model="tab1" align-tabs="center" color="primary" class="mb-10">
               <v-tab :value="1">企业邮箱登录</v-tab>
             </v-tabs>
-            <passwordFrom ref="entPassRef" placeholder="请输入企业邮箱" :isCounter="true" :validEmail="true" @handleEnter="handleLogin"></passwordFrom>
+            <passwordFrom
+              ref="entPassRef"
+              placeholder="请输入企业邮箱"
+              :isCounter="true"
+              :validEmail="true"
+              @handleEnter="handleLogin"
+            />
           </div>
           <!-- 个人登录 -->
           <div v-show="!isEnterpriseLogin" class="login-tab">
@@ -156,7 +162,14 @@ const isAgree = ref(false)
 const isEnterpriseLogin = ref(route.query?.entLogin || false)
 
 const handleChangeLogin = () => {
+  console.log('切换登录模式前:', { 
+    isEnterpriseLogin: isEnterpriseLogin.value, 
+    entPassRef: entPassRef.value,
+    entPassRefLoginData: entPassRef.value?.loginData 
+  })
+  
   isEnterpriseLogin.value = !isEnterpriseLogin.value
+  
   nextTick(() => {
     // tab.value = isEnterpriseLogin.value ? 2 : 1 // 为了验证邮箱validate,企业邮箱登录时需要tab
     tab.value = 2 // 为了验证邮箱validate,企业邮箱登录时需要tab=2
@@ -188,8 +201,36 @@ const handleLogin = async () => {
   loginLoading.value = true
   try {
     let params, api = {}
-    if (isEnterpriseLogin.value) { params = { ...entPassRef.value.loginData }; api = 'handlePasswordLogin'}
-    else { params = tab.value === 1 ? { ...phoneRef.value.loginData } : { ...passRef.value.loginData }; api = tab.value === 1 ? 'handleSmsLogin' : 'handlePasswordLogin'}
+    if (isEnterpriseLogin.value) { 
+      // 添加安全检查,确保企业登录数据完整
+      if (!entPassRef.value || !entPassRef.value.loginData) {
+        console.error('企业登录组件引用或数据不存在:', { entPassRef: entPassRef.value, loginData: entPassRef.value?.loginData })
+        Snackbar.error('数据获取失败,请刷新页面重试')
+        return
+      }
+      
+      if (!entPassRef.value.loginData.password) {
+        console.error('企业登录密码缺失:', entPassRef.value.loginData)
+        Snackbar.error('请输入密码')
+        return
+      }
+      
+      if (!entPassRef.value.loginData.phone) {
+        console.error('企业登录邮箱缺失:', entPassRef.value.loginData)
+        Snackbar.error('请输入企业邮箱')
+        return
+      }
+      
+      params = { ...entPassRef.value.loginData }
+      api = 'handlePasswordLogin'
+      
+      // 调试日志
+      console.log('企业登录数据:', params)
+    }
+    else { 
+      params = tab.value === 1 ? { ...phoneRef.value.loginData } : { ...passRef.value.loginData }
+      api = tab.value === 1 ? 'handleSmsLogin' : 'handlePasswordLogin'
+    }
     if (!params.captchaVerification && captchaStr.value) params.captchaVerification = captchaStr.value
     if (!params.captchaVerification) {
       getCode() // 验证码组件