Header.vue 10 KB

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