userHeader.vue 8.5 KB

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