Header.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. <!--<a class="item" :href="url + '/user'">买家中心</a>
  35. <a class="item" :href="url + '/vendor'">卖家中心</a>-->
  36. <a class="item" href="/user#/index">买家中心</a>
  37. <a class="item" href="/vendor#/index">卖家中心</a>
  38. </template>
  39. <template v-else>
  40. <a class="item" @click="onLoginClick()">登录</a>
  41. <a class="item" href="http://account.ubtob.com/sso/register">注册</a>
  42. <nuxt-link class="item" :to="'/'">商城首页</nuxt-link>
  43. </template>
  44. <nuxt-link class="item" to="/help/home">帮助中心</nuxt-link>
  45. </div>
  46. </div>
  47. </nav>
  48. </header>
  49. </template>
  50. <script>
  51. export default {
  52. name: 'header',
  53. data () {
  54. return {
  55. showEnterprises: false
  56. }
  57. },
  58. computed: {
  59. user () {
  60. return this.$store.state.option.user
  61. },
  62. enterprise () {
  63. let ens = this.user.data.enterprises
  64. if (ens && ens.length) {
  65. return ens.find(item => item.current) || ens[0]
  66. }
  67. return {}
  68. },
  69. url () {
  70. return this.$store.state.option.url
  71. }
  72. },
  73. methods: {
  74. logout () {
  75. this.$router.push('/auth/logout')
  76. },
  77. onLoginClick () {
  78. this.$http.get('/login/page').then(response => {
  79. if (response.data) {
  80. this.$router.push('/auth/login')
  81. }
  82. })
  83. // TODO 待Account Center改版
  84. },
  85. toggleEnterprises () {
  86. this.showEnterprises = !this.showEnterprises
  87. },
  88. // 切换当前企业
  89. switchEnterprise (en) {
  90. this.toggleEnterprises()
  91. this.$http.get(`/user/authentication/${en.uu}`).then(() => {
  92. this.$store.dispatch('loadUserInfo')
  93. })
  94. }
  95. },
  96. beforeMount () {
  97. // this.$store.dispatch('loadUserInfo')
  98. }
  99. }
  100. </script>
  101. <style lang="scss" scoped>
  102. .header .navbar{
  103. min-height: inherit;
  104. border-radius: 0;
  105. }
  106. @import '~assets/scss/mixins';
  107. @import '~assets/scss/variables';
  108. $nav-height: 36px;
  109. .header {
  110. height: $nav-height;
  111. .navbar {
  112. width: 100%;
  113. height: 100%;
  114. font-size: $font-size-small;
  115. background-color: $black-light;
  116. .navbar-container {
  117. .item-wrap {
  118. display: inline-block;
  119. }
  120. .item {
  121. color: $grey;
  122. display: inline-block;
  123. height: $nav-height;
  124. line-height: $nav-height;
  125. }
  126. a {
  127. color: $grey;
  128. }
  129. .navbar-header {
  130. float: left;
  131. .navbar-logo {
  132. margin-bottom: 2px;
  133. }
  134. .navbar-slogan {
  135. margin-left: $sm-pad;
  136. }
  137. }
  138. .navbar-right {
  139. float: right;
  140. .item {
  141. padding: 0 $pad;
  142. }
  143. .dropdown {
  144. .dropdown-toggle {
  145. line-height: $nav-height;
  146. a:hover {
  147. color: $red !important;
  148. }
  149. }
  150. .dropdown-menu {
  151. width: 220px;
  152. margin-left: -1px;
  153. border: $border;
  154. border-top: none;
  155. padding: 1em;
  156. margin:0;
  157. .menu-item-first {
  158. margin-bottom: 10px;
  159. }
  160. .menu-item {
  161. line-height: 30px;
  162. a {
  163. color: $accent;
  164. }
  165. }
  166. }
  167. &:hover {
  168. background-color: $white;
  169. .dropdown-toggle {
  170. color: $text;
  171. }
  172. a {
  173. color: $text
  174. }
  175. }
  176. }
  177. }
  178. }
  179. }
  180. }
  181. </style>