userHeader.vue 8.9 KB

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