海鲜小程序

index.js 1.8KB

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. dot: Boolean,
  15. info: null,
  16. badge: null,
  17. text: String,
  18. useSlot: Boolean,
  19. },
  20. data: {
  21. viewStyle: '',
  22. },
  23. mounted() {
  24. this.updateStyle();
  25. },
  26. methods: {
  27. updateStyle() {
  28. if (!this.parent) {
  29. return;
  30. }
  31. const { data, children } = this.parent;
  32. const {
  33. columnNum,
  34. border,
  35. square,
  36. gutter,
  37. clickable,
  38. center,
  39. direction,
  40. iconSize,
  41. } = data;
  42. const width = `${100 / columnNum}%`;
  43. const styleWrapper = [];
  44. styleWrapper.push(`width: ${width}`);
  45. if (square) {
  46. styleWrapper.push(`padding-top: ${width}`);
  47. }
  48. if (gutter) {
  49. const gutterValue = addUnit(gutter);
  50. styleWrapper.push(`padding-right: ${gutterValue}`);
  51. const index = children.indexOf(this);
  52. if (index >= columnNum && !square) {
  53. styleWrapper.push(`margin-top: ${gutterValue}`);
  54. }
  55. }
  56. let contentStyle = '';
  57. if (square && gutter) {
  58. const gutterValue = addUnit(gutter);
  59. contentStyle = `
  60. right: ${gutterValue};
  61. bottom: ${gutterValue};
  62. height: auto;
  63. `;
  64. }
  65. this.setData({
  66. viewStyle: styleWrapper.join('; '),
  67. contentStyle,
  68. center,
  69. border,
  70. square,
  71. gutter,
  72. clickable,
  73. direction,
  74. iconSize,
  75. });
  76. },
  77. onClick() {
  78. this.$emit('click');
  79. this.jumpLink();
  80. },
  81. },
  82. });