Header.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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" @mouseenter="showEnterpriseToggle = true" @mouseleave="showEnterpriseToggle = 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" v-if="showEnterpriseToggle">
  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. <span>您可切换至以下账户:</span>
  26. <!--<input type="text" placeholder="请输入公司名称" v-model="keyword"><span class="search-enterprise" @click="searchEnterprise()">搜索</span>-->
  27. </li>
  28. <li class="menu-item"
  29. v-for="en in user.data.enterprises"
  30. v-if="en.uu!=enterprise.uu">
  31. <a @click="switchEnterprise(en)" :title="en.enName">{{ en.enName }}</a>
  32. </li>
  33. <li class="menu-item" v-if="enterprise.uu">
  34. <a @click="switchEnterprise({uu: 0})"><span v-text="user.data.userName"></span>(个人账户)</a>
  35. </li>
  36. </ul>
  37. </div>
  38. <nuxt-link class="item" :to="'/'">商城首页</nuxt-link>
  39. <!--<nuxt-link class="item" to="/user">买家中心</nuxt-link>
  40. <nuxt-link class="item" to="/vendor">卖家中心</nuxt-link>-->
  41. <!--<a class="item" :href="url + '/user'">买家中心</a>
  42. <a class="item" :href="url + '/vendor'">卖家中心</a>-->
  43. <a class="item" href="/user#/index">买家中心</a>
  44. <a class="item" @click="toVendor">卖家中心</a>
  45. </template>
  46. <template v-else>
  47. <a class="item" @click="onLoginClick()">登录</a>
  48. <a class="item" @click="onRegisterClick">注册</a>
  49. <nuxt-link class="item" :to="'/'">商城首页</nuxt-link>
  50. </template>
  51. <nuxt-link class="item" to="/help/home">帮助中心</nuxt-link>
  52. <!--<a class="item" href="/help#/home">帮助中心</a>-->
  53. </div>
  54. </div>
  55. </nav>
  56. </header>
  57. </template>
  58. <script>
  59. export default {
  60. name: 'header',
  61. data () {
  62. return {
  63. // showEnterprises: false
  64. // searchEnterpriseArr: [],
  65. // keyword: '',
  66. // isSearching: false
  67. showEnterpriseToggle: false
  68. }
  69. },
  70. computed: {
  71. user () {
  72. return this.$store.state.option.user
  73. },
  74. enterprise () {
  75. let ens = this.user.data.enterprises
  76. if (ens && ens.length) {
  77. return ens.find(item => item.current) || {enName: '个人账户'}
  78. } else {
  79. return {enName: '个人账户'}
  80. }
  81. },
  82. url () {
  83. return this.$store.state.option.url
  84. }
  85. },
  86. methods: {
  87. logout () {
  88. this.$http.get('/logout/crossBefore').then(response => {
  89. if (response.data) {
  90. window.location.href = response.data.logoutUrl + '&baseUrl=' + encodeURIComponent(window.location.protocol + '//' + window.location.host + response.data.baseUrl)
  91. }
  92. })
  93. },
  94. onLoginClick () {
  95. this.$http.get('/login/page', {params: {returnUrl: window.location.href}}).then(response => {
  96. if (response.data) {
  97. window.location.href = response.data.content + '&baseUrl=' + encodeURIComponent(window.location.protocol + '//' + window.location.host + response.data.baseUrl)
  98. }
  99. })
  100. // TODO 待Account Center改版
  101. },
  102. onRegisterClick () {
  103. this.$http.get('/register/page').then(response => {
  104. if (response.data) {
  105. window.location.href = response.data.content
  106. }
  107. })
  108. },
  109. // toggleEnterprises () {
  110. // this.showEnterprises = !this.showEnterprises
  111. // },
  112. // 切换当前企业
  113. switchEnterprise (en) {
  114. // this.toggleEnterprises()
  115. this.showEnterpriseToggle = false
  116. this.$http.get(`/user/authentication/${en.uu}`).then(() => {
  117. this.$store.dispatch('loadUserInfo')
  118. // let href = window.location.href
  119. // let hrefPath = href.slice(href.length - 14, href.length)
  120. // if (hrefPath === 'register-saler' && en.uu !== 0 && en.isVendor === 313) {
  121. // window.location.href = '/vendor#/index'
  122. // } else {
  123. // window.location.reload()
  124. // }
  125. window.location.href = '/'
  126. })
  127. },
  128. toVendor: function () {
  129. let isSelf = true
  130. let tempEnterprise = {}
  131. let ens = this.user.data.enterprises
  132. if (ens && ens.length) {
  133. ens.forEach(function (item) {
  134. if (item.current) {
  135. isSelf = false
  136. tempEnterprise = item
  137. }
  138. })
  139. } else {
  140. isSelf = true
  141. }
  142. if (isSelf) {
  143. window.location.href = '/register-saler'
  144. } else {
  145. if (tempEnterprise.isVendor === 313) {
  146. window.location.href = '/vendor#/index'
  147. } else {
  148. window.location.href = '/register-saler'
  149. }
  150. }
  151. }
  152. // searchEnterprise () {
  153. // let key = this.keyword
  154. // let enterprise = this.user.data.enterprises
  155. // this.isSearching = true
  156. // this.searchEnterpriseArr = []
  157. // if (this.keyword === '') {
  158. // this.isSearching = false
  159. // } else {
  160. // for (let i = 0; i < enterprise.length; i++) {
  161. // if (enterprise[i].enName.indexOf(key) !== -1) {
  162. // this.searchEnterpriseArr.push(enterprise[i])
  163. // }
  164. // }
  165. // }
  166. // }
  167. }
  168. }
  169. </script>
  170. <style lang="scss" scoped>
  171. .header .navbar{
  172. min-height: inherit;
  173. border-radius: 0;
  174. }
  175. .header .navbar .navbar-container .navbar-right .dropdown .dropdown-menu li span,.header .navbar .navbar-container .navbar-right .dropdown .dropdown-menu li a{
  176. font-size: 12px;
  177. }
  178. .header .navbar .navbar-container .navbar-right .dropdown .dropdown-menu .menu-item a{
  179. width: 100%;
  180. display: inline-block;
  181. overflow: hidden;
  182. text-overflow: ellipsis;
  183. white-space: nowrap;
  184. height: 30px;
  185. }
  186. .header .navbar .navbar-container .navbar-right .dropdown .dropdown-menu .menu-item{
  187. height: 30px;
  188. }
  189. .dropdown-menu>li>a{
  190. padding: 0;
  191. line-height: 30px;
  192. }
  193. .dropdown-menu>li a:hover{
  194. background: none;
  195. text-decoration: underline !important;
  196. }
  197. .dropdown-menu>li>a.pull-right{
  198. padding: 0;
  199. color: #1162a4 !important;
  200. line-height: inherit;
  201. }
  202. .member-text{
  203. width: 80%;
  204. white-space: nowrap;
  205. overflow: hidden;
  206. text-overflow: ellipsis;
  207. display: inline-block;
  208. }
  209. @import '~assets/scss/mixins';
  210. @import '~assets/scss/variables';
  211. $nav-height: 36px;
  212. .header {
  213. height: $nav-height;
  214. .navbar {
  215. width: 100%;
  216. height: 100%;
  217. font-size: $font-size-small;
  218. background-color: $black-light;
  219. .navbar-container {
  220. .item-wrap {
  221. display: inline-block;
  222. }
  223. .item {
  224. color: $grey;
  225. display: inline-block;
  226. height: $nav-height;
  227. line-height: $nav-height;
  228. }
  229. a {
  230. color: $grey;
  231. }
  232. .navbar-header {
  233. float: left;
  234. .navbar-logo {
  235. margin-bottom: 2px;
  236. }
  237. .navbar-slogan {
  238. margin-left: $sm-pad;
  239. }
  240. }
  241. .navbar-right {
  242. float: right;
  243. .item {
  244. padding: 0 $pad;
  245. }
  246. .dropdown {
  247. .dropdown-toggle {
  248. line-height: $nav-height;
  249. border-left: 1px solid $black-light;
  250. border-right: 1px solid $black-light;
  251. height: 35px;
  252. a {
  253. margin-left: 15px;
  254. float: right;
  255. &:hover {
  256. color: $red !important;
  257. }
  258. }
  259. &:hover {
  260. border-left: 1px solid #999;
  261. border-right: 1px solid #999;
  262. }
  263. span {
  264. display: inline-block;
  265. max-width: 190px;
  266. overflow: hidden;
  267. text-overflow: ellipsis;
  268. white-space: nowrap;
  269. float: right;
  270. }
  271. }
  272. .dropdown-menu {
  273. padding: 0 6px 13px;
  274. margin:0;
  275. border-radius: 0;
  276. max-height: 330px;
  277. overflow-y: auto;
  278. right: unset;
  279. background: #fff;
  280. border: 1px solid #999999;
  281. border-top: none;
  282. -webkit-box-shadow: none;
  283. -moz-box-shadow: none;
  284. box-shadow: none;
  285. .menu-item-first {
  286. background: #eee;
  287. padding: 0 12px;
  288. line-height: 30px;
  289. max-width: 300px;
  290. >span:nth-child(1) {
  291. cursor: default;
  292. }
  293. input {
  294. width: 174px;
  295. height: 24px;
  296. margin-left: 35px;
  297. background: #fff;
  298. border: 1px solid #5078cb;
  299. padding-left: 4px;
  300. }
  301. .search-enterprise {
  302. display: inline-block;
  303. width: 36px;
  304. height: 24px;
  305. color: #fff;
  306. background: #5078cb;
  307. text-align: center;
  308. line-height: 24px;
  309. cursor: pointer;
  310. }
  311. }
  312. .menu-item {
  313. padding: 0 12px;
  314. max-width: 300px;
  315. background: #f6f6f6;
  316. a {
  317. color: #333;
  318. line-height: 30px;
  319. &:hover {
  320. color: #5078cb;
  321. text-decoration: none!important;
  322. }
  323. }
  324. }
  325. }
  326. &:hover {
  327. background-color: $white;
  328. .dropdown-toggle {
  329. color: $text;
  330. }
  331. a {
  332. color: $text
  333. }
  334. }
  335. }
  336. }
  337. }
  338. }
  339. }
  340. </style>