From 8156f3e7431fb85bebfea9e2c7fcb8cb34b0a9e0 Mon Sep 17 00:00:00 2001 From: ZLY Date: Mon, 8 Dec 2025 09:36:10 +0800 Subject: [PATCH] =?UTF-8?q?feat(componentCoding):=20=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E9=85=8D=E7=BD=AEcode-server=E6=9C=8D=E5=8A=A1=E5=99=A8URI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../componentCoding/index.tsx | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/pages/componentDevelopment/componentCoding/index.tsx b/src/pages/componentDevelopment/componentCoding/index.tsx index ea4fe30..3dce977 100644 --- a/src/pages/componentDevelopment/componentCoding/index.tsx +++ b/src/pages/componentDevelopment/componentCoding/index.tsx @@ -112,9 +112,29 @@ const ComponentCoding = () => { useEffect(() => { componentCoding.id && getComponentInfo(); - const uri = process.env.NEXT_PUBLIC_DEV_CODE_SERVER_HOST; const codeServerFolderPre = '/app/data'; + // 根据当前域名决定使用的URL + const getCodeServerUri = () => { + const hostname = window.location.hostname; + const protocol = window.location.protocol; + + // localhost 使用环境变量配置 + if (hostname === 'localhost' || hostname === '127.0.0.1') { + return process.env.NEXT_PUBLIC_DEV_CODE_SERVER_HOST; + } + + // IP地址使用当前IP拼接端口8443 + const ipRegex = /^(\d{1,3}\.){3}\d{1,3}$/; + if (ipRegex.test(hostname)) { + return `${protocol}//${hostname}:8443`; + } + + // 域名直接使用当前域名 + return `${protocol}//${hostname}`; + }; + + const uri = getCodeServerUri(); // 使用传入的localProjectPath或默认值 const path = componentCoding.localProjectPath || '/000000/admin_testcode1/master'; setServerUrl(`${uri}?folder=${codeServerFolderPre}${path}`);