|
@@ -3,7 +3,7 @@ import { apiLogin } from '@/pages/Login/api'
|
|
|
import { iFromValues } from '@/types/login'
|
|
|
import { ProjectInfo } from '@/types/project'
|
|
|
import { iGroup, iUserInfo } from '@/types/setting'
|
|
|
-import { apiGetGroupList, apiProjectInfo } from '@/utils/common/api'
|
|
|
+import { apiGetGroupList, apiProjectInfo, apiUserInfo } from '@/utils/common/api'
|
|
|
import { delUserInfo, getUserInfo, saveUserInfo } from '@/utils/common/user'
|
|
|
import consts from '@/utils/consts'
|
|
|
import history from '@/utils/history'
|
|
@@ -26,6 +26,8 @@ class UserState {
|
|
|
role: '',
|
|
|
telephone: ''
|
|
|
}
|
|
|
+ @observable loading: boolean = false
|
|
|
+
|
|
|
@observable userInfo: iUserInfo = this.initUserState
|
|
|
|
|
|
@observable permission: [] = []
|
|
@@ -57,7 +59,6 @@ class UserState {
|
|
|
const { code = -1, data } = await apiLogin(values)
|
|
|
if (code === consts.RET_CODE.SUCCESS) {
|
|
|
await this.getProjectInfo()
|
|
|
- saveUserInfo(data)
|
|
|
this.userInfo = data
|
|
|
history.push('/')
|
|
|
}
|
|
@@ -74,18 +75,31 @@ class UserState {
|
|
|
|
|
|
@action async logout() {
|
|
|
await apiLogout()
|
|
|
- delUserInfo()
|
|
|
this.userInfo = this.initUserState
|
|
|
- history.push('/login')
|
|
|
+ history.replace('/login')
|
|
|
+ }
|
|
|
+
|
|
|
+ @action async check() {
|
|
|
+ if (!this.userInfo?.id) {
|
|
|
+ this.toggleLoading()
|
|
|
+ await this.getUserInfo()
|
|
|
+ this.toggleLoading()
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- @action check() {
|
|
|
- const user: iUserInfo | null = getUserInfo()
|
|
|
- if (user) {
|
|
|
- this.userInfo = user
|
|
|
+ @action async getUserInfo() {
|
|
|
+ const { code = -1, data } = await apiUserInfo()
|
|
|
+ if (code === consts.RET_CODE.SUCCESS) {
|
|
|
+ this.userInfo = data
|
|
|
+ } else {
|
|
|
+ history.replace('/login')
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @action toggleLoading() {
|
|
|
+ this.loading = !this.loading
|
|
|
+ }
|
|
|
+
|
|
|
@action getGroupList() {
|
|
|
apiGetGroupList().then(({ code = -1, data = [] }) => {
|
|
|
if (code === consts.RET_CODE.SUCCESS) {
|