index.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <view :class="'custom-class ' + utils.bem('grid-item', { square })" :style="viewStyle" @tap="onClick">
  3. <view
  4. :class="
  5. 'content-class ' +
  6. utils.bem('grid-item__content', [direction, { center, square, clickable, surround: border && gutter }]) +
  7. ' ' +
  8. (border ? 'van-hairline--surround' : '')
  9. "
  10. :style="contentStyle"
  11. >
  12. <block v-if="useSlot">
  13. <slot />
  14. </block>
  15. <block v-else>
  16. <view class="van-grid-item__icon icon-class">
  17. <van-icon v-if="icon" :name="icon" :dot="dot" :info="badge || info" :size="iconSize" />
  18. <slot v-else name="icon"></slot>
  19. </view>
  20. <view class="van-grid-item__text text-class">
  21. <text v-if="text">{{ text }}</text>
  22. <slot v-else name="text"></slot>
  23. </view>
  24. </block>
  25. </view>
  26. </view>
  27. </template>
  28. <script module="utils" lang="wxs" src="@/miniprogram_npm/@vant/weapp/wxs/utils.wxs"></script>
  29. <script>
  30. 'use strict';
  31. Object.defineProperty(exports, '__esModule', {
  32. value: true
  33. });
  34. var link_1 = require('../mixins/link');
  35. var component_1 = require('../common/component');
  36. var utils_1 = require('../common/utils');
  37. component_1.VantComponent({
  38. relation: {
  39. name: 'grid',
  40. type: 'ancestor',
  41. current: 'grid-item'
  42. },
  43. classes: ['content-class', 'icon-class', 'text-class'],
  44. mixins: [link_1.link],
  45. props: {
  46. icon: String,
  47. dot: Boolean,
  48. info: null,
  49. badge: null,
  50. text: String,
  51. useSlot: Boolean
  52. },
  53. data: {
  54. viewStyle: ''
  55. },
  56. mounted: function () {
  57. this.updateStyle();
  58. },
  59. methods: {
  60. updateStyle: function () {
  61. if (!this.parent) {
  62. return;
  63. }
  64. var _a = this.parent;
  65. var data = _a.data;
  66. var children = _a.children;
  67. var columnNum = data.columnNum;
  68. var border = data.border;
  69. var square = data.square;
  70. var gutter = data.gutter;
  71. var clickable = data.clickable;
  72. var center = data.center;
  73. var direction = data.direction;
  74. var iconSize = data.iconSize;
  75. var width = 100 / columnNum + '%';
  76. var styleWrapper = [];
  77. styleWrapper.push('width: ' + width);
  78. if (square) {
  79. styleWrapper.push('padding-top: ' + width);
  80. }
  81. if (gutter) {
  82. var gutterValue = utils_1.addUnit(gutter);
  83. styleWrapper.push('padding-right: ' + gutterValue);
  84. var index = children.indexOf(this);
  85. if (index >= columnNum && !square) {
  86. styleWrapper.push('margin-top: ' + gutterValue);
  87. }
  88. }
  89. var contentStyle = '';
  90. if (square && gutter) {
  91. var gutterValue = utils_1.addUnit(gutter);
  92. contentStyle = '\n right: ' + gutterValue + ';\n bottom: ' + gutterValue + ';\n height: auto;\n ';
  93. }
  94. this.setData({
  95. viewStyle: styleWrapper.join('; '),
  96. contentStyle: contentStyle,
  97. center: center,
  98. border: border,
  99. square: square,
  100. gutter: gutter,
  101. clickable: clickable,
  102. direction: direction,
  103. iconSize: iconSize
  104. });
  105. },
  106. onClick: function () {
  107. this.$emit('click');
  108. this.jumpLink();
  109. }
  110. }
  111. });
  112. </script>
  113. <style>
  114. @import './index.css';
  115. </style>