tj
2025-05-08 88315e144ab2076ee1a75b24f80b165844fb3ff6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<template>
  <nav class="navbar navbar-expand-lg bg-light fixed-top">
    <div class="container-fluid">
      <a class="navbar-brand" href="#">
        <img src="@/assets/logo/logo.png" alt="云游四方" class="logo" />
        <span class="text-xl font-bold">云游四方</span>
      </a>
      <!-- <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
        aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation" >
        <span class="navbar-toggler-icon"></span>
      </button> -->
      <button class="navbar-toggler btn-sm" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
        aria-controls="navbarNav" aria-expanded="false" aria-label="导航菜单" ref="navbarToggler">
        <span class="navbar-toggler-icon"></span>
      </button>
      <div class="collapse navbar-collapse" id="navbarNav">
        <ul class="navbar-nav">
          <li v-for="item in navItems" :key="item.label" class="nav-item">
            <a class="nav-link" href="#" :class="{ active: isActive(item.path) }"
              @click.prevent="navigateTo(item.path)">
              {{ item.label }}
            </a>
          </li>
        </ul>
      </div>
      <div class="contact-phone d-none d-md-block">
        <img src="/icons/hotline.png" alt="电话" class="hot-line-img" />
        <span class="text-lg font-bold">13862676702</span>
      </div>
    </div>
  </nav>
</template>
 
<script setup>
import { ref } from 'vue';
import { useRouter, useRoute } from "vue-router";
 
const router = useRouter();
const route = useRoute()
 
const navItems = [
  { label: '首页', path: '/' },
  { label: '产品中心', path: '/product' },
  // { label: '关于我们', path: '/about#third-other' }
  { label: '关于我们', path: '/about2' }
];
 
// Handle navigation for the menu items
// const navigateTo = (path) => {
//   router.push(path);
// };
 
const isActive = (targetPath) => {
  // 可根据需要改为更精确的匹配逻辑
  return route.fullPath === targetPath || route.path === targetPath.split('#')[0];
};
 
// navbarToggler 引用,用于手动触发点击事件
const navbarToggler = ref(null);
const navigateTo = (path) => {
  if (path.includes('#')) {
    const [basePath, hash] = path.split('#');
    router.push({ path: basePath, hash: `#${hash}` });
  } else {
    router.push(path);
  }
  if (navbarToggler.value) {
    navbarToggler.value.click();
  }
 
};
 
 
 
 
</script>
 
<style scoped>
.navbar {
  padding: 10px 20px;
}
 
.navbar-brand {
  display: flex;
  align-items: center;
}
 
.logo {
  width: 40px;
  height: 40px;
  margin-right: 10px;
}
 
.nav-link {
  font-size: 16px;
}
 
.contact-phone {
  display: flex;
  align-items: center;
  font-size: 14px;
}
 
.contact-phone .el-icon {
  margin-right: 5px;
}
 
.navbar-nav .nav-link {
  margin-right: 15px;
}
 
.fixed-top {
  z-index: 1000;
}
 
.hot-line-img {
  width: 20px;
  height: 20px;
  margin-right: 5px;
}
</style>
<style scoped>
.navbar-nav .nav-link {
  color: #000;
  font-weight: normal;
  padding: 10px 15px;
  text-transform: uppercase;
  transition: color 0.3s, background-color 0.3s;
}
 
.navbar-nav .nav-link:hover {
  color: #007bff;
}
 
.navbar-nav .nav-link.active {
  color: #007bff;
  /* background-color: #007bff; */
  font-weight: bold;
  border-radius: 5px;
}
</style>