grid.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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/grid-item': {
  18. type: 'descendant',
  19. },
  20. };
  21. this.properties = props;
  22. this.data = {
  23. prefix,
  24. classPrefix: name,
  25. contentStyle: '',
  26. };
  27. this.observers = {
  28. 'column,hover,align,gutter,border'() {
  29. this.updateContentStyle();
  30. this.doForChild((child) => child.updateStyle());
  31. },
  32. };
  33. this.lifetimes = {
  34. attached() {
  35. this.updateContentStyle();
  36. },
  37. };
  38. this.methods = {
  39. doForChild(action) {
  40. this.$children.forEach(action);
  41. },
  42. updateContentStyle() {
  43. const contentStyles = [];
  44. const marginStyle = this.getContentMargin();
  45. marginStyle && contentStyles.push(marginStyle);
  46. this.setData({
  47. contentStyle: contentStyles.join(';'),
  48. });
  49. },
  50. getContentMargin() {
  51. const { gutter } = this.properties;
  52. let { border } = this.properties;
  53. if (!border)
  54. return `margin-left:-${gutter}rpx; margin-top:-${gutter}rpx`;
  55. if (!isObject(border))
  56. border = {};
  57. const { width = 2 } = border;
  58. return `margin-left:-${width}rpx; margin-top:-${width}rpx`;
  59. },
  60. };
  61. }
  62. };
  63. Grid = __decorate([
  64. wxComponent()
  65. ], Grid);
  66. export default Grid;