Przeglądaj źródła

企业登录,默认登录用户企业列表的第一个企业

lifanagju_citu 11 miesięcy temu
rodzic
commit
abcb523933
3 zmienionych plików z 26 dodań i 8 usunięć
  1. 4 1
      src/layout/personal/navBar.vue
  2. 6 2
      src/store/user.js
  3. 16 5
      src/views/login/index.vue

+ 4 - 1
src/layout/personal/navBar.vue

@@ -131,7 +131,10 @@ const changeLoginType = async () => {
   // router.push({ name: 'login', query: { loginType: 330 } })
 
   const data = await getUserBindEnterpriseList() // 申请通过才会数据,否则空数组
-  if (data?.length) changeRole()
+  if (data?.length) {
+    localStorage.setItem('companyInfo', JSON.stringify(data))
+    changeRole()
+  }
   else getApplyInfo()
 }
 

+ 6 - 2
src/store/user.js

@@ -20,8 +20,9 @@ export const useUserStore = defineStore('user',
       // 短信登录
       async handleSmsLogin (data) {
         return new Promise((resolve, reject) => {
-          const loginApi = data.type === 330 ? smsLoginOfEnterprise : smsLogin
+          const loginApi = data.loginType === 330 ? smsLoginOfEnterprise : smsLogin
           loginApi(data).then(res => {
+            // res.loginType = data.loginType
             setToken(res.accessToken)
             setRefreshToken(res.refreshToken)
             this.accountInfo = res
@@ -36,8 +37,9 @@ export const useUserStore = defineStore('user',
       // // 密码登录
       async handlePasswordLogin(data) {
         return new Promise((resolve, reject) => {
-          const loginApi = data.type === 330 ? passwordLoginOfEnterprise : passwordLogin
+          const loginApi = data.loginType === 330 ? passwordLoginOfEnterprise : passwordLogin
           loginApi(data).then(res => {
+            // res.loginType = data.loginType
             setToken(res.accessToken)
             setRefreshToken(res.refreshToken)
             this.accountInfo = res
@@ -89,7 +91,9 @@ export const useUserStore = defineStore('user',
         this.userInfo = {}
         this.baseInfo = {}
         this.accountInfo = {}
+        const companyInfo = localStorage.getItem('companyInfo')
         localStorage.clear()
+        localStorage.setItem('companyInfo', companyInfo)
       }
     }
   },

+ 16 - 5
src/views/login/index.vue

@@ -103,13 +103,24 @@ const handleLogin = async () => {
   loginLoading.value = true
   try {
     const type = loginType.value
-    if (tab.value === 1) {
-      await userStore.handleSmsLogin({ ...phoneRef.value.loginData, type })
-    } else {
-      await userStore.handlePasswordLogin({ ...passRef.value.loginData, type })
+    let params, api = {}
+    if (tab.value === 1) { params = { ...phoneRef.value.loginData }; api = 'handleSmsLogin'}
+    else { params = { ...passRef.value.loginData }; api = 'handlePasswordLogin'}
+    // 企业登录
+    if (type === 330) {
+      const companyList = JSON.parse(localStorage.getItem('companyInfo'))
+      if (companyList?.length) {
+        params.loginType = type // 前端判断是否是企业登录标识 330 为企业否者为个人
+        const companyInfo = companyList[0]
+        params.enterpriseId = companyInfo.enterpriseId
+      }
     }
+    // await userStore.handlePasswordLogin({ ...passRef.value.loginData, type }) //tab.value === 1
+    // await userStore.handleSmsLogin({ ...phoneRef.value.loginData, type })
+    await userStore[api](params)
     Snackbar.success(t('login.loginSuccess'))
-    router.push({ path: '/home' })
+    const path = type === 330 ? '/enterprise' : '/home'
+    router.push({ path })
   }
   finally {
     loginLoading.value = false