feat: nas首页
This commit is contained in:
50
app/index/view/public/nas_header.html
Normal file
50
app/index/view/public/nas_header.html
Normal file
@@ -0,0 +1,50 @@
|
||||
<header class="narsPage-head">
|
||||
<div class="headcenter">
|
||||
<img class="logico" style="cursor:pointer;" src="__IMAGES__/logo_nas.png" />
|
||||
{notempty name="header_navigation"}
|
||||
<nav class="headnav">
|
||||
{volist name="header_navigation" id="nav" key="idx"}
|
||||
<a class="navitem {eq name='idx' value='1'}hover{/eq}" href="{$nav.link}" target="{$nav.blank==1?'_blank':'_self'}">
|
||||
{$nav.name}
|
||||
</a>
|
||||
{/volist}
|
||||
</nav>
|
||||
{/notempty}
|
||||
</div>
|
||||
</header>
|
||||
<script type="text/javascript">
|
||||
$(function() {
|
||||
$('.headnav .navitem').each(function(idx, item) {
|
||||
$(item).removeClass('hover');
|
||||
if (compareUrls(location.href, item.href)) {
|
||||
$(item).addClass('hover').siblings();
|
||||
}
|
||||
});
|
||||
|
||||
// 比较两个URL是否相等(支持只有path的情况,并处理有无.html后缀的情况)
|
||||
function compareUrls(url1, url2) {
|
||||
// 如果输入的是相对路径,添加当前域名
|
||||
if (!url1.startsWith('http')) {
|
||||
url1 = window.location.origin + (url1.startsWith('/') ? '' : '/') + url1;
|
||||
}
|
||||
if (!url2.startsWith('http')) {
|
||||
url2 = window.location.origin + (url2.startsWith('/') ? '' : '/') + url2;
|
||||
}
|
||||
|
||||
// 将两个URL转换为URL对象
|
||||
const urlObj1 = new URL(url1);
|
||||
const urlObj2 = new URL(url2);
|
||||
|
||||
// 获取路径名并移除末尾的斜杠
|
||||
let path1 = urlObj1.pathname.replace(/\/$/, '');
|
||||
let path2 = urlObj2.pathname.replace(/\/$/, '');
|
||||
|
||||
// 移除.html后缀
|
||||
path1 = path1.replace(/\.html$/, '');
|
||||
path2 = path2.replace(/\.html$/, '');
|
||||
|
||||
// 比较处理后的路径
|
||||
return path1 === path2;
|
||||
}
|
||||
})
|
||||
</script>
|
||||
Reference in New Issue
Block a user