Header.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <template>
  2. <header class="header">
  3. <nav class="navbar">
  4. <div class="navbar-container container">
  5. <div class="navbar-header">
  6. <a href="http://www.ubtob.com" class="item navbar-link">
  7. <img src="/images/logo/uas.png" class="navbar-logo">
  8. <span class="navbar-slogan">进入优软云</span>
  9. </a>
  10. </div>
  11. <div class="navbar-right">
  12. <template v-if="user.logged">
  13. <div class="item-wrap dropdown">
  14. <div class="item dropdown-toggle">
  15. 欢迎您,{{ user.data.userName }}&nbsp;<a @click="logout()">[退出]</a>
  16. </div>
  17. <ul class="dropdown-menu">
  18. <li class="menu-item-first">
  19. <span>{{ enterprise.enName }}</span>
  20. <a class="pull-right" @click="toggleEnterprises()" v-if="user.data.enterprises.length > 1">
  21. {{ showEnterprises ? '取消' : '切换' }}
  22. </a>
  23. </li>
  24. <li class="menu-item"
  25. v-for="en in user.data.enterprises"
  26. v-if="showEnterprises && en.enName!=enterprise.enName">
  27. <a @click="switchEnterprise(en)">{{ en.enName }}</a>
  28. </li>
  29. </ul>
  30. </div>
  31. <nuxt-link class="item" :to="'/'">商城首页</nuxt-link>
  32. <nuxt-link class="item" to="/user">买家中心</nuxt-link>
  33. <nuxt-link class="item" to="/vendor">卖家中心</nuxt-link>
  34. </template>
  35. <template v-else>
  36. <a class="item" @click="onLoginClick()">登录</a>
  37. <a class="item" href="http://account.ubtob.com/sso/register">注册</a>
  38. <nuxt-link class="item" :to="'/'">商城首页</nuxt-link>
  39. </template>
  40. <nuxt-link class="item" to="/help/home">帮助中心</nuxt-link>
  41. </div>
  42. </div>
  43. </nav>
  44. </header>
  45. </template>
  46. <script>
  47. export default {
  48. name: 'header',
  49. data () {
  50. return {
  51. showEnterprises: false
  52. }
  53. },
  54. computed: {
  55. user () {
  56. return this.$store.state.option.user
  57. },
  58. enterprise () {
  59. let ens = this.user.data.enterprises
  60. if (ens && ens.length) {
  61. return ens.find(item => item.current) || ens[0]
  62. }
  63. return {}
  64. }
  65. },
  66. methods: {
  67. logout () {
  68. this.$store.dispatch('logout')
  69. },
  70. onLoginClick () {
  71. this.$http.get('/login/page').then(response => {
  72. // 跳转登录
  73. window.location.href = response.data.content
  74. })
  75. // TODO 待Account Center改版
  76. },
  77. toggleEnterprises () {
  78. this.showEnterprises = !this.showEnterprises
  79. },
  80. // 切换当前企业
  81. switchEnterprise (en) {
  82. this.toggleEnterprises()
  83. this.$http.get(`authentication/${en.enUU}`).then(() => {
  84. this.$store.dispatch('loadUserInfo')
  85. })
  86. }
  87. }
  88. }
  89. </script>
  90. <style lang="scss" scoped>
  91. .header .navbar{
  92. min-height: inherit;
  93. border-radius: 0;
  94. }
  95. @import '~assets/scss/mixins';
  96. @import '~assets/scss/variables';
  97. $nav-height: 36px;
  98. .header {
  99. height: $nav-height;
  100. .navbar {
  101. width: 100%;
  102. height: 100%;
  103. font-size: $font-size-small;
  104. background-color: $black-light;
  105. .navbar-container {
  106. .item-wrap {
  107. display: inline-block;
  108. }
  109. .item {
  110. color: $grey;
  111. display: inline-block;
  112. height: $nav-height;
  113. line-height: $nav-height;
  114. }
  115. a {
  116. color: $grey;
  117. }
  118. .navbar-header {
  119. float: left;
  120. .navbar-logo {
  121. margin-bottom: 2px;
  122. }
  123. .navbar-slogan {
  124. margin-left: $sm-pad;
  125. }
  126. }
  127. .navbar-right {
  128. float: right;
  129. .item {
  130. padding: 0 $pad;
  131. }
  132. .dropdown {
  133. .dropdown-toggle {
  134. line-height: $nav-height;
  135. a:hover {
  136. color: $red !important;
  137. }
  138. }
  139. .dropdown-menu {
  140. width: 220px;
  141. margin-left: -1px;
  142. border: $border;
  143. border-top: none;
  144. padding: 1em;
  145. .menu-item-first {
  146. margin-bottom: 10px;
  147. }
  148. .menu-item {
  149. line-height: 30px;
  150. a {
  151. color: $accent;
  152. }
  153. }
  154. }
  155. &:hover {
  156. background-color: $white;
  157. .dropdown-toggle {
  158. color: $text;
  159. }
  160. a {
  161. color: $text
  162. }
  163. }
  164. }
  165. }
  166. }
  167. }
  168. }
  169. </style>