浏览代码

Merge branch 'master' of http://182.92.126.35:3000/hrx/mky-vent-base

lxh 11 小时之前
父节点
当前提交
1b169fb738
共有 2 个文件被更改,包括 15 次插入8 次删除
  1. 5 3
      src/api/sys/user.ts
  2. 10 5
      src/store/modules/user.ts

+ 5 - 3
src/api/sys/user.ts

@@ -1,7 +1,7 @@
 import { defHttp } from '/@/utils/http/axios';
 import { LoginParams, LoginResultModel, GetUserInfoModel, AutoLoginParams, TokenInfo } from './model/userModel';
 
-import { ErrorMessageMode } from '/#/axios';
+import { ErrorMessageMode, SuccessMessageMode } from '/#/axios';
 import { useMessage } from '/@/hooks/web/useMessage';
 import { useUserStoreWithOut } from '/@/store/modules/user';
 import { setAuthCache } from '/@/utils/auth';
@@ -50,13 +50,14 @@ enum Api {
 /**
  * @description: user login api
  */
-export function loginApi(params: LoginParams, mode: ErrorMessageMode = 'modal') {
+export function loginApi(params: LoginParams, mode: ErrorMessageMode = 'modal', successMode: SuccessMessageMode = 'success') {
   return defHttp.post<LoginResultModel>(
     {
       url: Api.Login,
       params,
     },
     {
+      successMessageMode: successMode,
       errorMessageMode: mode,
     }
   );
@@ -65,7 +66,7 @@ export function loginApi(params: LoginParams, mode: ErrorMessageMode = 'modal')
 /**
  * @description: user auto login api
  */
-export function autoLoginApi(params: AutoLoginParams, mode: ErrorMessageMode = 'modal') {
+export function autoLoginApi(params: AutoLoginParams, mode: ErrorMessageMode = 'modal', successMode: SuccessMessageMode = 'success') {
   return defHttp.get<LoginResultModel>(
     {
       url: Api.autoLogin,
@@ -75,6 +76,7 @@ export function autoLoginApi(params: AutoLoginParams, mode: ErrorMessageMode = '
       },
     },
     {
+      successMessageMode: successMode,
       errorMessageMode: mode,
     }
   );

+ 10 - 5
src/store/modules/user.ts

@@ -1,5 +1,5 @@
 import type { UserInfo, LoginInfo } from '/#/store';
-import type { ErrorMessageMode } from '/#/axios';
+import type { ErrorMessageMode, SuccessMessageMode } from '/#/axios';
 import { defineStore } from 'pinia';
 import { store } from '/@/store';
 import { PageEnum } from '/@/enums/pageEnum';
@@ -141,11 +141,12 @@ export const useUserStore = defineStore({
       params: LoginParams & {
         goHome?: boolean;
         mode?: ErrorMessageMode;
+        successMode?: SuccessMessageMode;
       }
     ): Promise<GetUserInfoModel | null> {
       try {
-        const { goHome = true, mode, ...loginParams } = params;
-        const data = await loginApi(loginParams, mode);
+        const { goHome = true, mode, successMode, ...loginParams } = params;
+        const data = await loginApi(loginParams, mode, successMode);
         const { token, userInfo } = data;
         // save token
         this.setToken(token);
@@ -369,6 +370,7 @@ export const useUserStore = defineStore({
       params: Partial<LoginParams> & {
         goHome?: boolean;
         mode?: ErrorMessageMode;
+        successMode?: SuccessMessageMode;
       } = {}
     ) {
       try {
@@ -376,6 +378,7 @@ export const useUserStore = defineStore({
           username: MOCK_LOGIN_UESRNAME,
           password: MOCK_LOGIN_PASSWORD,
           checkKey: new Date().getTime(),
+          successMode: 'none' as SuccessMessageMode,
           ...params,
         };
         return this.login(loginParams);
@@ -388,6 +391,7 @@ export const useUserStore = defineStore({
       params: Partial<LoginParams> & {
         goHome?: boolean;
         mode?: ErrorMessageMode;
+        successMode?: SuccessMessageMode;
       } = {}
     ) {
       await this.logout();
@@ -402,10 +406,11 @@ export const useUserStore = defineStore({
       params: AutoLoginParams & {
         goHome?: boolean;
         mode?: ErrorMessageMode;
+        successMode?: SuccessMessageMode;
       }
     ) {
-      const { goHome = true, mode, ...loginParams } = params;
-      const data = await autoLoginApi(loginParams, mode);
+      const { goHome = true, mode, successMode = 'none', ...loginParams } = params;
+      const data = await autoLoginApi(loginParams, mode, successMode);
       const { token, userInfo } = data;
       // save token
       this.setToken(token);