-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(projects): 请求适配器函数范型重构、优化请求相关的命名
- Loading branch information
1 parent
02992dc
commit 7f9c98a
Showing
11 changed files
with
77 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,33 @@ | ||
/** 请求环境配置 */ | ||
/** 请求服务的环境配置 */ | ||
type ServiceEnv = Record<ServiceEnvType, ServiceEnvConfig>; | ||
|
||
/** 不同服务的环境配置 */ | ||
/** 不同请求服务的环境配置 */ | ||
const serviceEnv: ServiceEnv = { | ||
dev: { | ||
pattern: '/proxy-pattrn', | ||
url: 'http://localhost:8080', | ||
proxy: '/proxy-flag' | ||
secondUrl: 'http://localhost:8081' | ||
}, | ||
test: { | ||
pattern: '/proxy-pattrn', | ||
url: 'http://localhost:8080', | ||
proxy: '/proxy-flag' | ||
secondUrl: 'http://localhost:8081' | ||
}, | ||
prod: { | ||
pattern: '/proxy-pattrn', | ||
url: 'http://localhost:8080', | ||
proxy: '/proxy-flag' | ||
secondUrl: 'http://localhost:8081' | ||
} | ||
}; | ||
|
||
/** | ||
* 获取当前模式的环境配置 | ||
* 获取当前环境模式下的请求服务的配置 | ||
* @param env 环境 | ||
*/ | ||
export function getEnvConfig(env: ImportMetaEnv) { | ||
const { VITE_ENV_TYPE = 'dev' } = env; | ||
export function getServiceEnvConfig(env: ImportMetaEnv) { | ||
const { VITE_SERVICE_ENV = 'dev' } = env; | ||
|
||
const envConfig = serviceEnv[VITE_ENV_TYPE]; | ||
const config = serviceEnv[VITE_SERVICE_ENV]; | ||
|
||
return envConfig; | ||
return config; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export function adapterOfFetchDataWithAdapter(data: ApiDemo.DataWithAdapter): Demo.DataWithAdapter { | ||
const { dataId, dataName } = data; | ||
|
||
const result: Demo.DataWithAdapter = { | ||
id: dataId, | ||
name: dataName | ||
}; | ||
|
||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
import { getEnvConfig } from '~/.env-config'; | ||
import { getServiceEnvConfig } from '~/.env-config'; | ||
import { createRequest } from './request'; | ||
|
||
const envConfig = getEnvConfig(import.meta.env); | ||
const { pattern, url, secondUrl } = getServiceEnvConfig(import.meta.env); | ||
|
||
const isHttpProxy = import.meta.env.VITE_HTTP_PROXY === 'Y'; | ||
|
||
export const request = createRequest({ baseURL: isHttpProxy ? envConfig.proxy : envConfig.url }); | ||
export const request = createRequest({ baseURL: isHttpProxy ? pattern : url }); | ||
|
||
export const secondRequest = createRequest({ baseURL: isHttpProxy ? pattern : secondUrl }); | ||
|
||
export const mockRequest = createRequest({ baseURL: '/mock' }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7f9c98a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
soybean-admin – ./
soybean-admin.vercel.app
soybean.pro
soybean-admin-honghuangdc.vercel.app
soybean-admin-git-main-honghuangdc.vercel.app
www.soybean.pro