avatar.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. 'class',
  22. `${prefix}-class`,
  23. `${prefix}-class-image`,
  24. `${prefix}-class-icon`,
  25. `${prefix}-class-alt`,
  26. `${prefix}-class-content`,
  27. ];
  28. this.properties = avatarProps;
  29. this.data = {
  30. prefix,
  31. classPrefix: name,
  32. isShow: true,
  33. zIndex: 0,
  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. });
  44. },
  45. },
  46. };
  47. this.observers = {
  48. icon(icon) {
  49. const obj = setIcon('icon', icon, '');
  50. this.setData(Object.assign({}, obj));
  51. },
  52. };
  53. this.methods = {
  54. hide() {
  55. this.setData({
  56. isShow: false,
  57. });
  58. },
  59. updateCascading(zIndex) {
  60. this.setData({ zIndex });
  61. },
  62. onLoadError(e) {
  63. if (this.properties.hideOnLoadFailed) {
  64. this.setData({
  65. isShow: false,
  66. });
  67. }
  68. this.triggerEvent('error', e.detail);
  69. },
  70. };
  71. }
  72. };
  73. Avatar = __decorate([
  74. wxComponent()
  75. ], Avatar);
  76. export default Avatar;