Header.vue 8.8 KB

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