userHeader.vue 8.3 KB

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