grid.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 { isObject, SuperComponent, wxComponent } from '../common/src/index';
  8. import config from '../common/config';
  9. import props from './props';
  10. const { prefix } = config;
  11. const name = `${prefix}-grid`;
  12. let Grid = class Grid extends SuperComponent {
  13. constructor() {
  14. super(...arguments);
  15. this.externalClasses = ['t-class'];
  16. this.relations = {
  17. './grid-item': {
  18. type: 'descendant',
  19. },
  20. };
  21. this.properties = props;
  22. this.data = {
  23. classPrefix: name,
  24. contentStyle: '',
  25. };
  26. this.observers = {
  27. 'border,gutter,column,hover,align'() {
  28. this.updateContentStyle();
  29. },
  30. };
  31. this.lifetimes = {
  32. attached() {
  33. this.updateContentStyle();
  34. },
  35. detached() {
  36. this.destroyed();
  37. },
  38. created() {
  39. this.children = [];
  40. },
  41. };
  42. }
  43. updateContentStyle() {
  44. const contentStyles = [];
  45. const marginStyle = this.getContentMargin();
  46. marginStyle && contentStyles.push(marginStyle);
  47. this.setData({
  48. contentStyle: contentStyles.join(';'),
  49. });
  50. }
  51. // 判断需不需要在content上加负margin以实现gutter间距
  52. getContentMargin() {
  53. const { gutter = 0 } = this.properties;
  54. let { border } = this.properties;
  55. if (!border)
  56. return `margin-left:-${gutter}rpx; margin-top:-${gutter}rpx`;
  57. if (!isObject(border))
  58. border = {};
  59. const { width = 2 } = border;
  60. return `margin-left:-${width}rpx; margin-top:-${width}rpx`;
  61. }
  62. destroyed() {
  63. if (this.updateTimer) {
  64. clearTimeout(this.updateTimer);
  65. this.updateTimer = null;
  66. }
  67. }
  68. };
  69. Grid = __decorate([
  70. wxComponent()
  71. ], Grid);
  72. export default Grid;
  73. //# sourceMappingURL=grid.js.map