index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <template>
  2. <uni-shadow-root class="vant-skeleton-index"><view v-if="loading" :class="'custom-class '+(utils.bem('skeleton', [{animate}]))">
  3. <view v-if="avatar" :class="'avatar-class '+(utils.bem('skeleton__avatar', [avatarShape]))" :style="'width:' + avatarSize + ';height:' + avatarSize"></view>
  4. <view :class="utils.bem('skeleton__content')">
  5. <view v-if="title" :class="'title-class '+(utils.bem('skeleton__title'))" :style="'width:' + titleWidth"></view>
  6. <view v-for="(item,index) in (rowArray)" :key="item.index" :class="'row-class '+(utils.bem('skeleton__row'))" :style="'width:' + (isArray ? rowWidth[index] : rowWidth)"></view>
  7. </view>
  8. </view>
  9. <view v-else :class="utils.bem('skeleton__content')">
  10. <slot></slot>
  11. </view></uni-shadow-root>
  12. </template>
  13. <wxs src="../wxs/utils.wxs" module="utils"></wxs>
  14. <script>
  15. global['__wxVueOptions'] = {components:{}}
  16. global['__wxRoute'] = 'vant/skeleton/index'
  17. import { VantComponent } from '../common/component';
  18. VantComponent({
  19. classes: ['avatar-class', 'title-class', 'row-class'],
  20. props: {
  21. row: {
  22. type: Number,
  23. value: 0,
  24. observer(value) {
  25. this.setData({ rowArray: Array.from({ length: value }) });
  26. },
  27. },
  28. title: Boolean,
  29. avatar: Boolean,
  30. loading: {
  31. type: Boolean,
  32. value: true,
  33. },
  34. animate: {
  35. type: Boolean,
  36. value: true,
  37. },
  38. avatarSize: {
  39. type: String,
  40. value: '32px',
  41. },
  42. avatarShape: {
  43. type: String,
  44. value: 'round',
  45. },
  46. titleWidth: {
  47. type: String,
  48. value: '40%',
  49. },
  50. rowWidth: {
  51. type: null,
  52. value: '100%',
  53. observer(val) {
  54. this.setData({ isArray: val instanceof Array });
  55. },
  56. },
  57. },
  58. data: {
  59. isArray: false,
  60. rowArray: [],
  61. },
  62. });
  63. export default global['__wxComponents']['vant/skeleton/index']
  64. </script>
  65. <style platform="mp-weixin">
  66. @import '../common/index.css';.van-skeleton{box-sizing:border-box;display:flex;padding:var(--skeleton-padding,0 16px);width:100%}.van-skeleton__avatar{background-color:var(--skeleton-avatar-background-color,#f2f3f5);flex-shrink:0;margin-right:var(--padding-md,16px)}.van-skeleton__avatar--round{border-radius:100%}.van-skeleton__content{flex:1}.van-skeleton__avatar+.van-skeleton__content{padding-top:var(--padding-xs,8px)}.van-skeleton__row,.van-skeleton__title{background-color:var(--skeleton-row-background-color,#f2f3f5);height:var(--skeleton-row-height,16px)}.van-skeleton__title{margin:0}.van-skeleton__row:not(:first-child){margin-top:var(--skeleton-row-margin-top,12px)}.van-skeleton__title+.van-skeleton__row{margin-top:20px}.van-skeleton--animate{animation:van-skeleton-blink 1.2s ease-in-out infinite}@keyframes van-skeleton-blink{50%{opacity:.6}}
  67. </style>