SkeletonCard.uvue
2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<template>
<view class="skeleton-container">
<view class="skeleton-grid" :style="gridStyle">
<view v-for="i in count"
:key="'skeleton-' + i"
class="skeleton-card-wrapper">
<!-- ✅ 卡片容器 - 保持与真实卡片相同的外观 -->
<view class="skeleton-card-box">
<un-skeleton
:loading="true"
:animate="true"
:title="true"
titleWidth="75%"
titleHeight="16px"
:rows="1"
rowsWidth="60%"
rowsHeight="14px"
:avatar="true"
avatarSize="20px"
avatarShape="square" />
</view>
</view>
</view>
</view>
</template>
<script setup lang="uts">
import { computed } from 'vue';
interface SkeletonCardProps {
count: number
parentCssVars?: UTSJSONObject | null
}
const props = withDefaults(defineProps<SkeletonCardProps>(), {
count: 6,
parentCssVars: null
});
// ✅ 合并父级 CSS 变量(优先使用父级传递的)
const gridStyle = computed(() => {
if (props.parentCssVars != null) {
return props.parentCssVars;
}
// 降级方案:使用默认值
return {
'--column-width': '50%',
'--grid-row-margin-left': '-6px',
'--grid-row-margin-right': '-6px',
'--grid-cell-padding-left': '6px',
'--grid-cell-padding-right': '6px'
} as UTSJSONObject;
});
</script>
<style scoped lang="scss">
.skeleton-container {
width: 100%;
box-sizing: border-box;
background-color: transparent;
}
.skeleton-grid {
width: 100%;
display: flex;
flex-direction: row;
flex-wrap: wrap;
box-sizing: border-box;
// ✅ 直接使用父级传递的 CSS 变量
margin-left: var(--grid-row-margin-left, -6px);
margin-right: var(--grid-row-margin-right, -6px);
}
.skeleton-card-wrapper {
// ✅ 直接使用父级传递的 CSS 变量(支持 2-5 列)
width: var(--column-width, 50%);
flex-shrink: 0;
box-sizing: border-box;
padding-left: var(--grid-cell-padding-left, 6px);
padding-right: var(--grid-cell-padding-right, 6px);
padding-bottom: 12px;
}
// ✅ 骨架屏卡片容器 - 保持与真实卡片相同的外观
.skeleton-card-box {
width: 100%;
background-color: #FFFFFF;
border-radius: 16px;
padding: 16px;
border: 1.5px solid #F1F5F9;
box-sizing: border-box;
}
</style>