Browse Source

16. 个人信息的功能接入

YunaiV 2 years ago
parent
commit
cbddf13cd0
5 changed files with 47 additions and 9 deletions
  1. 12 1
      src/api/path/system.api.ts
  2. 5 0
      src/api/path/system.d.ts
  3. 10 1
      src/i18n/en/index.ts
  4. 10 1
      src/i18n/zh/index.ts
  5. 10 6
      src/views/login/index.vue

+ 12 - 1
src/api/path/system.api.ts

@@ -1,7 +1,7 @@
 import { http } from '@/api/http'
 import { httpErrorHandle } from '@/utils'
 import { RequestHttpEnum, ModuleTypeEnum } from '@/enums/httpEnum'
-import { AuthLoginRespVO } from './system'
+import {AuthLoginRespVO, ProfileVO} from './system'
 
 // * 登录
 export const loginApi = async (data: object) => {
@@ -24,6 +24,17 @@ export const logoutApi = async () => {
   }
 }
 
+// 查询用户个人信息
+export const getUserProfileApi = async () => {
+  try {
+    const res = await http(RequestHttpEnum.GET)<ProfileVO>(`${ModuleTypeEnum.SYSTEM}/user/profile/get`)
+    return res
+  } catch (err) {
+    httpErrorHandle()
+  }
+}
+
+
 // 获取验证图片  以及token
 export const getCodeApi = async (data: any) => {
   try {

+ 5 - 0
src/api/path/system.d.ts

@@ -16,3 +16,8 @@ export interface AuthLoginRespVO {
    */
   expiresTime: number
 }
+
+export interface ProfileVO {
+  id: number
+  nickname: string
+}

+ 10 - 1
src/i18n/en/index.ts

@@ -34,9 +34,18 @@ const http = {
   token_overdue_message: 'Login expired, please log in again!'
 }
 
+const captcha = {
+  verification: 'Please complete security verification',
+  slide: 'Swipe right to complete verification',
+  point: 'Please click',
+  success: 'Verification succeeded',
+  fail: 'verification failed'
+}
+
 export default {
   global,
   http,
   login,
-  project
+  project,
+  captcha
 }

+ 10 - 1
src/i18n/zh/index.ts

@@ -39,9 +39,18 @@ const http = {
   token_overdue_message: '登录过期,请重新登录!'
 }
 
+const captcha = {
+  verification: '请完成安全验证',
+  slide: '向右滑动完成验证',
+  point: '请依次点击',
+  success: '验证成功',
+  fail: '验证失败',
+}
+
 export default {
   global,
   http,
   login,
-  project
+  project,
+  captcha
 }

+ 10 - 6
src/views/login/index.vue

@@ -147,7 +147,7 @@ import { PageEnum } from '@/enums/pageEnum'
 import { StorageEnum } from '@/enums/storageEnum'
 import { icon } from '@/plugins'
 import { routerTurnByName } from '@/utils'
-import {getTenantIdByNameApi, loginApi} from '@/api/path'
+import {getTenantIdByNameApi, getUserProfileApi, loginApi} from '@/api/path'
 import { Verify } from '@/components/Verifition'
 
 interface FormState {
@@ -269,14 +269,19 @@ const handleSubmit = async (params: any) => {
         captchaVerification: params.captchaVerification
       })
       if(loginRes && loginRes.data) {
-        // Token 信息
+        // Token 信息(先存储下,保证可以加载个人信息)
         const tokenValue = loginRes.data.accessToken
         const tokenName = 'Authorization'
+        systemStore.setItem(SystemStoreEnum.USER_INFO, {
+          [SystemStoreUserInfoEnum.USER_TOKEN]: tokenValue,
+          [SystemStoreUserInfoEnum.TOKEN_NAME]: tokenName
+        })
+
         // 个人信息
+        const profileRes = await getUserProfileApi()
         const id = loginRes.data.userId
-        const username = '芋道源码'
-        const nickname = '芋道源码'
-
+        const username = profileRes?.data?.nickname
+        const nickname = profileRes?.data?.nickname
         // 存储到 pinia
         systemStore.setItem(SystemStoreEnum.USER_INFO, {
           [SystemStoreUserInfoEnum.USER_TOKEN]: tokenValue,
@@ -284,7 +289,6 @@ const handleSubmit = async (params: any) => {
           [SystemStoreUserInfoEnum.USER_ID]: id,
           [SystemStoreUserInfoEnum.USER_NAME]: username,
           [SystemStoreUserInfoEnum.NICK_NAME]: nickname,
-          t
         })
 
         window['$message'].success(t('login.login_success'))