avatar.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <script>
  2. export default {
  3. name: "LemonAvatar",
  4. inject: ["IMUI"],
  5. props: {
  6. src: String,
  7. icon: {
  8. type: String,
  9. default: "lemon-icon-people",
  10. },
  11. circle: {
  12. type: Boolean,
  13. default() {
  14. return this.IMUI ? this.IMUI.avatarCricle : false;
  15. },
  16. },
  17. size: {
  18. type: Number,
  19. default: 32,
  20. },
  21. },
  22. data() {
  23. return {
  24. imageFinishLoad: true,
  25. };
  26. },
  27. render() {
  28. return (
  29. <span
  30. style={this.style}
  31. class={["lemon-avatar", { "lemon-avatar--circle": this.circle }]}
  32. on-click={e => this.$emit("click", e)}
  33. >
  34. {(this.imageFinishLoad || !this.src) && <i class={this.icon} />}
  35. <img src={this.src} onLoad={this._handleLoad} />
  36. </span>
  37. );
  38. },
  39. computed: {
  40. style() {
  41. const size = `${this.size}px`;
  42. return {
  43. width: size,
  44. height: size,
  45. lineHeight: size,
  46. fontSize: `${this.size / 2}px`,
  47. };
  48. },
  49. },
  50. methods: {
  51. _handleLoad() {
  52. this.imageFinishLoad = false;
  53. },
  54. },
  55. };
  56. </script>
  57. <style lang="stylus">
  58. @import '~styles/utils/index'
  59. +b(lemon-avatar)
  60. font-variant tabular-nums
  61. line-height 1.5
  62. box-sizing border-box
  63. margin 0
  64. padding 0
  65. list-style none
  66. display inline-block
  67. text-align center
  68. background #ccc
  69. color rgba(255,255,255,0.7)
  70. white-space nowrap
  71. position relative
  72. overflow hidden
  73. vertical-align middle
  74. border-radius 4px
  75. +m(circle)
  76. border-radius 50%
  77. img
  78. width 100%
  79. height 100%
  80. display block
  81. </style>