-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
503 additions
and
333 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
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,26 +1,28 @@ | ||
import {proxy} from "ctool-config"; | ||
import _axios from "axios"; | ||
import platform from "@/helper/platform" | ||
import { proxy } from "ctool-config"; | ||
import _axios, { AxiosHeaders } from "axios"; | ||
import platform from "@/helper/platform"; | ||
import qs from "qs"; | ||
import useSetting from "@/store/setting"; | ||
|
||
// 对外请求代理方法 | ||
export const axios = () => { | ||
const storeSetting = useSetting() | ||
const instance = _axios.create() | ||
const storeSetting = useSetting(); | ||
const instance = _axios.create(); | ||
instance.interceptors.request.use(config => { | ||
// 判断是否需要使用代理 | ||
if (platform.runtime.webSecurity() && (config.url && proxy.is(config.url))) { | ||
if (platform.runtime.webSecurity() && config.url && proxy.is(config.url)) { | ||
if (!storeSetting.items.proxy_enable || !storeSetting.items.proxy_url) { | ||
throw new Error($t('main_network_request_proxy_prompt')) | ||
throw new Error($t("main_network_request_proxy_prompt")); | ||
} | ||
config.headers = !config.headers ? {} : config.headers | ||
const connector = config.url.includes("?") ? "&" : "?" | ||
config.headers["Ctool-Proxy-Url"] = `${config.url}${config.params ? `${connector}${qs.stringify(config.params)}` : ""}`; | ||
config.headers = !config.headers ? new AxiosHeaders() : config.headers; | ||
const connector = config.url.includes("?") ? "&" : "?"; | ||
config.headers["Ctool-Proxy-Url"] = `${config.url}${ | ||
config.params ? `${connector}${qs.stringify(config.params)}` : "" | ||
}`; | ||
config.params = undefined; | ||
config.url = storeSetting.items.proxy_url | ||
config.url = storeSetting.items.proxy_url; | ||
} | ||
return config; | ||
}); | ||
return instance | ||
} | ||
return instance; | ||
}; |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.