grid.js 2.7 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 { 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. 'column,hover,align'() {
  28. this.updateContentStyle();
  29. },
  30. 'gutter,border'() {
  31. this.updateContentStyle();
  32. this.doForChild((child) => child.updateStyle());
  33. },
  34. };
  35. this.lifetimes = {
  36. attached() {
  37. this.updateContentStyle();
  38. },
  39. created() {
  40. this.children = [];
  41. },
  42. };
  43. this.methods = {
  44. doForChild(action) {
  45. var _a;
  46. const children = (_a = this.getRelationNodes('./grid-item')) !== null && _a !== void 0 ? _a : [];
  47. children.forEach(action);
  48. },
  49. updateContentStyle() {
  50. const contentStyles = [];
  51. const marginStyle = this.getContentMargin();
  52. marginStyle && contentStyles.push(marginStyle);
  53. this.setData({
  54. contentStyle: contentStyles.join(';'),
  55. });
  56. },
  57. getContentMargin() {
  58. const { gutter } = this.properties;
  59. let { border } = this.properties;
  60. if (!border)
  61. return `margin-left:-${gutter}rpx; margin-top:-${gutter}rpx`;
  62. if (!isObject(border))
  63. border = {};
  64. const { width = 2 } = border;
  65. return `margin-left:-${width}rpx; margin-top:-${width}rpx`;
  66. },
  67. };
  68. }
  69. };
  70. Grid = __decorate([
  71. wxComponent()
  72. ], Grid);
  73. export default Grid;