index.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <template>
  2. <uni-shadow-root class="vant-card-index"><view class="custom-class van-card">
  3. <view :class="utils.bem('card__header', { center: centered })">
  4. <view class="van-card__thumb" @click="onClickThumb">
  5. <image v-if="thumb" :src="thumb" :mode="thumbMode" :lazy-load="lazyLoad" class="van-card__img thumb-class"></image>
  6. <slot v-else name="thumb"></slot>
  7. <van-tag v-if="tag" mark type="danger" custom-class="van-card__tag">
  8. {{ tag }}
  9. </van-tag>
  10. <slot v-else name="tag"></slot>
  11. </view>
  12. <view :class="'van-card__content '+(utils.bem('card__content', { center: centered }))">
  13. <view>
  14. <view v-if="title" class="van-card__title title-class">{{ title }}</view>
  15. <slot v-else name="title"></slot>
  16. <view v-if="desc" class="van-card__desc desc-class">{{ desc }}</view>
  17. <slot v-else name="desc"></slot>
  18. <slot name="tags"></slot>
  19. </view>
  20. <view class="van-card__bottom">
  21. <slot name="price-top"></slot>
  22. <view v-if="price || price === 0" class="van-card__price price-class">
  23. <text>{{ currency }}</text>
  24. <text class="van-card__price-integer">{{ integerStr }}</text>
  25. <text class="van-card__price-decimal">{{ decimalStr }}</text>
  26. </view>
  27. <slot v-else name="price"></slot>
  28. <view v-if="originPrice || originPrice === 0" class="van-card__origin-price origin-price-class">{{ currency }} {{ originPrice }}</view>
  29. <slot v-else name="origin-price"></slot>
  30. <view v-if="num" class="van-card__num num-class">x {{ num }}</view>
  31. <slot v-else name="num"></slot>
  32. <slot name="bottom"></slot>
  33. </view>
  34. </view>
  35. </view>
  36. <view class="van-card__footer">
  37. <slot name="footer"></slot>
  38. </view>
  39. </view></uni-shadow-root>
  40. </template>
  41. <wxs src="../wxs/utils.wxs" module="utils"></wxs>
  42. <script>
  43. import VanTag from '../tag/index.vue'
  44. global['__wxVueOptions'] = {components:{'van-tag': VanTag}}
  45. global['__wxRoute'] = 'vant/card/index'
  46. import { link } from '../mixins/link';
  47. import { VantComponent } from '../common/component';
  48. VantComponent({
  49. classes: [
  50. 'num-class',
  51. 'desc-class',
  52. 'thumb-class',
  53. 'title-class',
  54. 'price-class',
  55. 'origin-price-class',
  56. ],
  57. mixins: [link],
  58. props: {
  59. tag: String,
  60. num: String,
  61. desc: String,
  62. thumb: String,
  63. title: String,
  64. price: {
  65. type: String,
  66. observer: 'updatePrice',
  67. },
  68. centered: Boolean,
  69. lazyLoad: Boolean,
  70. thumbLink: String,
  71. originPrice: String,
  72. thumbMode: {
  73. type: String,
  74. value: 'aspectFit',
  75. },
  76. currency: {
  77. type: String,
  78. value: '¥',
  79. },
  80. },
  81. methods: {
  82. updatePrice() {
  83. const { price } = this.data;
  84. const priceArr = price.toString().split('.');
  85. this.setData({
  86. integerStr: priceArr[0],
  87. decimalStr: priceArr[1] ? `.${priceArr[1]}` : '',
  88. });
  89. },
  90. onClickThumb() {
  91. this.jumpLink('thumbLink');
  92. },
  93. },
  94. });
  95. export default global['__wxComponents']['vant/card/index']
  96. </script>
  97. <style platform="mp-weixin">
  98. @import '../common/index.css';.van-card{background-color:var(--card-background-color,#fafafa);box-sizing:border-box;color:var(--card-text-color,#323233);font-size:var(--card-font-size,12px);padding:var(--card-padding,8px 16px);position:relative}.van-card__header{display:flex}.van-card__header--center{align-items:center;justify-content:center}.van-card__thumb{flex:none;height:var(--card-thumb-size,88px);margin-right:var(--padding-xs,8px);position:relative;width:var(--card-thumb-size,88px)}.van-card__thumb:empty{display:none}.van-card__img{border-radius:8px;height:100%;width:100%}.van-card__content{display:flex;flex:1;flex-direction:column;justify-content:space-between;min-height:var(--card-thumb-size,88px);min-width:0;position:relative}.van-card__content--center{justify-content:center}.van-card__desc,.van-card__title{word-wrap:break-word}.van-card__title{font-weight:700;line-height:var(--card-title-line-height,16px)}.van-card__desc{color:var(--card-desc-color,#646566);line-height:var(--card-desc-line-height,20px)}.van-card__bottom{line-height:20px}.van-card__price{color:var(--card-price-color,#ee0a24);display:inline-block;font-size:var(--card-price-font-size,12px);font-weight:700}.van-card__price-integer{font-size:var(--card-price-integer-font-size,16px)}.van-card__price-decimal,.van-card__price-integer{font-family:var(--card-price-font-family,Avenir-Heavy,PingFang SC,Helvetica Neue,Arial,sans-serif)}.van-card__origin-price{color:var(--card-origin-price-color,#646566);display:inline-block;font-size:var(--card-origin-price-font-size,10px);margin-left:5px;text-decoration:line-through}.van-card__num{float:right}.van-card__tag{left:0;position:absolute!important;top:2px}.van-card__footer{flex:none;text-align:right;width:100%}
  99. </style>