From 5fb7f5fd28d0a6d5cbdc27f40860eab7b0eb2242 Mon Sep 17 00:00:00 2001 From: java110 <928255095@qq.com> Date: Sat, 7 Mar 2020 00:28:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E5=8F=91=E5=89=8D=E6=AE=B5=E6=A1=86?= =?UTF-8?q?=E6=9E=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/components/commonTop/commonTop.html | 14 +++--- public/vcCore/vcFramework.js | 58 ++++++++++++++++++---- 2 files changed, 54 insertions(+), 18 deletions(-) diff --git a/public/components/commonTop/commonTop.html b/public/components/commonTop/commonTop.html index d139b0aea..d69151aa4 100644 --- a/public/components/commonTop/commonTop.html +++ b/public/components/commonTop/commonTop.html @@ -10,14 +10,14 @@ - - - - - - + + + + + + - + diff --git a/public/vcCore/vcFramework.js b/public/vcCore/vcFramework.js index 1c20d24da..5f74b32a4 100644 --- a/public/vcCore/vcFramework.js +++ b/public/vcCore/vcFramework.js @@ -117,16 +117,40 @@ if (_vcCreateEl.hasAttribute("location") && 'head' == _vcCreateEl.getAttribute('location')) { let _componentHs = _componentHeader[0].childNodes; - for(let _hsIndex = 0; _hsIndex < _componentHs.length;_hsIndex ++ ){ - console.log('_xxx',_componentHs[_hsIndex]); - //_header[0].appendChild(_componentHeader[0]); - let _componentScript = _componentHs[_hsIndex]; - _header[0].appendChild(_componentHs[_hsIndex]); - } - //_header[0].appendChild(_componentHeader[0]); + // for(let _hsIndex = 0; _hsIndex < _componentHs.length;_hsIndex ++ ){ + // console.log('_xxx',_componentHs[_hsIndex]); + // //_header[0].appendChild(_componentHeader[0]); + // let _componentScript = _componentHs[_hsIndex]; + // if(_componentScript.tagName == 'SCRIPT'){ + // console.log('script',_componentScript); + // let scriptObj = document.createElement("script"); + // scriptObj.src = _componentHs[_hsIndex].src; + // scriptObj.type = "text/javascript"; + // _header[0].appendChild(scriptObj); + // }else{ + // _header[0].appendChild(_componentHs[_hsIndex]); + // } + // } + //console.log('header',_header) + _header[0].appendChild(_componentHeader[0]); } else if (_vcCreateEl.hasAttribute("location") && 'body' == _vcCreateEl.getAttribute('location')) { _vcCreateEl.parentNode.replaceChild(_componentHeader[0].childNodes[0], _vcCreateEl); + let _bodyComponentHs = _componentHeader[0].childNodes; + for(let _bsIndex = 0; _bsIndex < _bodyComponentHs.length;_bsIndex ++ ){ + //_header[0].appendChild(_componentHeader[0]); + let _bComponentScript = _bodyComponentHs[_bsIndex]; + if(_bComponentScript.tagName == 'SCRIPT'){ + let scriptObj = document.createElement("script"); + scriptObj.src = _bComponentScript.src; + scriptObj.type = "text/javascript"; + document.getElementsByTagName("body")[0].appendChild(scriptObj); + }else{ + _header[0].appendChild(_bodyComponentHs[_bsIndex]); + } + + } + } else { //_vcCreateEl.parentNode.replaceChild(_componentBody[0].childNodes[0], _vcCreateEl); @@ -137,11 +161,23 @@ } - //let _scripts = document.body.getElementsByTagName("script"); - for(let i=0;i<_scripts.length;i++){ - //一段一段执行script - eval(_scripts[i]); + let _tmpScripts = document.head.getElementsByTagName("script"); + let _tmpBody = document.getElementsByTagName('body'); + for(let _scriptsIndex = 0; _scriptsIndex < _tmpScripts.length; _scriptsIndex++){ + let _tmpScript = _tmpScripts[_scriptsIndex]; + + console.log('_head 中 script', _tmpScript.outerHTML) + let scriptObj = document.createElement("script"); + + scriptObj.src = _tmpScript.src; + //_tmpScript.parentNode.removeChild(_tmpScript); + scriptObj.type = "text/javascript"; + _tmpBody[0].appendChild(scriptObj); } + // for(let i=0;i<_scripts.length;i++){ + // //一段一段执行script + // eval(_scripts[i]); + // } };