Header.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. <script setup>
  2. import AppFunctions from "@/utils/AppFunctions";
  3. import { nextTick, onBeforeUnmount, onMounted, ref } from 'vue';
  4. import { getCompanyInfoAPI } from '@/apis/aboutourAPi.js';
  5. import { h } from 'vue';
  6. import { ElMessage } from 'element-plus'
  7. import { useRouter } from 'vue-router';
  8. import LanguageSwitcher from '../../../views/components/LanguageSwitcher.vue';
  9. // import myNavigation from "../../../views/components/myNavigation.vue";
  10. const router = useRouter()
  11. const CompanyInfo = ref({})//后台数据获取
  12. const CompanyInfo1 = ref(JSON.parse(window.sessionStorage.getItem('companyinfo')) ? JSON.parse(window.sessionStorage.getItem('companyinfo')) : '0')//从会话储存获取
  13. // 移动端菜单状态
  14. const isMobileMenuOpen = ref(false)
  15. // 移动端判断
  16. const isMobile = ref(false)
  17. // 检查是否为移动端
  18. const checkMobile = () => {
  19. isMobile.value = window.innerWidth <= 768
  20. }
  21. const getCompanyInfo = async () => {
  22. const { data: res } = await getCompanyInfoAPI()
  23. CompanyInfo.value = res.Data
  24. window.sessionStorage.setItem('companyinfo', JSON.stringify(res.Data))
  25. console.log('获取成功');
  26. }
  27. const toggleStickyHeader = () => {
  28. const scrolled = document.documentElement.scrollTop;
  29. if (scrolled > 100) {
  30. AppFunctions.addClass('.header-wrapper', 'sticky');
  31. } else if (scrolled <= 100) {
  32. AppFunctions.removeClass('.header-wrapper', 'sticky');
  33. }
  34. }
  35. const callPhone = () => {
  36. ElMessage({
  37. message: h('p', null, [
  38. h('span', null, '联系电话 '),
  39. h('i', { style: 'color: teal' }, `${CompanyInfo.value.Phone}`),
  40. ]),
  41. type: 'success',
  42. offset: 80
  43. })
  44. }
  45. // 切换移动端菜单
  46. const toggleMobileMenu = () => {
  47. if (isMobile.value) {
  48. isMobileMenuOpen.value = !isMobileMenuOpen.value
  49. }
  50. }
  51. // 关闭移动端菜单
  52. const closeMobileMenu = () => {
  53. isMobileMenuOpen.value = false
  54. }
  55. // 移动端菜单方向
  56. const direction = ref('ttb');
  57. const drawer = ref(false);
  58. const showMenu = () => {
  59. drawer.value = true;
  60. }
  61. // 处理drawer关闭
  62. const handleClose = (done) => {
  63. drawer.value = false;
  64. done();
  65. }
  66. onMounted(() => {
  67. // 初始化检查移动端
  68. checkMobile()
  69. // 监听窗口大小变化
  70. window.addEventListener('resize', checkMobile)
  71. })
  72. onBeforeUnmount(() => {
  73. // window.removeEventdivstener('scroll', toggleStickyHeader);
  74. // 移除监听器
  75. window.removeEventListener('resize', checkMobile)
  76. })
  77. </script>
  78. <template>
  79. <div class="header-wrapper">
  80. <div v-if="isMobile" class="header-mobile">
  81. <img src="../../../assets/images/menu.png" alt="" srcset="" @click="showMenu">
  82. <div class="header-mobile-title">
  83. <img src="../../../assets/images/inlogo.png" alt="">
  84. <div>
  85. <div class="mainTitle">中烟国际集团有限公司</div>
  86. <div class="assistantTitle"> China Tobacco International Group Limited</div>
  87. </div>
  88. </div>
  89. <LanguageSwitcher class="lang-switcher" />
  90. </div>
  91. <div v-else class="nav-wrapper header-default headerNew ">
  92. <div class="zgyc">
  93. <!-- <img src="../../../assets/images/newIndex/titleNew.png" alt="" srcset=""> -->
  94. <!-- #0F409E -->
  95. <img src="../../../assets/images/inlogo.png" alt="">
  96. <div>
  97. <div class="mainTitle">中烟国际集团有限公司</div>
  98. <div class="assistantTitle"> China Tobacco International Group Limited</div>
  99. </div>
  100. </div>
  101. <LanguageSwitcher class="lang-switcher" />
  102. <!-- <myNavigation></myNavigation> -->
  103. </div>
  104. <!-- 桌面端导航 -->
  105. <div class="nav desktop-nav" v-if="!isMobile">
  106. <div class="am-navss am-navss-pills">
  107. <div><router-link class="router" to="/index" @click="closeMobileMenu">{{ $t('message.t1')
  108. }}</router-link></div>
  109. <div><router-link class="router" to="/solution" @click="closeMobileMenu">{{ $t('message.t2')
  110. }}</router-link></div>
  111. <div><router-link class="router" to="/news" @click="closeMobileMenu">{{ $t('message.t3')
  112. }}</router-link></div>
  113. <!-- <div><router-link class="router" to="/example">客户案例</router-link></div> -->
  114. <div><router-link class="router" to="/MainBusiness" @click="closeMobileMenu">{{ $t('message.t4')
  115. }}</router-link>
  116. </div>
  117. <div><router-link class="router" to="/JoinUs" @click="closeMobileMenu">{{ $t('message.t5')
  118. }}</router-link></div>
  119. <div><router-link class="router" to="/ContactInformation" @click="closeMobileMenu">{{ $t('message.t6')
  120. }}</router-link></div>
  121. </div>
  122. </div>
  123. <!-- 移动端导航 -->
  124. <!-- <div class="nav mobile-nav responsive-nav" v-if="isMobileMenuOpen" :class="{ active: isMobileMenuOpen }">
  125. <ul class="am-navss am-navss-pills">
  126. <div><router-divnk class="router" to="/index" @cdivck="closeMobileMenu">{{ $t('message.t1') }}</router-divnk></div>
  127. <div><router-divnk class="router" to="/solution" @cdivck="closeMobileMenu">{{ $t('message.t2') }}</router-divnk></div>
  128. <div><router-divnk class="router" to="/product" @cdivck="closeMobileMenu">{{ $t('message.t3') }}</router-divnk></div>
  129. <div><router-divnk class="router" to="/news" @cdivck="closeMobileMenu">{{ $t('message.t4') }}</router-divnk></div>
  130. <div><router-divnk class="router" to="/about" @cdivck="closeMobileMenu">{{ $t('message.t5') }}</router-divnk></div>
  131. <div><router-divnk class="router" to="/about" @cdivck="closeMobileMenu">{{ $t('message.t6') }}</router-divnk></div>
  132. </ul>
  133. </div> -->
  134. <!-- 移动端遮罩层 -->
  135. <!-- <div v-if="isMobileMenuOpen" class="mobile-overlay" @cdivck="closeMobileMenu"></div> -->
  136. <el-drawer v-model="drawer" :direction="direction" :before-close="handleClose">
  137. <div class="am-navss am-navss-pills">
  138. <div><router-link class="router" to="/index" @click="closeMobileMenu">{{ $t('message.t1')
  139. }}</router-link></div>
  140. <div><router-link class="router" to="/solution" @click="closeMobileMenu">{{ $t('message.t2')
  141. }}</router-link></div>
  142. <div><router-link class="router" to="/news" @click="closeMobileMenu">{{ $t('message.t3')
  143. }}</router-link></div>
  144. <!-- <div><router-link class="router" to="/example">客户案例</router-link></div> -->
  145. <div><router-link class="router" to="/MainBusiness" @click="closeMobileMenu">{{ $t('message.t4')
  146. }}</router-link>
  147. </div>
  148. <div><router-link class="router" to="/JoinUs" @click="closeMobileMenu">{{ $t('message.t5')
  149. }}</router-link></div>
  150. <div><router-link class="router" to="/ContactInformation" @click="closeMobileMenu">{{ $t('message.t6')
  151. }}</router-link></div>
  152. </div>
  153. </el-drawer>
  154. </div>
  155. </template>
  156. <style lang="scss" scoped>
  157. // .el-drawer .el-drawer__body .am-navss div .router
  158. // Vue 3 深度渗透选择器示例
  159. :deep(.el-drawer) {
  160. // height: 36% !important;
  161. // 高度自适应怎么写
  162. height: auto!important;
  163. .el-drawer__header {
  164. padding: 1rem;
  165. border-bottom: 1px solid #eee;
  166. margin-bottom: 0rem !important;
  167. }
  168. .el-drawer__body {
  169. padding: 0rem 2rem;
  170. .am-navss {
  171. flex-direction: column;
  172. div {
  173. width: 100%;
  174. text-align: left;
  175. .router {
  176. padding: 1rem 0;
  177. border-bottom: 1px solid #f0f0f0;
  178. font-size: 1.2rem;
  179. &:hover {
  180. color: #F7B334;
  181. }
  182. }
  183. }
  184. }
  185. }
  186. }
  187. .header-mobile {
  188. display: flex;
  189. justify-content: space-between;
  190. align-items: center;
  191. padding: 2rem 5rem;
  192. background-color: #fff;
  193. position: relative;
  194. z-index: 1000;
  195. img {
  196. width: 4rem;
  197. height: 4rem;
  198. }
  199. .header-mobile-title {
  200. display: flex;
  201. align-items: center;
  202. }
  203. >div:nth-child(3){
  204. width: 4rem;
  205. height: 4rem;
  206. }
  207. }
  208. // 当前路由高亮样式
  209. .router.router-link-active {
  210. cursor: default;
  211. font-weight: 600 !important;
  212. color: #F7B334 !important;
  213. border-bottom: 0.2rem solid #F7B334;
  214. }
  215. // 基础导航链接样式
  216. .router {
  217. text-decoration: none;
  218. display: block;
  219. transition: all 0.3s ease;
  220. color: #555;
  221. // 响应式字体大小
  222. font-size: 1.0rem;
  223. padding-bottom: 0.2rem;
  224. // @media screen and (min-width: 480px) {
  225. // font-size: 1.1rem;
  226. // }
  227. // @media screen and (min-width: 768px) {
  228. // font-size: 1.4rem;
  229. // }
  230. // @media screen and (min-width: 1024px) {
  231. // font-size: 1.6rem;
  232. // }s
  233. @media screen and (min-width: 1200px) {
  234. font-size: 1.4rem;
  235. }
  236. }
  237. .header-wrapper {
  238. -moz-user-select: none;
  239. -khtml-user-select: none;
  240. user-select: none;
  241. background-color: #fff;
  242. position: relative;
  243. }
  244. .nav {
  245. margin: 0rem auto;
  246. @media screen and (min-width: 1024px) {
  247. padding-left: 1rem;
  248. padding-bottom: 0.8rem;
  249. }
  250. }
  251. .am-navss {
  252. width: 100%;
  253. display: flex;
  254. flex-wrap: wrap;
  255. justify-content: space-between;
  256. align-items: center;
  257. list-style: none;
  258. padding: 0;
  259. margin: 0;
  260. }
  261. // 导航容器样式
  262. .am-navss {
  263. display: flex;
  264. justify-content: space-between;
  265. align-items: center;
  266. width: 100%;
  267. }
  268. .am-navss>div {
  269. text-align: center;
  270. }
  271. .am-navss>div>a:hover,
  272. .am-navss>div>a:focus {
  273. background: none !important;
  274. }
  275. .nav .am-navss div a:hover {
  276. background: none !important;
  277. }
  278. // .nav .am-navss div a {
  279. // @media screen and (min-width: 1024px) {
  280. // font-weight: 400;
  281. // }
  282. // }
  283. .headerNew {
  284. display: flex;
  285. justify-content: space-between;
  286. align-items: center;
  287. margin: 0 auto;
  288. // @media screen and (min-width: 768px) {
  289. // padding-left: 100px;
  290. // }
  291. // @media screen and (min-width: 1024px) {
  292. // // padding-left: 21.5rem;
  293. // }
  294. // @media screen and (max-width: 767px) {
  295. // padding-left: 38px;
  296. // }
  297. }
  298. .zgyc {
  299. width: 35rem;
  300. height: 4.5rem;
  301. display: flex;
  302. justify-content: start;
  303. padding: 0.66rem 0;
  304. >img {
  305. width: 4.5rem;
  306. height: 4.5rem;
  307. margin: 0rem 1rem 0rem 0rem;
  308. }
  309. // @media screen and (min-width: 768px) {
  310. // width: 300px;
  311. // height: 75px;
  312. // }
  313. // @media screen and (min-width: 1024px) {
  314. // // width: 40rem;
  315. // }
  316. }
  317. .mainTitle {
  318. font-size: 2rem;
  319. font-weight: bold;
  320. color: #0F409E;
  321. }
  322. .assistantTitle {
  323. font-size: 1rem;
  324. line-height: 1rem;
  325. color: #999999;
  326. }
  327. // 移动端导航样式
  328. .mobile-nav {
  329. @media screen and (max-width: 767px) {
  330. position: fixed;
  331. top: 0;
  332. left: -100%;
  333. width: 80%;
  334. height: 100vh;
  335. background: white;
  336. transition: left 0.3s ease;
  337. z-index: 1000;
  338. padding: 80px 20px 20px;
  339. box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
  340. &.active {
  341. left: 0;
  342. }
  343. .am-navss {
  344. flex-direction: column;
  345. div {
  346. margin: 10px 0;
  347. a {
  348. font-size: 1.2rem;
  349. padding: 15px 0;
  350. border-bottom: 1px sodivd #eee;
  351. }
  352. }
  353. }
  354. }
  355. }
  356. // 桌面端导航
  357. .desktop-nav {
  358. display: block;
  359. }
  360. // 移动端遮罩层
  361. .mobile-overlay {
  362. @media screen and (max-width: 767px) {
  363. position: fixed;
  364. top: 0;
  365. left: 0;
  366. width: 100%;
  367. height: 100%;
  368. background: rgba(0, 0, 0, 0.5);
  369. z-index: 999;
  370. }
  371. }
  372. // 语言切换器响应式
  373. .lang-switcher {
  374. @media screen and (max-width: 767px) {
  375. // position: fixed;
  376. // top: 20px;
  377. // right: 80px;
  378. // z-index: 1002;
  379. }
  380. @media screen and (min-width: 1024px) {
  381. width: 40%;
  382. // margin-right:29.6rem;
  383. }
  384. }
  385. </style>