Header.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  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 LanguageSwitcher from '../../../views/components/LanguageSwitcher.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. </div>
  103. <!-- 桌面端导航 -->
  104. <div class="nav desktop-nav" v-if="!isMobile">
  105. <div class="am-navss am-navss-pills">
  106. <div><router-link class="router" to="/index" @click="closeMobileMenu">{{ $t('message.t1')
  107. }}</router-link></div>
  108. <div><router-link class="router" to="/solution" @click="closeMobileMenu">{{ $t('message.t2')
  109. }}</router-link></div>
  110. <div><router-link class="router" to="/news" @click="closeMobileMenu">{{ $t('message.t3')
  111. }}</router-link></div>
  112. <!-- <div><router-link class="router" to="/example">客户案例</router-link></div> -->
  113. <div><router-link class="router" to="/MainBusiness" @click="closeMobileMenu">{{ $t('message.t4')
  114. }}</router-link>
  115. </div>
  116. <div><router-link class="router" to="/JoinUs" @click="closeMobileMenu">{{ $t('message.t5')
  117. }}</router-link></div>
  118. <div><router-link class="router" to="/ContactInformation" @click="closeMobileMenu">{{ $t('message.t6')
  119. }}</router-link></div>
  120. </div>
  121. </div>
  122. <!-- 移动端导航 -->
  123. <!-- <div class="nav mobile-nav responsive-nav" v-if="isMobileMenuOpen" :class="{ active: isMobileMenuOpen }">
  124. <ul class="am-navss am-navss-pills">
  125. <div><router-divnk class="router" to="/index" @cdivck="closeMobileMenu">{{ $t('message.t1') }}</router-divnk></div>
  126. <div><router-divnk class="router" to="/solution" @cdivck="closeMobileMenu">{{ $t('message.t2') }}</router-divnk></div>
  127. <div><router-divnk class="router" to="/product" @cdivck="closeMobileMenu">{{ $t('message.t3') }}</router-divnk></div>
  128. <div><router-divnk class="router" to="/news" @cdivck="closeMobileMenu">{{ $t('message.t4') }}</router-divnk></div>
  129. <div><router-divnk class="router" to="/about" @cdivck="closeMobileMenu">{{ $t('message.t5') }}</router-divnk></div>
  130. <div><router-divnk class="router" to="/about" @cdivck="closeMobileMenu">{{ $t('message.t6') }}</router-divnk></div>
  131. </ul>
  132. </div> -->
  133. <!-- 移动端遮罩层 -->
  134. <!-- <div v-if="isMobileMenuOpen" class="mobile-overlay" @cdivck="closeMobileMenu"></div> -->
  135. <el-drawer v-model="drawer" :direction="direction" :before-close="handleClose">
  136. <div class="am-navss am-navss-pills">
  137. <div><router-link class="router" to="/index" @click="closeMobileMenu">{{ $t('message.t1')
  138. }}</router-link></div>
  139. <div><router-link class="router" to="/solution" @click="closeMobileMenu">{{ $t('message.t2')
  140. }}</router-link></div>
  141. <div><router-link class="router" to="/news" @click="closeMobileMenu">{{ $t('message.t3')
  142. }}</router-link></div>
  143. <!-- <div><router-link class="router" to="/example">客户案例</router-link></div> -->
  144. <div><router-link class="router" to="/MainBusiness" @click="closeMobileMenu">{{ $t('message.t4')
  145. }}</router-link>
  146. </div>
  147. <div><router-link class="router" to="/JoinUs" @click="closeMobileMenu">{{ $t('message.t5')
  148. }}</router-link></div>
  149. <div><router-link class="router" to="/ContactInformation" @click="closeMobileMenu">{{ $t('message.t6')
  150. }}</router-link></div>
  151. </div>
  152. </el-drawer>
  153. </div>
  154. </template>
  155. <style lang="scss" scoped>
  156. // .el-drawer .el-drawer__body .am-navss div .router
  157. // Vue 3 深度渗透选择器示例
  158. :deep(.el-drawer) {
  159. // height: 36% !important;
  160. // 高度自适应怎么写
  161. height: auto!important;
  162. .el-drawer__header {
  163. padding: 1rem;
  164. border-bottom: 1px solid #eee;
  165. margin-bottom: 0rem !important;
  166. }
  167. .el-drawer__body {
  168. padding: 0rem 2rem;
  169. .am-navss {
  170. flex-direction: column;
  171. div {
  172. width: 100%;
  173. text-align: left;
  174. .router {
  175. padding: 1rem 0;
  176. border-bottom: 1px solid #f0f0f0;
  177. font-size: 1.2rem;
  178. &:hover {
  179. color: #F7B334;
  180. }
  181. }
  182. }
  183. }
  184. }
  185. }
  186. .header-mobile {
  187. display: flex;
  188. justify-content: space-between;
  189. align-items: center;
  190. padding: 2rem 5rem;
  191. background-color: #fff;
  192. position: relative;
  193. z-index: 1000;
  194. img {
  195. width: 4rem;
  196. height: 4rem;
  197. }
  198. .header-mobile-title {
  199. display: flex;
  200. align-items: center;
  201. }
  202. >div:nth-child(3){
  203. width: 4rem;
  204. height: 4rem;
  205. }
  206. }
  207. // 当前路由高亮样式
  208. .router.router-link-active {
  209. cursor: default;
  210. font-weight: 600 !important;
  211. color: #F7B334 !important;
  212. border-bottom: 0.2rem solid #F7B334;
  213. }
  214. // 基础导航链接样式
  215. .router {
  216. text-decoration: none;
  217. display: block;
  218. transition: all 0.3s ease;
  219. color: #555;
  220. // 响应式字体大小
  221. font-size: 1.0rem;
  222. padding-bottom: 0.2rem;
  223. // @media screen and (min-width: 480px) {
  224. // font-size: 1.1rem;
  225. // }
  226. // @media screen and (min-width: 768px) {
  227. // font-size: 1.4rem;
  228. // }
  229. // @media screen and (min-width: 1024px) {
  230. // font-size: 1.6rem;
  231. // }s
  232. @media screen and (min-width: 1200px) {
  233. font-size: 1.4rem;
  234. }
  235. }
  236. .header-wrapper {
  237. -moz-user-select: none;
  238. -khtml-user-select: none;
  239. user-select: none;
  240. background-color: #fff;
  241. position: relative;
  242. }
  243. .nav {
  244. margin: 0rem auto;
  245. @media screen and (min-width: 1024px) {
  246. padding-left: 1rem;
  247. padding-bottom: 0.8rem;
  248. }
  249. }
  250. .am-navss {
  251. width: 100%;
  252. display: flex;
  253. flex-wrap: wrap;
  254. justify-content: space-between;
  255. align-items: center;
  256. list-style: none;
  257. padding: 0;
  258. margin: 0;
  259. }
  260. // 导航容器样式
  261. .am-navss {
  262. display: flex;
  263. justify-content: space-between;
  264. align-items: center;
  265. width: 100%;
  266. }
  267. .am-navss>div {
  268. text-align: center;
  269. }
  270. .am-navss>div>a:hover,
  271. .am-navss>div>a:focus {
  272. background: none !important;
  273. }
  274. .nav .am-navss div a:hover {
  275. background: none !important;
  276. }
  277. // .nav .am-navss div a {
  278. // @media screen and (min-width: 1024px) {
  279. // font-weight: 400;
  280. // }
  281. // }
  282. .headerNew {
  283. display: flex;
  284. justify-content: space-between;
  285. align-items: center;
  286. margin: 0 auto;
  287. // @media screen and (min-width: 768px) {
  288. // padding-left: 100px;
  289. // }
  290. // @media screen and (min-width: 1024px) {
  291. // // padding-left: 21.5rem;
  292. // }
  293. // @media screen and (max-width: 767px) {
  294. // padding-left: 38px;
  295. // }
  296. }
  297. .zgyc {
  298. width: 35rem;
  299. height: 4.5rem;
  300. display: flex;
  301. justify-content: start;
  302. padding: 0.66rem 0;
  303. >img {
  304. width: 4.5rem;
  305. height: 4.5rem;
  306. margin: 0rem 1rem 0rem 0rem;
  307. }
  308. // @media screen and (min-width: 768px) {
  309. // width: 300px;
  310. // height: 75px;
  311. // }
  312. // @media screen and (min-width: 1024px) {
  313. // // width: 40rem;
  314. // }
  315. }
  316. .mainTitle {
  317. font-size: 2rem;
  318. font-weight: bold;
  319. color: #0F409E;
  320. }
  321. .assistantTitle {
  322. font-size: 1rem;
  323. line-height: 1rem;
  324. color: #999999;
  325. }
  326. // 移动端导航样式
  327. .mobile-nav {
  328. @media screen and (max-width: 767px) {
  329. position: fixed;
  330. top: 0;
  331. left: -100%;
  332. width: 80%;
  333. height: 100vh;
  334. background: white;
  335. transition: left 0.3s ease;
  336. z-index: 1000;
  337. padding: 80px 20px 20px;
  338. box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
  339. &.active {
  340. left: 0;
  341. }
  342. .am-navss {
  343. flex-direction: column;
  344. div {
  345. margin: 10px 0;
  346. a {
  347. font-size: 1.2rem;
  348. padding: 15px 0;
  349. border-bottom: 1px sodivd #eee;
  350. }
  351. }
  352. }
  353. }
  354. }
  355. // 桌面端导航
  356. .desktop-nav {
  357. display: block;
  358. }
  359. // 移动端遮罩层
  360. .mobile-overlay {
  361. @media screen and (max-width: 767px) {
  362. position: fixed;
  363. top: 0;
  364. left: 0;
  365. width: 100%;
  366. height: 100%;
  367. background: rgba(0, 0, 0, 0.5);
  368. z-index: 999;
  369. }
  370. }
  371. // 语言切换器响应式
  372. .lang-switcher {
  373. @media screen and (max-width: 767px) {
  374. // position: fixed;
  375. // top: 20px;
  376. // right: 80px;
  377. // z-index: 1002;
  378. }
  379. @media screen and (min-width: 1024px) {
  380. width: 40%;
  381. // margin-right:29.6rem;
  382. }
  383. }
  384. </style>