UserView.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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" :style="imgStyle"/>
  5. <Tooltip v-if="showname" :disabled="loadIng" :delay="delay" :transfer="transfer" :placement="placement" maxWidth="auto" @on-popper-show="getUserData(30)">
  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. imgsize: {
  83. },
  84. imgfontsize: {
  85. },
  86. showname: {
  87. type: Boolean,
  88. default: true
  89. },
  90. info: {
  91. default: null
  92. },
  93. },
  94. data() {
  95. return {
  96. loadIng: true,
  97. nickname: null,
  98. userimg: '',
  99. profession: ''
  100. }
  101. },
  102. mounted() {
  103. this.getUserData(300);
  104. },
  105. watch: {
  106. username() {
  107. this.getUserData(300);
  108. },
  109. info: {
  110. handler() {
  111. this.upInfo()
  112. },
  113. deep: true
  114. }
  115. },
  116. computed: {
  117. userInfo() {
  118. const {username, nickname, userimg} = this;
  119. return {username, nickname, userimg}
  120. },
  121. imgStyle() {
  122. const {imgsize, imgfontsize} = this;
  123. const myStyle = {};
  124. if (imgsize) {
  125. const size = /^\d+$/.test(imgsize) ? (imgsize + 'px') : imgsize;
  126. myStyle.width = size;
  127. myStyle.height = size;
  128. myStyle.lineHeight = size;
  129. }
  130. if (imgfontsize) {
  131. myStyle.fontSize = /^\d+$/.test(imgfontsize) ? (imgfontsize + 'px') : imgfontsize;
  132. }
  133. return myStyle;
  134. }
  135. },
  136. methods: {
  137. isJson(obj) {
  138. return typeof (obj) == "object" && Object.prototype.toString.call(obj).toLowerCase() == "[object object]" && typeof obj.length == "undefined";
  139. },
  140. upInfo() {
  141. if (this.isJson(this.info)) {
  142. this.$set(this.info, 'nickname', this.nickname);
  143. this.$set(this.info, 'userimg', this.userimg);
  144. }
  145. },
  146. getUserData(cacheTime) {
  147. $A.getUserBasic(this.username, (data, success) => {
  148. if (success) {
  149. this.nickname = data.nickname;
  150. this.userimg = data.userimg;
  151. this.profession = data.profession;
  152. } else {
  153. this.nickname = '';
  154. this.userimg = '';
  155. this.profession = '';
  156. }
  157. this.loadIng = false;
  158. this.$emit("on-result", data);
  159. this.upInfo();
  160. }, cacheTime);
  161. }
  162. }
  163. }
  164. </script>