avatar.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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, systemInfo } 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. };
  19. this.externalClasses = [
  20. `${prefix}-class`,
  21. `${prefix}-class-image`,
  22. `${prefix}-class-icon`,
  23. `${prefix}-class-alt`,
  24. `${prefix}-class-content`,
  25. ];
  26. this.properties = avatarProps;
  27. this.data = {
  28. prefix,
  29. classPrefix: name,
  30. isShow: true,
  31. zIndex: 0,
  32. systemInfo,
  33. };
  34. this.relations = {
  35. '../avatar-group/avatar-group': {
  36. type: 'ancestor',
  37. linked(parent) {
  38. this.parent = parent;
  39. this.setData({
  40. shape: this.data.shape || parent.data.shape || 'circle',
  41. size: this.data.size || parent.data.size,
  42. bordered: true,
  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. onLoadError(e) {
  60. if (this.properties.hideOnLoadFailed) {
  61. this.setData({
  62. isShow: false,
  63. });
  64. }
  65. this.triggerEvent('error', e.detail);
  66. },
  67. };
  68. }
  69. };
  70. Avatar = __decorate([
  71. wxComponent()
  72. ], Avatar);
  73. export default Avatar;