flat: 添加高德地图全量代理
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import './utils/amap_system';
|
||||||
import { AvatarDropdown, AvatarName, Footer, SelectLang } from '@/components';
|
import { AvatarDropdown, AvatarName, Footer, SelectLang } from '@/components';
|
||||||
import type { Settings as LayoutSettings } from '@ant-design/pro-components';
|
import type { Settings as LayoutSettings } from '@ant-design/pro-components';
|
||||||
import { SettingDrawer } from '@ant-design/pro-components';
|
import { SettingDrawer } from '@ant-design/pro-components';
|
||||||
@@ -216,8 +217,9 @@ export async function render(oldRender: () => void) {
|
|||||||
const checkRegion = 5 * 60 * 1000;
|
const checkRegion = 5 * 60 * 1000;
|
||||||
export const request = {
|
export const request = {
|
||||||
...errorConfig,
|
...errorConfig,
|
||||||
baseURL: process.env.NODE_ENV === 'development' ? '' : 'https://qd.zhaopinzao8dian.com/api',
|
// baseURL: process.env.NODE_ENV === 'development' ? '' : 'https://qd.zhaopinzao8dian.com/api',
|
||||||
// baseURL: 'http://39.98.44.136:8080',
|
// baseURL: 'http://39.98.44.136:8080',
|
||||||
|
baseURL: process.env.NODE_ENV === 'development' ? '' : 'http://10.213.6.207:19010/api',
|
||||||
requestInterceptors: [
|
requestInterceptors: [
|
||||||
(url: any, options: { headers: any }) => {
|
(url: any, options: { headers: any }) => {
|
||||||
const headers = options.headers ? options.headers : [];
|
const headers = options.headers ? options.headers : [];
|
||||||
|
|||||||
75
src/utils/amap_system.ts
Normal file
75
src/utils/amap_system.ts
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
// amap_proxy.ts
|
||||||
|
const hookScript = (): void => {
|
||||||
|
// 1. 内网入口地址
|
||||||
|
const proxyBase = 'http://10.213.6.207:19010';
|
||||||
|
|
||||||
|
// 2. 域名映射表 (Key: 原始域名, Value: 内网代理路径)
|
||||||
|
// 注意:顺序很重要,长路径优先匹配(虽然后缀不同一般没事)
|
||||||
|
const domainMap: Record<string, string> = {
|
||||||
|
'https://webapi.amap.com/maps': '/maps', // 特殊处理 maps
|
||||||
|
'https://webapi.amap.com': '/webAmap',
|
||||||
|
'https://restapi.amap.com': '/restAmap',
|
||||||
|
'https://a.amap.com': '/amap',
|
||||||
|
'https://lbs.amap.com': '/lbs',
|
||||||
|
'http://vector.amap.com': '/vector', // http 协议
|
||||||
|
'https://vdata.amap.com': '/vdata',
|
||||||
|
// 批量处理 vdata01-04
|
||||||
|
'https://vdata01.amap.com': '/vdata01',
|
||||||
|
'https://vdata02.amap.com': '/vdata02',
|
||||||
|
'https://vdata03.amap.com': '/vdata03',
|
||||||
|
'https://vdata04.amap.com': '/vdata04',
|
||||||
|
// 批量处理 webst01-04
|
||||||
|
'https://webst01.is.autonavi.com': '/webst01',
|
||||||
|
'https://webst02.is.autonavi.com': '/webst02',
|
||||||
|
'https://webst03.is.autonavi.com': '/webst03',
|
||||||
|
'https://webst04.is.autonavi.com': '/webst04',
|
||||||
|
// 批量处理 wprd01-04
|
||||||
|
'https://wprd01.is.autonavi.com': '/wprd01',
|
||||||
|
'https://wprd02.is.autonavi.com': '/wprd02',
|
||||||
|
'https://wprd03.is.autonavi.com': '/wprd03',
|
||||||
|
'https://wprd04.is.autonavi.com': '/wprd04',
|
||||||
|
};
|
||||||
|
|
||||||
|
// 通用替换函数
|
||||||
|
const replaceUrl = (url: string): string => {
|
||||||
|
for (const [origin, path] of Object.entries(domainMap)) {
|
||||||
|
if (url.indexOf(origin) !== -1) {
|
||||||
|
// 将 https://vdata01.amap.com/xxx 替换为 http://10.213.6.207:19010/vdata01/xxx
|
||||||
|
return url.replace(origin, `${proxyBase}${path}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return url;
|
||||||
|
};
|
||||||
|
|
||||||
|
// --- 拦截 Script 标签 (JS API 加载) ---
|
||||||
|
const scriptDescriptor = Object.getOwnPropertyDescriptor(HTMLScriptElement.prototype, 'src');
|
||||||
|
if (scriptDescriptor && scriptDescriptor.set) {
|
||||||
|
const nativeSet = scriptDescriptor.set;
|
||||||
|
Object.defineProperty(HTMLScriptElement.prototype, 'src', {
|
||||||
|
set: function (url: string) {
|
||||||
|
const newUrl = replaceUrl(url);
|
||||||
|
nativeSet.call(this, newUrl);
|
||||||
|
},
|
||||||
|
get: scriptDescriptor.get,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- 拦截 XMLHttpRequest (瓦片、搜索、矢量数据) ---
|
||||||
|
const nativeOpen = XMLHttpRequest.prototype.open;
|
||||||
|
XMLHttpRequest.prototype.open = function (
|
||||||
|
method: string,
|
||||||
|
url: string | URL,
|
||||||
|
async: boolean = true,
|
||||||
|
user?: string | null,
|
||||||
|
password?: string | null
|
||||||
|
): void {
|
||||||
|
const strUrl = url.toString();
|
||||||
|
const newUrl = replaceUrl(strUrl);
|
||||||
|
return nativeOpen.call(this, method, newUrl, async, user, password);
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log('高德地图内网全量代理已激活');
|
||||||
|
};
|
||||||
|
|
||||||
|
hookScript();
|
||||||
Reference in New Issue
Block a user