diff --git a/.env b/.env index ce9d7cb..2d2e251 100644 --- a/.env +++ b/.env @@ -1,6 +1,6 @@ # the base url of the application, the default is "/" # if use a sub directory, it must be end with "/", like "/admin/" but not "/admin" -VITE_BASE_URL=/ +VITE_BASE_URL=http://192.168.0.230:8086 VITE_APP_TITLE=MOC变更管理系统 @@ -23,7 +23,7 @@ VITE_ROUTE_HOME=home VITE_MENU_ICON=mdi:menu # whether to enable http proxy when is dev mode -VITE_HTTP_PROXY=Y +VITE_HTTP_PROXY=N # vue-router mode: hash | history | memory VITE_ROUTER_HISTORY_MODE=history diff --git a/.env.prod b/.env.prod index f567764..c57dc26 100644 --- a/.env.prod +++ b/.env.prod @@ -1,5 +1,6 @@ # backend service base url, prod environment -VITE_SERVICE_BASE_URL=https://mock.apifox.cn/m1/3109515-0-default +VITE_BASE_URL=http://192.168.0.230:8086 +VITE_SERVICE_BASE_URL=http://192.168.0.230:8086 # other backend service base url, prod environment VITE_OTHER_SERVICE_BASE_URL= `{ diff --git a/.env.test b/.env.test index dd18d7b..be921f0 100644 --- a/.env.test +++ b/.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_BASE_URL=http://192.168.0.230:8086 +VITE_SERVICE_BASE_URL=http://192.168.0.230:8086 # other backend service base url, test environment VITE_OTHER_SERVICE_BASE_URL= `{ diff --git a/src/service/api/auth.ts b/src/service/api/auth.ts index 1ffcf2b..4e742b6 100644 --- a/src/service/api/auth.ts +++ b/src/service/api/auth.ts @@ -1,17 +1,17 @@ import { request } from '../request'; /** - * Login + * 登录 * * @param userName User name * @param password Password */ -export function fetchLogin(userName: string, password: string) { +export function fetchLogin(username: string, password: string) { return request({ - url: '/auth/login', + url: '/api/auth/login', method: 'post', data: { - userName, + username, password } }); @@ -36,13 +36,3 @@ export function fetchRefreshToken(refreshToken: string) { } }); } - -/** - * return custom backend error - * - * @param code error code - * @param msg error message - */ -export function fetchCustomBackendError(code: string, msg: string) { - return request({ url: '/auth/error', params: { code, msg } }); -} diff --git a/src/service/request/index.ts b/src/service/request/index.ts index 76aef17..949e00e 100644 --- a/src/service/request/index.ts +++ b/src/service/request/index.ts @@ -1,14 +1,13 @@ import type { AxiosResponse } from 'axios'; -import { BACKEND_ERROR_CODE, createFlatRequest, createRequest } from '@sa/axios'; +import { BACKEND_ERROR_CODE, createFlatRequest } from '@sa/axios'; import { useAuthStore } from '@/store/modules/auth'; -import { localStg } from '@/utils/storage'; import { getServiceBaseURL } from '@/utils/service'; import { $t } from '@/locales'; import { getAuthorization, handleExpiredRequest, showErrorMsg } from './shared'; import type { RequestInstanceState } from './type'; const isHttpProxy = import.meta.env.DEV && import.meta.env.VITE_HTTP_PROXY === 'Y'; -const { baseURL, otherBaseURL } = getServiceBaseURL(import.meta.env, isHttpProxy); +const { baseURL } = getServiceBaseURL(import.meta.env, isHttpProxy); export const request = createFlatRequest( { @@ -100,13 +99,12 @@ export const request = createFlatRequest( }, onError(error) { // when the request is fail, you can show error message - let message = error.message; let backendErrorCode = ''; // get backend error message and code if (error.code === BACKEND_ERROR_CODE) { - message = error.response?.data?.msg || message; + message = error.response?.data?.message || message; backendErrorCode = String(error.response?.data?.code || ''); } @@ -126,45 +124,3 @@ export const request = createFlatRequest( } } ); - -export const demoRequest = createRequest( - { - baseURL: otherBaseURL.demo - }, - { - transform(response: AxiosResponse) { - return response.data.result; - }, - async onRequest(config) { - const { headers } = config; - - // set token - const token = localStg.get('token'); - const Authorization = token ? `Bearer ${token}` : null; - Object.assign(headers, { Authorization }); - - return config; - }, - isBackendSuccess(response) { - // when the backend response code is "200", it means the request is success - // you can change this logic by yourself - return response.data.status === '200'; - }, - async onBackendFail(_response) { - // when the backend response code is not "200", it means the request is fail - // for example: the token is expired, refresh token and retry request - }, - onError(error) { - // when the request is fail, you can show error message - - let message = error.message; - - // show backend error message - if (error.code === BACKEND_ERROR_CODE) { - message = error.response?.data?.message || message; - } - - window.$message?.error(message); - } - } -); diff --git a/src/typings/app.d.ts b/src/typings/app.d.ts index 78a36f7..4464866 100644 --- a/src/typings/app.d.ts +++ b/src/typings/app.d.ts @@ -566,7 +566,7 @@ declare namespace App { /** The backend service response code */ code: string; /** The backend service response message */ - msg: string; + message: string; /** The backend service response data */ data: T; }; diff --git a/src/utils/service.ts b/src/utils/service.ts index a275b39..9598038 100644 --- a/src/utils/service.ts +++ b/src/utils/service.ts @@ -15,9 +15,14 @@ export function createServiceConfig(env: Env.ImportMeta) { // eslint-disable-next-line no-console console.error('VITE_OTHER_SERVICE_BASE_URL is not a valid json5 string'); } - + let url = 'http://192.168.0.230:8086'; + if(env.DEV){ + url = 'http://192.168.0.230:8086'; + }else{ + url = window.location.origin; + } const httpConfig: App.Service.SimpleServiceConfig = { - baseURL: VITE_SERVICE_BASE_URL, + baseURL: url, other }; diff --git a/src/views/login/index.vue b/src/views/login/index.vue index dcef0d9..c22c705 100644 --- a/src/views/login/index.vue +++ b/src/views/login/index.vue @@ -1,16 +1,11 @@