UserView.vue 5.0 KB

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