userHeader.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. <template>
  2. <div class="user-contentCompontent">
  3. <div class="user-name">
  4. <img src="/images/component/default.png"/>
  5. <div class="user-info">
  6. <p v-text="userInfo.data.userName"></p>
  7. <p>
  8. <span class="en-name">{{enterpriseInfo2.enName}}</span>
  9. </p>
  10. <div class="switch" v-if="isShow">
  11. <a @click="setShowEnterpriseToggle(!showEnterpriseToggle, $event)">切换</a>
  12. <span class="vir">|</span>
  13. <a class="exit" @click="showLogout = true">退出</a>
  14. <ul class="en-list" v-show="showEnterpriseToggle">
  15. <li class="menu-item"
  16. v-for="en in sortEnterprises"
  17. v-if="en.uu != enterpriseInfo2.uu"
  18. v-bind:key="en.uu">
  19. <a @click="switchEnterprise(en)">{{ en.enName }}</a>
  20. </li>
  21. <li class="menu-item" v-if="enterpriseInfo2.uu">
  22. <a @click="switchEnterprise({uu: 0})"><span v-text="userInfo.data.userName"></span>(个人账户)</a>
  23. </li>
  24. </ul>
  25. </div>
  26. </div>
  27. </div>
  28. <div class="deleteKuang" v-if="showLogout">
  29. <div class="kuangContent">
  30. <div class="title">系统提示</div>
  31. <div class="titleinfo">是否退出登录</div>
  32. <!--<div class="info" v-show="isUploadpro">*存在已上架信息</div>-->
  33. <div class="K_btn">
  34. <div class="cancelBtn" @click="showLogout = false">取消</div>
  35. <div class="answerBtn" @click="logout()">确定</div>
  36. </div>
  37. </div>
  38. </div>
  39. </div>
  40. </template>
  41. <script>
  42. export default {
  43. data () {
  44. return {
  45. showEnterpriseToggle: false,
  46. showLogout: false // 退出登录提示框
  47. }
  48. },
  49. props: {
  50. isShow: {
  51. default: true,
  52. type: Boolean
  53. }
  54. },
  55. mounted () {
  56. this.$nextTick(() => {
  57. document.body.addEventListener('click', () => {
  58. this.setShowEnterpriseToggle(false)
  59. }, false)
  60. })
  61. },
  62. methods: {
  63. // 切换当前企业
  64. switchEnterprise(en) {
  65. this.showEnterpriseToggle = false
  66. this.$http.get(`/user/authentication/${en.uu}`).then(() => {
  67. // this.$store.dispatch('loadUserInfo')
  68. this.$store.dispatch('loadUserInfo').then(() => {
  69. this.$emit('switchEnAction')
  70. })
  71. this.$store.dispatch('loadStoreStatus', { op: 'check' }).then(() => {
  72. this.$emit('updateLoad')
  73. })
  74. })
  75. },
  76. setShowEnterpriseToggle(flag, e) {
  77. if (e) {
  78. e.stopPropagation()
  79. }
  80. this.showEnterpriseToggle = flag
  81. },
  82. logout () {
  83. this.$http.get('/logout/crossBefore', {params: {returnUrl: window.location.protocol + '//' + window.location.host}}).then(response => {
  84. if (response.data) {
  85. window.location.href = response.data.logoutUrl + '&baseUrl=' + encodeURIComponent(window.location.protocol + '//' + window.location.host + response.data.baseUrl)
  86. }
  87. })
  88. }
  89. },
  90. computed: {
  91. userInfo () {
  92. // console.log(this.$store.state.option.user)
  93. return this.$store.state.option.user
  94. },
  95. enterpriseInfo2 () {
  96. if (this.userInfo.data.enterprises) {
  97. console.log(1)
  98. let ens = this.userInfo.data.enterprises.slice()
  99. if (ens && ens.length) {
  100. for (let i = 0; i < ens.length; i++) {
  101. if (ens[i].current) {
  102. return ens[i]
  103. }
  104. }
  105. }
  106. return {enName: this.userInfo.data.userName + '(个人账户)'}
  107. } else {
  108. return ''
  109. }
  110. },
  111. sortEnterprises () {
  112. if (this.user.data.enterprises) {
  113. let ens = this.user.data.enterprises.slice()
  114. if (ens && ens.length) {
  115. ens.sort(function (a, b) {
  116. return b.lastLoginTime - a.lastLoginTime
  117. })
  118. }
  119. return ens
  120. } else {
  121. return ''
  122. }
  123. }
  124. }
  125. }
  126. </script>
  127. <style lang="scss">
  128. .user-contentCompontent{
  129. .user-name{
  130. height: 1.8rem;
  131. padding: .28rem 0 .28rem .34rem;
  132. background: #fff;
  133. width: 100%;
  134. position: relative;
  135. img{
  136. display: inline-block;
  137. width: 1.25rem;
  138. height: 1.25rem;
  139. border: 1px solid #c5dbfc;
  140. border-radius: .05rem;
  141. vertical-align: middle;
  142. }
  143. .user-info {
  144. margin-left:.25rem;
  145. display: inline-block;
  146. vertical-align: middle;
  147. /*position: relative;*/
  148. p{
  149. font-size:.3rem;
  150. margin:0;
  151. display: block;
  152. overflow: hidden;
  153. text-overflow: ellipsis;
  154. white-space: nowrap;
  155. max-width: 3.92rem;
  156. &:nth-child(2) {
  157. position: relative;
  158. margin-top: .2rem;
  159. padding-right: .7rem;
  160. overflow: unset;
  161. max-width: unset;
  162. .en-name {
  163. overflow: hidden;
  164. text-overflow: ellipsis;
  165. white-space: nowrap;
  166. max-width: 3.22rem;
  167. display: inline-block;
  168. }
  169. a {
  170. position: absolute;
  171. right: 0;
  172. }
  173. .exit {
  174. right: -.8rem;
  175. }
  176. .vir {
  177. position: absolute;
  178. right: -.14rem;
  179. }
  180. }
  181. }
  182. .switch {
  183. position: absolute;
  184. right: 1rem;
  185. top: 1.01rem;
  186. .en-list {
  187. position: absolute;
  188. max-width: 3rem;
  189. max-height: 3rem;
  190. overflow-y: auto;
  191. border-radius: .05rem;
  192. background: rgba(0, 0, 0, 0.6);
  193. z-index: 10;
  194. left: -1rem;
  195. .menu-item {
  196. height: .6rem;
  197. line-height: .6rem;
  198. font-size: .3rem;
  199. padding: 0 .2rem;
  200. overflow: hidden;
  201. white-space: nowrap;
  202. text-overflow: ellipsis;
  203. &:active, &:focus, &:hover {
  204. background: #7d7d7d;
  205. }
  206. a {
  207. color: #fff;
  208. }
  209. }
  210. }
  211. }
  212. }
  213. > a {
  214. font-size: .24rem;
  215. position: absolute;
  216. top: .45rem;
  217. right: .1rem;
  218. color: #3f84f6;
  219. border: 1px solid #3f84f6;
  220. border-radius: .2rem;
  221. padding: .06rem .12rem;
  222. }
  223. }
  224. ul.switch-list {
  225. li {
  226. display: inline-block;
  227. width: 50%;
  228. height: .63rem;
  229. line-height: .63rem;
  230. text-align: center;
  231. font-size: .28rem;
  232. color: #666;
  233. background: #fff;
  234. border: 1px solid #b4b4b4;
  235. border-right: none;
  236. &.active {
  237. background: #0067e7;
  238. border: 1px solid #0067e7;
  239. color: #fff;
  240. }
  241. &:first-child {
  242. border-left: none;
  243. }
  244. &:last-child {
  245. border-right: none;
  246. }
  247. }
  248. &.vendor-switch {
  249. li {
  250. width: 50%;
  251. }
  252. }
  253. }
  254. .seek {
  255. .seek-type {
  256. margin-top: .15rem;
  257. li {
  258. font-size: .28rem;
  259. color: #666;
  260. display: inline-block;
  261. width: 50%;
  262. text-align: center;
  263. div {
  264. border-bottom: 1px solid #c1c4c9;
  265. margin: 0 auto;
  266. height: .46rem;
  267. line-height: .46rem;
  268. }
  269. &.active {
  270. color: #3f84f6;
  271. div {
  272. border-color: #3f84f6;
  273. }
  274. }
  275. }
  276. }
  277. }
  278. .deleteKuang {
  279. position: fixed;
  280. background: rgba(0,0,0,0.5);
  281. top: 0;
  282. left: 0;
  283. right: 0;
  284. bottom: 0;
  285. z-index: 9999;
  286. .kuangContent {
  287. border-radius: 5px;
  288. background: #fff;
  289. width: 5rem;
  290. position: absolute;
  291. left: 50%;
  292. top: 50%;
  293. transform: translate3d(-50%, -50%, 0);
  294. overflow: hidden;
  295. .titleinfo {
  296. font-size: .3rem;
  297. color: #666;
  298. text-align: center;
  299. margin-top: 0.5rem;
  300. margin-bottom: 0.1rem;
  301. }
  302. .title {
  303. background: #5078cb;
  304. height: .7rem;
  305. line-height: .7rem;
  306. font-size: .3rem;
  307. color: #fff;
  308. text-align: center;
  309. }
  310. .info {
  311. color: #f00;
  312. text-align: center;
  313. }
  314. .K_btn {
  315. margin-top: 0.4rem;
  316. line-height: 0.7rem;
  317. height: 0.7rem;
  318. &::after{
  319. clear: both;
  320. display: block;
  321. content: ' ';
  322. visibility: hidden;
  323. zoom: 1;
  324. }
  325. div {
  326. float: left;
  327. width: 50%;
  328. font-size: 0.3rem;
  329. text-align: center;
  330. &.cancelBtn {
  331. background: #b4b5b9;
  332. color: #333;
  333. }
  334. &.answerBtn {
  335. background: #5078cb;
  336. color: #fff;
  337. }
  338. }
  339. }
  340. }
  341. }
  342. }
  343. </style>