Header.vue 6.0 KB

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