|
@@ -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()
|
|
|
+ if (!this.loginType) 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()
|
|
|
+ if (!this.loginType) 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
|
|
|
+ const data = await api({ userId: userId || this.accountInfo.userId })
|
|
|
this.baseInfo = await this.getFieldText(data)
|
|
|
localStorage.setItem('baseInfo', JSON.stringify(this.baseInfo))
|
|
|
} catch (error) {
|
|
@@ -90,6 +90,7 @@ export const useUserStore = defineStore('user',
|
|
|
},
|
|
|
// 退出登录
|
|
|
async userLogout () {
|
|
|
+ const loginUserPhone = this.userInfo?.phone || ''
|
|
|
await logout()
|
|
|
removeToken()
|
|
|
this.userInfo = {}
|
|
@@ -98,6 +99,7 @@ export const useUserStore = defineStore('user',
|
|
|
const companyInfo = localStorage.getItem('companyInfo')
|
|
|
localStorage.clear()
|
|
|
localStorage.setItem('companyInfo', companyInfo)
|
|
|
+ localStorage.setItem('loginUserPhone', loginUserPhone)
|
|
|
}
|
|
|
}
|
|
|
},
|