index.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <template>
  2. <view style="position: relative;">
  3. <u-avatar
  4. @longpress="longpress"
  5. @click="click"
  6. @onError="errorHandle"
  7. :src="getAvatarUrl"
  8. :text="avatarText"
  9. bgColor="#e5e5e5"
  10. :defaultUrl="getDdefaultUrl"
  11. :shape="shape"
  12. :size="size"
  13. mode="aspectFill"
  14. font-size="14">
  15. </u-avatar>
  16. <slot></slot>
  17. </view>
  18. </template>
  19. <script>
  20. import defaultGroupIcon from "@/pages_im/static/images/contact_my_group.png";
  21. import defaultNotifyIcon from "@/pages_im/static/images/default_notify_icon.png";
  22. export default {
  23. name: "MyAvatar",
  24. props: {
  25. src: String,
  26. shape: {
  27. type: String,
  28. default: "square",
  29. },
  30. size: {
  31. type: String,
  32. default: "46",
  33. },
  34. isGroup: {
  35. type: Boolean,
  36. default: false,
  37. },
  38. isNotify: {
  39. type: Boolean,
  40. default: false,
  41. },
  42. desc: String,
  43. },
  44. data() {
  45. return {
  46. avatarText: undefined,
  47. defaultFaceIcon: "https://cqtyt-2025.oss-cn-beijing.aliyuncs.com/huyi/imagesNew/0d7f54fe8adc4d3689923f9bfc83d4c9.png"
  48. };
  49. },
  50. computed: {
  51. getAvatarUrl() {
  52. if (this.isGroup) {
  53. return defaultGroupIcon;
  54. }
  55. else if (this.isNotify) {
  56. return defaultNotifyIcon;
  57. }
  58. else{
  59. if (this.src) {
  60. return this.src;
  61. }else{
  62. return this.defaultFaceIcon;
  63. }
  64. }
  65. this.avatarText = this.desc ? this.desc.slice(0, 1) : "未知";
  66. return "";
  67. },
  68. getDdefaultUrl() {
  69. return this.isGroup ? defaultGroupIcon : undefined;
  70. },
  71. },
  72. methods: {
  73. errorHandle() {
  74. this.avatarText = this.desc ? this.desc.slice(0, 1) : "未知";
  75. },
  76. redirectShow() {
  77. if (this.avatarText) {
  78. this.avatarText = undefined;
  79. }
  80. },
  81. click() {
  82. this.$emit("click");
  83. },
  84. longpress() {
  85. this.$emit("longpress");
  86. },
  87. },
  88. watch: {
  89. src() {
  90. this.redirectShow();
  91. },
  92. desc() {
  93. this.redirectShow();
  94. },
  95. },
  96. };
  97. </script>
  98. <style>
  99. </style>