Header.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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.$router.push('/auth/logout')
  69. },
  70. onLoginClick () {
  71. this.$http.get('/login/page').then(response => {
  72. if (response.data) {
  73. this.$router.push('/auth/login')
  74. }
  75. })
  76. // TODO 待Account Center改版
  77. },
  78. toggleEnterprises () {
  79. this.showEnterprises = !this.showEnterprises
  80. },
  81. // 切换当前企业
  82. switchEnterprise (en) {
  83. this.toggleEnterprises()
  84. this.$http.get(`/user/authentication/${en.uu}`).then(() => {
  85. this.$store.dispatch('loadUserInfo')
  86. })
  87. }
  88. },
  89. beforeMount () {
  90. // this.$store.dispatch('loadUserInfo')
  91. }
  92. }
  93. </script>
  94. <style lang="scss" scoped>
  95. .header .navbar{
  96. min-height: inherit;
  97. border-radius: 0;
  98. }
  99. @import '~assets/scss/mixins';
  100. @import '~assets/scss/variables';
  101. $nav-height: 36px;
  102. .header {
  103. height: $nav-height;
  104. .navbar {
  105. width: 100%;
  106. height: 100%;
  107. font-size: $font-size-small;
  108. background-color: $black-light;
  109. .navbar-container {
  110. .item-wrap {
  111. display: inline-block;
  112. }
  113. .item {
  114. color: $grey;
  115. display: inline-block;
  116. height: $nav-height;
  117. line-height: $nav-height;
  118. }
  119. a {
  120. color: $grey;
  121. }
  122. .navbar-header {
  123. float: left;
  124. .navbar-logo {
  125. margin-bottom: 2px;
  126. }
  127. .navbar-slogan {
  128. margin-left: $sm-pad;
  129. }
  130. }
  131. .navbar-right {
  132. float: right;
  133. .item {
  134. padding: 0 $pad;
  135. }
  136. .dropdown {
  137. .dropdown-toggle {
  138. line-height: $nav-height;
  139. a:hover {
  140. color: $red !important;
  141. }
  142. }
  143. .dropdown-menu {
  144. width: 220px;
  145. margin-left: -1px;
  146. border: $border;
  147. border-top: none;
  148. padding: 1em;
  149. .menu-item-first {
  150. margin-bottom: 10px;
  151. }
  152. .menu-item {
  153. line-height: 30px;
  154. a {
  155. color: $accent;
  156. }
  157. }
  158. }
  159. &:hover {
  160. background-color: $white;
  161. .dropdown-toggle {
  162. color: $text;
  163. }
  164. a {
  165. color: $text
  166. }
  167. }
  168. }
  169. }
  170. }
  171. }
  172. }
  173. </style>