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}`);