Header.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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" v-if="user.data.enterprises && user.data.enterprises.length > 0">
  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. // 切换当前企业
  124. switchEnterprise (en) {
  125. this.showEnterpriseToggle = false
  126. this.$http.get(`/user/authentication/${en.uu}`).then(() => {
  127. this.$store.dispatch('loadUserInfo')
  128. // let path = this.$route.path
  129. // if (path === '/register-saler' && en.uu !== 0 && en.isVendor === 313) {
  130. // window.location.href = '/vendor#/index'
  131. // } else {
  132. // window.location.reload()
  133. // }
  134. window.location.href = '/'
  135. })
  136. },
  137. toVendor: function () {
  138. let isSelf = true
  139. let tempEnterprise = {}
  140. let ens = this.user.data.enterprises
  141. if (ens && ens.length) {
  142. ens.forEach(function (item) {
  143. if (item.current) {
  144. isSelf = false
  145. tempEnterprise = item
  146. }
  147. })
  148. } else {
  149. isSelf = true
  150. }
  151. if (isSelf) {
  152. window.location.href = '/personalMaterial'
  153. } else {
  154. if (tempEnterprise.isVendor === 313) {
  155. window.location.href = '/vendor#/index'
  156. } else {
  157. window.location.href = '/register-saler'
  158. }
  159. }
  160. }
  161. // searchEnterprise () {
  162. // let key = this.keyword
  163. // let enterprise = this.user.data.enterprises
  164. // this.isSearching = true
  165. // this.searchEnterpriseArr = []
  166. // if (this.keyword === '') {
  167. // this.isSearching = false
  168. // } else {
  169. // for (let i = 0; i < enterprise.length; i++) {
  170. // if (enterprise[i].enName.indexOf(key) !== -1) {
  171. // this.searchEnterpriseArr.push(enterprise[i])
  172. // }
  173. // }
  174. // }
  175. // }
  176. }
  177. }
  178. </script>
  179. <style lang="scss" scoped>
  180. .header .navbar{
  181. min-height: inherit;
  182. border-radius: 0;
  183. }
  184. .header .navbar .navbar-container .navbar-right .dropdown .dropdown-menu li span,.header .navbar .navbar-container .navbar-right .dropdown .dropdown-menu li a{
  185. font-size: 12px;
  186. }
  187. .header .navbar .navbar-container .navbar-right .dropdown .dropdown-menu .menu-item a{
  188. width: 100%;
  189. display: inline-block;
  190. overflow: hidden;
  191. text-overflow: ellipsis;
  192. white-space: nowrap;
  193. height: 25px;
  194. }
  195. .header .navbar .navbar-container .navbar-right .dropdown .dropdown-menu .menu-item{
  196. height: 30px;
  197. }
  198. .dropdown-menu>li>a{
  199. padding: 0;
  200. line-height: 30px;
  201. }
  202. .dropdown-menu>li a:hover{
  203. background: none;
  204. text-decoration: underline !important;
  205. }
  206. .dropdown-menu>li>a.pull-right{
  207. padding: 0;
  208. color: #1162a4 !important;
  209. line-height: inherit;
  210. }
  211. .member-text{
  212. width: 80%;
  213. white-space: nowrap;
  214. overflow: hidden;
  215. text-overflow: ellipsis;
  216. display: inline-block;
  217. }
  218. @import '~assets/scss/mixins';
  219. @import '~assets/scss/variables';
  220. $nav-height: 36px;
  221. .header {
  222. height: $nav-height;
  223. .navbar {
  224. width: 100%;
  225. height: 100%;
  226. font-size: $font-size-small;
  227. background-color: $black-light;
  228. .navbar-container {
  229. .item-wrap {
  230. display: inline-block;
  231. }
  232. .item {
  233. color: $grey;
  234. display: inline-block;
  235. height: $nav-height;
  236. line-height: $nav-height;
  237. }
  238. a {
  239. color: $grey;
  240. }
  241. .navbar-header {
  242. float: left;
  243. .navbar-logo {
  244. margin-bottom: 2px;
  245. }
  246. .navbar-slogan {
  247. margin-left: $sm-pad;
  248. }
  249. }
  250. .navbar-right {
  251. float: right;
  252. .item {
  253. padding: 0 $pad;
  254. }
  255. .dropdown {
  256. .dropdown-toggle {
  257. line-height: $nav-height;
  258. border-left: 1px solid $black-light;
  259. border-right: 1px solid $black-light;
  260. height: 35px;
  261. a {
  262. margin-left: 15px;
  263. float: right;
  264. &:hover {
  265. color: $red !important;
  266. }
  267. }
  268. &:hover {
  269. border-left: 1px solid #999;
  270. border-right: 1px solid #999;
  271. }
  272. span {
  273. display: inline-block;
  274. max-width: 190px;
  275. overflow: hidden;
  276. text-overflow: ellipsis;
  277. white-space: nowrap;
  278. float: right;
  279. }
  280. }
  281. .menu-item-first {
  282. background: #eee;
  283. padding: 0 12px;
  284. line-height: 30px;
  285. font-size: 12px;
  286. >span:nth-child(1) {
  287. cursor: default;
  288. font-weight: bold;
  289. }
  290. input {
  291. width: 174px;
  292. height: 24px;
  293. margin-left: 35px;
  294. background: #fff;
  295. border: 1px solid #5078cb;
  296. padding-left: 4px;
  297. }
  298. .search-enterprise {
  299. display: inline-block;
  300. width: 36px;
  301. height: 24px;
  302. color: #fff;
  303. background: #5078cb;
  304. text-align: center;
  305. line-height: 24px;
  306. cursor: pointer;
  307. }
  308. }
  309. .dropdown-menu {
  310. padding: 0 6px 13px;
  311. margin:0;
  312. border-radius: 0;
  313. right: unset;
  314. background: #fff;
  315. border: 1px solid #999999;
  316. border-top: none;
  317. -webkit-box-shadow: none;
  318. -moz-box-shadow: none;
  319. box-shadow: none;
  320. ::-webkit-scrollbar {
  321. background: #f6f6f6;
  322. }
  323. ul {
  324. max-height: 300px;
  325. overflow-y: auto;
  326. background: #f6f6f6;
  327. }
  328. .menu-item {
  329. padding: 0 12px;
  330. a {
  331. color: #333;
  332. max-width: 300px;
  333. line-height: 30px;
  334. width: auto;
  335. &:hover {
  336. color: #5078cb;
  337. text-decoration: none!important;
  338. }
  339. }
  340. }
  341. }
  342. &:hover {
  343. background-color: $white;
  344. .dropdown-toggle {
  345. color: $text;
  346. }
  347. a {
  348. color: $text
  349. }
  350. }
  351. }
  352. }
  353. }
  354. }
  355. }
  356. </style>