avatar.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  2. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  3. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  4. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  5. return c > 3 && r && Object.defineProperty(target, key, r), r;
  6. };
  7. import { SuperComponent, wxComponent } from '../common/src/index';
  8. import config from '../common/config';
  9. import avatarProps from './props';
  10. import { setIcon } from '../common/utils';
  11. const { prefix } = config;
  12. const name = `${prefix}-avatar`;
  13. let Avatar = class Avatar extends SuperComponent {
  14. constructor() {
  15. super(...arguments);
  16. this.options = {
  17. multipleSlots: true,
  18. styleIsolation: 'apply-shared',
  19. };
  20. this.externalClasses = [
  21. `${prefix}-class`,
  22. `${prefix}-class-image`,
  23. `${prefix}-class-icon`,
  24. `${prefix}-class-alt`,
  25. `${prefix}-class-content`,
  26. ];
  27. this.properties = avatarProps;
  28. this.data = {
  29. prefix,
  30. classPrefix: name,
  31. isShow: true,
  32. zIndex: 0,
  33. borderedWithGroup: false,
  34. };
  35. this.relations = {
  36. '../avatar-group/avatar-group': {
  37. type: 'ancestor',
  38. linked(parent) {
  39. var _a;
  40. this.parent = parent;
  41. this.setData({
  42. size: (_a = this.data.size) !== null && _a !== void 0 ? _a : parent.data.size,
  43. borderedWithGroup: true,
  44. });
  45. },
  46. },
  47. };
  48. this.observers = {
  49. icon(icon) {
  50. const obj = setIcon('icon', icon, '');
  51. this.setData(Object.assign({}, obj));
  52. },
  53. };
  54. this.methods = {
  55. hide() {
  56. this.setData({
  57. isShow: false,
  58. });
  59. },
  60. updateCascading(zIndex) {
  61. this.setData({ zIndex });
  62. },
  63. onLoadError(e) {
  64. if (this.properties.hideOnLoadFailed) {
  65. this.setData({
  66. isShow: false,
  67. });
  68. }
  69. this.triggerEvent('error', e.detail);
  70. },
  71. };
  72. }
  73. };
  74. Avatar = __decorate([
  75. wxComponent()
  76. ], Avatar);
  77. export default Avatar;