Header.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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><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 > 1">
  21. {{ showEnterprises ? '取消' : '切换' }}
  22. </a>
  23. </li>
  24. <li class="menu-item"
  25. v-for="en in user.data.enterprises"
  26. v-if="showEnterprises && en.enName!=enterprise.enName">
  27. <a @click="switchEnterprise(en)">{{ 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" @click="toVendor">卖家中心</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').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. let href = window.location.href
  108. let hrefPath = href.slice(href.length - 14, href.length)
  109. if (hrefPath === 'register-saler' && en.uu !== 0 && en.isVendor === 313) {
  110. window.location.href = '/vendor#/index'
  111. } else {
  112. window.location.reload()
  113. }
  114. })
  115. },
  116. toVendor: function () {
  117. let isSelf = true
  118. let tempEnterprise = {}
  119. let ens = this.user.data.enterprises
  120. if (ens && ens.length) {
  121. ens.forEach(function (item) {
  122. if (item.current) {
  123. isSelf = false
  124. tempEnterprise = item
  125. }
  126. })
  127. } else {
  128. isSelf = true
  129. }
  130. if (isSelf) {
  131. window.location.href = '/register-saler'
  132. } else {
  133. if (tempEnterprise.isVendor === 313) {
  134. window.location.href = '/vendor#/index'
  135. } else {
  136. window.location.href = '/register-saler'
  137. }
  138. }
  139. }
  140. },
  141. beforeMount () {
  142. // this.$store.dispatch('loadUserInfo')
  143. }
  144. }
  145. </script>
  146. <style lang="scss" scoped>
  147. .header .navbar{
  148. min-height: inherit;
  149. border-radius: 0;
  150. }
  151. .header .navbar .navbar-container .navbar-right .dropdown .dropdown-menu li span,.header .navbar .navbar-container .navbar-right .dropdown .dropdown-menu li a{
  152. font-size: 12px;
  153. }
  154. .dropdown-menu>li>a{
  155. padding: 0;
  156. line-height: 30px;
  157. }
  158. .dropdown-menu>li a:hover{
  159. background: none;
  160. text-decoration: underline !important;
  161. }
  162. .dropdown-menu>li>a.pull-right{
  163. padding: 0;
  164. color: #1162a4 !important;
  165. line-height: inherit;
  166. }
  167. @import '~assets/scss/mixins';
  168. @import '~assets/scss/variables';
  169. $nav-height: 36px;
  170. .header {
  171. height: $nav-height;
  172. .navbar {
  173. width: 100%;
  174. height: 100%;
  175. font-size: $font-size-small;
  176. background-color: $black-light;
  177. .navbar-container {
  178. .item-wrap {
  179. display: inline-block;
  180. }
  181. .item {
  182. color: $grey;
  183. display: inline-block;
  184. height: $nav-height;
  185. line-height: $nav-height;
  186. }
  187. a {
  188. color: $grey;
  189. }
  190. .navbar-header {
  191. float: left;
  192. .navbar-logo {
  193. margin-bottom: 2px;
  194. }
  195. .navbar-slogan {
  196. margin-left: $sm-pad;
  197. }
  198. }
  199. .navbar-right {
  200. float: right;
  201. .item {
  202. padding: 0 $pad;
  203. }
  204. .dropdown {
  205. .dropdown-toggle {
  206. line-height: $nav-height;
  207. a:hover {
  208. color: $red !important;
  209. }
  210. }
  211. .dropdown-menu {
  212. width: 220px;
  213. margin-left: -1px;
  214. border: $border;
  215. border-top: none;
  216. padding: 1em;
  217. margin:0;
  218. .menu-item-first {
  219. margin-bottom: 10px;
  220. }
  221. .menu-item {
  222. line-height: 30px;
  223. a {
  224. color: $accent;
  225. }
  226. }
  227. }
  228. &:hover {
  229. background-color: $white;
  230. .dropdown-toggle {
  231. color: $text;
  232. }
  233. a {
  234. color: $text
  235. }
  236. }
  237. }
  238. }
  239. }
  240. }
  241. }
  242. </style>