userHeader.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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 :class="{'long': !isShow}">
  8. <span class="en-name">{{enData.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 != enData.uu"
  18. v-bind:key="en.uu">
  19. <a @click="switchEnterprise(en)">{{ en.enName }}</a>
  20. </li>
  21. <li class="menu-item" v-if="enData.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. return this.$store.state.option.user
  93. },
  94. enData () {
  95. return this.user.data.enterprise
  96. },
  97. sortEnterprises () {
  98. if (this.user.data.enterprises) {
  99. let ens = this.user.data.enterprises.slice()
  100. if (ens && ens.length) {
  101. ens.sort(function (a, b) {
  102. return b.lastLoginTime - a.lastLoginTime
  103. })
  104. }
  105. return ens
  106. } else {
  107. return ''
  108. }
  109. }
  110. }
  111. }
  112. </script>
  113. <style lang="scss">
  114. .user-contentCompontent{
  115. .user-name{
  116. height: 1.8rem;
  117. padding: .28rem 0 .28rem .34rem;
  118. background: #fff;
  119. width: 100%;
  120. position: relative;
  121. img{
  122. display: inline-block;
  123. width: 1.25rem;
  124. height: 1.25rem;
  125. border: 1px solid #c5dbfc;
  126. border-radius: .05rem;
  127. vertical-align: middle;
  128. }
  129. .user-info {
  130. margin-left:.25rem;
  131. display: inline-block;
  132. vertical-align: middle;
  133. /*position: relative;*/
  134. p{
  135. font-size:.3rem;
  136. margin:0;
  137. display: block;
  138. overflow: hidden;
  139. text-overflow: ellipsis;
  140. white-space: nowrap;
  141. max-width: 3.92rem;
  142. &:nth-child(2) {
  143. position: relative;
  144. margin-top: .2rem;
  145. padding-right: .7rem;
  146. overflow: unset;
  147. max-width: unset;
  148. &.long {
  149. padding-right: 0;
  150. span {
  151. max-width: 5rem;
  152. }
  153. }
  154. .en-name {
  155. overflow: hidden;
  156. text-overflow: ellipsis;
  157. white-space: nowrap;
  158. max-width: 3.22rem;
  159. display: inline-block;
  160. }
  161. a {
  162. position: absolute;
  163. right: 0;
  164. }
  165. }
  166. }
  167. .switch {
  168. position: absolute;
  169. right: 1rem;
  170. top: 1.01rem;
  171. .en-list {
  172. position: absolute;
  173. max-width: 3rem;
  174. max-height: 3rem;
  175. overflow-y: auto;
  176. border-radius: .05rem;
  177. background: rgba(0, 0, 0, 0.6);
  178. z-index: 10;
  179. left: -1rem;
  180. .menu-item {
  181. height: .6rem;
  182. line-height: .6rem;
  183. font-size: .3rem;
  184. padding: 0 .2rem;
  185. overflow: hidden;
  186. white-space: nowrap;
  187. text-overflow: ellipsis;
  188. &:active, &:focus, &:hover {
  189. background: #7d7d7d;
  190. }
  191. a {
  192. color: #fff;
  193. }
  194. }
  195. }
  196. .exit {
  197. right: -.8rem;
  198. }
  199. .vir {
  200. margin: 0 .1rem;
  201. }
  202. }
  203. }
  204. > a {
  205. font-size: .24rem;
  206. position: absolute;
  207. top: .45rem;
  208. right: .1rem;
  209. color: #3f84f6;
  210. border: 1px solid #3f84f6;
  211. border-radius: .2rem;
  212. padding: .06rem .12rem;
  213. }
  214. }
  215. ul.switch-list {
  216. li {
  217. display: inline-block;
  218. width: 50%;
  219. height: .63rem;
  220. line-height: .63rem;
  221. text-align: center;
  222. font-size: .28rem;
  223. color: #666;
  224. background: #fff;
  225. border: 1px solid #b4b4b4;
  226. border-right: none;
  227. &.active {
  228. background: #0067e7;
  229. border: 1px solid #0067e7;
  230. color: #fff;
  231. }
  232. &:first-child {
  233. border-left: none;
  234. }
  235. &:last-child {
  236. border-right: none;
  237. }
  238. }
  239. &.vendor-switch {
  240. li {
  241. width: 50%;
  242. }
  243. }
  244. }
  245. .seek {
  246. .seek-type {
  247. margin-top: .15rem;
  248. li {
  249. font-size: .28rem;
  250. color: #666;
  251. display: inline-block;
  252. width: 50%;
  253. text-align: center;
  254. div {
  255. border-bottom: 1px solid #c1c4c9;
  256. margin: 0 auto;
  257. height: .46rem;
  258. line-height: .46rem;
  259. }
  260. &.active {
  261. color: #3f84f6;
  262. div {
  263. border-color: #3f84f6;
  264. }
  265. }
  266. }
  267. }
  268. }
  269. .deleteKuang {
  270. position: fixed;
  271. background: rgba(0,0,0,0.5);
  272. top: 0;
  273. left: 0;
  274. right: 0;
  275. bottom: 0;
  276. z-index: 9999;
  277. .kuangContent {
  278. border-radius: 5px;
  279. background: #fff;
  280. width: 5rem;
  281. position: absolute;
  282. left: 50%;
  283. top: 50%;
  284. transform: translate3d(-50%, -50%, 0);
  285. overflow: hidden;
  286. .titleinfo {
  287. font-size: .3rem;
  288. color: #666;
  289. text-align: center;
  290. margin-top: 0.5rem;
  291. margin-bottom: 0.1rem;
  292. }
  293. .title {
  294. background: #5078cb;
  295. height: .7rem;
  296. line-height: .7rem;
  297. font-size: .3rem;
  298. color: #fff;
  299. text-align: center;
  300. }
  301. .info {
  302. color: #f00;
  303. text-align: center;
  304. }
  305. .K_btn {
  306. margin-top: 0.4rem;
  307. line-height: 0.7rem;
  308. height: 0.7rem;
  309. &::after{
  310. clear: both;
  311. display: block;
  312. content: ' ';
  313. visibility: hidden;
  314. zoom: 1;
  315. }
  316. div {
  317. float: left;
  318. width: 50%;
  319. font-size: 0.3rem;
  320. text-align: center;
  321. &.cancelBtn {
  322. background: #b4b5b9;
  323. color: #333;
  324. }
  325. &.answerBtn {
  326. background: #5078cb;
  327. color: #fff;
  328. }
  329. }
  330. }
  331. }
  332. }
  333. }
  334. </style>