top-nav-user-info.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <template>
  2. <ul class="nav navbar-nav navbar-right">
  3. <li>
  4. <img :src="userImageSrc" class="user-profile-img" />
  5. </li>
  6. <li class="dropdown">
  7. <a
  8. href="#"
  9. class="dropdown-toggle"
  10. data-toggle="dropdown"
  11. role="button"
  12. aria-haspopup="true"
  13. aria-expanded="false"
  14. >
  15. {{ loginInfo != undefined ? loginInfo.userName : "" }}
  16. <span class="caret" />
  17. </a>
  18. <ul class="dropdown-menu">
  19. <li>
  20. <a @click="setUserParameters">{{ $t("lang.top-nav-user-info.personalSettings") }}</a>
  21. </li>
  22. <li>
  23. <a @click="logout"><i class="fa fa-sign-out pull-right" />{{ $t("lang.top-nav-user-info.cancellation") }}</a>
  24. </li>
  25. </ul>
  26. </li>
  27. </ul>
  28. </template>
  29. <script>
  30. import Common from '../common/Common.js';
  31. import AuthSettingResource from '../api/commom/AuthSettingResource.js';
  32. export default {
  33. props: {
  34. loginInfo: {
  35. type: Object,
  36. default: function(){
  37. return null;
  38. },
  39. },
  40. },
  41. data: function () {
  42. this.Common = Common;
  43. return {
  44. };
  45. },
  46. computed: {
  47. userImageSrc: function () {
  48. if (this.loginInfo == null || this.loginInfo.imageName == null) {
  49. return null;
  50. }
  51. return Common.getThumbnailImageSrc('com.leanwo.prodog.base.model.User', this.loginInfo.imageName);
  52. },
  53. },
  54. mounted: function () {
  55. var _self = this;
  56. },
  57. methods: {
  58. setUserParameters: function () {
  59. this.$router.push('/desktop/userParameters');
  60. },
  61. logout: function () {
  62. Common.clearLocalStorage();
  63. //path为指定路径,直接删除该路径下的cookie
  64. $.removeCookie('#accountId', { path: '/' });
  65. $.removeCookie('token', { path: '/' });
  66. // bug fixed by jack
  67. // 清除掉/pcapp路径的cookie
  68. $.removeCookie('#accountId', { path: '/pcapp' });
  69. $.removeCookie('token', { path: '/pcapp' });
  70. this.$router.push('/login');
  71. // 这边存在问题,模块化以后,需要修复
  72. // AuthSettingResource.getAuthSettingDto().then(
  73. // successData => {
  74. // if (successData != null) {
  75. // var url =
  76. // 'http://jaccount.sjtu.edu.cn/oauth2/logout?client_id=' +
  77. // successData.jaccountClientId +
  78. // '&post_logout_redirect_uri=' +
  79. // Common.getRedirectUrl('#/login');
  80. // window.location.href = url;
  81. // } else {
  82. // this.$router.push('/login');
  83. // }
  84. // },
  85. // errorData => {
  86. // Common.processException(errorData);
  87. // },
  88. // );
  89. },
  90. },
  91. };
  92. </script>
  93. <style scoped>
  94. .user-profile-img {
  95. width: 29px;
  96. height: 29px;
  97. border-radius: 50%;
  98. margin-top: 10px;
  99. }
  100. </style>