From 317665addc550dbb0207273e7576f1349adec526 Mon Sep 17 00:00:00 2001 From: Apcallover <1503963513@qq.com> Date: Sun, 23 Nov 2025 14:50:18 +0800 Subject: [PATCH] =?UTF-8?q?flat:=20=E6=B7=BB=E5=8A=A0=E9=AB=98=E5=BE=B7?= =?UTF-8?q?=E5=9C=B0=E5=9B=BE=E5=85=A8=E9=87=8F=E4=BB=A3=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app.tsx | 4 ++- src/utils/amap_system.ts | 75 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 src/utils/amap_system.ts diff --git a/src/app.tsx b/src/app.tsx index 584436f..fba80d9 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -1,3 +1,4 @@ +import './utils/amap_system'; import { AvatarDropdown, AvatarName, Footer, SelectLang } from '@/components'; import type { Settings as LayoutSettings } 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; export const request = { ...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: process.env.NODE_ENV === 'development' ? '' : 'http://10.213.6.207:19010/api', requestInterceptors: [ (url: any, options: { headers: any }) => { const headers = options.headers ? options.headers : []; diff --git a/src/utils/amap_system.ts b/src/utils/amap_system.ts new file mode 100644 index 0000000..6577eeb --- /dev/null +++ b/src/utils/amap_system.ts @@ -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 = { + '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(); \ No newline at end of file