UserView.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <div class="user-view-inline">
  3. <div class="user-view-info">
  4. <UserImg v-if="showimg" class="user-view-img" :info="userInfo"/>
  5. <Tooltip :disabled="loadIng" :delay="delay" :transfer="transfer" :placement="placement" maxWidth="auto" @on-popper-show="popperShow">
  6. {{nickname || username}}
  7. <div slot="content" style="white-space:normal">
  8. <div>{{$L('用户名')}}: {{username}}</div>
  9. <div>{{$L('职位/职称')}}: {{profession || '-'}}</div>
  10. </div>
  11. </Tooltip>
  12. </div>
  13. </div>
  14. </template>
  15. <style lang="scss">
  16. .user-view-inline {
  17. .user-view-info {
  18. .ivu-tooltip {
  19. max-width: 100%;
  20. display: flex;
  21. flex-direction: column;
  22. justify-content: center;
  23. .ivu-tooltip-rel {
  24. max-width: 100%;
  25. white-space: nowrap;
  26. overflow: hidden;
  27. text-overflow: ellipsis;
  28. }
  29. }
  30. .user-view-img {
  31. .usertext-container-text {
  32. transform: scale(0.86);
  33. }
  34. }
  35. }
  36. }
  37. </style>
  38. <style lang="scss" scoped>
  39. .user-view-inline {
  40. display: inline-block;
  41. max-width: 100%;
  42. .user-view-info {
  43. display: flex;
  44. align-items: center;
  45. .user-view-img {
  46. width: 16px;
  47. height: 16px;
  48. font-size: 12px;
  49. line-height: 16px;
  50. border-radius: 50%;
  51. margin-right: 3px;
  52. }
  53. .user-view-title {
  54. flex: 1;
  55. line-height: 1.2;
  56. }
  57. }
  58. }
  59. </style>
  60. <script>
  61. export default {
  62. name: 'UserView',
  63. props: {
  64. username: {
  65. default: ''
  66. },
  67. delay: {
  68. type: Number,
  69. default: 600
  70. },
  71. transfer: {
  72. type: Boolean,
  73. default: true
  74. },
  75. placement: {
  76. default: 'bottom'
  77. },
  78. showimg: {
  79. type: Boolean,
  80. default: false
  81. },
  82. info: {
  83. default: null
  84. },
  85. },
  86. data() {
  87. return {
  88. loadIng: true,
  89. nickname: null,
  90. userimg: '',
  91. profession: ''
  92. }
  93. },
  94. mounted() {
  95. this.getUserData(300);
  96. },
  97. watch: {
  98. username() {
  99. this.getUserData(300);
  100. },
  101. info: {
  102. handler() {
  103. this.upInfo()
  104. },
  105. deep: true
  106. }
  107. },
  108. computed: {
  109. userInfo() {
  110. const {username, nickname, userimg} = this;
  111. return {username, nickname, userimg}
  112. }
  113. },
  114. methods: {
  115. isJson(obj) {
  116. return typeof (obj) == "object" && Object.prototype.toString.call(obj).toLowerCase() == "[object object]" && typeof obj.length == "undefined";
  117. },
  118. upInfo() {
  119. if (this.isJson(this.info)) {
  120. this.$set(this.info, 'nickname', this.nickname);
  121. this.$set(this.info, 'userimg', this.userimg);
  122. }
  123. },
  124. popperShow() {
  125. this.getUserData(30)
  126. },
  127. getUserData(cacheTime) {
  128. $A.getUserBasic(this.username, (data, success) => {
  129. if (success) {
  130. this.nickname = data.nickname;
  131. this.userimg = data.userimg;
  132. this.profession = data.profession;
  133. } else {
  134. this.nickname = '';
  135. this.userimg = '';
  136. this.profession = '';
  137. }
  138. this.loadIng = false;
  139. this.$emit("on-result", data);
  140. this.upInfo();
  141. }, cacheTime);
  142. }
  143. }
  144. }
  145. </script>