Header.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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;|&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">帮助中心</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. })
  119. },
  120. toVendor: function () {
  121. let isSelf = true
  122. let tempEnterprise = {}
  123. let ens = this.user.data.enterprises
  124. if (ens && ens.length) {
  125. ens.forEach(function (item) {
  126. if (item.current) {
  127. isSelf = false
  128. tempEnterprise = item
  129. }
  130. })
  131. } else {
  132. isSelf = true
  133. }
  134. if (isSelf) {
  135. window.location.href = '/register-saler'
  136. } else {
  137. if (tempEnterprise.isVendor === 313) {
  138. window.location.href = '/vendor#/index'
  139. } else {
  140. window.location.href = '/register-saler'
  141. }
  142. }
  143. }
  144. },
  145. beforeMount () {
  146. // this.$store.dispatch('loadUserInfo')
  147. }
  148. }
  149. </script>
  150. <style lang="scss" scoped>
  151. .header .navbar{
  152. min-height: inherit;
  153. border-radius: 0;
  154. }
  155. .header .navbar .navbar-container .navbar-right .dropdown .dropdown-menu li span,.header .navbar .navbar-container .navbar-right .dropdown .dropdown-menu li a{
  156. font-size: 12px;
  157. }
  158. .header .navbar .navbar-container .navbar-right .dropdown .dropdown-menu .menu-item a{
  159. width: 100%;
  160. display: inline-block;
  161. overflow: hidden;
  162. text-overflow: ellipsis;
  163. white-space: nowrap;
  164. height: 30px;
  165. }
  166. .header .navbar .navbar-container .navbar-right .dropdown .dropdown-menu .menu-item{
  167. height: 30px;
  168. }
  169. .dropdown-menu>li>a{
  170. padding: 0;
  171. line-height: 30px;
  172. }
  173. .dropdown-menu>li a:hover{
  174. background: none;
  175. text-decoration: underline !important;
  176. }
  177. .dropdown-menu>li>a.pull-right{
  178. padding: 0;
  179. color: #1162a4 !important;
  180. line-height: inherit;
  181. }
  182. .member-text{
  183. width: 80%;
  184. white-space: nowrap;
  185. overflow: hidden;
  186. text-overflow: ellipsis;
  187. display: inline-block;
  188. }
  189. @import '~assets/scss/mixins';
  190. @import '~assets/scss/variables';
  191. $nav-height: 36px;
  192. .header {
  193. height: $nav-height;
  194. .navbar {
  195. width: 100%;
  196. height: 100%;
  197. font-size: $font-size-small;
  198. background-color: $black-light;
  199. .navbar-container {
  200. .item-wrap {
  201. display: inline-block;
  202. }
  203. .item {
  204. color: $grey;
  205. display: inline-block;
  206. height: $nav-height;
  207. line-height: $nav-height;
  208. }
  209. a {
  210. color: $grey;
  211. }
  212. .navbar-header {
  213. float: left;
  214. .navbar-logo {
  215. margin-bottom: 2px;
  216. }
  217. .navbar-slogan {
  218. margin-left: $sm-pad;
  219. }
  220. }
  221. .navbar-right {
  222. float: right;
  223. .item {
  224. padding: 0 $pad;
  225. }
  226. .dropdown {
  227. .dropdown-toggle {
  228. line-height: $nav-height;
  229. a {
  230. margin-left: 15px;
  231. float: right;
  232. &:hover {
  233. color: $red !important;
  234. }
  235. }
  236. span {
  237. display: inline-block;
  238. max-width: 190px;
  239. overflow: hidden;
  240. text-overflow: ellipsis;
  241. white-space: nowrap;
  242. float: right;
  243. }
  244. }
  245. .dropdown-menu {
  246. min-width: 220px;
  247. margin-left: -1px;
  248. border: $border;
  249. border-top: none;
  250. padding: 1em;
  251. margin:0;
  252. border: none;
  253. border-radius: 0;
  254. .menu-item-first {
  255. margin-bottom: 10px;
  256. }
  257. .menu-item {
  258. line-height: 30px;
  259. a {
  260. color: $accent;
  261. }
  262. }
  263. }
  264. &:hover {
  265. background-color: $white;
  266. .dropdown-toggle {
  267. color: $text;
  268. }
  269. a {
  270. color: $text
  271. }
  272. }
  273. }
  274. }
  275. }
  276. }
  277. }
  278. </style>