UserView.vue 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <template>
  2. <div class="user-view-inline">
  3. <Tooltip :disabled="loadIng" :delay="delay" :transfer="transfer" :placement="placement" @on-popper-show="popperShow">
  4. {{nickname || username}}
  5. <div slot="content">
  6. <div>{{$L('用户名')}}: {{username}}</div>
  7. <div>{{$L('职位/职称')}}: {{profession || '-'}}</div>
  8. </div>
  9. </Tooltip>
  10. </div>
  11. </template>
  12. <style lang="scss" scoped>
  13. .user-view-inline {
  14. display: inline-block;
  15. }
  16. </style>
  17. <script>
  18. export default {
  19. name: 'UserView',
  20. props: {
  21. username: {
  22. default: ''
  23. },
  24. delay: {
  25. type: Number,
  26. default: 600
  27. },
  28. transfer: {
  29. type: Boolean,
  30. default: true
  31. },
  32. placement: {
  33. default: 'bottom'
  34. },
  35. info: {
  36. default: null
  37. },
  38. },
  39. data() {
  40. return {
  41. loadIng: true,
  42. nickname: null,
  43. profession: ''
  44. }
  45. },
  46. mounted() {
  47. this.getUserData(300);
  48. },
  49. watch: {
  50. username() {
  51. this.getUserData(300);
  52. },
  53. },
  54. methods: {
  55. isJson(obj) {
  56. return typeof (obj) == "object" && Object.prototype.toString.call(obj).toLowerCase() == "[object object]" && typeof obj.length == "undefined";
  57. },
  58. popperShow() {
  59. this.getUserData(30)
  60. },
  61. getUserData(cacheTime) {
  62. $A.getUserBasic(this.username, (data, success) => {
  63. if (success) {
  64. this.nickname = data.nickname;
  65. this.profession = data.profession;
  66. } else {
  67. this.nickname = '';
  68. this.profession = '';
  69. }
  70. this.loadIng = false;
  71. this.$emit("on-result", data);
  72. //
  73. if (this.isJson(this.info)) {
  74. this.$set(this.info, 'nickname', this.nickname);
  75. }
  76. }, cacheTime);
  77. }
  78. }
  79. }
  80. </script>