index.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <template>
  2. <uni-shadow-root class="vant-grid-item-index"><view :class="'custom-class '+(utils.bem('grid-item', { square }))" :style="viewStyle" @click="onClick">
  3. <view :class="'content-class '+(utils.bem('grid-item__content', [direction, { center, square, clickable, surround: border && gutter }]))+' '+(border ? 'van-hairline--surround' : '')" :style="contentStyle">
  4. <block v-if="useSlot">
  5. <slot></slot>
  6. </block>
  7. <block v-else>
  8. <view class="van-grid-item__icon icon-class">
  9. <van-icon v-if="icon" :name="icon" :color="iconColor" :dot="dot" :info="badge || info" :size="iconSize"></van-icon>
  10. <slot v-else name="icon"></slot>
  11. </view>
  12. <view class="van-grid-item__text text-class">
  13. <text v-if="text">{{ text }}</text>
  14. <slot v-else name="text"></slot>
  15. </view>
  16. </block>
  17. </view>
  18. </view></uni-shadow-root>
  19. </template>
  20. <wxs src="../wxs/utils.wxs" module="utils"></wxs>
  21. <script>
  22. import VanIcon from '../icon/index.vue'
  23. global['__wxVueOptions'] = {components:{'van-icon': VanIcon}}
  24. global['__wxRoute'] = 'vant/grid-item/index'
  25. import { link } from '../mixins/link';
  26. import { VantComponent } from '../common/component';
  27. import { addUnit } from '../common/utils';
  28. VantComponent({
  29. relation: {
  30. name: 'grid',
  31. type: 'ancestor',
  32. current: 'grid-item',
  33. },
  34. classes: ['content-class', 'icon-class', 'text-class'],
  35. mixins: [link],
  36. props: {
  37. icon: String,
  38. iconColor: String,
  39. dot: Boolean,
  40. info: null,
  41. badge: null,
  42. text: String,
  43. useSlot: Boolean,
  44. },
  45. data: {
  46. viewStyle: '',
  47. },
  48. mounted() {
  49. this.updateStyle();
  50. },
  51. methods: {
  52. updateStyle() {
  53. if (!this.parent) {
  54. return;
  55. }
  56. const { data, children } = this.parent;
  57. const {
  58. columnNum,
  59. border,
  60. square,
  61. gutter,
  62. clickable,
  63. center,
  64. direction,
  65. iconSize,
  66. } = data;
  67. const width = `${100 / columnNum}%`;
  68. const styleWrapper = [];
  69. styleWrapper.push(`width: ${width}`);
  70. if (square) {
  71. styleWrapper.push(`padding-top: ${width}`);
  72. }
  73. if (gutter) {
  74. const gutterValue = addUnit(gutter);
  75. styleWrapper.push(`padding-right: ${gutterValue}`);
  76. const index = children.indexOf(this);
  77. if (index >= columnNum && !square) {
  78. styleWrapper.push(`margin-top: ${gutterValue}`);
  79. }
  80. }
  81. let contentStyle = '';
  82. if (square && gutter) {
  83. const gutterValue = addUnit(gutter);
  84. contentStyle = `
  85. right: ${gutterValue};
  86. bottom: ${gutterValue};
  87. height: auto;
  88. `;
  89. }
  90. this.setData({
  91. viewStyle: styleWrapper.join('; '),
  92. contentStyle,
  93. center,
  94. border,
  95. square,
  96. gutter,
  97. clickable,
  98. direction,
  99. iconSize,
  100. });
  101. },
  102. onClick() {
  103. this.$emit('click');
  104. this.jumpLink();
  105. },
  106. },
  107. });
  108. export default global['__wxComponents']['vant/grid-item/index']
  109. </script>
  110. <style platform="mp-weixin">
  111. @import '../common/index.css';.van-grid-item{position:relative;float:left;box-sizing:border-box}.van-grid-item--square{height:0}.van-grid-item__content{display:-webkit-flex;display:flex;-webkit-flex-direction:column;flex-direction:column;box-sizing:border-box;height:100%;padding:16px 8px;padding:var(--grid-item-content-padding,16px 8px);background-color:#fff;background-color:var(--grid-item-content-background-color,#fff)}.van-grid-item__content:after{z-index:1;border-width:0 1px 1px 0;border-bottom-width:var(--border-width-base,1px);border-right-width:var(--border-width-base,1px);border-top-width:0}.van-grid-item__content--surround:after{border-width:1px;border-width:var(--border-width-base,1px)}.van-grid-item__content--center{-webkit-align-items:center;align-items:center;-webkit-justify-content:center;justify-content:center}.van-grid-item__content--square{position:absolute;top:0;right:0;left:0}.van-grid-item__content--horizontal{-webkit-flex-direction:row;flex-direction:row}.van-grid-item__content--horizontal .van-grid-item__icon+.van-grid-item__text{margin-top:0;margin-left:8px}.van-grid-item__content--clickable:active{background-color:#f2f3f5;background-color:var(--grid-item-content-active-color,#f2f3f5)}.van-grid-item__icon{display:-webkit-flex;display:flex;-webkit-align-items:center;align-items:center;font-size:26px;font-size:var(--grid-item-icon-size,26px);height:26px;height:var(--grid-item-icon-size,26px)}.van-grid-item__text{word-wrap:break-word;color:#646566;color:var(--grid-item-text-color,#646566);font-size:12px;font-size:var(--grid-item-text-font-size,12px)}.van-grid-item__icon+.van-grid-item__text{margin-top:8px}
  112. </style>