فهرست منبع

chore: 登录时接口异常调整

lujialiang 1 هفته پیش
والد
کامیت
508a3871e3
4فایلهای تغییر یافته به همراه19 افزوده شده و 50 حذف شده
  1. 2 1
      .env.test
  2. 3 33
      src/service/api/auth.ts
  3. 4 4
      src/service/request/index.ts
  4. 10 12
      src/store/modules/auth/index.ts

+ 2 - 1
.env.test

@@ -1,5 +1,6 @@
 # backend service base url, test environment
-VITE_SERVICE_BASE_URL=https://mock.apifox.cn/m1/3109515-0-default
+# VITE_SERVICE_BASE_URL=https://mock.apifox.cn/m1/3109515-0-default
+VITE_SERVICE_BASE_URL=http://observe-server.cestong.com.cn
 
 # other backend service base url, test environment
 VITE_OTHER_SERVICE_BASE_URL= `{

+ 3 - 33
src/service/api/auth.ts

@@ -1,32 +1,7 @@
 import { baseRequest, request } from '../request';
-
-/**
- * Login
- *
- * @param userName User name
- * @param password Password
- */
-export function fetchLogin(userName: string, password: string) {
+/** Login */
+export function fetchLogin(data: object) {
   return request<Api.Auth.LoginToken>({
-    url: '/auth/login',
-    method: 'post',
-    data: {
-      userName,
-      password
-    }
-  });
-}
-
-/**
- * Login demo
- *
- * @param userName User name
- * @param password Password
- * @param code Code
- * @param uuid uuid
- */
-export function fetchLoginDemo(data: object) {
-  return baseRequest<Api.Auth.LoginToken>({
     url: '/api/v1/login',
     method: 'post',
     data
@@ -35,12 +10,7 @@ export function fetchLoginDemo(data: object) {
 
 /** Get user info */
 export function fetchGetUserInfo() {
-  return request<Api.Auth.UserInfo>({ url: '/auth/getUserInfo' });
-}
-
-/** Get user info demo */
-export function fetchGetUserInfoDemo() {
-  return baseRequest<Api.Auth.UserInfo>({ url: '/api/v1/getinfo' });
+  return request<Api.Auth.UserInfo>({ url: '/api/v1/getinfo' });
 }
 
 /** Get Code demo */

+ 4 - 4
src/service/request/index.ts

@@ -12,10 +12,10 @@ const { baseURL, otherBaseURL } = getServiceBaseURL(import.meta.env, isHttpProxy
 
 export const request = createFlatRequest<App.Service.Response, RequestInstanceState>(
   {
-    baseURL,
-    headers: {
+    baseURL
+    /* headers: {
       apifoxToken: 'XL299LiMEDZ0H5h3A29PxwQXdMJqWyY2'
-    }
+    } */
   },
   {
     async onRequest(config: { headers: any }) {
@@ -96,7 +96,7 @@ export const request = createFlatRequest<App.Service.Response, RequestInstanceSt
       return null;
     },
     transformBackendResponse(response: { data: { data: any } }) {
-      return response.data.data;
+      return response.data;
     },
     onError(error: { message: any; code: any; response: { data: { msg: any; code: string } } }) {
       // when the request is fail, you can show error message

+ 10 - 12
src/store/modules/auth/index.ts

@@ -5,8 +5,7 @@ import { useRoute } from 'vue-router';
 import { SetupStoreId } from '@/enum';
 import { useRouterPush } from '@/hooks/common/router';
 import { $t } from '@/locales';
-import { fetchGetUserInfoDemo, fetchLoginDemo } from '@/service/api';
-// import { fetchLogin, fetchGetUserInfo } from '@/service/api';
+import { fetchGetUserInfo, fetchLogin } from '@/service/api';
 import { localStg } from '@/utils/storage';
 import { useRouteStore } from '../route';
 import { useTabStore } from '../tab';
@@ -65,13 +64,15 @@ export const useAuthStore = defineStore(SetupStoreId.Auth, () => {
    */
   async function login(params: object, redirect = true) {
     startLoading();
-    // 待完善 此处和目前业务逻辑不同,关于refreshToken需后续处理
-    const { token: currentToken, currentAuthority: refreshToken, error } = await fetchLoginDemo(params);
-    // const { data: loginToken, error } = await fetchLogin('Soybean', '123456');
-    console.log('error-----', error);
+    const { data, error } = await fetchLogin(params);
     if (!error) {
-      const pass = await loginByToken({ token: currentToken, refreshToken, data: null, code: 200 });
-      // const pass = await loginByToken(loginToken);
+      const loginToken = {
+        token: data.token,
+        refreshToken: '',
+        data: null,
+        code: 200
+      };
+      const pass = await loginByToken(loginToken);
 
       if (pass) {
         await routeStore.initAuthRoute();
@@ -112,13 +113,10 @@ export const useAuthStore = defineStore(SetupStoreId.Auth, () => {
   }
 
   async function getUserInfo() {
-    const { data: info, error } = await fetchGetUserInfoDemo();
-    // const { data: info, error } = await fetchGetUserInfo();
+    const { data: info, error } = await fetchGetUserInfo();
 
     if (!error) {
       // update store
-      // 此处为权限测试方式
-      // const testInfo = { roles: ['R_SUPER'] };
       Object.assign(userInfo, info);
 
       return true;