Header.vue 11 KB

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