Header.vue 6.4 KB

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