|
| 1 | +<script lang="ts" setup> |
| 2 | +import { onMounted } from "vue"; |
| 3 | +import { skeletonProps } from "./skeleton"; |
| 4 | +import { isString } from "../_utils"; |
| 5 | +
|
| 6 | +defineProps(skeletonProps); |
| 7 | +
|
| 8 | +onMounted(() => {}); |
| 9 | +function getStyleVal(target: number | string) { |
| 10 | + if (isString(target)) { |
| 11 | + return target; |
| 12 | + } |
| 13 | + return `${target}rpx`; |
| 14 | +} |
| 15 | +</script> |
| 16 | + |
| 17 | +<script lang="ts"> |
| 18 | +import { PREFIX } from "../_constants"; |
| 19 | +const componentName = `${PREFIX}-skeleton`; |
| 20 | +
|
| 21 | +export default { |
| 22 | + name: componentName, |
| 23 | + options: { |
| 24 | + virtualHost: true, |
| 25 | + addGlobalClass: true, |
| 26 | + // #ifndef H5 |
| 27 | + styleIsolation: "shared", |
| 28 | + // #endif |
| 29 | + }, |
| 30 | +}; |
| 31 | +</script> |
| 32 | + |
| 33 | +<template> |
| 34 | + <view class="unip-skeleton"> |
| 35 | + <view |
| 36 | + v-if="loading" |
| 37 | + class="unip-skeleton__wrapper" |
| 38 | + style="display: flex; flex-direction: row" |
| 39 | + > |
| 40 | + <!-- 头像 --> |
| 41 | + <template v-if="type === 'avatar'"> |
| 42 | + <view |
| 43 | + class="unip-skeleton__wrapper__avatar" |
| 44 | + :class="[ |
| 45 | + `unip-skeleton__wrapper__avatar--${avatarShape}`, |
| 46 | + animate && 'animate', |
| 47 | + ]" |
| 48 | + :style="{ |
| 49 | + width: getStyleVal(avatarSize), |
| 50 | + height: getStyleVal(avatarSize), |
| 51 | + }" |
| 52 | + /> |
| 53 | + </template> |
| 54 | + <!-- 标题 --> |
| 55 | + <template v-else-if="type === 'title'"> |
| 56 | + <view class="unip-skeleton__wrapper__title__list"> |
| 57 | + <view |
| 58 | + v-for="idx in rows" |
| 59 | + :key="idx" |
| 60 | + class="unip-skeleton__wrapper__title" |
| 61 | + :class="[animate && 'animate']" |
| 62 | + :style="{ |
| 63 | + height: getStyleVal(titleHeight), |
| 64 | + width: idx === 1 ? '50%' : getStyleVal(titleWidth), |
| 65 | + }" |
| 66 | + /> |
| 67 | + </view> |
| 68 | + </template> |
| 69 | + </view> |
| 70 | + </view> |
| 71 | +</template> |
| 72 | + |
| 73 | +<style lang="scss"> |
| 74 | +@import "./index"; |
| 75 | +</style> |
0 commit comments