index.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { link } from '../mixins/link';
  2. import { VantComponent } from '../common/component';
  3. import { addUnit } from '../common/utils';
  4. VantComponent({
  5. relation: {
  6. name: 'grid',
  7. type: 'ancestor',
  8. current: 'grid-item',
  9. },
  10. classes: ['content-class', 'icon-class', 'text-class'],
  11. mixins: [link],
  12. props: {
  13. icon: String,
  14. iconColor: String,
  15. dot: Boolean,
  16. info: null,
  17. badge: null,
  18. text: String,
  19. useSlot: Boolean,
  20. },
  21. data: {
  22. viewStyle: '',
  23. },
  24. mounted() {
  25. this.updateStyle();
  26. },
  27. methods: {
  28. updateStyle() {
  29. if (!this.parent) {
  30. return;
  31. }
  32. const { data, children } = this.parent;
  33. const {
  34. columnNum,
  35. border,
  36. square,
  37. gutter,
  38. clickable,
  39. center,
  40. direction,
  41. iconSize,
  42. } = data;
  43. const width = `${100 / columnNum}%`;
  44. const styleWrapper = [];
  45. styleWrapper.push(`width: ${width}`);
  46. if (square) {
  47. styleWrapper.push(`padding-top: ${width}`);
  48. }
  49. if (gutter) {
  50. const gutterValue = addUnit(gutter);
  51. styleWrapper.push(`padding-right: ${gutterValue}`);
  52. const index = children.indexOf(this);
  53. if (index >= columnNum && !square) {
  54. styleWrapper.push(`margin-top: ${gutterValue}`);
  55. }
  56. }
  57. let contentStyle = '';
  58. if (square && gutter) {
  59. const gutterValue = addUnit(gutter);
  60. contentStyle = `
  61. right: ${gutterValue};
  62. bottom: ${gutterValue};
  63. height: auto;
  64. `;
  65. }
  66. this.setData({
  67. viewStyle: styleWrapper.join('; '),
  68. contentStyle,
  69. center,
  70. border,
  71. square,
  72. gutter,
  73. clickable,
  74. direction,
  75. iconSize,
  76. });
  77. },
  78. onClick() {
  79. this.$emit('click');
  80. this.jumpLink();
  81. },
  82. },
  83. });