Header.vue 7.3 KB

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