UserView.vue 5.1 KB

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