Header.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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">卖家中心</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.$router.push('/auth/logout')
  81. },
  82. onLoginClick () {
  83. this.$http.get('/login/page', {params: {returnUrl: window.location.href}}).then(response => {
  84. if (response.data) {
  85. this.$router.push('/auth/login')
  86. // window.location.href = response.data.content
  87. }
  88. })
  89. // TODO 待Account Center改版
  90. },
  91. onRegisterClick () {
  92. this.$http.get('/register/page').then(response => {
  93. if (response.data) {
  94. // this.$router.push('/auth/login')
  95. window.location.href = response.data.content
  96. }
  97. })
  98. },
  99. toggleEnterprises () {
  100. this.showEnterprises = !this.showEnterprises
  101. },
  102. // 切换当前企业
  103. switchEnterprise (en) {
  104. this.toggleEnterprises()
  105. this.$http.get(`/user/authentication/${en.uu}`).then(() => {
  106. this.$store.dispatch('loadUserInfo')
  107. // window.location.reload()
  108. })
  109. }
  110. },
  111. beforeMount () {
  112. // this.$store.dispatch('loadUserInfo')
  113. }
  114. }
  115. </script>
  116. <style lang="scss" scoped>
  117. .header .navbar{
  118. min-height: inherit;
  119. border-radius: 0;
  120. }
  121. .header .navbar .navbar-container .navbar-right .dropdown .dropdown-menu li span,.header .navbar .navbar-container .navbar-right .dropdown .dropdown-menu li a{
  122. font-size: 12px;
  123. }
  124. .header .navbar .navbar-container .navbar-right .dropdown .dropdown-menu .menu-item a{
  125. width: 100%;
  126. display: inline-block;
  127. overflow: hidden;
  128. text-overflow: ellipsis;
  129. white-space: nowrap;
  130. height: 30px;
  131. }
  132. .header .navbar .navbar-container .navbar-right .dropdown .dropdown-menu .menu-item{
  133. height: 30px;
  134. }
  135. .dropdown-menu>li>a{
  136. padding: 0;
  137. line-height: 30px;
  138. }
  139. .dropdown-menu>li a:hover{
  140. background: none;
  141. text-decoration: underline !important;
  142. }
  143. .dropdown-menu>li>a.pull-right{
  144. padding: 0;
  145. color: #1162a4 !important;
  146. line-height: inherit;
  147. }
  148. .member-text{
  149. width: 80%;
  150. white-space: nowrap;
  151. overflow: hidden;
  152. text-overflow: ellipsis;
  153. display: inline-block;
  154. }
  155. @import '~assets/scss/mixins';
  156. @import '~assets/scss/variables';
  157. $nav-height: 36px;
  158. .header {
  159. height: $nav-height;
  160. .navbar {
  161. width: 100%;
  162. height: 100%;
  163. font-size: $font-size-small;
  164. background-color: $black-light;
  165. .navbar-container {
  166. .item-wrap {
  167. display: inline-block;
  168. }
  169. .item {
  170. color: $grey;
  171. display: inline-block;
  172. height: $nav-height;
  173. line-height: $nav-height;
  174. }
  175. a {
  176. color: $grey;
  177. }
  178. .navbar-header {
  179. float: left;
  180. .navbar-logo {
  181. margin-bottom: 2px;
  182. }
  183. .navbar-slogan {
  184. margin-left: $sm-pad;
  185. }
  186. }
  187. .navbar-right {
  188. float: right;
  189. .item {
  190. padding: 0 $pad;
  191. }
  192. .dropdown {
  193. .dropdown-toggle {
  194. line-height: $nav-height;
  195. a:hover {
  196. color: $red !important;
  197. }
  198. }
  199. .dropdown-menu {
  200. min-width: 220px;
  201. margin-left: -1px;
  202. border: $border;
  203. border-top: none;
  204. padding: 1em;
  205. margin:0;
  206. border: none;
  207. border-radius: 0;
  208. .menu-item-first {
  209. margin-bottom: 10px;
  210. }
  211. .menu-item {
  212. line-height: 30px;
  213. a {
  214. color: $accent;
  215. }
  216. }
  217. }
  218. &:hover {
  219. background-color: $white;
  220. .dropdown-toggle {
  221. color: $text;
  222. }
  223. a {
  224. color: $text
  225. }
  226. }
  227. }
  228. }
  229. }
  230. }
  231. }
  232. </style>