From 1228dfc97bc52a701f1bb6b1a475d76f13eb6772 Mon Sep 17 00:00:00 2001 From: Jason Date: Wed, 22 Sep 2021 12:02:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=8E=B7=E5=8F=96=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E5=9F=BA=E7=A1=80=E4=BF=A1=E6=81=AF=E7=9A=84=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/interfaces/user.ts | 7 ++++++- src/router/index.ts | 2 +- src/store/modules/auth.ts | 5 ++++- src/types/user.d.ts | 4 ++-- src/views/Home/index.vue | 13 +++++-------- src/views/User/index.vue | 19 ++++++++++--------- 6 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/api/interfaces/user.ts b/src/api/interfaces/user.ts index b55664a..ca655f6 100644 --- a/src/api/interfaces/user.ts +++ b/src/api/interfaces/user.ts @@ -1,10 +1,15 @@ -import { BaseInfo } from '@/types/user' +import { BaseInfo, UserIndex } from '@/types/user' import request from '@/utils/request' +const index = (): Promise => { + return request.get('user') +} + const info = (): Promise => { return request.get('user/info') } export default { + index, info } diff --git a/src/router/index.ts b/src/router/index.ts index a5fbb3f..88e1f2f 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -55,7 +55,7 @@ router.beforeEach((to, from, next) => { if (to.name !== 'AuthLogin' && to.meta.requiresAuth && !isAuthenticated) { next({ name: 'AuthLogin', query: { to: to.path }}) } else if (isAuthenticated && (to.name == 'AuthLogin' || to.name == 'AuthRegister')) { - next({ name: 'Home' }) + next({ name: 'User' }) } else { next() } diff --git a/src/store/modules/auth.ts b/src/store/modules/auth.ts index 6a24003..64da89a 100644 --- a/src/store/modules/auth.ts +++ b/src/store/modules/auth.ts @@ -1,4 +1,4 @@ -import { auth } from '@/api' +import { auth, user } from '@/api' import { PERSISTED_KEY, State } from '@/store' import { LoginData } from '@/types/auth' import { Module } from 'vuex' @@ -16,6 +16,9 @@ export default { commit('setAccessToken', response, { root: true }) // 刷新用户中心页面 commit('refresh/setUser', true, { root: true }) + user.info().then(info => { + commit('setUserInfo', info, { root: true }) + }) resolve(response) }).catch(error => { reject(error) diff --git a/src/types/user.d.ts b/src/types/user.d.ts index e8e36a2..36ca347 100644 --- a/src/types/user.d.ts +++ b/src/types/user.d.ts @@ -5,6 +5,6 @@ export declare interface BaseInfo { avatar: string } -export declare type UserInfo = BaseInfo & { - level: number +export declare type UserIndex = BaseInfo & { + balance: string } diff --git a/src/views/Home/index.vue b/src/views/Home/index.vue index 342dd16..8a6f183 100644 --- a/src/views/Home/index.vue +++ b/src/views/Home/index.vue @@ -7,18 +7,15 @@ - -