copyright-official-website/src/components/HeaderNav.vue

370 lines
9.8 KiB
Vue
Raw Normal View History

2024-06-03 09:43:48 +08:00
<template>
2024-11-20 15:02:25 +08:00
<div id="nav" class="header-nav" :class="{ 'fixed-nav': isFixed }" v-show="HeaderNav">
2024-06-03 09:43:48 +08:00
<div class="box">
2024-09-14 16:28:01 +08:00
<a class="nav-icon" href="https://www.aimzhu.com" @click="gotoHomePage">
2024-06-03 09:43:48 +08:00
<img :src="logoSrc" alt="首页logo">
</a>
<!-- <router-link to="/HomePage" @click="gotoHomePage">
<img :src="logoSrc" alt="首页logo">
</router-link> -->
2024-06-03 09:43:48 +08:00
<div class="nav router-container" :class="routerColor">
<ul>
<li><router-link to="/HomePage" replace @click="activateHomePage" :class="{ activeHomePage: $route.path === '/HomePage' }">首页</router-link></li>
2024-06-03 09:43:48 +08:00
<li><router-link to="/ShouFei" @click="activate" :class="{ active: $route.path === '/ShouFei' }">收费介绍</router-link></li>
<li><router-link to="/KeFu" @click="activate" :class="{ active: $route.path === '/KeFu' }">客服中心</router-link></li>
<li><router-link to="/ZhengShu" @click="activate" :class="{ active: $route.path === '/ZhengShu' }">证书展示</router-link></li>
<!-- <li><router-link to="/DaiLiShang" @click="activate" :class="{ active: $route.path === '/DaiLiShang' }">代理商展示</router-link></li> -->
<!-- <li><router-link to="/TransactionCenter" @click="activate" :class="{ active: $route.path === '/TransactionCenter' }">交易中心</router-link></li> -->
<li><router-link to="/HelpCenter" @click="activate" :class="{ active: $route.path === '/HelpCenter' }">帮助中心</router-link></li>
<!-- <li><router-link to="/AboutUs" @click="aa()" class="acss">关于我们</router-link></li> -->
</ul>
</div>
<div class="phone">
<div class="phoneBox">
<div class="leftIcon">
<img :src="phoneIcon" alt="">
</div>
<div class="rightMessage" :class="phoneColor">
<span>全国服务热线</span>
<span>400 086 1633</span>
</div>
</div>
</div>
2024-09-14 16:28:01 +08:00
<div class="login-register">
<a id="login" href="https://www.aimzhu.com/operator/" :class="loginClass">登录</a>
<!-- <a id="login" href=" http://192.168.0.115:8091/operator" :class="loginClass">登录</a> -->
2024-09-14 16:28:01 +08:00
<a id="register" href="https://www.aimzhu.com/Register.html">免费注册</a>
<!-- <a id="register" href="http://192.168.0.121:5502/src/components/Register.html">免费注册</a> -->
2024-09-14 16:28:01 +08:00
</div>
2024-06-03 09:43:48 +08:00
</div>
</div>
<router-view></router-view>
</template>
<script>
export default {
data() {
return {
// logoSrc: '/src/assets/img/headicon1.png',
// logoSrc: '/assets/img/headicon1.png',
logoSrc: '/assets/img/headicon21.png',
2024-06-03 09:43:48 +08:00
isFixed: false,
shouldReloadHomePage: false, // 添加标志,用于判断是否需要刷新首页
2024-06-03 09:43:48 +08:00
// isHomePage: true, // 用于跟踪是否在首页
// logoSrc: import('/assets/img/headicon1.png'), // 默认的logo图片
2024-11-20 15:02:25 +08:00
currentRoute: '/HomePage', // 默认激活首页
HeaderNav: true,
phoneIcon: '/assets/img/nav-phone1.png',
2024-06-03 09:43:48 +08:00
}
},
methods:{
gotoHomePage() {
this.$router.push('/HomePage');
// window.location.reload(); // 刷新页面
2024-06-03 09:43:48 +08:00
},
activateHomePage() {
this.isFixed = false; // 重置为默认样式
// this.logoSrc = '/assets/img/headicon1.png';
this.logoSrc = '/assets/img/headicon21.png';
this.phoneIcon = '/assets/img/nav-phone1.png';
// his.shouldReloadHomePage = true; // 设置刷新标志
// 如果当前不是在首页,则设置标志以刷新
// if (this.$route.path !== '/HomePage') {
// this.shouldRefreshHome = true; // 设置刷新标志
// }
},
// refreshHomePage() {
// window.location.href = window.location.href
// alert(11)
// },
2024-06-03 09:43:48 +08:00
activate() {
this.isFixed = true; // 激活固定样式
// this.logoSrc = '/assets/img/headicon2.png';
this.logoSrc = '/assets/img/headicon21.png';
this.phoneIcon = '/assets/img/nav-phone2.png';
2024-06-03 09:43:48 +08:00
},
handleScroll() {
if (this.$route.path === '/HomePage') {
this.isFixed = window.scrollY > 0; // 仅在首页路由时,滚动时更新样式
// this.logoSrc = ('window.scrollY > 0' ? '/src/assets/img/headicon2.png': '/src/assets/img/headicon1.png')
if(window.scrollY > 0) {
// this.logoSrc = '/assets/img/headicon2.png';
this.logoSrc = '/assets/img/headicon21.png';
this.phoneIcon = '/assets/img/nav-phone2.png';
2024-06-03 09:43:48 +08:00
} else {
// this.logoSrc = '/assets/img/headicon1.png';
this.logoSrc = '/assets/img/headicon21.png';
this.phoneIcon = '/assets/img/nav-phone1.png';
2024-06-03 09:43:48 +08:00
}
}
},
},
mounted() {
window.addEventListener('scroll', this.handleScroll);
},
beforeDestroy() {
window.removeEventListener('scroll', this.handleScroll);
},
watch: {
$route(to, from) {
if (to.path !== '/HomePage') {
this.activate(); // 点击非首页路由时激活固定样式
2024-06-03 09:43:48 +08:00
} else {
this.activateHomePage(); // 点击首页路由时重置为默认样式
2024-06-03 09:43:48 +08:00
}
},
2024-11-20 15:02:25 +08:00
// '$route': {
// immediate: true, // 立即执行一次监听函数
// handler(newRoute) {
// // 根据路由名称或路径来设置show的值
// this.HeaderNav = newRoute.name !== 'MobilePage' && !newRoute.path.includes('MobilePage');
// this.currentRoute = newRoute.path; // 更新当前路由路径
// }
// }
2024-11-20 15:02:25 +08:00
// $route(to, from) {
// // 当路由跳转到首页且设置了刷新标志时,刷新页面
// if (to.path === '/HomePage' && this.shouldRefreshHome) {
// this.activateHomePage(); // 点击首页路由时重置为默认样式
// window.location.reload(); // 刷新页面
// this.shouldRefreshHome = false; // 重置刷新标志
// } else {
// this.activate(); // 点击非首页路由时激活固定样式
// }
// }
2024-06-03 09:43:48 +08:00
},
computed: {
navClass() {
return {
'fixed-nav': this.isFixed || this.$route.path === '/HomePage',
};
},
loginClass() {
return {
'border-login': this.isFixed,
'line-height-login': this.isFixed,
2024-06-03 09:43:48 +08:00
};
},
phoneColor() {
return {
'phoneMessageColor': this.isFixed,
}
},
2024-06-03 09:43:48 +08:00
routerColor() {
return {
'active-color': this.$route.path === '/HomePage',
};
}
},
}
</script>
<style scoped>
2024-07-10 17:48:45 +08:00
img {
width: 100%;
height: 100%;
vertical-align: middle;
border: 0px solid transparent !important ;
}
2024-06-03 09:43:48 +08:00
.border-login {
2024-09-14 16:28:01 +08:00
border: .0094rem solid #42210B;
2024-06-03 09:43:48 +08:00
}
.line-height-login {
2024-09-14 16:28:01 +08:00
line-height: .3rem;
2024-06-03 09:43:48 +08:00
}
.activeHomePage {
color: #333;
}
.active {
color: #F7931E;
font-weight: 700;
}
.active1 {
position: fixed;
/* top: 0; */
display: flex;
flex-direction: row;
width: 100%;
2024-09-14 16:28:01 +08:00
height: 1rem;
2024-06-03 09:43:48 +08:00
margin: 0 auto ;
background-color: #fff;
transition: all .5s ease-in-out;
2024-09-14 16:28:01 +08:00
box-shadow: 0 .025rem .15rem 0 rgba(0,60,103,.15);
2024-06-03 09:43:48 +08:00
z-index: 9999999;
}
.active2 {
2024-09-14 16:28:01 +08:00
border: .025rem solid #42210B;
2024-06-03 09:43:48 +08:00
}
.phoneMessageColor {
color: #42210B !important;
}
2024-06-03 09:43:48 +08:00
.header-nav {
position: absolute;
display: flex;
justify-content: center;
width: 100%;
2024-09-14 16:28:01 +08:00
height: 1rem;
2024-06-03 09:43:48 +08:00
margin: 0 auto ;
background-color: transparent;
z-index: 99999;
}
.fixed-nav {
position: fixed;
background-color: #fff;
transition: all 0 ease-in-out;
2024-09-14 16:28:01 +08:00
box-shadow: 0 .025rem .15rem 0 rgba(0,60,103,.15);
2024-06-03 09:43:48 +08:00
}
.header-nav .box {
position: absolute;
display: flex;
2024-09-14 16:28:01 +08:00
flex-wrap: wrap;
justify-content: space-around;
width: 100%;
/* width: 1500px; */
/* width: 18.75rem; */
height: 1rem;
2024-06-03 09:43:48 +08:00
margin: 0 auto;
/* border: 1px solid red; */
}
2024-09-14 16:28:01 +08:00
.header-nav .nav-icon {
/* width: 3.25rem;
height: .575rem; */
width: 1.7875rem;
2024-09-14 16:28:01 +08:00
height: .575rem;
margin-left: .625rem;
margin-top: .2125rem;
2024-06-03 09:43:48 +08:00
/* border: 1px solid blue; */
}
.header-nav .nav {
display: flex;
2024-09-14 16:28:01 +08:00
height: 1rem;
line-height: 1rem;
width: 8.4rem;
2024-06-03 09:43:48 +08:00
}
.header-nav .nav ul {
display: flex;
2024-09-14 16:28:01 +08:00
flex-wrap: wrap;
justify-content: space-around;
width: 100%;
2024-06-03 09:43:48 +08:00
}
.header-nav .nav ul li {
2024-09-14 16:28:01 +08:00
/* margin-right: .25rem;
margin-left: .25rem; */
/* width: 1rem; */
/* padding: 0 0.2rem; */
/* margin: 0 .5rem; */
font-size: .1875rem;
2024-06-03 09:43:48 +08:00
color: #42210B;
2024-09-14 16:28:01 +08:00
text-align: center;
}
/* .header-nav .nav ul li:first-child {
margin-left: 0.1px;
}
.header-nav .nav ul li:last-child {
margin-right: 0.1px;
} */
.header-nav .nav ul li a {
width: 1rem;
2024-06-03 09:43:48 +08:00
}
/* .header-nav .nav ul li a {
color: #FFF;
font-weight: 400;
} */
.header-nav .nav ul .router-link-active {
color: #42210B!;
/* color: #FFF; */
}
.header-nav .phone {
display: flex;
flex-wrap: wrap;
justify-content: center;
align-content: center;
width: 2.2rem;
height: 1rem;
/* background-color: pink; */
}
.header-nav .phone .phoneBox {
display: flex;
justify-content: start;
width: 2.2rem;
height: 0.6rem;
/* background-color: skyblue; */
}
.header-nav .phone .phoneBox .leftIcon {
width: 0.6rem;
height: 0.6rem;
}
.header-nav .phone .phoneBox .rightMessage {
display: flex;
flex-direction: column;
justify-content: space-around;
color: #fff;
}
.header-nav .phone .phoneBox .rightMessage span {
font-size: 0.2rem;
}
2024-09-14 16:28:01 +08:00
.header-nav .login-register {
display: flex;
width: 3.5rem;
height: 1rem;
}
2024-06-03 09:43:48 +08:00
.header-nav #login {
2024-09-14 16:28:01 +08:00
width: .875rem;
height: .325rem;
line-height: .3rem;
2024-06-03 09:43:48 +08:00
padding: auto;
text-align: center;
2024-09-14 16:28:01 +08:00
margin: auto .125rem auto auto ;
border-radius: .25rem;
font-size: .175rem;
2024-06-03 09:43:48 +08:00
background-color: rgba(255,255,255,.4);
}
#register {
2024-09-14 16:28:01 +08:00
width: 1.25rem;
height: .325rem;
line-height: .3rem;
2024-06-03 09:43:48 +08:00
text-align: center;
2024-09-14 16:28:01 +08:00
margin: .3375rem .375rem;
border-radius: .25rem;
font-size: .175rem;
2024-06-03 09:43:48 +08:00
background-color: #42210B;
color: #FFF;
}
#login:hover {
background-color: #42210B;
color: #fff;
cursor: pointer;
}
#register:hover {
background-color: #332817;
}
a:hover {
color: #333;
font-weight: 700;
}
</style>