Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

u-avatar.vue 14 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <view class="u-avatar" :style="[wrapStyle]" @tap="click">
  3. <image
  4. @error="loadError"
  5. :style="[imgStyle]"
  6. class="u-avatar-img"
  7. v-if="!text && avatar"
  8. :src="avatar"
  9. :mode="mode"
  10. ></image>
  11. <text class="u-line-1" v-else-if="text">{{text}}</text>
  12. <slot v-else></slot>
  13. </view>
  14. </template>
  15. <script>
  16. let base64Avatar = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAeO0lEQVR4Xu1dCbQcVZn+/+q3kOSFJYRAlpek69aLGcjoROOGIIogBxdwAxUZBycMLkedGUGRgApHIgzojKM448Iw45kjKG4YDEcZBWUZRg3qUUBeuqreewkJELKQBcLLS9c/52u64lu6X1dVV3fXcv9zKv3y3q27fPd+/d/lv//PpEUjoBGoiwBrbNqHwNatW2eOjo4e7nne4UR0eKFQmC0ih+PB/6ufQkR7mHkPPsvlcuWzt7d39+joaOXngYGB0fbVOt8laYLE3P8bN240u7q6FDOrcrls4ZOILCLC54w4imPmnSLiEJHNzI7neQ4z26Ojo87xxx//eBxl6DyeR0ATpImR4LruC4noFBE5lYhOqJLAaCLLpl9l5meq5HmQme9m5nuLxeJw0xnnNANNkBAd7zjOKhF5BRGdxMyvJaJ5IV7vZNKNRHSXiDzAzP+nlML/tQRAQBNkGpBGRkbMsbGxN1YJ8Uoi6g+AaRqS/FFEfgUNs2fPnjtWrlz5dBoq3Yk6aoJMQr1UKi1i5jcahvEGEQE5Cp3omDaWuU1E7jAMY313d/f6/v7+/W0sO/FFaYJgpWvb8wqFwhs8zwMh8MSymE5870+t4GNEtN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地方,如个人中心,或者评论列表页的用户头像展示等场所。
  20. * @tutorial https://www.uviewui.com/components/avatar.html
  21. * @property {String} bg-color 背景颜色,一般显示文字时用(默认#ffffff)
  22. * @property {String} src 头像路径,如加载失败,将会显示默认头像
  23. * @property {String Number} size 头像尺寸,可以为指定字符串(large, default, mini),或者数值,单位rpx(默认default)
  24. * @property {String} mode 显示类型,见上方说明(默认circle)
  25. * @property {String} text 用文字替代图片,级别优先于src
  26. * @property {String} img-mode 头像图片的裁剪类型,与uni的image组件的mode参数一致,如效果达不到需求,可尝试传widthFix值(默认aspectFill)
  27. * @property {String} index 用户传递的标识符值,如果是列表循环,可穿v-for的index值
  28. * @event {Function} click 头像被点击
  29. * @example <u-avatar :src="src"></u-avatar>
  30. */
  31. export default {
  32. name: 'u-avatar',
  33. props: {
  34. // 背景颜色
  35. bgColor: {
  36. type: String,
  37. default: 'transparent'
  38. },
  39. // 头像路径
  40. src: {
  41. type: String,
  42. default: ''
  43. },
  44. // 尺寸,large-大,default-中等,mini-小,如果为数值,则单位为rpx
  45. // 宽度等于高度
  46. size: {
  47. type: [String, Number],
  48. default: 'default'
  49. },
  50. // 头像模型,square-带圆角方形,circle-圆形
  51. mode: {
  52. type: String,
  53. default: 'circle'
  54. },
  55. // 文字内容
  56. text: {
  57. type: String,
  58. default: ''
  59. },
  60. // 图片的裁剪模型
  61. imgMode: {
  62. type: String,
  63. default: 'aspectFill'
  64. },
  65. // 标识符
  66. index: {
  67. type: [String, Number],
  68. default: ''
  69. }
  70. },
  71. data() {
  72. return {
  73. error: false,
  74. // 头像的地址,因为如果加载错误,需要赋值为默认图片,props值无法修改,所以需要一个中间值
  75. avatar: this.src ? this.src : base64Avatar,
  76. }
  77. },
  78. watch: {
  79. src(n) {
  80. // 用户可能会在头像加载失败时,再次修改头像值,所以需要重新赋值
  81. this.avatar = n;
  82. }
  83. },
  84. computed: {
  85. wrapStyle() {
  86. let style = {};
  87. style.height = this.size == 'large' ? '120rpx' : this.size == 'default' ?
  88. '90rpx' : this.size == 'mini' ? '70rpx' : this.size + 'rpx';
  89. style.width = style.height;
  90. style.flex = `0 0 ${style.height}`;
  91. style.backgroundColor = this.bgColor;
  92. style.borderRadius = this.mode == 'circle' ? '500px' : '5px';
  93. if(this.text) style.padding = `0 6rpx`;
  94. return style;
  95. },
  96. imgStyle() {
  97. let style = {};
  98. style.borderRadius = this.mode == 'circle' ? '500px' : '5px';
  99. return style;
  100. },
  101. },
  102. methods: {
  103. // 图片加载错误时,显示默认头像
  104. loadError() {
  105. this.error = true;
  106. this.avatar = base64Avatar;
  107. },
  108. click() {
  109. this.$emit('click', this.index);
  110. }
  111. }
  112. }
  113. </script>
  114. <style lang="scss" scoped>
  115. @import "../../libs/css/style.components.scss";
  116. .u-avatar {
  117. display: inline-flex;
  118. align-items: center;
  119. justify-content: center;
  120. font-size: 28rpx;
  121. color: $u-content-color;
  122. border-radius: 10px;
  123. overflow: hidden;
  124. }
  125. .u-avatar-img {
  126. width: 100%;
  127. height: 100%;
  128. }
  129. </style>