header.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <template>
  2. <div class="header-layout" >
  3. <div class="h-left" @click="active = !active">
  4. <div class="l-con" :class="{active:active}" >
  5. <span class="l1"></span>
  6. <span class="l2"></span>
  7. <span class="l3"></span>
  8. </div>
  9. </div>
  10. <div class="h-center">
  11. <vcenter>
  12. <img :src="`${$cdn}images/logo.png`" @click="()=>{goto({name:'home'})} " alt>
  13. </vcenter>
  14. </div>
  15. <div class="h-right">
  16. <div v-if="$route.name==='cases'" style="text-align:right">
  17. <i class="iconfont icon-sousuo" @click="()=>{searchActive = true;active = false}"></i>
  18. </div>
  19. <div class="h-user" v-else-if="isAccout">
  20. <i class="iconfont icon-cart" @click="$router.push({path:'/cart'})"><span>{{count>99?'99+':count}}</span></i>
  21. <img ref="userList" :src="`${$cdn}images/icon/nav_icon.png`" @click="userList=!userList" alt="">
  22. <ul :class="{'ul-active':userList}" >
  23. <li v-for="(item,i) in manage" :key="i" @click="handleClick(item)">{{item.name}}</li>
  24. </ul>
  25. </div>
  26. <div class="btn-buy" @click="buy" v-else>{{langHeader.buy}}</div>
  27. </div>
  28. <div class="search-active" :style="{maxHeight:searchActive?'140px':'0'}">
  29. <input type="text" v-model="searchTxt" :placeholder="langHeader.placeholder">
  30. <i @click="()=>{searchActive = false;searchTxt=''}" class="iconfont icon-cuowu"></i>
  31. <div v-if="scene.length>0&&searchActive" class="logo"></div>
  32. </div>
  33. <div class="search-result" id="search-result" @touchmove.stop :style="{maxHeight:scene.length>0&&searchActive?'calc(100vh - 140px)':'0'}">
  34. <div class="items" @click="linkto(item.webSite)" v-for="(item,i) in scene" :key="i">
  35. <div class="card-img" :style="{backgroundImage: `url(${item.thumb||`${$cdn}images/default.png`})`}"></div>
  36. <div class="item-txt">
  37. <p>{{typeArr[item.sceneType]}}</p>
  38. <p v-html="maskTitle(item.sceneName)"></p>
  39. <p><span>作者:</span>{{item.nickName}}</p>
  40. </div>
  41. </div>
  42. <div class="paging" v-if="scene.length>0&&searchActive">
  43. <vcenter>
  44. <Paging :current="currentPage" @clickHandle="pageChange" :total="total" :equable="pageSize" />
  45. </vcenter>
  46. </div>
  47. </div>
  48. <div class="nav-active" :style="{maxHeight:active?'100vh':'0'}">
  49. <div class="nav-bg">
  50. <img :src="`${$cdn}images/nav-bg.png`" alt="">
  51. </div>
  52. <ul v-for="(item, index) in langHeader.navs" :key="index">
  53. <li>
  54. <div class="n-name" @click="clickItem(item)">
  55. <span>{{item.title}}</span>
  56. <img
  57. v-if="item.sub.length>0"
  58. :src="`${$cdn}images/sanjiao.png`"
  59. :class="{active:activeIdx===item.id}"
  60. alt
  61. >
  62. </div>
  63. <div class="n-child" :class="{'open':activeIdx===item.id}">
  64. <div v-for="(sub,i) in item.sub" :key="i" @click="goto(sub.to)">
  65. <i class="iconfont" :class="sub.icon"></i>
  66. <span>{{sub.name}}</span>
  67. <img v-if="sub.isNew" class="new-icon" :src="`${$cdn}images/new.png`" alt="">
  68. </div>
  69. </div>
  70. </li>
  71. </ul>
  72. <div class="language">
  73. <span :class="{active:language === '中'}" @click="changLang('中')">中</span>
  74. <span :class="{active:language === 'en'}" @click="changLang('en')">En</span>
  75. </div>
  76. </div>
  77. </div>
  78. </template>
  79. <script>
  80. import vcenter from '@/components/vcenter/'
  81. import { mapState } from 'vuex'
  82. import Paging from '@/components/Paging'
  83. export default {
  84. computed: {
  85. ...mapState({
  86. token: state => state.user.token,
  87. langHeader: state => state.language.home.headers,
  88. language: state => state.language.current
  89. }),
  90. isAccout: function () {
  91. if (this.$route.matched.length > 0) {
  92. return this.$route.matched[0]['name'] === 'manage'
  93. }
  94. return false
  95. }
  96. },
  97. data () {
  98. let typeArr = {
  99. 2: '房地产',
  100. 1: '博物馆',
  101. 5: '家居',
  102. 4: '餐饮',
  103. 0: '其他'
  104. }
  105. let manage = [
  106. {
  107. name: '我的账号',
  108. to: {path: '/information'}
  109. },
  110. {
  111. name: '我的订单',
  112. to: {path: '/order'}
  113. },
  114. {
  115. name: '我的场景',
  116. to: {path: '/myscene'}
  117. },
  118. {
  119. name: '我的设备',
  120. to: {path: '/device'}
  121. },
  122. {
  123. name: '消费记录',
  124. to: {path: '/consumption'}
  125. },
  126. {
  127. name: '修改密码',
  128. to: {path: '/change'}
  129. },
  130. {
  131. name: '退出登录',
  132. to: 'logout'
  133. }
  134. ]
  135. return {
  136. manage,
  137. active: false,
  138. searchActive: false,
  139. searchTxt: '',
  140. activeIdx: '',
  141. count: 0,
  142. typeArr,
  143. total: 0,
  144. pageSize: 10,
  145. currentPage: 1,
  146. scene: [],
  147. userList: false
  148. }
  149. },
  150. watch: {
  151. currentPage () {
  152. this.getData()
  153. },
  154. searchTxt (newVal) {
  155. if (newVal) {
  156. this.currentPage === 1 ? this.getData() : this.currentPage = 1
  157. } else {
  158. this.scene = []
  159. }
  160. }
  161. },
  162. mounted () {
  163. document.addEventListener('click', (e) => {
  164. if (this.$refs.userList) {
  165. if (!this.$refs.userList.contains(e.target)) {
  166. this.userList = false
  167. }
  168. }
  169. })
  170. if (this.token) {
  171. let cart = JSON.parse(this.$store.state.user.cart)
  172. let count = 0
  173. cart.forEach(item => {
  174. count += item.goodsCount
  175. })
  176. this.count = count
  177. }
  178. this.$bus.$on('updateCart', data => {
  179. this.count = data
  180. })
  181. },
  182. methods: {
  183. pageChange (data) {
  184. this.currentPage = data
  185. },
  186. handleClick (item) {
  187. if (item.to === 'logout') {
  188. this.$store.dispatch('logout')
  189. this.$router.push({name: 'home'})
  190. } else {
  191. this.$router.push(item.to)
  192. }
  193. this.userList = false
  194. },
  195. clickItem (item) {
  196. this.activeIdx = this.activeIdx === item.id ? '' : item.id
  197. if (item.url) {
  198. this.active = false
  199. if (item.url === '/login' && this.token) {
  200. this.$router.push({
  201. path: '/information'
  202. })
  203. } else {
  204. this.$router.push({
  205. path: item.url,
  206. query: {
  207. id: item.id
  208. }
  209. })
  210. }
  211. }
  212. },
  213. changLang (lang) {
  214. this.$store.commit('change_language', lang)
  215. this.active = false
  216. },
  217. linkto (url) {
  218. location.href = url.replace('http://', 'https://')
  219. },
  220. maskTitle (name) {
  221. if (!name) { return '' }
  222. let html = ''
  223. var arr = name.split(this.searchTxt)
  224. html = arr.join('<span style="background:#feced4;">' + this.searchTxt + '</span>')
  225. return html
  226. },
  227. buy () {
  228. let name = this.$route.name
  229. name === 'binocular' || name === 'purchasetwo' ? this.$router.push({name: 'purchasetwo'}) : this.$router.push({name: 'purchase'})
  230. this.active = false
  231. },
  232. goto (to) {
  233. this.$router.push(to)
  234. this.active = false
  235. },
  236. format (time) {
  237. let date = new Date(time)
  238. return date.format('yyyy-MM-dd')
  239. },
  240. async getData () {
  241. document.querySelector('#search-result').scrollTo(0, 0)
  242. let params = {
  243. pageSize: this.pageSize,
  244. pageNum: this.currentPage,
  245. searchKey: this.searchTxt
  246. }
  247. let result = await this.$http({
  248. method: 'post',
  249. data: params,
  250. url: '/scene/search'
  251. })
  252. let data = result.data.data
  253. this.scene = data.list
  254. this.total = data.total
  255. }
  256. },
  257. components: {
  258. vcenter,
  259. Paging
  260. }
  261. }
  262. </script>
  263. <style lang="scss" scoped>
  264. @import './style.scss';
  265. </style>