header.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. <script setup lang="ts">
  2. import { ref, computed } from 'vue'
  3. import { useRouter, useRoute } from 'vue-router'
  4. import { useI18n } from 'vue-i18n'
  5. import logoCn from '@/assets/images/logoCn.png'
  6. import logoEn from '@/assets/images/logoEn.png'
  7. import shopbtn from '@/assets/images/footer/shopbtn.gif'
  8. import shopbtnEn from '@/assets/images/footer/shopbtn-en.gif'
  9. import { useUserStore } from '@/stores/user'
  10. import { pcHeader, languageList } from './data'
  11. const router = useRouter();
  12. //得到i18n的locale
  13. const userStore = useUserStore()
  14. const info = computed(() => userStore.getUserInfo)
  15. const isLogin = computed(() => userStore.isLogin)
  16. const { locale:langauge, t } = useI18n();
  17. const navs = pcHeader(t)
  18. const languageObj = computed(() => languageList.find(item => item.value === langauge.value) || {})
  19. console.log('languageObj', info.value, userStore)
  20. </script>
  21. <template>
  22. <div class="header-layout">
  23. <div class="headercontainer clear flex justify-between items-center">
  24. <img :src="locale === 'zh' ? logoCn : logoEn" alt="logo">
  25. <div class="menu">
  26. <div
  27. class="list"
  28. ref="list"
  29. >
  30. <a
  31. v-for="nav in navs"
  32. :key="nav.text"
  33. :class="{active: hoverCp === nav.cp}"
  34. class="header-item"
  35. :style="{'margin-right': langauge==='en' ? '30px' : '48px'}"
  36. @click="toNav(nav)"
  37. >{{nav.text}}
  38. <ul class="child-list" v-if="nav.items">
  39. <li class="" v-for="(item, index) in nav.items" :key="index" @click.stop="toNav(item)">
  40. {{ item.text }}
  41. </li>
  42. </ul>
  43. </a>
  44. </div>
  45. </div>
  46. <div class="ctrl">
  47. <div class="shop-btn" @click="router.push({name: 'mallMeta'})" v-if="!isShop">
  48. <img :src="langauge==='en' ? shopbtnEn : shopbtn" alt="" srcset="">
  49. </div>
  50. <div class="language-w">
  51. <div class="list">
  52. <a class="header-item">
  53. <p class="guoqi" :style="{'background-image': `url(${languageObj.img})`}">{{ languageObj.name }}</p>
  54. <ul class="child-list">
  55. <li v-for="item in languageList" :key="item.name" :style="{'background-image': `url(${item.img})`}" @click="changeLanguage(item.value)">{{ item.name }}</li>
  56. </ul>
  57. </a>
  58. </div>
  59. </div>
  60. <div class="user" @click="router.push('/login/login')" v-if="!isLogin"></div>
  61. <div v-else-if="info" class="user-w">
  62. <div class="user avatar" :class="{vip: info.incrementNum}" :style="{'background-image': `url(${info.head})`}" @click="router.push('/information')">
  63. <div class="member-icon" @click.stop="router.push({name: 'member'})" v-if="info.incrementNum"></div>
  64. </div>
  65. <div class="list avatarList">
  66. <a class="header-item" @click="router.push('/information')">
  67. <ul class="child-list">
  68. <li @click="router.push('/information')">{{ t('header.myaccount') }}</li>
  69. <li @click.stop="handleLogout">{{ t('header.logout') }}</li>
  70. </ul>
  71. </a>
  72. </div>
  73. </div>
  74. <div class="cart" @click="handleCartClick">
  75. <h-icon type="xingouwuche" class="icon" />
  76. <span v-if="cartCount">{{cartCount}}</span>
  77. </div>
  78. </div>
  79. </div>
  80. </div>
  81. <!-- <div class="header">
  82. <div class="logo contentPage">
  83. <img :src="locale === 'zh' ? logoCn : logoEn" alt="logo">
  84. </div>
  85. </div> -->
  86. </template>
  87. <style lang="less" scoped>
  88. .language-w {
  89. .header-item {
  90. margin-right: 20px !important;
  91. display: inline-block;
  92. p {
  93. color: #323233;
  94. font-size: 14px;
  95. font-weight: normal;
  96. padding-left: 28px;
  97. background: url(~@/assets/images/home/China.png) no-repeat left center;
  98. background-size: 20px 14px;
  99. }
  100. }
  101. .child-list {
  102. background: #fff;
  103. li {
  104. color: #323233;
  105. font-size: 14px;
  106. font-weight: normal;
  107. padding: 0 13px 0 40px;
  108. background: url(~@/assets/images/home/China.png) no-repeat 13px center;
  109. background-size: 20px 14px;
  110. }
  111. }
  112. }
  113. .header-layout {
  114. // $mc: .5s cubic-bezier(.77, 0, .175, 1);
  115. // $ts: all $mc;
  116. background-color: #fff;
  117. color: #fff;
  118. justify-content: space-between;
  119. color: #323233;
  120. height: 80px;
  121. box-shadow:0px 3px 6px rgba(0,0,0,0.1);
  122. .headercontainer {
  123. height: 100%;
  124. width: 1316px;
  125. padding: 0 20px;
  126. margin: 0 auto;
  127. }
  128. .child-layout {
  129. position: absolute;
  130. top: 100%;
  131. max-height: 0;
  132. left: 0;
  133. right: 0;
  134. // transition: max-height $mc;
  135. overflow: hidden;
  136. box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  137. .silp {
  138. position: absolute;
  139. width: 1px;
  140. height: 100%;
  141. background-color: #ededed;
  142. z-index: 2;
  143. }
  144. }
  145. .logo-layout {
  146. text-align: center;
  147. text-align: left;
  148. margin-right: 52px;
  149. float: left;
  150. height: 100%;
  151. .logo {
  152. position: relative;
  153. width: 150px;
  154. height: 100%;
  155. display: inline-block;
  156. color: #fff;
  157. }
  158. }
  159. .menu {
  160. float: left;
  161. min-width: 600px;
  162. .lang {
  163. box-sizing: border-box;
  164. text-align: center;
  165. padding-right: 10px;
  166. a {
  167. display: inline-block;
  168. font-size: 16px;
  169. font-weight: bold;
  170. margin-left: 5px;
  171. color: #727272;
  172. transition: color 0.2s ease;
  173. &:hover{
  174. color: #fff;
  175. }
  176. }
  177. .active{
  178. color: #fff;
  179. }
  180. }
  181. }
  182. .list {
  183. justify-content: space-between;
  184. height: 100%;
  185. a {
  186. display: inline-block;
  187. // padding: 30px 47px 25px 0;
  188. margin-right: 48px;
  189. line-height: 80px;
  190. font-size: 16px;
  191. text-decoration: none;
  192. font-weight: bold;
  193. position: relative;
  194. transition: color 0.3s ease;
  195. &::before {
  196. z-index: 2;
  197. }
  198. &.active {
  199. color: #727272;
  200. &::after {
  201. border-top-color: #727272;
  202. transform: translateY(-50%) scale(1.3);
  203. }
  204. &::before {
  205. transform: translateY(-50%) scale(0.7);
  206. border-top-color: #000;
  207. }
  208. }
  209. }
  210. }
  211. .ctrl {
  212. align-items: center;
  213. font-size: 16px;
  214. &>div {
  215. display: inline-block;
  216. vertical-align: middle;
  217. }
  218. .shop-btn {
  219. margin-right: 25px;
  220. cursor: pointer;
  221. height: 34px;
  222. line-height: 34px;
  223. text-align: center;
  224. font-weight: 400;
  225. height: 34px;
  226. background: linear-gradient(180deg, #1EDAE5 1%, #069199 100%);
  227. border-radius: 17px;
  228. color: #FFFFFF;
  229. img {
  230. height: 34px;
  231. }
  232. }
  233. .country {
  234. width: 20px;
  235. height: 21px;
  236. display: inline-block;
  237. background: url(~@/assets/images/home/China.png) no-repeat center center;
  238. vertical-align: middle;
  239. }
  240. .language-w {
  241. // padding: 0 30px 0 10px;
  242. }
  243. .language {
  244. margin: 0 15px 0 0;
  245. color: #8F8F8F;
  246. cursor: pointer;
  247. vertical-align: middle;
  248. font-size: 16px;
  249. font-weight: 600;
  250. &.is-active {
  251. color: #323233;
  252. }
  253. }
  254. .user {
  255. width: 20px;
  256. height: 20px;
  257. background: url(~@/assets/images/home/account-icon.png) no-repeat center center;
  258. cursor: pointer;
  259. background-size: cover;
  260. &.avatar {
  261. width: 34px;
  262. height: 34px;
  263. border: 1px solid #EFEFEF;
  264. border-radius: 50%;
  265. position: relative;
  266. &.vip {
  267. border-color: #D8AF7C;
  268. }
  269. }
  270. .member-icon {
  271. width: 12px;
  272. height: 12px;
  273. background: url(~@/assets/images/refactor/usercenter/avatar_vip.png) no-repeat center center;
  274. background-size: cover;
  275. position: absolute;
  276. right: -2px;
  277. bottom: 0;
  278. }
  279. }
  280. .cart {
  281. color: #323233;
  282. margin-left: 18px;
  283. cursor: pointer;
  284. position: relative;
  285. .icon {
  286. font-size: 26px;
  287. }
  288. span {
  289. display: block;
  290. position: absolute;
  291. left: 9px;
  292. top: 0;
  293. font-size: 12px;
  294. line-height: 16px;
  295. text-align: center;
  296. font-weight: bold;
  297. color: #FFFFFF;
  298. line-height: 14px;
  299. height: 16px;
  300. min-width: 16px;
  301. padding: 0 2px;
  302. background: linear-gradient(135deg, #696D75 0%, #3C3F41 100%);
  303. border-radius: 4px;
  304. }
  305. }
  306. }
  307. }
  308. .header-item:hover {
  309. position: relative;
  310. .child-list {
  311. display: block;
  312. }
  313. }
  314. .child-list {
  315. position: absolute;
  316. // width: 112px;
  317. box-shadow: 0px -2px 6px rgba(113,113,113,0.16);
  318. margin-top: -10px;
  319. left: 50%;
  320. transform: translateX(-50%);
  321. z-index: 1;
  322. display: none;
  323. transition: all linear 0.5s;
  324. padding-top: 6px;
  325. white-space: nowrap;
  326. background: #fff;
  327. &::before {
  328. position: absolute;
  329. display: block;
  330. top: -5px;
  331. left: 50%;
  332. margin-left: -2px;
  333. width: 0;
  334. height: 0px;
  335. content: '';
  336. background: #fff;
  337. border-style: solid;
  338. border-width: 4px;
  339. border-color: #fff #fff transparent transparent;
  340. transform: rotate(-45deg);
  341. box-shadow: 1px -1px 0px rgba(113,113,113,0.16);
  342. z-index: 1;
  343. }
  344. li {
  345. height: 48px;
  346. line-height: 48px;
  347. font-size: 16px;
  348. text-align: center;
  349. position: relative;
  350. background: #fff;
  351. z-index: 2;
  352. width: 100%;
  353. padding: 0 25px;
  354. &:hover {
  355. background-color: #EBEBEB;
  356. }
  357. }
  358. }
  359. .list {
  360. &:hover {
  361. .header-item {
  362. color: #909090;
  363. }
  364. }
  365. .header-item:hover {
  366. position: relative;
  367. color: #323233;
  368. transition: 0s;
  369. .child-list {
  370. display: block;
  371. }
  372. }
  373. }
  374. .user-w {
  375. .avatarList{
  376. position: absolute;
  377. z-index: 1;
  378. }
  379. .list {
  380. height: 100%;
  381. top: 0;
  382. .header-item {
  383. display: block;
  384. width: 32px;
  385. padding-top: 80px;
  386. }
  387. }
  388. }
  389. @media screen and (max-width: 1600px){
  390. }
  391. @media screen and (max-width: 1450px){
  392. }
  393. </style>