Ver código fonte

获取当前登录的企业用户信息

lifanagju_citu 11 meses atrás
pai
commit
c31f3779d8
2 arquivos alterados com 21 adições e 13 exclusões
  1. 8 0
      src/api/personal/user.js
  2. 13 13
      src/store/user.js

+ 8 - 0
src/api/personal/user.js

@@ -31,3 +31,11 @@ export const getUserRegisterEnterpriseApply = async (params) => {
     params
   })
 }
+
+// 获取当前登录的企业用户信息
+export const getEnterprisingUserInfo = async (params) => {
+  return await request.get({
+    url: '/app-admin-api/menduner/system/enterprise-user-bind/get/user',
+    params
+  })
+}

+ 13 - 13
src/store/user.js

@@ -2,7 +2,7 @@ import { defineStore } from 'pinia'
 import { setToken, removeToken, setRefreshToken } from '@/utils/auth'
 import { smsLogin, passwordLogin, getBaseInfo, passwordLoginOfEnterprise, smsLoginOfEnterprise } from '@/api/common/index'
 import { logout } from '@/api/common/index'
-import { getUserInfo } from '@/api/personal/user'
+import { getUserInfo, getEnterprisingUserInfo } from '@/api/personal/user'
 import Snackbar from '@/plugins/snackbar'
 import { timesTampChange } from '@/utils/date'
 import { getBaseInfoDictOfName } from '@/utils/getText'
@@ -11,6 +11,7 @@ import { getBaseInfoDictOfName } from '@/utils/getText'
 export const useUserStore = defineStore('user',
   {
     state: () => ({
+      loginType: null, // 登录类型 // 330为企业登录
       accountInfo: {}, // 登录返回的信息
       userInfo: {}, // 当前登录账号信息
       baseInfo: {}, // 人才信息
@@ -22,16 +23,14 @@ export const useUserStore = defineStore('user',
         return new Promise((resolve, reject) => {
           const loginApi = data.loginType === 330 ? smsLoginOfEnterprise : smsLogin
           loginApi(data).then(res => {
-            // res.loginType = data.loginType
+            this.loginType = data.loginType
             setToken(res.accessToken)
             setRefreshToken(res.refreshToken)
             this.accountInfo = res
             localStorage.setItem('accountInfo', JSON.stringify(res))
             localStorage.setItem('expiresTime', res.expiresTime) // token过期时间
-            if (!data.loginType) { // 个人登录
-              this.getUserInfos()
-              this.getUserBaseInfos()
-            }
+            this.getUserInfos()
+            this.getUserBaseInfos()
             resolve()
           }).catch(err => { reject(err) })
         })
@@ -41,16 +40,14 @@ export const useUserStore = defineStore('user',
         return new Promise((resolve, reject) => {
           const loginApi = data.loginType === 330 ? passwordLoginOfEnterprise : passwordLogin
           loginApi(data).then(res => {
-            // res.loginType = data.loginType
+            this.loginType = data.loginType
             setToken(res.accessToken)
             setRefreshToken(res.refreshToken)
             this.accountInfo = res
             localStorage.setItem('accountInfo', JSON.stringify(res))
             localStorage.setItem('expiresTime', res.expiresTime) // token过期时间
-            if (!data.loginType) { // 个人登录
-              this.getUserInfos()
-              this.getUserBaseInfos()
-            }
+            this.getUserInfos()
+            this.getUserBaseInfos()
             resolve()
           }).catch(err => { reject(err) })
         })
@@ -58,7 +55,8 @@ export const useUserStore = defineStore('user',
       // 获取当前登录账户信息
       async getUserInfos () {
         try {
-          const data = await getUserInfo({ id: this.accountInfo.userId })
+          const api = this.loginType ? getEnterprisingUserInfo : getUserInfo
+          const data = await api({ id: this.accountInfo.userId })
           this.userInfo = data
           localStorage.setItem('userInfo', JSON.stringify(data))
         } catch (error) {
@@ -68,7 +66,9 @@ export const useUserStore = defineStore('user',
       // 获取当前登录账户的基本信息(人才信息)
       async getUserBaseInfos (userId = null) {
         try {
-          const data = await getBaseInfo({ userId: userId || this.accountInfo.userId })
+          const api = this.loginType ? null : getBaseInfo
+          if (!api) return localStorage.setItem('baseInfo', JSON.stringify({}))
+          const data = await api({ userId: userId || this.accountInfo.userId })
           this.baseInfo = await this.getFieldText(data)
           localStorage.setItem('baseInfo', JSON.stringify(this.baseInfo))
         } catch (error) {