avatar-group.js 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 avatarGroupProps from './props';
  10. const { prefix } = config;
  11. const name = `${prefix}-avatar-group`;
  12. let AvatarGroup = class AvatarGroup extends SuperComponent {
  13. constructor() {
  14. super(...arguments);
  15. this.externalClasses = [`${prefix}-class`, `${prefix}-class-content`, `${prefix}-class-image`];
  16. this.properties = avatarGroupProps;
  17. this.data = {
  18. prefix,
  19. classPrefix: name,
  20. hasChild: true,
  21. length: 0,
  22. className: '',
  23. };
  24. this.options = {
  25. multipleSlots: true,
  26. };
  27. this.relations = {
  28. '../avatar/avatar': {
  29. type: 'descendant',
  30. },
  31. };
  32. this.lifetimes = {
  33. attached() {
  34. this.setClass();
  35. },
  36. ready() {
  37. this.setData({
  38. length: this.$children.length,
  39. });
  40. this.handleMax();
  41. this.handleChildCascading();
  42. },
  43. };
  44. this.observers = {
  45. 'cascading, size'() {
  46. this.setClass();
  47. },
  48. };
  49. this.methods = {
  50. setClass() {
  51. const { cascading, size } = this.properties;
  52. const direction = cascading.split('-')[0];
  53. const classList = [
  54. name,
  55. `${prefix}-class`,
  56. `${name}-offset-${direction}-${size.indexOf('px') > -1 ? 'medium' : size}`,
  57. ];
  58. this.setData({
  59. className: classList.join(' '),
  60. });
  61. },
  62. handleMax() {
  63. const { max } = this.data;
  64. const len = this.$children.length;
  65. if (!max || max > len)
  66. return;
  67. const restAvatars = this.$children.splice(max, len - max);
  68. restAvatars.forEach((child) => {
  69. child.hide();
  70. });
  71. },
  72. handleChildCascading() {
  73. if (this.properties.cascading === 'right-up')
  74. return;
  75. const defaultZIndex = 100;
  76. this.$children.forEach((child, index) => {
  77. child.updateCascading(defaultZIndex - index * 10);
  78. });
  79. },
  80. };
  81. }
  82. };
  83. AvatarGroup = __decorate([
  84. wxComponent()
  85. ], AvatarGroup);
  86. export default AvatarGroup;