index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <div class="header-layout">
  3. <div class="container">
  4. <div class="logo-layout">
  5. <router-link :to="{name: 'home'}" class="logo">
  6. <vcenter>
  7. <img :src="language === 'en' ? `@/assets/images/home/logo-cn.png` : require('@/assets/images/home/logo-cn.png')" alt>
  8. </vcenter>
  9. </router-link>
  10. </div>
  11. <div class="menu">
  12. <div
  13. class="list"
  14. ref="list"
  15. >
  16. <a
  17. v-for="nav in langHeader.navs"
  18. :key="nav.text"
  19. :class="{active: hoverCp === nav.cp}"
  20. >{{nav.text}}</a>
  21. </div>
  22. </div>
  23. <div class="ctrl">
  24. <div class="shop-btn">在线商城</div>
  25. <div class="language-w">
  26. <span class="country"></span>
  27. <span class="language">简体中文</span>
  28. </div>
  29. <div class="user">1</div>
  30. </div>
  31. </div>
  32. </div>
  33. </template>
  34. <script>
  35. import { mapState } from 'vuex'
  36. import vcenter from '@/components/vcenter'
  37. import { getPosition, isWide } from '@/util'
  38. import browser from '@/util/browser'
  39. export default {
  40. data () {
  41. return {
  42. height: 0,
  43. hoverCp: '',
  44. overb: false,
  45. active: true,
  46. ismobile: browser.mobile,
  47. browserLang: browser.language,
  48. isWide,
  49. count: 0
  50. }
  51. },
  52. methods: {
  53. clickHandle (nav) {
  54. if (nav.cp === 'case_overview') {
  55. this.$router.push({name: 'cases', params: {id: '房地产'}})
  56. } else if (nav.cp === 'service_overview') {
  57. this.$router.push({name: 'service_list', params: {id: 'use', active: 'pro'}})
  58. } else {
  59. this.$router.push({ name: nav.cp })
  60. }
  61. },
  62. handleLogout () {
  63. this.$toast.showConfirm('warn', this.language === 'en' ? 'Are you sure to log out?' : '确定要退出登录吗?', async () => {
  64. await this.$store.dispatch('logout')
  65. this.$router.push({name: 'home'})
  66. })
  67. },
  68. showCp (cp, height) {
  69. clearTimeout(this.timeout)
  70. if (cp !== 'about' && cp !== 'location') {
  71. this.$bus.$emit('showMask')
  72. }
  73. this.hoverCp = cp
  74. this.height = height
  75. },
  76. hideCp () {
  77. clearTimeout(this.timeout)
  78. this.$bus.$emit('hideMask')
  79. this.height = 0
  80. this.timeout = setTimeout(() => {
  81. this.hoverCp = null
  82. }, 200)
  83. },
  84. searchHandle () {
  85. if (this.hoverCp === 'isearch') {
  86. this.hideCp()
  87. } else {
  88. this.showCp('isearch', window.innerHeight - 68)
  89. }
  90. },
  91. loginHandle (type = null) {
  92. if (type === 'cart' && this.language === 'en') {
  93. return window.open('https://www.alibaba.com/product-detail/4DKanKan-Pro-3D-camera-3D-space_62183626283.html?spm=a2700.icbuShop.74.1.66b35b10I4miJd')
  94. }
  95. this.$bus.$emit('showAside')
  96. }
  97. },
  98. computed: {
  99. ...mapState({
  100. language: state => state.language.current,
  101. langHeader: state => state.language.home.headers,
  102. split: state => state.ui.navDivision,
  103. isLogin: state => state.user.token,
  104. info: state => state.user.info,
  105. deviceLogin: state => state.user.deviceLogin
  106. })
  107. },
  108. mounted () {
  109. let lang = ~this.browserLang.indexOf('zh') ? '中' : 'en'
  110. this.$store.commit('change_language', lang)
  111. if (this.isLogin && !this.deviceLogin) {
  112. let cart = JSON.parse(this.$store.state.user.cart)
  113. let count = 0
  114. cart.forEach(item => {
  115. count += item.goodsCount
  116. })
  117. this.count = count
  118. }
  119. this.$bus.$on('hadload', data => {
  120. this.$store.commit('change_nav_division', getPosition(this.$refs.list).x)
  121. })
  122. this.$bus.$on('updateCart', data => {
  123. this.count = data
  124. })
  125. this.$bus.$on('hideSearch', target => {
  126. if (this.$refs.isearchref) {
  127. if (!this.$refs.isearchref.contains(target)) {
  128. this.hideCp()
  129. }
  130. }
  131. })
  132. this.sizeHandle = () => {
  133. this.isWide = Math.round(devicePixelRatio * 100) === 100 ? window.innerWidth > 1600 : true
  134. this.$nextTick(() => {
  135. this.$store.commit('change_nav_division', getPosition(this.$refs.list).x)
  136. })
  137. }
  138. window.addEventListener('resize', this.sizeHandle)
  139. setTimeout(this.sizeHandle, 300)
  140. },
  141. destroyed () {
  142. window.removeEventListener('resize', this.sizeHandle)
  143. },
  144. components: { vcenter },
  145. watch: {
  146. language (newVal) {
  147. document.title = newVal === 'en' ? '4DKanKan' : '四维看看'
  148. }
  149. }
  150. }
  151. </script>
  152. <style lang="scss" scoped>
  153. @import "./istyle.scss";
  154. </style>