index.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <template>
  2. <div :class="mode == 'square' ? 'chatface' : 'brround avatar cover-image'" :style="transform" style="overflow: hidden; width: 40px; height: 40px">
  3. <img v-if="faceUrl && !num" :src="faceUrl" class="w-100 h-100" />
  4. <div v-else :style="styles" class="w-100 h-100 d-flex ai-center jc-center">{{ text }}</div>
  5. </div>
  6. </template>
  7. <script>
  8. export default {
  9. name: 'nameAvatar',
  10. props: {
  11. scale: {
  12. type: String,
  13. default: '1',
  14. },
  15. num: [Number, String],
  16. name: String,
  17. mode: {
  18. type: String,
  19. default: '',
  20. },
  21. fontColor: {
  22. type: String,
  23. default: '#fff',
  24. },
  25. backgroundColor: {
  26. type: String,
  27. default: '#3696F2',
  28. },
  29. faceUrl: {
  30. type: String,
  31. default: '',
  32. },
  33. },
  34. data() {
  35. return {};
  36. },
  37. watch: {},
  38. computed: {
  39. // eslint-disable-next-line vue/return-in-computed-property
  40. text() {
  41. if (this.num !== undefined) {
  42. return `+${this.num}`;
  43. } else {
  44. if (this.name) {
  45. return this.name.slice(-2);
  46. }
  47. }
  48. },
  49. transform() {
  50. let style = {};
  51. if (this.scale) {
  52. style['transform'] = `scale(${this.scale}, ${this.scale})`;
  53. }
  54. return style;
  55. },
  56. styles() {
  57. let style = {};
  58. if (this.size) {
  59. style['font-size'] = '12px';
  60. }
  61. if (this.fontColor) {
  62. style.color = this.fontColor;
  63. }
  64. if (this.backgroundColor) {
  65. style['background'] = this.backgroundColor;
  66. }
  67. return style;
  68. },
  69. },
  70. methods: {},
  71. };
  72. </script>
  73. <style lang="scss" scoped>
  74. @import './base.scss';
  75. .avatar {
  76. display: inline-block;
  77. position: relative;
  78. text-align: center;
  79. vertical-align: bottom;
  80. font-size: 8px;
  81. user-select: none;
  82. z-index: 10;
  83. &:hover {
  84. z-index: 100;
  85. }
  86. }
  87. .brround {
  88. border-radius: 50%;
  89. }
  90. .chatface {
  91. display: block;
  92. border-radius: 8px;
  93. overflow: hidden;
  94. img {
  95. width: 100%;
  96. height: 100%;
  97. }
  98. }
  99. </style>