Header.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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 && 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. window.location.reload()
  104. })
  105. }
  106. },
  107. beforeMount () {
  108. // this.$store.dispatch('loadUserInfo')
  109. }
  110. }
  111. </script>
  112. <style lang="scss" scoped>
  113. .header .navbar{
  114. min-height: inherit;
  115. border-radius: 0;
  116. }
  117. .header .navbar .navbar-container .navbar-right .dropdown .dropdown-menu li span,.header .navbar .navbar-container .navbar-right .dropdown .dropdown-menu li a{
  118. font-size: 12px;
  119. }
  120. .dropdown-menu>li>a{
  121. padding: 0;
  122. line-height: 30px;
  123. }
  124. .dropdown-menu>li a:hover{
  125. background: none;
  126. text-decoration: underline !important;
  127. }
  128. .dropdown-menu>li>a.pull-right{
  129. padding: 0;
  130. color: #1162a4 !important;
  131. line-height: inherit;
  132. }
  133. @import '~assets/scss/mixins';
  134. @import '~assets/scss/variables';
  135. $nav-height: 36px;
  136. .header {
  137. height: $nav-height;
  138. .navbar {
  139. width: 100%;
  140. height: 100%;
  141. font-size: $font-size-small;
  142. background-color: $black-light;
  143. .navbar-container {
  144. .item-wrap {
  145. display: inline-block;
  146. }
  147. .item {
  148. color: $grey;
  149. display: inline-block;
  150. height: $nav-height;
  151. line-height: $nav-height;
  152. }
  153. a {
  154. color: $grey;
  155. }
  156. .navbar-header {
  157. float: left;
  158. .navbar-logo {
  159. margin-bottom: 2px;
  160. }
  161. .navbar-slogan {
  162. margin-left: $sm-pad;
  163. }
  164. }
  165. .navbar-right {
  166. float: right;
  167. .item {
  168. padding: 0 $pad;
  169. }
  170. .dropdown {
  171. .dropdown-toggle {
  172. line-height: $nav-height;
  173. a:hover {
  174. color: $red !important;
  175. }
  176. }
  177. .dropdown-menu {
  178. width: 220px;
  179. margin-left: -1px;
  180. border: $border;
  181. border-top: none;
  182. padding: 1em;
  183. margin:0;
  184. .menu-item-first {
  185. margin-bottom: 10px;
  186. }
  187. .menu-item {
  188. line-height: 30px;
  189. a {
  190. color: $accent;
  191. }
  192. }
  193. }
  194. &:hover {
  195. background-color: $white;
  196. .dropdown-toggle {
  197. color: $text;
  198. }
  199. a {
  200. color: $text
  201. }
  202. }
  203. }
  204. }
  205. }
  206. }
  207. }
  208. </style>